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