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
23 #pragma interface "apt-pkg/pkgcache.h"
28 #include <apt-pkg/mmap.h>
32 class pkgVersioningSystem
;
36 // Cache element predeclarations
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
;
68 // These are all the constants used in the cache structures
70 // WARNING - if you change these lists you must also edit
71 // the stringification in pkgcache.cc and also consider whether
72 // the cache file will become incompatible.
75 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
76 Conflicts
=5,Replaces
=6,Obsoletes
=7,DpkgBreaks
=8};
77 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
78 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
83 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
84 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
85 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
86 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
87 HalfInstalled
=4,ConfigFiles
=5,Installed
=6};
92 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
93 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
98 // Memory mapped cache file
102 unsigned long sHash(const string
&S
) const;
103 unsigned long sHash(const char *S
) const;
107 // Pointers to the arrays of items
112 PackageFile
*PkgFileP
;
117 StringItem
*StringItemP
;
120 virtual bool ReMap();
121 inline bool Sync() {return Map
.Sync();};
122 inline MMap
&GetMap() {return Map
;};
123 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
125 // String hashing function (512 range)
126 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
127 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
129 // Usefull transformation things
130 const char *Priority(unsigned char Priority
);
133 PkgIterator
FindPkg(const string
&Name
);
134 Header
&Head() {return *HeaderP
;};
135 inline PkgIterator
PkgBegin();
136 inline PkgIterator
PkgEnd();
137 inline PkgFileIterator
FileBegin();
138 inline PkgFileIterator
FileEnd();
140 // Make me a function
141 pkgVersioningSystem
*VS
;
144 static const char *CompTypeDeb(unsigned char Comp
);
145 static const char *CompType(unsigned char Comp
);
146 static const char *DepType(unsigned char Dep
);
148 pkgCache(MMap
*Map
,bool DoMap
= true);
149 virtual ~pkgCache() {};
153 struct pkgCache::Header
155 // Signature information
156 unsigned long Signature
;
161 // Size of structure values
162 unsigned short HeaderSz
;
163 unsigned short PackageSz
;
164 unsigned short PackageFileSz
;
165 unsigned short VersionSz
;
166 unsigned short DescriptionSz
;
167 unsigned short DependencySz
;
168 unsigned short ProvidesSz
;
169 unsigned short VerFileSz
;
170 unsigned short DescFileSz
;
173 unsigned long PackageCount
;
174 unsigned long VersionCount
;
175 unsigned long DescriptionCount
;
176 unsigned long DependsCount
;
177 unsigned long PackageFileCount
;
178 unsigned long VerFileCount
;
179 unsigned long DescFileCount
;
180 unsigned long ProvidesCount
;
183 map_ptrloc FileList
; // struct PackageFile
184 map_ptrloc StringList
; // struct StringItem
185 map_ptrloc VerSysName
; // StringTable
186 map_ptrloc Architecture
; // StringTable
187 unsigned long MaxVerFileSize
;
188 unsigned long MaxDescFileSize
;
190 /* Allocation pools, there should be one of these for each structure
191 excluding the header */
192 DynamicMMap::Pool Pools
[8];
194 // Rapid package name lookup
195 map_ptrloc HashTable
[2*1048];
197 bool CheckSizes(Header
&Against
) const;
201 struct pkgCache::Package
204 map_ptrloc Name
; // Stringtable
205 map_ptrloc VersionList
; // Version
206 map_ptrloc CurrentVer
; // Version
207 map_ptrloc Section
; // StringTable (StringItem)
210 map_ptrloc NextPackage
; // Package
211 map_ptrloc RevDepends
; // Dependency
212 map_ptrloc ProvidesList
; // Provides
214 // Install/Remove/Purge etc
215 unsigned char SelectedState
; // What
216 unsigned char InstState
; // Flags
217 unsigned char CurrentState
; // State
223 struct pkgCache::PackageFile
226 map_ptrloc FileName
; // Stringtable
227 map_ptrloc Archive
; // Stringtable
228 map_ptrloc Component
; // Stringtable
229 map_ptrloc Version
; // Stringtable
230 map_ptrloc Origin
; // Stringtable
231 map_ptrloc Label
; // Stringtable
232 map_ptrloc Architecture
; // Stringtable
233 map_ptrloc Site
; // Stringtable
234 map_ptrloc IndexType
; // Stringtable
239 map_ptrloc NextFile
; // PackageFile
241 time_t mtime
; // Modification time for the file
244 struct pkgCache::VerFile
246 map_ptrloc File
; // PackageFile
247 map_ptrloc NextFile
; // PkgVerFile
248 map_ptrloc Offset
; // File offset
252 struct pkgCache::DescFile
254 map_ptrloc File
; // PackageFile
255 map_ptrloc NextFile
; // PkgVerFile
256 map_ptrloc Offset
; // File offset
260 struct pkgCache::Version
262 map_ptrloc VerStr
; // Stringtable
263 map_ptrloc Section
; // StringTable (StringItem)
264 map_ptrloc Arch
; // StringTable
267 map_ptrloc FileList
; // VerFile
268 map_ptrloc NextVer
; // Version
269 map_ptrloc DescriptionList
; // Description
270 map_ptrloc DependsList
; // Dependency
271 map_ptrloc ParentPkg
; // Package
272 map_ptrloc ProvidesList
; // Provides
274 map_ptrloc Size
; // These are the .deb size
275 map_ptrloc InstalledSize
;
278 unsigned char Priority
;
281 struct pkgCache::Description
283 // Language Code store the description translation language code. If
284 // the value has a 0 lenght then this is readed using the Package
285 // file else the Translation-CODE are used.
286 map_ptrloc language_code
; // StringTable
287 map_ptrloc md5sum
; // StringTable
290 map_ptrloc FileList
; // DescFile
291 map_ptrloc NextDesc
; // Description
292 map_ptrloc ParentPkg
; // Package
297 struct pkgCache::Dependency
299 map_ptrloc Version
; // Stringtable
300 map_ptrloc Package
; // Package
301 map_ptrloc NextDepends
; // Dependency
302 map_ptrloc NextRevDepends
; // Dependency
303 map_ptrloc ParentVer
; // Version
305 // Specific types of depends
308 unsigned char CompareOp
;
311 struct pkgCache::Provides
313 map_ptrloc ParentPkg
; // Pacakge
314 map_ptrloc Version
; // Version
315 map_ptrloc ProvideVersion
; // Stringtable
316 map_ptrloc NextProvides
; // Provides
317 map_ptrloc NextPkgProv
; // Provides
320 struct pkgCache::StringItem
322 map_ptrloc String
; // Stringtable
323 map_ptrloc NextItem
; // StringItem
326 #include <apt-pkg/cacheiterators.h>
328 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
329 {return PkgIterator(*this);};
330 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
331 {return PkgIterator(*this,PkgP
);};
332 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
333 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
334 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
335 {return PkgFileIterator(*this,PkgFileP
);};
337 // Oh I wish for Real Name Space Support
338 class pkgCache::Namespace
342 typedef pkgCache::PkgIterator PkgIterator
;
343 typedef pkgCache::VerIterator VerIterator
;
344 typedef pkgCache::DescIterator DescIterator
;
345 typedef pkgCache::DepIterator DepIterator
;
346 typedef pkgCache::PrvIterator PrvIterator
;
347 typedef pkgCache::PkgFileIterator PkgFileIterator
;
348 typedef pkgCache::VerFileIterator VerFileIterator
;
349 typedef pkgCache::Version Version
;
350 typedef pkgCache::Description Description
;
351 typedef pkgCache::Package Package
;
352 typedef pkgCache::Header Header
;
353 typedef pkgCache::Dep Dep
;
354 typedef pkgCache::Flag Flag
;