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
46 template<typename Str
, typename Itr
> class Iterator
;
52 class PkgFileIterator
;
53 class VerFileIterator
;
54 class DescFileIterator
;
58 // These are all the constants used in the cache structures
60 // WARNING - if you change these lists you must also edit
61 // the stringification in pkgcache.cc and also consider whether
62 // the cache file will become incompatible.
65 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
66 Conflicts
=5,Replaces
=6,Obsoletes
=7,DpkgBreaks
=8,Enhances
=9};
67 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
68 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
73 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
74 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
75 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
76 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
77 HalfInstalled
=4,ConfigFiles
=5,Installed
=6,
78 TriggersAwaited
=7,TriggersPending
=8};
83 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
84 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
89 // Memory mapped cache file
93 unsigned long sHash(const string
&S
) const;
94 unsigned long sHash(const char *S
) const;
98 // Pointers to the arrays of items
103 PackageFile
*PkgFileP
;
108 StringItem
*StringItemP
;
111 virtual bool ReMap();
112 inline bool Sync() {return Map
.Sync();};
113 inline MMap
&GetMap() {return Map
;};
114 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
116 // String hashing function (512 range)
117 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
118 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
120 // Usefull transformation things
121 const char *Priority(unsigned char Priority
);
124 PkgIterator
FindPkg(const string
&Name
);
125 Header
&Head() {return *HeaderP
;};
126 inline PkgIterator
PkgBegin();
127 inline PkgIterator
PkgEnd();
128 inline PkgFileIterator
FileBegin();
129 inline PkgFileIterator
FileEnd();
131 // Make me a function
132 pkgVersioningSystem
*VS
;
135 static const char *CompTypeDeb(unsigned char Comp
);
136 static const char *CompType(unsigned char Comp
);
137 static const char *DepType(unsigned char Dep
);
139 pkgCache(MMap
*Map
,bool DoMap
= true);
140 virtual ~pkgCache() {};
143 // Header structure /*{{{*/
144 struct pkgCache::Header
146 // Signature information
147 unsigned long Signature
;
152 // Size of structure values
153 unsigned short HeaderSz
;
154 unsigned short PackageSz
;
155 unsigned short PackageFileSz
;
156 unsigned short VersionSz
;
157 unsigned short DescriptionSz
;
158 unsigned short DependencySz
;
159 unsigned short ProvidesSz
;
160 unsigned short VerFileSz
;
161 unsigned short DescFileSz
;
164 unsigned long PackageCount
;
165 unsigned long VersionCount
;
166 unsigned long DescriptionCount
;
167 unsigned long DependsCount
;
168 unsigned long PackageFileCount
;
169 unsigned long VerFileCount
;
170 unsigned long DescFileCount
;
171 unsigned long ProvidesCount
;
174 map_ptrloc FileList
; // struct PackageFile
175 map_ptrloc StringList
; // struct StringItem
176 map_ptrloc VerSysName
; // StringTable
177 map_ptrloc Architecture
; // StringTable
178 unsigned long MaxVerFileSize
;
179 unsigned long MaxDescFileSize
;
181 /* Allocation pools, there should be one of these for each structure
182 excluding the header */
183 DynamicMMap::Pool Pools
[8];
185 // Rapid package name lookup
186 map_ptrloc HashTable
[2*1048];
188 bool CheckSizes(Header
&Against
) const;
192 struct pkgCache::Package
/*{{{*/
195 map_ptrloc Name
; // Stringtable
196 map_ptrloc VersionList
; // Version
197 map_ptrloc CurrentVer
; // Version
198 map_ptrloc Section
; // StringTable (StringItem)
201 map_ptrloc NextPackage
; // Package
202 map_ptrloc RevDepends
; // Dependency
203 map_ptrloc ProvidesList
; // Provides
205 // Install/Remove/Purge etc
206 unsigned char SelectedState
; // What
207 unsigned char InstState
; // Flags
208 unsigned char CurrentState
; // State
214 struct pkgCache::PackageFile
/*{{{*/
217 map_ptrloc FileName
; // Stringtable
218 map_ptrloc Archive
; // Stringtable
219 map_ptrloc Codename
; // Stringtable
220 map_ptrloc Component
; // Stringtable
221 map_ptrloc Version
; // Stringtable
222 map_ptrloc Origin
; // Stringtable
223 map_ptrloc Label
; // Stringtable
224 map_ptrloc Architecture
; // Stringtable
225 map_ptrloc Site
; // Stringtable
226 map_ptrloc IndexType
; // Stringtable
231 map_ptrloc NextFile
; // PackageFile
233 time_t mtime
; // Modification time for the file
236 struct pkgCache::VerFile
/*{{{*/
238 map_ptrloc File
; // PackageFile
239 map_ptrloc NextFile
; // PkgVerFile
240 map_ptrloc Offset
; // File offset
244 struct pkgCache::DescFile
/*{{{*/
246 map_ptrloc File
; // PackageFile
247 map_ptrloc NextFile
; // PkgVerFile
248 map_ptrloc Offset
; // File offset
252 struct pkgCache::Version
/*{{{*/
254 map_ptrloc VerStr
; // Stringtable
255 map_ptrloc Section
; // StringTable (StringItem)
256 map_ptrloc Arch
; // StringTable
259 map_ptrloc FileList
; // VerFile
260 map_ptrloc NextVer
; // Version
261 map_ptrloc DescriptionList
; // Description
262 map_ptrloc DependsList
; // Dependency
263 map_ptrloc ParentPkg
; // Package
264 map_ptrloc ProvidesList
; // Provides
266 map_ptrloc Size
; // These are the .deb size
267 map_ptrloc InstalledSize
;
270 unsigned char Priority
;
273 struct pkgCache::Description
/*{{{*/
275 // Language Code store the description translation language code. If
276 // the value has a 0 lenght then this is readed using the Package
277 // file else the Translation-CODE are used.
278 map_ptrloc language_code
; // StringTable
279 map_ptrloc md5sum
; // StringTable
282 map_ptrloc FileList
; // DescFile
283 map_ptrloc NextDesc
; // Description
284 map_ptrloc ParentPkg
; // Package
289 struct pkgCache::Dependency
/*{{{*/
291 map_ptrloc Version
; // Stringtable
292 map_ptrloc Package
; // Package
293 map_ptrloc NextDepends
; // Dependency
294 map_ptrloc NextRevDepends
; // Dependency
295 map_ptrloc ParentVer
; // Version
297 // Specific types of depends
300 unsigned char CompareOp
;
303 struct pkgCache::Provides
/*{{{*/
305 map_ptrloc ParentPkg
; // Pacakge
306 map_ptrloc Version
; // Version
307 map_ptrloc ProvideVersion
; // Stringtable
308 map_ptrloc NextProvides
; // Provides
309 map_ptrloc NextPkgProv
; // Provides
312 struct pkgCache::StringItem
/*{{{*/
314 map_ptrloc String
; // Stringtable
315 map_ptrloc NextItem
; // StringItem
318 #include <apt-pkg/cacheiterators.h>
320 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
321 {return PkgIterator(*this);};
322 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
323 {return PkgIterator(*this,PkgP
);};
324 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
325 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
326 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
327 {return PkgFileIterator(*this,PkgFileP
);};
329 // Oh I wish for Real Name Space Support
330 class pkgCache::Namespace
/*{{{*/
334 typedef pkgCache::PkgIterator PkgIterator
;
335 typedef pkgCache::VerIterator VerIterator
;
336 typedef pkgCache::DescIterator DescIterator
;
337 typedef pkgCache::DepIterator DepIterator
;
338 typedef pkgCache::PrvIterator PrvIterator
;
339 typedef pkgCache::PkgFileIterator PkgFileIterator
;
340 typedef pkgCache::VerFileIterator VerFileIterator
;
341 typedef pkgCache::Version Version
;
342 typedef pkgCache::Description Description
;
343 typedef pkgCache::Package Package
;
344 typedef pkgCache::Header Header
;
345 typedef pkgCache::Dep Dep
;
346 typedef pkgCache::Flag Flag
;