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};
89 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
90 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
95 // Memory mapped cache file
99 unsigned long sHash(const string
&S
) const;
100 unsigned long sHash(const char *S
) const;
104 // Pointers to the arrays of items
109 PackageFile
*PkgFileP
;
114 StringItem
*StringItemP
;
117 virtual bool ReMap();
118 inline bool Sync() {return Map
.Sync();};
119 inline MMap
&GetMap() {return Map
;};
120 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
122 // String hashing function (512 range)
123 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
124 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
126 // Usefull transformation things
127 const char *Priority(unsigned char Priority
);
130 PkgIterator
FindPkg(const string
&Name
);
131 Header
&Head() {return *HeaderP
;};
132 inline PkgIterator
PkgBegin();
133 inline PkgIterator
PkgEnd();
134 inline PkgFileIterator
FileBegin();
135 inline PkgFileIterator
FileEnd();
137 // Make me a function
138 pkgVersioningSystem
*VS
;
141 static const char *CompTypeDeb(unsigned char Comp
);
142 static const char *CompType(unsigned char Comp
);
143 static const char *DepType(unsigned char Dep
);
145 pkgCache(MMap
*Map
,bool DoMap
= true);
146 virtual ~pkgCache() {};
150 struct pkgCache::Header
152 // Signature information
153 unsigned long Signature
;
158 // Size of structure values
159 unsigned short HeaderSz
;
160 unsigned short PackageSz
;
161 unsigned short PackageFileSz
;
162 unsigned short VersionSz
;
163 unsigned short DescriptionSz
;
164 unsigned short DependencySz
;
165 unsigned short ProvidesSz
;
166 unsigned short VerFileSz
;
167 unsigned short DescFileSz
;
170 unsigned long PackageCount
;
171 unsigned long VersionCount
;
172 unsigned long DescriptionCount
;
173 unsigned long DependsCount
;
174 unsigned long PackageFileCount
;
175 unsigned long VerFileCount
;
176 unsigned long DescFileCount
;
177 unsigned long ProvidesCount
;
180 map_ptrloc FileList
; // struct PackageFile
181 map_ptrloc StringList
; // struct StringItem
182 map_ptrloc VerSysName
; // StringTable
183 map_ptrloc Architecture
; // StringTable
184 unsigned long MaxVerFileSize
;
185 unsigned long MaxDescFileSize
;
187 /* Allocation pools, there should be one of these for each structure
188 excluding the header */
189 DynamicMMap::Pool Pools
[8];
191 // Rapid package name lookup
192 map_ptrloc HashTable
[2*1048];
194 bool CheckSizes(Header
&Against
) const;
198 struct pkgCache::Package
201 map_ptrloc Name
; // Stringtable
202 map_ptrloc VersionList
; // Version
203 map_ptrloc CurrentVer
; // Version
204 map_ptrloc Section
; // StringTable (StringItem)
207 map_ptrloc NextPackage
; // Package
208 map_ptrloc RevDepends
; // Dependency
209 map_ptrloc ProvidesList
; // Provides
211 // Install/Remove/Purge etc
212 unsigned char SelectedState
; // What
213 unsigned char InstState
; // Flags
214 unsigned char CurrentState
; // State
220 struct pkgCache::PackageFile
223 map_ptrloc FileName
; // Stringtable
224 map_ptrloc Archive
; // Stringtable
225 map_ptrloc Component
; // Stringtable
226 map_ptrloc Version
; // Stringtable
227 map_ptrloc Origin
; // Stringtable
228 map_ptrloc Label
; // Stringtable
229 map_ptrloc Architecture
; // Stringtable
230 map_ptrloc Site
; // Stringtable
231 map_ptrloc IndexType
; // Stringtable
236 map_ptrloc NextFile
; // PackageFile
238 time_t mtime
; // Modification time for the file
241 struct pkgCache::VerFile
243 map_ptrloc File
; // PackageFile
244 map_ptrloc NextFile
; // PkgVerFile
245 map_ptrloc Offset
; // File offset
249 struct pkgCache::DescFile
251 map_ptrloc File
; // PackageFile
252 map_ptrloc NextFile
; // PkgVerFile
253 map_ptrloc Offset
; // File offset
257 struct pkgCache::Version
259 map_ptrloc VerStr
; // Stringtable
260 map_ptrloc Section
; // StringTable (StringItem)
261 map_ptrloc Arch
; // StringTable
264 map_ptrloc FileList
; // VerFile
265 map_ptrloc NextVer
; // Version
266 map_ptrloc DescriptionList
; // Description
267 map_ptrloc DependsList
; // Dependency
268 map_ptrloc ParentPkg
; // Package
269 map_ptrloc ProvidesList
; // Provides
271 map_ptrloc Size
; // These are the .deb size
272 map_ptrloc InstalledSize
;
275 unsigned char Priority
;
278 struct pkgCache::Description
280 // Language Code store the description translation language code. If
281 // the value has a 0 lenght then this is readed using the Package
282 // file else the Translation-CODE are used.
283 map_ptrloc language_code
; // StringTable
284 map_ptrloc md5sum
; // StringTable
287 map_ptrloc FileList
; // DescFile
288 map_ptrloc NextDesc
; // Description
289 map_ptrloc ParentPkg
; // Package
294 struct pkgCache::Dependency
296 map_ptrloc Version
; // Stringtable
297 map_ptrloc Package
; // Package
298 map_ptrloc NextDepends
; // Dependency
299 map_ptrloc NextRevDepends
; // Dependency
300 map_ptrloc ParentVer
; // Version
302 // Specific types of depends
305 unsigned char CompareOp
;
308 struct pkgCache::Provides
310 map_ptrloc ParentPkg
; // Pacakge
311 map_ptrloc Version
; // Version
312 map_ptrloc ProvideVersion
; // Stringtable
313 map_ptrloc NextProvides
; // Provides
314 map_ptrloc NextPkgProv
; // Provides
317 struct pkgCache::StringItem
319 map_ptrloc String
; // Stringtable
320 map_ptrloc NextItem
; // StringItem
323 #include <apt-pkg/cacheiterators.h>
325 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
326 {return PkgIterator(*this);};
327 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
328 {return PkgIterator(*this,PkgP
);};
329 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
330 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
331 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
332 {return PkgFileIterator(*this,PkgFileP
);};
334 // Oh I wish for Real Name Space Support
335 class pkgCache::Namespace
339 typedef pkgCache::PkgIterator PkgIterator
;
340 typedef pkgCache::VerIterator VerIterator
;
341 typedef pkgCache::DescIterator DescIterator
;
342 typedef pkgCache::DepIterator DepIterator
;
343 typedef pkgCache::PrvIterator PrvIterator
;
344 typedef pkgCache::PkgFileIterator PkgFileIterator
;
345 typedef pkgCache::VerFileIterator VerFileIterator
;
346 typedef pkgCache::Version Version
;
347 typedef pkgCache::Description Description
;
348 typedef pkgCache::Package Package
;
349 typedef pkgCache::Header Header
;
350 typedef pkgCache::Dep Dep
;
351 typedef pkgCache::Flag Flag
;