]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | // $Id: pkgcache.h,v 1.7 1998/07/19 04:22:01 jgg Exp $ | |
4 | /* ###################################################################### | |
5 | ||
6 | Cache - Structure definitions for the cache file | |
7 | ||
8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of | |
9 | this format. Also be sure to keep that file up-to-date!! | |
10 | ||
11 | Clients should always use the CacheIterators classes for access to the | |
12 | cache. They provide a simple STL-like method for traversing the links | |
13 | of the datastructure. | |
14 | ||
15 | See pkgcachegen.h for information about generating cache structures. | |
16 | ||
17 | ##################################################################### */ | |
18 | /*}}}*/ | |
19 | // Header section: pkglib | |
20 | #ifndef PKGLIB_PKGCACHE_H | |
21 | #define PKGLIB_PKGCACHE_H | |
22 | ||
23 | #ifdef __GNUG__ | |
24 | #pragma interface "apt-pkg/pkgcache.h" | |
25 | #endif | |
26 | ||
27 | #include <string> | |
28 | #include <time.h> | |
29 | #include <apt-pkg/mmap.h> | |
30 | ||
31 | class pkgCache | |
32 | { | |
33 | public: | |
34 | // Cache element predeclarations | |
35 | struct Header; | |
36 | struct Package; | |
37 | struct PackageFile; | |
38 | struct Version; | |
39 | struct Provides; | |
40 | struct Dependency; | |
41 | struct StringItem; | |
42 | struct VerFile; | |
43 | ||
44 | // Iterators | |
45 | class PkgIterator; | |
46 | class VerIterator; | |
47 | class DepIterator; | |
48 | class PrvIterator; | |
49 | class PkgFileIterator; | |
50 | class VerFileIterator; | |
51 | friend PkgIterator; | |
52 | friend VerIterator; | |
53 | friend DepIterator; | |
54 | friend PrvIterator; | |
55 | friend PkgFileIterator; | |
56 | friend VerFileIterator; | |
57 | ||
58 | // These are all the constants used in the cache structures | |
59 | struct Dep | |
60 | { | |
61 | enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4, | |
62 | Conflicts=5,Replaces=6}; | |
63 | enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3, | |
64 | Greater=0x4,Equals=0x5,NotEquals=0x6}; | |
65 | }; | |
66 | ||
67 | struct State | |
68 | { | |
69 | enum VerPriority {Important=1,Required=2,Standard=3,Optional=5,Extra=5}; | |
70 | enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4}; | |
71 | enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3}; | |
72 | enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2, | |
73 | UnInstalled=3,HalfInstalled=4,ConfigFiles=5,Installed=6}; | |
74 | }; | |
75 | ||
76 | struct Flag | |
77 | { | |
78 | enum PkgFlags {Auto=(1<<0),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3), | |
79 | ImmediateConf=(1<<4)}; | |
80 | enum PkgFFlags {NotSource=(1<<0)}; | |
81 | }; | |
82 | ||
83 | protected: | |
84 | ||
85 | // Memory mapped cache file | |
86 | string CacheFile; | |
87 | MMap ⤅ | |
88 | ||
89 | bool Public; | |
90 | bool ReadOnly; | |
91 | ||
92 | static unsigned long sHash(string S); | |
93 | static unsigned long sHash(const char *S); | |
94 | ||
95 | public: | |
96 | ||
97 | // Pointers to the arrays of items | |
98 | Header *HeaderP; | |
99 | Package *PkgP; | |
100 | VerFile *VerFileP; | |
101 | PackageFile *PkgFileP; | |
102 | Version *VerP; | |
103 | Provides *ProvideP; | |
104 | Dependency *DepP; | |
105 | StringItem *StringItemP; | |
106 | char *StrP; | |
107 | ||
108 | virtual bool ReMap(); | |
109 | inline bool Sync() {return Map.Sync();}; | |
110 | ||
111 | // String hashing function (512 range) | |
112 | inline unsigned long Hash(string S) const {return sHash(S);}; | |
113 | inline unsigned long Hash(const char *S) const {return sHash(S);}; | |
114 | ||
115 | // Usefull transformation things | |
116 | const char *Priority(unsigned char Priority); | |
117 | ||
118 | // Accessors | |
119 | PkgIterator FindPkg(string Name); | |
120 | Header &Head() {return *HeaderP;}; | |
121 | inline PkgIterator PkgBegin(); | |
122 | inline PkgIterator PkgEnd(); | |
123 | inline PkgFileIterator FileBegin(); | |
124 | inline PkgFileIterator FileEnd(); | |
125 | ||
126 | pkgCache(MMap &Map); | |
127 | virtual ~pkgCache() {}; | |
128 | }; | |
129 | ||
130 | // Header structure | |
131 | struct pkgCache::Header | |
132 | { | |
133 | // Signature information | |
134 | unsigned long Signature; | |
135 | short MajorVersion; | |
136 | short MinorVersion; | |
137 | bool Dirty; | |
138 | ||
139 | // Size of structure values | |
140 | unsigned short HeaderSz; | |
141 | unsigned short PackageSz; | |
142 | unsigned short PackageFileSz; | |
143 | unsigned short VersionSz; | |
144 | unsigned short DependencySz; | |
145 | unsigned short ProvidesSz; | |
146 | unsigned short VerFileSz; | |
147 | ||
148 | // Structure counts | |
149 | unsigned long PackageCount; | |
150 | unsigned long VersionCount; | |
151 | unsigned long DependsCount; | |
152 | unsigned long PackageFileCount; | |
153 | ||
154 | // Offsets | |
155 | unsigned long FileList; // struct PackageFile | |
156 | unsigned long StringList; // struct StringItem | |
157 | unsigned long MaxVerFileSize; | |
158 | ||
159 | /* Allocation pools, there should be one of these for each structure | |
160 | excluding the header */ | |
161 | DynamicMMap::Pool Pools[7]; | |
162 | ||
163 | // Rapid package name lookup | |
164 | unsigned long HashTable[512]; | |
165 | ||
166 | bool CheckSizes(Header &Against) const; | |
167 | Header(); | |
168 | }; | |
169 | ||
170 | struct pkgCache::Package | |
171 | { | |
172 | // Pointers | |
173 | unsigned long Name; // Stringtable | |
174 | unsigned long VersionList; // Version | |
175 | unsigned long TargetVer; // Version | |
176 | unsigned long CurrentVer; // Version | |
177 | unsigned long TargetDist; // StringTable (StringItem) | |
178 | unsigned long Section; // StringTable (StringItem) | |
179 | ||
180 | // Linked list | |
181 | unsigned long NextPackage; // Package | |
182 | unsigned long RevDepends; // Dependency | |
183 | unsigned long ProvidesList; // Provides | |
184 | ||
185 | // Install/Remove/Purge etc | |
186 | unsigned char SelectedState; // What | |
187 | unsigned char InstState; // Flags | |
188 | unsigned char CurrentState; // State | |
189 | ||
190 | unsigned short ID; | |
191 | unsigned long Flags; | |
192 | }; | |
193 | ||
194 | struct pkgCache::PackageFile | |
195 | { | |
196 | // Names | |
197 | unsigned long FileName; // Stringtable | |
198 | unsigned long Version; // Stringtable | |
199 | unsigned long Distribution; // Stringtable | |
200 | unsigned long Size; | |
201 | ||
202 | // Linked list | |
203 | unsigned long NextFile; // PackageFile | |
204 | unsigned short ID; | |
205 | unsigned long Flags; | |
206 | time_t mtime; // Modification time for the file | |
207 | }; | |
208 | ||
209 | struct pkgCache::VerFile | |
210 | { | |
211 | unsigned long File; // PackageFile | |
212 | unsigned long NextFile; // PkgVerFile | |
213 | unsigned long Offset; | |
214 | unsigned short Size; | |
215 | }; | |
216 | ||
217 | struct pkgCache::Version | |
218 | { | |
219 | unsigned long VerStr; // Stringtable | |
220 | unsigned long Section; // StringTable (StringItem) | |
221 | ||
222 | // Lists | |
223 | unsigned long FileList; // VerFile | |
224 | unsigned long NextVer; // Version | |
225 | unsigned long DependsList; // Dependency | |
226 | unsigned long ParentPkg; // Package | |
227 | unsigned long ProvidesList; // Provides | |
228 | ||
229 | unsigned long Size; | |
230 | unsigned long InstalledSize; | |
231 | unsigned short ID; | |
232 | unsigned char Priority; | |
233 | }; | |
234 | ||
235 | struct pkgCache::Dependency | |
236 | { | |
237 | unsigned long Version; // Stringtable | |
238 | unsigned long Package; // Package | |
239 | unsigned long NextDepends; // Dependency | |
240 | unsigned long NextRevDepends; // Dependency | |
241 | unsigned long ParentVer; // Version | |
242 | ||
243 | // Specific types of depends | |
244 | unsigned char Type; | |
245 | unsigned char CompareOp; | |
246 | unsigned short ID; | |
247 | }; | |
248 | ||
249 | struct pkgCache::Provides | |
250 | { | |
251 | unsigned long ParentPkg; // Pacakge | |
252 | unsigned long Version; // Version | |
253 | unsigned long ProvideVersion; // Stringtable | |
254 | unsigned long NextProvides; // Provides | |
255 | unsigned long NextPkgProv; // Provides | |
256 | }; | |
257 | ||
258 | struct pkgCache::StringItem | |
259 | { | |
260 | unsigned long String; // Stringtable | |
261 | unsigned long NextItem; // StringItem | |
262 | }; | |
263 | ||
264 | #include <apt-pkg/cacheiterators.h> | |
265 | ||
266 | inline pkgCache::PkgIterator pkgCache::PkgBegin() | |
267 | {return PkgIterator(*this);}; | |
268 | inline pkgCache::PkgIterator pkgCache::PkgEnd() | |
269 | {return PkgIterator(*this,PkgP);}; | |
270 | inline pkgCache::PkgFileIterator pkgCache::FileBegin() | |
271 | {return PkgFileIterator(*this);}; | |
272 | inline pkgCache::PkgFileIterator pkgCache::FileEnd() | |
273 | {return PkgFileIterator(*this,PkgFileP);}; | |
274 | ||
275 | #endif |