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
;
33 // Cache element predeclarations
48 class PkgFileIterator
;
49 class VerFileIterator
;
50 friend class PkgIterator
;
51 friend class VerIterator
;
52 friend class DepIterator
;
53 friend class PrvIterator
;
54 friend class PkgFileIterator
;
55 friend class VerFileIterator
;
59 // These are all the constants used in the cache structures
62 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
63 Conflicts
=5,Replaces
=6,Obsoletes
=7};
64 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
65 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
70 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
71 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
72 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
73 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
74 HalfInstalled
=4,ConfigFiles
=5,Installed
=6};
79 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
80 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
85 // Memory mapped cache file
89 unsigned long sHash(const string
&S
) const;
90 unsigned long sHash(const char *S
) const;
94 // Pointers to the arrays of items
98 PackageFile
*PkgFileP
;
102 StringItem
*StringItemP
;
105 virtual bool ReMap();
106 inline bool Sync() {return Map
.Sync();};
107 inline MMap
&GetMap() {return Map
;};
108 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
110 // String hashing function (512 range)
111 inline unsigned long Hash(const string
&S
) const {return sHash(S
);};
112 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
114 // Usefull transformation things
115 const char *Priority(unsigned char Priority
);
118 PkgIterator
FindPkg(const string
&Name
);
119 Header
&Head() {return *HeaderP
;};
120 inline PkgIterator
PkgBegin();
121 inline PkgIterator
PkgEnd();
122 inline PkgFileIterator
FileBegin();
123 inline PkgFileIterator
FileEnd();
125 // Make me a function
126 pkgVersioningSystem
*VS
;
129 static const char *CompTypeDeb(unsigned char Comp
);
130 static const char *CompType(unsigned char Comp
);
131 static const char *DepType(unsigned char Dep
);
133 pkgCache(MMap
*Map
,bool DoMap
= true);
134 virtual ~pkgCache() {};
138 struct pkgCache::Header
140 // Signature information
141 unsigned long Signature
;
146 // Size of structure values
147 unsigned short HeaderSz
;
148 unsigned short PackageSz
;
149 unsigned short PackageFileSz
;
150 unsigned short VersionSz
;
151 unsigned short DependencySz
;
152 unsigned short ProvidesSz
;
153 unsigned short VerFileSz
;
156 unsigned long PackageCount
;
157 unsigned long VersionCount
;
158 unsigned long DependsCount
;
159 unsigned long PackageFileCount
;
160 unsigned long VerFileCount
;
161 unsigned long ProvidesCount
;
164 map_ptrloc FileList
; // struct PackageFile
165 map_ptrloc StringList
; // struct StringItem
166 map_ptrloc VerSysName
; // StringTable
167 map_ptrloc Architecture
; // StringTable
168 unsigned long MaxVerFileSize
;
170 /* Allocation pools, there should be one of these for each structure
171 excluding the header */
172 DynamicMMap::Pool Pools
[7];
174 // Rapid package name lookup
175 map_ptrloc HashTable
[2*1048];
177 bool CheckSizes(Header
&Against
) const;
181 struct pkgCache::Package
184 map_ptrloc Name
; // Stringtable
185 map_ptrloc VersionList
; // Version
186 map_ptrloc CurrentVer
; // Version
187 map_ptrloc Section
; // StringTable (StringItem)
190 map_ptrloc NextPackage
; // Package
191 map_ptrloc RevDepends
; // Dependency
192 map_ptrloc ProvidesList
; // Provides
194 // Install/Remove/Purge etc
195 unsigned char SelectedState
; // What
196 unsigned char InstState
; // Flags
197 unsigned char CurrentState
; // State
203 struct pkgCache::PackageFile
206 map_ptrloc FileName
; // Stringtable
207 map_ptrloc Archive
; // Stringtable
208 map_ptrloc Component
; // Stringtable
209 map_ptrloc Version
; // Stringtable
210 map_ptrloc Origin
; // Stringtable
211 map_ptrloc Label
; // Stringtable
212 map_ptrloc Architecture
; // Stringtable
213 map_ptrloc Site
; // Stringtable
214 map_ptrloc IndexType
; // Stringtable
219 map_ptrloc NextFile
; // PackageFile
221 time_t mtime
; // Modification time for the file
224 struct pkgCache::VerFile
226 map_ptrloc File
; // PackageFile
227 map_ptrloc NextFile
; // PkgVerFile
228 map_ptrloc Offset
; // File offset
232 struct pkgCache::Version
234 map_ptrloc VerStr
; // Stringtable
235 map_ptrloc Section
; // StringTable (StringItem)
236 map_ptrloc Arch
; // StringTable
239 map_ptrloc FileList
; // VerFile
240 map_ptrloc NextVer
; // Version
241 map_ptrloc DependsList
; // Dependency
242 map_ptrloc ParentPkg
; // Package
243 map_ptrloc ProvidesList
; // Provides
245 map_ptrloc Size
; // These are the .deb size
246 map_ptrloc InstalledSize
;
249 unsigned char Priority
;
252 struct pkgCache::Dependency
254 map_ptrloc Version
; // Stringtable
255 map_ptrloc Package
; // Package
256 map_ptrloc NextDepends
; // Dependency
257 map_ptrloc NextRevDepends
; // Dependency
258 map_ptrloc ParentVer
; // Version
260 // Specific types of depends
263 unsigned char CompareOp
;
266 struct pkgCache::Provides
268 map_ptrloc ParentPkg
; // Pacakge
269 map_ptrloc Version
; // Version
270 map_ptrloc ProvideVersion
; // Stringtable
271 map_ptrloc NextProvides
; // Provides
272 map_ptrloc NextPkgProv
; // Provides
275 struct pkgCache::StringItem
277 map_ptrloc String
; // Stringtable
278 map_ptrloc NextItem
; // StringItem
281 #include <apt-pkg/cacheiterators.h>
283 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
284 {return PkgIterator(*this);};
285 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
286 {return PkgIterator(*this,PkgP
);};
287 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
288 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
289 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
290 {return PkgFileIterator(*this,PkgFileP
);};
292 // Oh I wish for Real Name Space Support
293 class pkgCache::Namespace
297 typedef pkgCache::PkgIterator PkgIterator
;
298 typedef pkgCache::VerIterator VerIterator
;
299 typedef pkgCache::DepIterator DepIterator
;
300 typedef pkgCache::PrvIterator PrvIterator
;
301 typedef pkgCache::PkgFileIterator PkgFileIterator
;
302 typedef pkgCache::VerFileIterator VerFileIterator
;
303 typedef pkgCache::Version Version
;
304 typedef pkgCache::Package Package
;
305 typedef pkgCache::Header Header
;
306 typedef pkgCache::Dep Dep
;
307 typedef pkgCache::Flag Flag
;