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
52 class PkgFileIterator
;
53 class VerFileIterator
;
54 class DescFileIterator
;
56 friend class PkgIterator
;
57 friend class VerIterator
;
58 friend class DescInterator
;
59 friend class DepIterator
;
60 friend class PrvIterator
;
61 friend class PkgFileIterator
;
62 friend class VerFileIterator
;
63 friend class DescFileIterator
;
64 friend class TagIterator
;
68 // These are all the constants used in the cache structures
70 // WARNING - if you change these lists you must also edit
71 // the stringification in pkgcache.cc and also consider whether
72 // the cache file will become incompatible.
75 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
76 Conflicts
=5,Replaces
=6,Obsoletes
=7,DpkgBreaks
=8,Enhances
=9};
77 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
78 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
83 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
84 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
85 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
86 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
87 HalfInstalled
=4,ConfigFiles
=5,Installed
=6,
88 TriggersAwaited
=7,TriggersPending
=8};
93 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
94 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
99 // Memory mapped cache file
103 unsigned long sHash(const string
&S
) const;
104 unsigned long sHash(const char *S
) const;
108 // Pointers to the arrays of items
113 PackageFile
*PkgFileP
;
119 StringItem
*StringItemP
;
122 virtual bool ReMap();
123 inline bool Sync() {return Map
.Sync();};
124 inline MMap
&GetMap() {return Map
;};
125 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
127 // String hashing function (512 range)
128 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
129 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
131 // Usefull transformation things
132 const char *Priority(unsigned char Priority
);
135 PkgIterator
FindPkg(const string
&Name
);
136 Header
&Head() {return *HeaderP
;};
137 inline PkgIterator
PkgBegin();
138 inline PkgIterator
PkgEnd();
139 inline PkgFileIterator
FileBegin();
140 inline PkgFileIterator
FileEnd();
142 // Make me a function
143 pkgVersioningSystem
*VS
;
146 static const char *CompTypeDeb(unsigned char Comp
);
147 static const char *CompType(unsigned char Comp
);
148 static const char *DepType(unsigned char Dep
);
150 pkgCache(MMap
*Map
,bool DoMap
= true);
151 virtual ~pkgCache() {};
154 // Header structure /*{{{*/
155 struct pkgCache::Header
157 // Signature information
158 unsigned long Signature
;
163 // Size of structure values
164 unsigned short HeaderSz
;
165 unsigned short PackageSz
;
166 unsigned short PackageFileSz
;
167 unsigned short VersionSz
;
168 unsigned short TagSz
;
169 unsigned short DescriptionSz
;
170 unsigned short DependencySz
;
171 unsigned short ProvidesSz
;
172 unsigned short VerFileSz
;
173 unsigned short DescFileSz
;
176 unsigned long PackageCount
;
177 unsigned long VersionCount
;
178 unsigned long TagCount
;
179 unsigned long DescriptionCount
;
180 unsigned long DependsCount
;
181 unsigned long PackageFileCount
;
182 unsigned long VerFileCount
;
183 unsigned long DescFileCount
;
184 unsigned long ProvidesCount
;
187 map_ptrloc FileList
; // struct PackageFile
188 map_ptrloc StringList
; // struct StringItem
189 map_ptrloc VerSysName
; // StringTable
190 map_ptrloc Architecture
; // StringTable
191 unsigned long MaxVerFileSize
;
192 unsigned long MaxDescFileSize
;
194 /* Allocation pools, there should be one of these for each structure
195 excluding the header */
196 DynamicMMap::Pool Pools
[8];
198 // Rapid package name lookup
199 map_ptrloc HashTable
[2*1048];
201 bool CheckSizes(Header
&Against
) const;
205 struct pkgCache::Package
/*{{{*/
208 map_ptrloc Name
; // Stringtable
209 map_ptrloc Display
; // Stringtable
210 map_ptrloc VersionList
; // Version
211 map_ptrloc CurrentVer
; // Version
212 map_ptrloc Section
; // StringTable (StringItem)
215 map_ptrloc NextPackage
; // Package
216 map_ptrloc RevDepends
; // Dependency
217 map_ptrloc ProvidesList
; // Provides
218 map_ptrloc TagList
; // Tag
220 // Install/Remove/Purge etc
221 unsigned char SelectedState
; // What
222 unsigned char InstState
; // Flags
223 unsigned char CurrentState
; // State
229 struct pkgCache::PackageFile
232 map_ptrloc FileName
; // Stringtable
233 map_ptrloc Archive
; // Stringtable
234 map_ptrloc Component
; // Stringtable
235 map_ptrloc Version
; // Stringtable
236 map_ptrloc Origin
; // Stringtable
237 map_ptrloc Label
; // Stringtable
238 map_ptrloc Architecture
; // Stringtable
239 map_ptrloc Site
; // Stringtable
240 map_ptrloc IndexType
; // Stringtable
245 map_ptrloc NextFile
; // PackageFile
247 time_t mtime
; // Modification time for the file
250 struct pkgCache::VerFile
/*{{{*/
252 map_ptrloc File
; // PackageFile
253 map_ptrloc NextFile
; // PkgVerFile
254 map_ptrloc Offset
; // File offset
258 struct pkgCache::Tag
/*{{{*/
260 map_ptrloc Name
; // Stringtable
261 map_ptrloc NextTag
; // Tag
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 Display
; // Stringtable
276 map_ptrloc Section
; // StringTable (StringItem)
277 map_ptrloc Arch
; // StringTable
280 map_ptrloc FileList
; // VerFile
281 map_ptrloc NextVer
; // Version
282 map_ptrloc DescriptionList
; // Description
283 map_ptrloc DependsList
; // Dependency
284 map_ptrloc ParentPkg
; // Package
285 map_ptrloc ProvidesList
; // Provides
287 map_ptrloc Size
; // These are the .deb size
288 map_ptrloc InstalledSize
;
291 unsigned char Priority
;
294 struct pkgCache::Description
/*{{{*/
296 // Language Code store the description translation language code. If
297 // the value has a 0 lenght then this is readed using the Package
298 // file else the Translation-CODE are used.
299 map_ptrloc language_code
; // StringTable
300 map_ptrloc md5sum
; // StringTable
303 map_ptrloc FileList
; // DescFile
304 map_ptrloc NextDesc
; // Description
305 map_ptrloc ParentPkg
; // Package
310 struct pkgCache::Dependency
/*{{{*/
312 map_ptrloc Version
; // Stringtable
313 map_ptrloc Package
; // Package
314 map_ptrloc NextDepends
; // Dependency
315 map_ptrloc NextRevDepends
; // Dependency
316 map_ptrloc ParentVer
; // Version
318 // Specific types of depends
321 unsigned char CompareOp
;
324 struct pkgCache::Provides
/*{{{*/
326 map_ptrloc ParentPkg
; // Pacakge
327 map_ptrloc Version
; // Version
328 map_ptrloc ProvideVersion
; // Stringtable
329 map_ptrloc NextProvides
; // Provides
330 map_ptrloc NextPkgProv
; // Provides
333 struct pkgCache::StringItem
/*{{{*/
335 map_ptrloc String
; // Stringtable
336 map_ptrloc NextItem
; // StringItem
339 #include <apt-pkg/cacheiterators.h>
341 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
342 {return PkgIterator(*this);};
343 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
344 {return PkgIterator(*this,PkgP
);};
345 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
346 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
347 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
348 {return PkgFileIterator(*this,PkgFileP
);};
350 // Oh I wish for Real Name Space Support
351 class pkgCache::Namespace
/*{{{*/
355 typedef pkgCache::PkgIterator PkgIterator
;
356 typedef pkgCache::VerIterator VerIterator
;
357 typedef pkgCache::TagIterator TagIterator
;
358 typedef pkgCache::DescIterator DescIterator
;
359 typedef pkgCache::DepIterator DepIterator
;
360 typedef pkgCache::PrvIterator PrvIterator
;
361 typedef pkgCache::PkgFileIterator PkgFileIterator
;
362 typedef pkgCache::VerFileIterator VerFileIterator
;
363 typedef pkgCache::Version Version
;
364 typedef pkgCache::Description Description
;
365 typedef pkgCache::Package Package
;
366 typedef pkgCache::Header Header
;
367 typedef pkgCache::Dep Dep
;
368 typedef pkgCache::Flag Flag
;