1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $
4 /* ######################################################################
6 Cache - Structure definitions for the cache file
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!!
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
15 See pkgcachegen.h for information about generating cache structures.
17 ##################################################################### */
19 #ifndef PKGLIB_PKGCACHE_H
20 #define PKGLIB_PKGCACHE_H
25 #include <apt-pkg/mmap.h>
29 class pkgVersioningSystem
;
33 // Cache element predeclarations
51 class PkgFileIterator
;
52 class VerFileIterator
;
53 class DescFileIterator
;
54 friend class PkgIterator
;
55 friend class VerIterator
;
56 friend class DescInterator
;
57 friend class DepIterator
;
58 friend class PrvIterator
;
59 friend class PkgFileIterator
;
60 friend class VerFileIterator
;
61 friend class DescFileIterator
;
65 // These are all the constants used in the cache structures
67 // WARNING - if you change these lists you must also edit
68 // the stringification in pkgcache.cc and also consider whether
69 // the cache file will become incompatible.
72 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
73 Conflicts
=5,Replaces
=6,Obsoletes
=7,DpkgBreaks
=8};
74 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
75 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
80 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
81 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
82 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
83 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
84 HalfInstalled
=4,ConfigFiles
=5,Installed
=6,
85 TriggersAwaited
=7,TriggersPending
=8};
90 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
91 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
96 // Memory mapped cache file
100 unsigned long sHash(const string
&S
) const;
101 unsigned long sHash(const char *S
) const;
105 // Pointers to the arrays of items
110 PackageFile
*PkgFileP
;
115 StringItem
*StringItemP
;
118 virtual bool ReMap();
119 inline bool Sync() {return Map
.Sync();};
120 inline MMap
&GetMap() {return Map
;};
121 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
123 // String hashing function (512 range)
124 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
125 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
127 // Usefull transformation things
128 const char *Priority(unsigned char Priority
);
131 PkgIterator
FindPkg(const string
&Name
);
132 Header
&Head() {return *HeaderP
;};
133 inline PkgIterator
PkgBegin();
134 inline PkgIterator
PkgEnd();
135 inline PkgFileIterator
FileBegin();
136 inline PkgFileIterator
FileEnd();
138 // Make me a function
139 pkgVersioningSystem
*VS
;
142 static const char *CompTypeDeb(unsigned char Comp
);
143 static const char *CompType(unsigned char Comp
);
144 static const char *DepType(unsigned char Dep
);
146 pkgCache(MMap
*Map
,bool DoMap
= true);
147 virtual ~pkgCache() {};
151 struct pkgCache::Header
153 // Signature information
154 unsigned long Signature
;
159 // Size of structure values
160 unsigned short HeaderSz
;
161 unsigned short PackageSz
;
162 unsigned short PackageFileSz
;
163 unsigned short VersionSz
;
164 unsigned short DescriptionSz
;
165 unsigned short DependencySz
;
166 unsigned short ProvidesSz
;
167 unsigned short VerFileSz
;
168 unsigned short DescFileSz
;
171 unsigned long PackageCount
;
172 unsigned long VersionCount
;
173 unsigned long DescriptionCount
;
174 unsigned long DependsCount
;
175 unsigned long PackageFileCount
;
176 unsigned long VerFileCount
;
177 unsigned long DescFileCount
;
178 unsigned long ProvidesCount
;
181 map_ptrloc FileList
; // struct PackageFile
182 map_ptrloc StringList
; // struct StringItem
183 map_ptrloc VerSysName
; // StringTable
184 map_ptrloc Architecture
; // StringTable
185 unsigned long MaxVerFileSize
;
186 unsigned long MaxDescFileSize
;
188 /* Allocation pools, there should be one of these for each structure
189 excluding the header */
190 DynamicMMap::Pool Pools
[8];
192 // Rapid package name lookup
193 map_ptrloc HashTable
[2*1048];
195 bool CheckSizes(Header
&Against
) const;
199 struct pkgCache::Package
202 map_ptrloc Name
; // Stringtable
203 map_ptrloc VersionList
; // Version
204 map_ptrloc CurrentVer
; // Version
205 map_ptrloc Section
; // StringTable (StringItem)
208 map_ptrloc NextPackage
; // Package
209 map_ptrloc RevDepends
; // Dependency
210 map_ptrloc ProvidesList
; // Provides
212 // Install/Remove/Purge etc
213 unsigned char SelectedState
; // What
214 unsigned char InstState
; // Flags
215 unsigned char CurrentState
; // State
221 struct pkgCache::PackageFile
224 map_ptrloc FileName
; // Stringtable
225 map_ptrloc Archive
; // Stringtable
226 map_ptrloc Component
; // Stringtable
227 map_ptrloc Version
; // Stringtable
228 map_ptrloc Origin
; // Stringtable
229 map_ptrloc Label
; // Stringtable
230 map_ptrloc Architecture
; // Stringtable
231 map_ptrloc Site
; // Stringtable
232 map_ptrloc IndexType
; // Stringtable
237 map_ptrloc NextFile
; // PackageFile
239 time_t mtime
; // Modification time for the file
242 struct pkgCache::VerFile
244 map_ptrloc File
; // PackageFile
245 map_ptrloc NextFile
; // PkgVerFile
246 map_ptrloc Offset
; // File offset
250 struct pkgCache::DescFile
252 map_ptrloc File
; // PackageFile
253 map_ptrloc NextFile
; // PkgVerFile
254 map_ptrloc Offset
; // File offset
258 struct pkgCache::Version
260 map_ptrloc VerStr
; // Stringtable
261 map_ptrloc Section
; // StringTable (StringItem)
262 map_ptrloc Arch
; // StringTable
265 map_ptrloc FileList
; // VerFile
266 map_ptrloc NextVer
; // Version
267 map_ptrloc DescriptionList
; // Description
268 map_ptrloc DependsList
; // Dependency
269 map_ptrloc ParentPkg
; // Package
270 map_ptrloc ProvidesList
; // Provides
272 map_ptrloc Size
; // These are the .deb size
273 map_ptrloc InstalledSize
;
276 unsigned char Priority
;
279 struct pkgCache::Description
281 // Language Code store the description translation language code. If
282 // the value has a 0 lenght then this is readed using the Package
283 // file else the Translation-CODE are used.
284 map_ptrloc language_code
; // StringTable
285 map_ptrloc md5sum
; // StringTable
288 map_ptrloc FileList
; // DescFile
289 map_ptrloc NextDesc
; // Description
290 map_ptrloc ParentPkg
; // Package
295 struct pkgCache::Dependency
297 map_ptrloc Version
; // Stringtable
298 map_ptrloc Package
; // Package
299 map_ptrloc NextDepends
; // Dependency
300 map_ptrloc NextRevDepends
; // Dependency
301 map_ptrloc ParentVer
; // Version
303 // Specific types of depends
306 unsigned char CompareOp
;
309 struct pkgCache::Provides
311 map_ptrloc ParentPkg
; // Pacakge
312 map_ptrloc Version
; // Version
313 map_ptrloc ProvideVersion
; // Stringtable
314 map_ptrloc NextProvides
; // Provides
315 map_ptrloc NextPkgProv
; // Provides
318 struct pkgCache::StringItem
320 map_ptrloc String
; // Stringtable
321 map_ptrloc NextItem
; // StringItem
324 #include <apt-pkg/cacheiterators.h>
326 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
327 {return PkgIterator(*this);};
328 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
329 {return PkgIterator(*this,PkgP
);};
330 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
331 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
332 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
333 {return PkgFileIterator(*this,PkgFileP
);};
335 // Oh I wish for Real Name Space Support
336 class pkgCache::Namespace
340 typedef pkgCache::PkgIterator PkgIterator
;
341 typedef pkgCache::VerIterator VerIterator
;
342 typedef pkgCache::DescIterator DescIterator
;
343 typedef pkgCache::DepIterator DepIterator
;
344 typedef pkgCache::PrvIterator PrvIterator
;
345 typedef pkgCache::PkgFileIterator PkgFileIterator
;
346 typedef pkgCache::VerFileIterator VerFileIterator
;
347 typedef pkgCache::Version Version
;
348 typedef pkgCache::Description Description
;
349 typedef pkgCache::Package Package
;
350 typedef pkgCache::Header Header
;
351 typedef pkgCache::Dep Dep
;
352 typedef pkgCache::Flag Flag
;