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
68 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
69 Conflicts
=5,Replaces
=6,Obsoletes
=7};
70 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
71 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
76 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
77 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
78 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
79 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
80 HalfInstalled
=4,ConfigFiles
=5,Installed
=6};
85 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
86 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
91 // Memory mapped cache file
95 unsigned long sHash(const string
&S
) const;
96 unsigned long sHash(const char *S
) const;
100 // Pointers to the arrays of items
105 PackageFile
*PkgFileP
;
110 StringItem
*StringItemP
;
113 virtual bool ReMap();
114 inline bool Sync() {return Map
.Sync();};
115 inline MMap
&GetMap() {return Map
;};
116 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
118 // String hashing function (512 range)
119 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
120 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
122 // Usefull transformation things
123 const char *Priority(unsigned char Priority
);
126 PkgIterator
FindPkg(const string
&Name
);
127 Header
&Head() {return *HeaderP
;};
128 inline PkgIterator
PkgBegin();
129 inline PkgIterator
PkgEnd();
130 inline PkgFileIterator
FileBegin();
131 inline PkgFileIterator
FileEnd();
133 // Make me a function
134 pkgVersioningSystem
*VS
;
137 static const char *CompTypeDeb(unsigned char Comp
);
138 static const char *CompType(unsigned char Comp
);
139 static const char *DepType(unsigned char Dep
);
141 pkgCache(MMap
*Map
,bool DoMap
= true);
142 virtual ~pkgCache() {};
146 struct pkgCache::Header
148 // Signature information
149 unsigned long Signature
;
154 // Size of structure values
155 unsigned short HeaderSz
;
156 unsigned short PackageSz
;
157 unsigned short PackageFileSz
;
158 unsigned short VersionSz
;
159 unsigned short DescriptionSz
;
160 unsigned short DependencySz
;
161 unsigned short ProvidesSz
;
162 unsigned short VerFileSz
;
163 unsigned short DescFileSz
;
166 unsigned long PackageCount
;
167 unsigned long VersionCount
;
168 unsigned long DescriptionCount
;
169 unsigned long DependsCount
;
170 unsigned long PackageFileCount
;
171 unsigned long VerFileCount
;
172 unsigned long DescFileCount
;
173 unsigned long ProvidesCount
;
176 map_ptrloc FileList
; // struct PackageFile
177 map_ptrloc StringList
; // struct StringItem
178 map_ptrloc VerSysName
; // StringTable
179 map_ptrloc Architecture
; // StringTable
180 unsigned long MaxVerFileSize
;
181 unsigned long MaxDescFileSize
;
183 /* Allocation pools, there should be one of these for each structure
184 excluding the header */
185 DynamicMMap::Pool Pools
[8];
187 // Rapid package name lookup
188 map_ptrloc HashTable
[2*1048];
190 bool CheckSizes(Header
&Against
) const;
194 struct pkgCache::Package
197 map_ptrloc Name
; // Stringtable
198 map_ptrloc VersionList
; // Version
199 map_ptrloc CurrentVer
; // Version
200 map_ptrloc Section
; // StringTable (StringItem)
203 map_ptrloc NextPackage
; // Package
204 map_ptrloc RevDepends
; // Dependency
205 map_ptrloc ProvidesList
; // Provides
207 // Install/Remove/Purge etc
208 unsigned char SelectedState
; // What
209 unsigned char InstState
; // Flags
210 unsigned char CurrentState
; // State
216 struct pkgCache::PackageFile
219 map_ptrloc FileName
; // Stringtable
220 map_ptrloc Archive
; // Stringtable
221 map_ptrloc Component
; // Stringtable
222 map_ptrloc Version
; // Stringtable
223 map_ptrloc Origin
; // Stringtable
224 map_ptrloc Label
; // Stringtable
225 map_ptrloc Architecture
; // Stringtable
226 map_ptrloc Site
; // Stringtable
227 map_ptrloc IndexType
; // Stringtable
232 map_ptrloc NextFile
; // PackageFile
234 time_t mtime
; // Modification time for the file
237 struct pkgCache::VerFile
239 map_ptrloc File
; // PackageFile
240 map_ptrloc NextFile
; // PkgVerFile
241 map_ptrloc Offset
; // File offset
245 struct pkgCache::DescFile
247 map_ptrloc File
; // PackageFile
248 map_ptrloc NextFile
; // PkgVerFile
249 map_ptrloc Offset
; // File offset
253 struct pkgCache::Version
255 map_ptrloc VerStr
; // Stringtable
256 map_ptrloc Section
; // StringTable (StringItem)
257 map_ptrloc Arch
; // StringTable
260 map_ptrloc FileList
; // VerFile
261 map_ptrloc NextVer
; // Version
262 map_ptrloc DescriptionList
; // Description
263 map_ptrloc DependsList
; // Dependency
264 map_ptrloc ParentPkg
; // Package
265 map_ptrloc ProvidesList
; // Provides
267 map_ptrloc Size
; // These are the .deb size
268 map_ptrloc InstalledSize
;
271 unsigned char Priority
;
274 struct pkgCache::Description
276 // Language Code store the description translation language code. If
277 // the value has a 0 lenght then this is readed using the Package
278 // file else the Translation-CODE are used.
279 map_ptrloc language_code
; // StringTable
280 map_ptrloc md5sum
; // StringTable
283 map_ptrloc FileList
; // DescFile
284 map_ptrloc NextDesc
; // Description
285 map_ptrloc ParentPkg
; // Package
290 struct pkgCache::Dependency
292 map_ptrloc Version
; // Stringtable
293 map_ptrloc Package
; // Package
294 map_ptrloc NextDepends
; // Dependency
295 map_ptrloc NextRevDepends
; // Dependency
296 map_ptrloc ParentVer
; // Version
298 // Specific types of depends
301 unsigned char CompareOp
;
304 struct pkgCache::Provides
306 map_ptrloc ParentPkg
; // Pacakge
307 map_ptrloc Version
; // Version
308 map_ptrloc ProvideVersion
; // Stringtable
309 map_ptrloc NextProvides
; // Provides
310 map_ptrloc NextPkgProv
; // Provides
313 struct pkgCache::StringItem
315 map_ptrloc String
; // Stringtable
316 map_ptrloc NextItem
; // StringItem
319 #include <apt-pkg/cacheiterators.h>
321 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
322 {return PkgIterator(*this);};
323 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
324 {return PkgIterator(*this,PkgP
);};
325 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
326 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
327 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
328 {return PkgFileIterator(*this,PkgFileP
);};
330 // Oh I wish for Real Name Space Support
331 class pkgCache::Namespace
335 typedef pkgCache::PkgIterator PkgIterator
;
336 typedef pkgCache::VerIterator VerIterator
;
337 typedef pkgCache::DescIterator DescIterator
;
338 typedef pkgCache::DepIterator DepIterator
;
339 typedef pkgCache::PrvIterator PrvIterator
;
340 typedef pkgCache::PkgFileIterator PkgFileIterator
;
341 typedef pkgCache::VerFileIterator VerFileIterator
;
342 typedef pkgCache::Version Version
;
343 typedef pkgCache::Description Description
;
344 typedef pkgCache::Package Package
;
345 typedef pkgCache::Header Header
;
346 typedef pkgCache::Dep Dep
;
347 typedef pkgCache::Flag Flag
;