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
23 #pragma interface "apt-pkg/pkgcache.h"
28 #include <apt-pkg/mmap.h>
32 class pkgVersioningSystem
;
36 // Cache element predeclarations
51 class PkgFileIterator
;
52 class VerFileIterator
;
53 friend class PkgIterator
;
54 friend class VerIterator
;
55 friend class DepIterator
;
56 friend class PrvIterator
;
57 friend class PkgFileIterator
;
58 friend class VerFileIterator
;
62 // These are all the constants used in the cache structures
65 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
66 Conflicts
=5,Replaces
=6,Obsoletes
=7};
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};
82 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
83 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
88 // Memory mapped cache file
92 unsigned long sHash(const string
&S
) const;
93 unsigned long sHash(const char *S
) const;
97 // Pointers to the arrays of items
101 PackageFile
*PkgFileP
;
105 StringItem
*StringItemP
;
108 virtual bool ReMap();
109 inline bool Sync() {return Map
.Sync();};
110 inline MMap
&GetMap() {return Map
;};
111 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
113 // String hashing function (512 range)
114 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
115 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
117 // Usefull transformation things
118 const char *Priority(unsigned char Priority
);
121 PkgIterator
FindPkg(const string
&Name
);
122 Header
&Head() {return *HeaderP
;};
123 inline PkgIterator
PkgBegin();
124 inline PkgIterator
PkgEnd();
125 inline PkgFileIterator
FileBegin();
126 inline PkgFileIterator
FileEnd();
128 // Make me a function
129 pkgVersioningSystem
*VS
;
132 static const char *CompTypeDeb(unsigned char Comp
);
133 static const char *CompType(unsigned char Comp
);
134 static const char *DepType(unsigned char Dep
);
136 pkgCache(MMap
*Map
,bool DoMap
= true);
137 virtual ~pkgCache() {};
141 struct pkgCache::Header
143 // Signature information
144 unsigned long Signature
;
149 // Size of structure values
150 unsigned short HeaderSz
;
151 unsigned short PackageSz
;
152 unsigned short PackageFileSz
;
153 unsigned short VersionSz
;
154 unsigned short DependencySz
;
155 unsigned short ProvidesSz
;
156 unsigned short VerFileSz
;
159 unsigned long PackageCount
;
160 unsigned long VersionCount
;
161 unsigned long DependsCount
;
162 unsigned long PackageFileCount
;
163 unsigned long VerFileCount
;
164 unsigned long ProvidesCount
;
167 map_ptrloc FileList
; // struct PackageFile
168 map_ptrloc StringList
; // struct StringItem
169 map_ptrloc VerSysName
; // StringTable
170 map_ptrloc Architecture
; // StringTable
171 unsigned long MaxVerFileSize
;
173 /* Allocation pools, there should be one of these for each structure
174 excluding the header */
175 DynamicMMap::Pool Pools
[7];
177 // Rapid package name lookup
178 map_ptrloc HashTable
[2*1048];
180 bool CheckSizes(Header
&Against
) const;
184 struct pkgCache::Package
187 map_ptrloc Name
; // Stringtable
188 map_ptrloc VersionList
; // Version
189 map_ptrloc CurrentVer
; // Version
190 map_ptrloc Section
; // StringTable (StringItem)
193 map_ptrloc NextPackage
; // Package
194 map_ptrloc RevDepends
; // Dependency
195 map_ptrloc ProvidesList
; // Provides
197 // Install/Remove/Purge etc
198 unsigned char SelectedState
; // What
199 unsigned char InstState
; // Flags
200 unsigned char CurrentState
; // State
206 struct pkgCache::PackageFile
209 map_ptrloc FileName
; // Stringtable
210 map_ptrloc Archive
; // Stringtable
211 map_ptrloc Component
; // Stringtable
212 map_ptrloc Version
; // Stringtable
213 map_ptrloc Origin
; // Stringtable
214 map_ptrloc Label
; // Stringtable
215 map_ptrloc Architecture
; // Stringtable
216 map_ptrloc Site
; // Stringtable
217 map_ptrloc IndexType
; // Stringtable
222 map_ptrloc NextFile
; // PackageFile
224 time_t mtime
; // Modification time for the file
227 struct pkgCache::VerFile
229 map_ptrloc File
; // PackageFile
230 map_ptrloc NextFile
; // PkgVerFile
231 map_ptrloc Offset
; // File offset
235 struct pkgCache::Version
237 map_ptrloc VerStr
; // Stringtable
238 map_ptrloc Section
; // StringTable (StringItem)
239 map_ptrloc Arch
; // StringTable
242 map_ptrloc FileList
; // VerFile
243 map_ptrloc NextVer
; // Version
244 map_ptrloc DependsList
; // Dependency
245 map_ptrloc ParentPkg
; // Package
246 map_ptrloc ProvidesList
; // Provides
248 map_ptrloc Size
; // These are the .deb size
249 map_ptrloc InstalledSize
;
252 unsigned char Priority
;
255 struct pkgCache::Dependency
257 map_ptrloc Version
; // Stringtable
258 map_ptrloc Package
; // Package
259 map_ptrloc NextDepends
; // Dependency
260 map_ptrloc NextRevDepends
; // Dependency
261 map_ptrloc ParentVer
; // Version
263 // Specific types of depends
266 unsigned char CompareOp
;
269 struct pkgCache::Provides
271 map_ptrloc ParentPkg
; // Pacakge
272 map_ptrloc Version
; // Version
273 map_ptrloc ProvideVersion
; // Stringtable
274 map_ptrloc NextProvides
; // Provides
275 map_ptrloc NextPkgProv
; // Provides
278 struct pkgCache::StringItem
280 map_ptrloc String
; // Stringtable
281 map_ptrloc NextItem
; // StringItem
284 #include <apt-pkg/cacheiterators.h>
286 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
287 {return PkgIterator(*this);};
288 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
289 {return PkgIterator(*this,PkgP
);};
290 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
291 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
292 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
293 {return PkgFileIterator(*this,PkgFileP
);};
295 // Oh I wish for Real Name Space Support
296 class pkgCache::Namespace
300 typedef pkgCache::PkgIterator PkgIterator
;
301 typedef pkgCache::VerIterator VerIterator
;
302 typedef pkgCache::DepIterator DepIterator
;
303 typedef pkgCache::PrvIterator PrvIterator
;
304 typedef pkgCache::PkgFileIterator PkgFileIterator
;
305 typedef pkgCache::VerFileIterator VerFileIterator
;
306 typedef pkgCache::Version Version
;
307 typedef pkgCache::Package Package
;
308 typedef pkgCache::Header Header
;
309 typedef pkgCache::Dep Dep
;
310 typedef pkgCache::Flag Flag
;