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
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};
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};
88 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
89 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
94 // Memory mapped cache file
98 unsigned long sHash(const string
&S
) const;
99 unsigned long sHash(const char *S
) const;
103 // Pointers to the arrays of items
108 PackageFile
*PkgFileP
;
113 StringItem
*StringItemP
;
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();};
121 // String hashing function (512 range)
122 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
123 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
125 // Usefull transformation things
126 const char *Priority(unsigned char Priority
);
129 PkgIterator
FindPkg(const string
&Name
);
130 Header
&Head() {return *HeaderP
;};
131 inline PkgIterator
PkgBegin();
132 inline PkgIterator
PkgEnd();
133 inline PkgFileIterator
FileBegin();
134 inline PkgFileIterator
FileEnd();
136 // Make me a function
137 pkgVersioningSystem
*VS
;
140 static const char *CompTypeDeb(unsigned char Comp
);
141 static const char *CompType(unsigned char Comp
);
142 static const char *DepType(unsigned char Dep
);
144 pkgCache(MMap
*Map
,bool DoMap
= true);
145 virtual ~pkgCache() {};
149 struct pkgCache::Header
151 // Signature information
152 unsigned long Signature
;
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
;
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
;
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
;
186 /* Allocation pools, there should be one of these for each structure
187 excluding the header */
188 DynamicMMap::Pool Pools
[8];
190 // Rapid package name lookup
191 map_ptrloc HashTable
[2*1048];
193 bool CheckSizes(Header
&Against
) const;
197 struct pkgCache::Package
200 map_ptrloc Name
; // Stringtable
201 map_ptrloc VersionList
; // Version
202 map_ptrloc CurrentVer
; // Version
203 map_ptrloc Section
; // StringTable (StringItem)
206 map_ptrloc NextPackage
; // Package
207 map_ptrloc RevDepends
; // Dependency
208 map_ptrloc ProvidesList
; // Provides
210 // Install/Remove/Purge etc
211 unsigned char SelectedState
; // What
212 unsigned char InstState
; // Flags
213 unsigned char CurrentState
; // State
219 struct pkgCache::PackageFile
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
235 map_ptrloc NextFile
; // PackageFile
237 time_t mtime
; // Modification time for the file
240 struct pkgCache::VerFile
242 map_ptrloc File
; // PackageFile
243 map_ptrloc NextFile
; // PkgVerFile
244 map_ptrloc Offset
; // File offset
248 struct pkgCache::DescFile
250 map_ptrloc File
; // PackageFile
251 map_ptrloc NextFile
; // PkgVerFile
252 map_ptrloc Offset
; // File offset
256 struct pkgCache::Version
258 map_ptrloc VerStr
; // Stringtable
259 map_ptrloc Section
; // StringTable (StringItem)
260 map_ptrloc Arch
; // StringTable
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
270 map_ptrloc Size
; // These are the .deb size
271 map_ptrloc InstalledSize
;
274 unsigned char Priority
;
277 struct pkgCache::Description
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
286 map_ptrloc FileList
; // DescFile
287 map_ptrloc NextDesc
; // Description
288 map_ptrloc ParentPkg
; // Package
293 struct pkgCache::Dependency
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
301 // Specific types of depends
304 unsigned char CompareOp
;
307 struct pkgCache::Provides
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
316 struct pkgCache::StringItem
318 map_ptrloc String
; // Stringtable
319 map_ptrloc NextItem
; // StringItem
322 #include <apt-pkg/cacheiterators.h>
324 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
325 {return PkgIterator(*this);};
326 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
327 {return PkgIterator(*this,PkgP
);};
328 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
329 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
330 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
331 {return PkgFileIterator(*this,PkgFileP
);};
333 // Oh I wish for Real Name Space Support
334 class pkgCache::Namespace
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
;