PL3118 and PL3131 fix: use the correct ext2 attribute bits if possible;
[util-vserver.git] / src / vutil.h
1 // $Id: vutil.h,v 1.1 2003/09/29 22:01:57 ensc Exp $
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on vutil.h by Jacques Gelinas
5 //  
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10 //  
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //  
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 #pragma interface
21 #ifndef VUTIL_H
22 #define VUTIL_H
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <sys/wait.h>
27 #include <string>
28 #include <set>
29 #include <algorithm>
30 #include <iostream>
31 #include <list>
32
33 using namespace std;
34
35 extern int debug;
36 extern bool testmode;
37
38 // Patch to help compile this utility on unpatched kernel source
39 #ifndef EXT2_IMMUTABLE_FL
40 #define EXT2_IMMUTABLE_FL 0x00000010
41 #endif
42
43 #ifndef EXT2_IUNLINK_FL
44 /* Set both bits for backward compatibility */
45 #define EXT2_IUNLINK_FL 0x08008000
46 #endif
47
48 #ifndef EXT2_BARRIER_FL
49 #define EXT2_BARRIER_FL 0x04000000
50 #endif
51
52
53 FILE *vutil_execdistcmd (const char *, const string &, const char *);
54 extern const char K_DUMPFILES[];
55 extern const char K_UNIFILES[];
56 extern const char K_PKGVERSION[];
57
58 class PACKAGE{
59 public:
60         string name;
61         string version; // version + release
62         PACKAGE(string &_name, string &_version)
63                 : name (_name), version(_version)
64         {
65         }
66         PACKAGE(const char *_name, const char *_version)
67                 : name (_name), version(_version)
68         {
69         }
70         PACKAGE(const string &line)
71         {
72                 *this = line;
73         }
74         PACKAGE & operator = (const string &_line)
75         {
76                 string line (_line);
77                 string::iterator pos = find (line.begin(),line.end(),'=');
78                 if (pos != line.end()){
79                         name = string(line.begin(),pos);
80                         version = string(pos + 1,line.end());
81                 }
82                 return *this;
83         }
84         PACKAGE (const PACKAGE &pkg)
85         {
86                 name = pkg.name;
87                 version = pkg.version;
88         }
89         bool operator == (const PACKAGE &v) const
90         {
91                 return name == v.name && version == v.version;
92         }
93         bool operator < (const PACKAGE &v) const
94         {
95                 bool ret = false;
96                 if (name < v.name){
97                         ret = true;
98                 }else if (name == v.name && version < v.version){
99                         ret = true;
100                 }
101                 return ret;
102         }
103         // Load the file member of the package, but exclude configuration file
104         void loadfiles(const string &ref, set<string> &files)
105         {
106                 if (debug > 2) cout << "Loading files for package " << name << endl;
107                 string namever = name + '-' + version;
108                 FILE *fin = vutil_execdistcmd (K_UNIFILES,ref,namever.c_str());
109                 if (fin != NULL){
110                         char tmp[1000];
111                         while (fgets(tmp,sizeof(tmp)-1,fin)!=NULL){
112                                 int last = strlen(tmp)-1;
113                                 if (last >= 0 && tmp[last] == '\n') tmp[last] = '\0';
114                                 files.insert (tmp);
115                         }
116                 }
117                 if (debug > 2) cout << "Done\n";
118         }
119         #if 0
120         bool locate(const string &path)
121         {
122                 return find (files.begin(),files.end(),path) != files.end();
123         }
124         #endif
125 };
126
127 // Check if two package have the same name (but potentially different version)
128 class same_name{
129         const PACKAGE &pkg;
130 public:
131         same_name(const PACKAGE &_pkg) : pkg(_pkg) {}
132         bool operator()(const PACKAGE &p)
133         {
134                 return pkg.name == p.name;
135         }
136 };
137
138
139 #include "vutil.p"
140
141 #endif
142