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