]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b2e465d6 | 3 | // $Id: pkgcache.h,v 1.23 2001/02/20 07:03:17 jgg Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | Cache - Structure definitions for the cache file | |
7 | ||
094a497d | 8 | Please see doc/apt-pkg/cache.sgml for a more detailed description of |
578bfd0a AL |
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 | /*}}}*/ | |
578bfd0a AL |
19 | #ifndef PKGLIB_PKGCACHE_H |
20 | #define PKGLIB_PKGCACHE_H | |
21 | ||
6c139d6e | 22 | #ifdef __GNUG__ |
094a497d | 23 | #pragma interface "apt-pkg/pkgcache.h" |
6c139d6e AL |
24 | #endif |
25 | ||
578bfd0a AL |
26 | #include <string> |
27 | #include <time.h> | |
094a497d | 28 | #include <apt-pkg/mmap.h> |
b2e465d6 AL |
29 | |
30 | class pkgVersioningSystem; | |
578bfd0a AL |
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; | |
dcb79bae | 42 | struct VerFile; |
578bfd0a AL |
43 | |
44 | // Iterators | |
45 | class PkgIterator; | |
46 | class VerIterator; | |
47 | class DepIterator; | |
48 | class PrvIterator; | |
49 | class PkgFileIterator; | |
dcb79bae | 50 | class VerFileIterator; |
b2e465d6 AL |
51 | friend class PkgIterator; |
52 | friend class VerIterator; | |
53 | friend class DepIterator; | |
54 | friend class PrvIterator; | |
55 | friend class PkgFileIterator; | |
56 | friend class VerFileIterator; | |
57 | ||
58 | class Namespace; | |
dcb79bae | 59 | |
f55a958f | 60 | // These are all the constants used in the cache structures |
6c139d6e AL |
61 | struct Dep |
62 | { | |
63 | enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4, | |
b2e465d6 | 64 | Conflicts=5,Replaces=6,Obsoletes=7}; |
6c139d6e AL |
65 | enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3, |
66 | Greater=0x4,Equals=0x5,NotEquals=0x6}; | |
67 | }; | |
68 | ||
69 | struct State | |
70 | { | |
fbfb2a7c | 71 | enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5}; |
6c139d6e AL |
72 | enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4}; |
73 | enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3}; | |
74 | enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2, | |
a005475e | 75 | HalfInstalled=4,ConfigFiles=5,Installed=6}; |
6c139d6e AL |
76 | }; |
77 | ||
78 | struct Flag | |
79 | { | |
138d4b3d | 80 | enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)}; |
3c124dde | 81 | enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)}; |
6c139d6e | 82 | }; |
578bfd0a AL |
83 | |
84 | protected: | |
85 | ||
86 | // Memory mapped cache file | |
87 | string CacheFile; | |
88 | MMap ⤅ | |
89 | ||
f9eec0e7 AL |
90 | unsigned long sHash(string S) const; |
91 | unsigned long sHash(const char *S) const; | |
578bfd0a AL |
92 | |
93 | public: | |
94 | ||
95 | // Pointers to the arrays of items | |
96 | Header *HeaderP; | |
97 | Package *PkgP; | |
dcb79bae | 98 | VerFile *VerFileP; |
578bfd0a AL |
99 | PackageFile *PkgFileP; |
100 | Version *VerP; | |
101 | Provides *ProvideP; | |
102 | Dependency *DepP; | |
103 | StringItem *StringItemP; | |
104 | char *StrP; | |
dcb79bae | 105 | |
578bfd0a AL |
106 | virtual bool ReMap(); |
107 | inline bool Sync() {return Map.Sync();}; | |
981d20eb | 108 | inline MMap &GetMap() {return Map;}; |
b2e465d6 AL |
109 | inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}; |
110 | ||
578bfd0a AL |
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 | ||
0149949b AL |
115 | // Usefull transformation things |
116 | const char *Priority(unsigned char Priority); | |
117 | ||
578bfd0a AL |
118 | // Accessors |
119 | PkgIterator FindPkg(string Name); | |
120 | Header &Head() {return *HeaderP;}; | |
121 | inline PkgIterator PkgBegin(); | |
122 | inline PkgIterator PkgEnd(); | |
ad00ae81 AL |
123 | inline PkgFileIterator FileBegin(); |
124 | inline PkgFileIterator FileEnd(); | |
b2e465d6 AL |
125 | |
126 | // Make me a function | |
127 | pkgVersioningSystem *VS; | |
128 | ||
129 | // Converters | |
130 | static const char *CompTypeDeb(unsigned char Comp); | |
131 | static const char *CompType(unsigned char Comp); | |
132 | static const char *DepType(unsigned char Dep); | |
ad00ae81 | 133 | |
b2e465d6 | 134 | pkgCache(MMap *Map,bool DoMap = true); |
578bfd0a AL |
135 | virtual ~pkgCache() {}; |
136 | }; | |
137 | ||
138 | // Header structure | |
139 | struct pkgCache::Header | |
140 | { | |
141 | // Signature information | |
142 | unsigned long Signature; | |
143 | short MajorVersion; | |
144 | short MinorVersion; | |
145 | bool Dirty; | |
146 | ||
147 | // Size of structure values | |
148 | unsigned short HeaderSz; | |
149 | unsigned short PackageSz; | |
150 | unsigned short PackageFileSz; | |
151 | unsigned short VersionSz; | |
152 | unsigned short DependencySz; | |
153 | unsigned short ProvidesSz; | |
dcb79bae AL |
154 | unsigned short VerFileSz; |
155 | ||
578bfd0a AL |
156 | // Structure counts |
157 | unsigned long PackageCount; | |
158 | unsigned long VersionCount; | |
159 | unsigned long DependsCount; | |
160 | unsigned long PackageFileCount; | |
a7e66b17 AL |
161 | unsigned long VerFileCount; |
162 | unsigned long ProvidesCount; | |
578bfd0a AL |
163 | |
164 | // Offsets | |
349cd3b8 AL |
165 | map_ptrloc FileList; // struct PackageFile |
166 | map_ptrloc StringList; // struct StringItem | |
b2e465d6 AL |
167 | map_ptrloc VerSysName; // StringTable |
168 | map_ptrloc Architecture; // StringTable | |
ad00ae81 | 169 | unsigned long MaxVerFileSize; |
578bfd0a AL |
170 | |
171 | /* Allocation pools, there should be one of these for each structure | |
172 | excluding the header */ | |
dcb79bae | 173 | DynamicMMap::Pool Pools[7]; |
578bfd0a AL |
174 | |
175 | // Rapid package name lookup | |
349cd3b8 | 176 | map_ptrloc HashTable[2*1048]; |
578bfd0a AL |
177 | |
178 | bool CheckSizes(Header &Against) const; | |
179 | Header(); | |
180 | }; | |
181 | ||
182 | struct pkgCache::Package | |
183 | { | |
184 | // Pointers | |
349cd3b8 AL |
185 | map_ptrloc Name; // Stringtable |
186 | map_ptrloc VersionList; // Version | |
349cd3b8 | 187 | map_ptrloc CurrentVer; // Version |
349cd3b8 | 188 | map_ptrloc Section; // StringTable (StringItem) |
578bfd0a AL |
189 | |
190 | // Linked list | |
349cd3b8 AL |
191 | map_ptrloc NextPackage; // Package |
192 | map_ptrloc RevDepends; // Dependency | |
193 | map_ptrloc ProvidesList; // Provides | |
578bfd0a AL |
194 | |
195 | // Install/Remove/Purge etc | |
196 | unsigned char SelectedState; // What | |
197 | unsigned char InstState; // Flags | |
198 | unsigned char CurrentState; // State | |
199 | ||
200 | unsigned short ID; | |
f55a958f | 201 | unsigned long Flags; |
578bfd0a AL |
202 | }; |
203 | ||
204 | struct pkgCache::PackageFile | |
205 | { | |
206 | // Names | |
349cd3b8 AL |
207 | map_ptrloc FileName; // Stringtable |
208 | map_ptrloc Archive; // Stringtable | |
209 | map_ptrloc Component; // Stringtable | |
210 | map_ptrloc Version; // Stringtable | |
211 | map_ptrloc Origin; // Stringtable | |
212 | map_ptrloc Label; // Stringtable | |
213 | map_ptrloc Architecture; // Stringtable | |
b2e465d6 AL |
214 | map_ptrloc Site; // Stringtable |
215 | map_ptrloc IndexType; // Stringtable | |
b0b4efb9 | 216 | unsigned long Size; |
3c124dde | 217 | unsigned long Flags; |
578bfd0a AL |
218 | |
219 | // Linked list | |
349cd3b8 | 220 | map_ptrloc NextFile; // PackageFile |
578bfd0a | 221 | unsigned short ID; |
578bfd0a AL |
222 | time_t mtime; // Modification time for the file |
223 | }; | |
224 | ||
dcb79bae AL |
225 | struct pkgCache::VerFile |
226 | { | |
349cd3b8 AL |
227 | map_ptrloc File; // PackageFile |
228 | map_ptrloc NextFile; // PkgVerFile | |
229 | map_ptrloc Offset; // File offset | |
dcb79bae AL |
230 | unsigned short Size; |
231 | }; | |
232 | ||
578bfd0a AL |
233 | struct pkgCache::Version |
234 | { | |
349cd3b8 AL |
235 | map_ptrloc VerStr; // Stringtable |
236 | map_ptrloc Section; // StringTable (StringItem) | |
237 | map_ptrloc Arch; // StringTable | |
17caf1b1 | 238 | |
578bfd0a | 239 | // Lists |
349cd3b8 AL |
240 | map_ptrloc FileList; // VerFile |
241 | map_ptrloc NextVer; // Version | |
242 | map_ptrloc DependsList; // Dependency | |
243 | map_ptrloc ParentPkg; // Package | |
244 | map_ptrloc ProvidesList; // Provides | |
578bfd0a | 245 | |
349cd3b8 AL |
246 | map_ptrloc Size; // These are the .deb size |
247 | map_ptrloc InstalledSize; | |
204fbdcc | 248 | unsigned short Hash; |
578bfd0a AL |
249 | unsigned short ID; |
250 | unsigned char Priority; | |
251 | }; | |
252 | ||
253 | struct pkgCache::Dependency | |
254 | { | |
349cd3b8 AL |
255 | map_ptrloc Version; // Stringtable |
256 | map_ptrloc Package; // Package | |
257 | map_ptrloc NextDepends; // Dependency | |
258 | map_ptrloc NextRevDepends; // Dependency | |
259 | map_ptrloc ParentVer; // Version | |
578bfd0a AL |
260 | |
261 | // Specific types of depends | |
262 | unsigned char Type; | |
263 | unsigned char CompareOp; | |
b2e465d6 | 264 | unsigned short ID; |
578bfd0a AL |
265 | }; |
266 | ||
267 | struct pkgCache::Provides | |
268 | { | |
349cd3b8 AL |
269 | map_ptrloc ParentPkg; // Pacakge |
270 | map_ptrloc Version; // Version | |
271 | map_ptrloc ProvideVersion; // Stringtable | |
272 | map_ptrloc NextProvides; // Provides | |
273 | map_ptrloc NextPkgProv; // Provides | |
578bfd0a AL |
274 | }; |
275 | ||
276 | struct pkgCache::StringItem | |
277 | { | |
349cd3b8 AL |
278 | map_ptrloc String; // Stringtable |
279 | map_ptrloc NextItem; // StringItem | |
578bfd0a AL |
280 | }; |
281 | ||
094a497d | 282 | #include <apt-pkg/cacheiterators.h> |
578bfd0a AL |
283 | |
284 | inline pkgCache::PkgIterator pkgCache::PkgBegin() | |
285 | {return PkgIterator(*this);}; | |
286 | inline pkgCache::PkgIterator pkgCache::PkgEnd() | |
287 | {return PkgIterator(*this,PkgP);}; | |
ad00ae81 | 288 | inline pkgCache::PkgFileIterator pkgCache::FileBegin() |
b2e465d6 | 289 | {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}; |
ad00ae81 AL |
290 | inline pkgCache::PkgFileIterator pkgCache::FileEnd() |
291 | {return PkgFileIterator(*this,PkgFileP);}; | |
578bfd0a | 292 | |
b2e465d6 AL |
293 | // Oh I wish for Real Name Space Support |
294 | class pkgCache::Namespace | |
295 | { | |
296 | public: | |
297 | ||
298 | typedef pkgCache::PkgIterator PkgIterator; | |
299 | typedef pkgCache::VerIterator VerIterator; | |
300 | typedef pkgCache::DepIterator DepIterator; | |
301 | typedef pkgCache::PrvIterator PrvIterator; | |
302 | typedef pkgCache::PkgFileIterator PkgFileIterator; | |
303 | typedef pkgCache::VerFileIterator VerFileIterator; | |
304 | typedef pkgCache::Version Version; | |
305 | typedef pkgCache::Package Package; | |
306 | typedef pkgCache::Header Header; | |
307 | typedef pkgCache::Dep Dep; | |
308 | typedef pkgCache::Flag Flag; | |
309 | }; | |
310 | ||
578bfd0a | 311 | #endif |