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
, string Arch
= "native");
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() {};
148 // Header structure /*{{{*/
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 GroupCount
;
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
[9];
191 // Rapid package and group name lookup
192 // Notice: Increase only both table sizes as the
193 // hashmethod assume the size of the Pkg one
194 map_ptrloc PkgHashTable
[2*1048];
195 map_ptrloc GrpHashTable
[2*1048];
197 bool CheckSizes(Header
&Against
) const;
201 struct pkgCache::Group
{ /*{{{*/
202 map_ptrloc Name
; // Stringtable
205 map_ptrloc FirstPackage
;// Package
206 map_ptrloc LastPackage
; // Package
207 map_ptrloc Next
; // Group
210 struct pkgCache::Package
/*{{{*/
213 map_ptrloc Name
; // Stringtable
214 map_ptrloc Arch
; // StringTable (StringItem)
215 map_ptrloc VersionList
; // Version
216 map_ptrloc CurrentVer
; // Version
217 map_ptrloc Section
; // StringTable (StringItem)
218 map_ptrloc Group
; // Group the Package belongs to
221 map_ptrloc NextPackage
; // Package
222 map_ptrloc RevDepends
; // Dependency
223 map_ptrloc ProvidesList
; // Provides
225 // Install/Remove/Purge etc
226 unsigned char SelectedState
; // What
227 unsigned char InstState
; // Flags
228 unsigned char CurrentState
; // State
234 struct pkgCache::PackageFile
/*{{{*/
237 map_ptrloc FileName
; // Stringtable
238 map_ptrloc Archive
; // Stringtable
239 map_ptrloc Codename
; // Stringtable
240 map_ptrloc Component
; // Stringtable
241 map_ptrloc Version
; // Stringtable
242 map_ptrloc Origin
; // Stringtable
243 map_ptrloc Label
; // Stringtable
244 map_ptrloc Architecture
; // Stringtable
245 map_ptrloc Site
; // Stringtable
246 map_ptrloc IndexType
; // Stringtable
251 map_ptrloc NextFile
; // PackageFile
253 time_t mtime
; // Modification time for the file
256 struct pkgCache::VerFile
/*{{{*/
258 map_ptrloc File
; // PackageFile
259 map_ptrloc NextFile
; // PkgVerFile
260 map_ptrloc Offset
; // File offset
264 struct pkgCache::DescFile
/*{{{*/
266 map_ptrloc File
; // PackageFile
267 map_ptrloc NextFile
; // PkgVerFile
268 map_ptrloc Offset
; // File offset
272 struct pkgCache::Version
/*{{{*/
274 map_ptrloc VerStr
; // Stringtable
275 map_ptrloc Section
; // StringTable (StringItem)
276 map_ptrloc Arch
; // StringTable
279 map_ptrloc FileList
; // VerFile
280 map_ptrloc NextVer
; // Version
281 map_ptrloc DescriptionList
; // Description
282 map_ptrloc DependsList
; // Dependency
283 map_ptrloc ParentPkg
; // Package
284 map_ptrloc ProvidesList
; // Provides
286 map_ptrloc Size
; // These are the .deb size
287 map_ptrloc InstalledSize
;
290 unsigned char Priority
;
293 struct pkgCache::Description
/*{{{*/
295 // Language Code store the description translation language code. If
296 // the value has a 0 lenght then this is readed using the Package
297 // file else the Translation-CODE are used.
298 map_ptrloc language_code
; // StringTable
299 map_ptrloc md5sum
; // StringTable
302 map_ptrloc FileList
; // DescFile
303 map_ptrloc NextDesc
; // Description
304 map_ptrloc ParentPkg
; // Package
309 struct pkgCache::Dependency
/*{{{*/
311 map_ptrloc Version
; // Stringtable
312 map_ptrloc Package
; // Package
313 map_ptrloc NextDepends
; // Dependency
314 map_ptrloc NextRevDepends
; // Dependency
315 map_ptrloc ParentVer
; // Version
317 // Specific types of depends
320 unsigned char CompareOp
;
323 struct pkgCache::Provides
/*{{{*/
325 map_ptrloc ParentPkg
; // Pacakge
326 map_ptrloc Version
; // Version
327 map_ptrloc ProvideVersion
; // Stringtable
328 map_ptrloc NextProvides
; // Provides
329 map_ptrloc NextPkgProv
; // Provides
332 struct pkgCache::StringItem
/*{{{*/
334 map_ptrloc String
; // Stringtable
335 map_ptrloc NextItem
; // StringItem
338 #include <apt-pkg/cacheiterators.h>
340 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
341 {return PkgIterator(*this);};
342 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
343 {return PkgIterator(*this,PkgP
);};
344 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
345 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
346 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
347 {return PkgFileIterator(*this,PkgFileP
);};
349 // Oh I wish for Real Name Space Support
350 class pkgCache::Namespace
/*{{{*/
354 typedef pkgCache::PkgIterator PkgIterator
;
355 typedef pkgCache::VerIterator VerIterator
;
356 typedef pkgCache::DescIterator DescIterator
;
357 typedef pkgCache::DepIterator DepIterator
;
358 typedef pkgCache::PrvIterator PrvIterator
;
359 typedef pkgCache::PkgFileIterator PkgFileIterator
;
360 typedef pkgCache::VerFileIterator VerFileIterator
;
361 typedef pkgCache::Version Version
;
362 typedef pkgCache::Description Description
;
363 typedef pkgCache::Package Package
;
364 typedef pkgCache::Header Header
;
365 typedef pkgCache::Dep Dep
;
366 typedef pkgCache::Flag Flag
;