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>
26 #include <apt-pkg/srkstring.h>
30 class pkgVersioningSystem
;
31 class pkgCache
/*{{{*/
34 // Cache element predeclarations
53 class PkgFileIterator
;
54 class VerFileIterator
;
55 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
;
65 friend class TagIterator
;
69 // These are all the constants used in the cache structures
71 // WARNING - if you change these lists you must also edit
72 // the stringification in pkgcache.cc and also consider whether
73 // the cache file will become incompatible.
76 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
77 Conflicts
=5,Replaces
=6,Obsoletes
=7,DpkgBreaks
=8,Enhances
=9};
78 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
79 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
84 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
85 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
86 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
87 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
88 HalfInstalled
=4,ConfigFiles
=5,Installed
=6,
89 TriggersAwaited
=7,TriggersPending
=8};
94 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
95 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
100 // Memory mapped cache file
104 unsigned long sHash(const string
&S
) const;
105 unsigned long sHash(const char *S
) const;
106 unsigned long sHash(const srkString
&S
) const;
110 // Pointers to the arrays of items
115 PackageFile
*PkgFileP
;
121 StringItem
*StringItemP
;
124 virtual bool ReMap();
125 inline bool Sync() {return Map
.Sync();};
126 inline MMap
&GetMap() {return Map
;};
127 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
129 // String hashing function (512 range)
130 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
131 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
132 inline unsigned long Hash(const srkString
&S
) const {return sHash(S
);};
134 // Usefull transformation things
135 const char *Priority(unsigned char Priority
);
138 PkgIterator
FindPkg(const string
&Name
);
139 PkgIterator
FindPkg(const srkString
&Name
);
140 Header
&Head() {return *HeaderP
;};
141 inline PkgIterator
PkgBegin();
142 inline PkgIterator
PkgEnd();
143 inline PkgFileIterator
FileBegin();
144 inline PkgFileIterator
FileEnd();
146 // Make me a function
147 pkgVersioningSystem
*VS
;
150 static const char *CompTypeDeb(unsigned char Comp
);
151 static const char *CompType(unsigned char Comp
);
152 static const char *DepType(unsigned char Dep
);
154 pkgCache(MMap
*Map
,bool DoMap
= true);
155 virtual ~pkgCache() {};
158 // Header structure /*{{{*/
159 struct pkgCache::Header
161 // Signature information
162 unsigned long Signature
;
167 // Size of structure values
168 unsigned short HeaderSz
;
169 unsigned short PackageSz
;
170 unsigned short PackageFileSz
;
171 unsigned short VersionSz
;
172 unsigned short TagSz
;
173 unsigned short DescriptionSz
;
174 unsigned short DependencySz
;
175 unsigned short ProvidesSz
;
176 unsigned short VerFileSz
;
177 unsigned short DescFileSz
;
180 unsigned long PackageCount
;
181 unsigned long VersionCount
;
182 unsigned long TagCount
;
183 unsigned long DescriptionCount
;
184 unsigned long DependsCount
;
185 unsigned long PackageFileCount
;
186 unsigned long VerFileCount
;
187 unsigned long DescFileCount
;
188 unsigned long ProvidesCount
;
191 map_ptrloc FileList
; // struct PackageFile
192 map_ptrloc StringList
; // struct StringItem
193 map_ptrloc VerSysName
; // StringTable
194 map_ptrloc Architecture
; // StringTable
195 unsigned long MaxVerFileSize
;
196 unsigned long MaxDescFileSize
;
198 /* Allocation pools, there should be one of these for each structure
199 excluding the header */
200 DynamicMMap::Pool Pools
[8];
202 // Rapid package name lookup
203 map_ptrloc HashTable
[2*1048];
205 bool CheckSizes(Header
&Against
) const;
209 struct pkgCache::Package
/*{{{*/
212 map_ptrloc Name
; // Stringtable
213 map_ptrloc Display
; // Stringtable
214 map_ptrloc VersionList
; // Version
215 map_ptrloc CurrentVer
; // Version
216 map_ptrloc Section
; // StringTable (StringItem)
219 map_ptrloc NextPackage
; // Package
220 map_ptrloc RevDepends
; // Dependency
221 map_ptrloc ProvidesList
; // Provides
222 map_ptrloc TagList
; // Tag
224 // Install/Remove/Purge etc
225 unsigned char SelectedState
; // What
226 unsigned char InstState
; // Flags
227 unsigned char CurrentState
; // State
233 struct pkgCache::PackageFile
236 map_ptrloc FileName
; // Stringtable
237 map_ptrloc Archive
; // Stringtable
238 map_ptrloc Component
; // Stringtable
239 map_ptrloc Version
; // Stringtable
240 map_ptrloc Origin
; // Stringtable
241 map_ptrloc Label
; // Stringtable
242 map_ptrloc Architecture
; // Stringtable
243 map_ptrloc Site
; // Stringtable
244 map_ptrloc IndexType
; // Stringtable
249 map_ptrloc NextFile
; // PackageFile
251 time_t mtime
; // Modification time for the file
254 struct pkgCache::VerFile
/*{{{*/
256 map_ptrloc File
; // PackageFile
257 map_ptrloc NextFile
; // PkgVerFile
258 map_ptrloc Offset
; // File offset
262 struct pkgCache::Tag
/*{{{*/
264 map_ptrloc Name
; // Stringtable
265 map_ptrloc NextTag
; // Tag
268 struct pkgCache::DescFile
/*{{{*/
270 map_ptrloc File
; // PackageFile
271 map_ptrloc NextFile
; // PkgVerFile
272 map_ptrloc Offset
; // File offset
276 struct pkgCache::Version
/*{{{*/
278 map_ptrloc VerStr
; // Stringtable
279 map_ptrloc Display
; // Stringtable
280 map_ptrloc Section
; // StringTable (StringItem)
281 map_ptrloc Arch
; // StringTable
284 map_ptrloc FileList
; // VerFile
285 map_ptrloc NextVer
; // Version
286 map_ptrloc DescriptionList
; // Description
287 map_ptrloc DependsList
; // Dependency
288 map_ptrloc ParentPkg
; // Package
289 map_ptrloc ProvidesList
; // Provides
291 map_ptrloc Size
; // These are the .deb size
292 map_ptrloc InstalledSize
;
295 unsigned char Priority
;
299 struct pkgCache::Description
/*{{{*/
301 // Language Code store the description translation language code. If
302 // the value has a 0 lenght then this is readed using the Package
303 // file else the Translation-CODE are used.
304 map_ptrloc language_code
; // StringTable
305 map_ptrloc md5sum
; // StringTable
308 map_ptrloc FileList
; // DescFile
309 map_ptrloc NextDesc
; // Description
310 map_ptrloc ParentPkg
; // Package
315 struct pkgCache::Dependency
/*{{{*/
317 map_ptrloc Version
; // Stringtable
318 map_ptrloc Package
; // Package
319 map_ptrloc NextDepends
; // Dependency
320 map_ptrloc NextRevDepends
; // Dependency
321 map_ptrloc ParentVer
; // Version
323 // Specific types of depends
326 unsigned char CompareOp
;
329 struct pkgCache::Provides
/*{{{*/
331 map_ptrloc ParentPkg
; // Pacakge
332 map_ptrloc Version
; // Version
333 map_ptrloc ProvideVersion
; // Stringtable
334 map_ptrloc NextProvides
; // Provides
335 map_ptrloc NextPkgProv
; // Provides
338 struct pkgCache::StringItem
/*{{{*/
340 map_ptrloc String
; // Stringtable
341 map_ptrloc NextItem
; // StringItem
344 #include <apt-pkg/cacheiterators.h>
346 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
347 {return PkgIterator(*this);};
348 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
349 {return PkgIterator(*this,PkgP
);};
350 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
351 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
352 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
353 {return PkgFileIterator(*this,PkgFileP
);};
355 // Oh I wish for Real Name Space Support
356 class pkgCache::Namespace
/*{{{*/
360 typedef pkgCache::PkgIterator PkgIterator
;
361 typedef pkgCache::VerIterator VerIterator
;
362 typedef pkgCache::TagIterator TagIterator
;
363 typedef pkgCache::DescIterator DescIterator
;
364 typedef pkgCache::DepIterator DepIterator
;
365 typedef pkgCache::PrvIterator PrvIterator
;
366 typedef pkgCache::PkgFileIterator PkgFileIterator
;
367 typedef pkgCache::VerFileIterator VerFileIterator
;
368 typedef pkgCache::Version Version
;
369 typedef pkgCache::Description Description
;
370 typedef pkgCache::Package Package
;
371 typedef pkgCache::Header Header
;
372 typedef pkgCache::Dep Dep
;
373 typedef pkgCache::Flag Flag
;