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
;
30 class pkgCache
/*{{{*/
33 // Cache element predeclarations
47 template<typename Str
, typename Itr
> class Iterator
;
54 class PkgFileIterator
;
55 class VerFileIterator
;
56 class DescFileIterator
;
60 // These are all the constants used in the cache structures
62 // WARNING - if you change these lists you must also edit
63 // the stringification in pkgcache.cc and also consider whether
64 // the cache file will become incompatible.
67 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
68 Conflicts
=5,Replaces
=6,Obsoletes
=7,DpkgBreaks
=8,Enhances
=9};
69 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
70 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
75 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
76 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
77 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
78 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
79 HalfInstalled
=4,ConfigFiles
=5,Installed
=6,
80 TriggersAwaited
=7,TriggersPending
=8};
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
106 PackageFile
*PkgFileP
;
111 StringItem
*StringItemP
;
114 virtual bool ReMap();
115 inline bool Sync() {return Map
.Sync();};
116 inline MMap
&GetMap() {return Map
;};
117 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
119 // String hashing function (512 range)
120 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
121 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
123 // Usefull transformation things
124 const char *Priority(unsigned char Priority
);
127 GrpIterator
FindGrp(const string
&Name
);
128 PkgIterator
FindPkg(const string
&Name
);
129 PkgIterator
FindPkg(const string
&Name
, const string
&Arch
);
131 Header
&Head() {return *HeaderP
;};
132 inline GrpIterator
GrpBegin();
133 inline GrpIterator
GrpEnd();
134 inline PkgIterator
PkgBegin();
135 inline PkgIterator
PkgEnd();
136 inline PkgFileIterator
FileBegin();
137 inline PkgFileIterator
FileEnd();
139 inline bool MultiArchCache() const { return MultiArchEnabled
; };
141 // Make me a function
142 pkgVersioningSystem
*VS
;
145 static const char *CompTypeDeb(unsigned char Comp
);
146 static const char *CompType(unsigned char Comp
);
147 static const char *DepType(unsigned char Dep
);
149 pkgCache(MMap
*Map
,bool DoMap
= true);
150 virtual ~pkgCache() {};
153 bool MultiArchEnabled
;
154 PkgIterator
SingleArchFindPkg(const string
&Name
);
157 // Header structure /*{{{*/
158 struct pkgCache::Header
160 // Signature information
161 unsigned long Signature
;
166 // Size of structure values
167 unsigned short HeaderSz
;
168 unsigned short PackageSz
;
169 unsigned short PackageFileSz
;
170 unsigned short VersionSz
;
171 unsigned short DescriptionSz
;
172 unsigned short DependencySz
;
173 unsigned short ProvidesSz
;
174 unsigned short VerFileSz
;
175 unsigned short DescFileSz
;
178 unsigned long GroupCount
;
179 unsigned long PackageCount
;
180 unsigned long VersionCount
;
181 unsigned long DescriptionCount
;
182 unsigned long DependsCount
;
183 unsigned long PackageFileCount
;
184 unsigned long VerFileCount
;
185 unsigned long DescFileCount
;
186 unsigned long ProvidesCount
;
189 map_ptrloc FileList
; // struct PackageFile
190 map_ptrloc StringList
; // struct StringItem
191 map_ptrloc VerSysName
; // StringTable
192 map_ptrloc Architecture
; // StringTable
193 unsigned long MaxVerFileSize
;
194 unsigned long MaxDescFileSize
;
196 /* Allocation pools, there should be one of these for each structure
197 excluding the header */
198 DynamicMMap::Pool Pools
[9];
200 // Rapid package and group name lookup
201 // Notice: Increase only both table sizes as the
202 // hashmethod assume the size of the Pkg one
203 map_ptrloc PkgHashTable
[2*1048];
204 map_ptrloc GrpHashTable
[2*1048];
206 bool CheckSizes(Header
&Against
) const;
210 struct pkgCache::Group
{ /*{{{*/
211 map_ptrloc Name
; // Stringtable
214 map_ptrloc FirstPackage
;// Package
215 map_ptrloc LastPackage
; // Package
216 map_ptrloc Next
; // Group
219 struct pkgCache::Package
/*{{{*/
222 map_ptrloc Name
; // Stringtable
223 map_ptrloc Arch
; // StringTable (StringItem)
224 map_ptrloc VersionList
; // Version
225 map_ptrloc CurrentVer
; // Version
226 map_ptrloc Section
; // StringTable (StringItem)
227 map_ptrloc Group
; // Group the Package belongs to
230 map_ptrloc NextPackage
; // Package
231 map_ptrloc RevDepends
; // Dependency
232 map_ptrloc ProvidesList
; // Provides
234 // Install/Remove/Purge etc
235 unsigned char SelectedState
; // What
236 unsigned char InstState
; // Flags
237 unsigned char CurrentState
; // State
243 struct pkgCache::PackageFile
/*{{{*/
246 map_ptrloc FileName
; // Stringtable
247 map_ptrloc Archive
; // Stringtable
248 map_ptrloc Codename
; // Stringtable
249 map_ptrloc Component
; // Stringtable
250 map_ptrloc Version
; // Stringtable
251 map_ptrloc Origin
; // Stringtable
252 map_ptrloc Label
; // Stringtable
253 map_ptrloc Architecture
; // Stringtable
254 map_ptrloc Site
; // Stringtable
255 map_ptrloc IndexType
; // Stringtable
260 map_ptrloc NextFile
; // PackageFile
262 time_t mtime
; // Modification time for the file
265 struct pkgCache::VerFile
/*{{{*/
267 map_ptrloc File
; // PackageFile
268 map_ptrloc NextFile
; // PkgVerFile
269 map_ptrloc Offset
; // File offset
273 struct pkgCache::DescFile
/*{{{*/
275 map_ptrloc File
; // PackageFile
276 map_ptrloc NextFile
; // PkgVerFile
277 map_ptrloc Offset
; // File offset
281 struct pkgCache::Version
/*{{{*/
283 map_ptrloc VerStr
; // Stringtable
284 map_ptrloc Section
; // StringTable (StringItem)
285 enum {None
, All
, Foreign
, Same
, Allowed
} MultiArch
;
288 map_ptrloc FileList
; // VerFile
289 map_ptrloc NextVer
; // Version
290 map_ptrloc DescriptionList
; // Description
291 map_ptrloc DependsList
; // Dependency
292 map_ptrloc ParentPkg
; // Package
293 map_ptrloc ProvidesList
; // Provides
295 map_ptrloc Size
; // These are the .deb size
296 map_ptrloc InstalledSize
;
299 unsigned char Priority
;
302 struct pkgCache::Description
/*{{{*/
304 // Language Code store the description translation language code. If
305 // the value has a 0 lenght then this is readed using the Package
306 // file else the Translation-CODE are used.
307 map_ptrloc language_code
; // StringTable
308 map_ptrloc md5sum
; // StringTable
311 map_ptrloc FileList
; // DescFile
312 map_ptrloc NextDesc
; // Description
313 map_ptrloc ParentPkg
; // Package
318 struct pkgCache::Dependency
/*{{{*/
320 map_ptrloc Version
; // Stringtable
321 map_ptrloc Package
; // Package
322 map_ptrloc NextDepends
; // Dependency
323 map_ptrloc NextRevDepends
; // Dependency
324 map_ptrloc ParentVer
; // Version
326 // Specific types of depends
329 unsigned char CompareOp
;
332 struct pkgCache::Provides
/*{{{*/
334 map_ptrloc ParentPkg
; // Pacakge
335 map_ptrloc Version
; // Version
336 map_ptrloc ProvideVersion
; // Stringtable
337 map_ptrloc NextProvides
; // Provides
338 map_ptrloc NextPkgProv
; // Provides
341 struct pkgCache::StringItem
/*{{{*/
343 map_ptrloc String
; // Stringtable
344 map_ptrloc NextItem
; // StringItem
347 #include <apt-pkg/cacheiterators.h>
349 inline pkgCache::GrpIterator
pkgCache::GrpBegin()
350 {return GrpIterator(*this);};
351 inline pkgCache::GrpIterator
pkgCache::GrpEnd()
352 {return GrpIterator(*this,GrpP
);};
353 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
354 {return PkgIterator(*this);};
355 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
356 {return PkgIterator(*this,PkgP
);};
357 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
358 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
359 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
360 {return PkgFileIterator(*this,PkgFileP
);};
362 // Oh I wish for Real Name Space Support
363 class pkgCache::Namespace
/*{{{*/
366 typedef pkgCache::GrpIterator GrpIterator
;
367 typedef pkgCache::PkgIterator PkgIterator
;
368 typedef pkgCache::VerIterator VerIterator
;
369 typedef pkgCache::DescIterator DescIterator
;
370 typedef pkgCache::DepIterator DepIterator
;
371 typedef pkgCache::PrvIterator PrvIterator
;
372 typedef pkgCache::PkgFileIterator PkgFileIterator
;
373 typedef pkgCache::VerFileIterator VerFileIterator
;
374 typedef pkgCache::Version Version
;
375 typedef pkgCache::Description Description
;
376 typedef pkgCache::Package Package
;
377 typedef pkgCache::Header Header
;
378 typedef pkgCache::Dep Dep
;
379 typedef pkgCache::Flag Flag
;