1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcache.h,v 1.23 2001/02/20 07:03:17 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>
30 class pkgVersioningSystem
;
34 // Cache element predeclarations
49 class PkgFileIterator
;
50 class VerFileIterator
;
51 friend class PkgIterator
;
52 friend class VerIterator
;
53 friend class DepIterator
;
54 friend class PrvIterator
;
55 friend class PkgFileIterator
;
56 friend class VerFileIterator
;
60 // These are all the constants used in the cache structures
63 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
64 Conflicts
=5,Replaces
=6,Obsoletes
=7};
65 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
66 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
71 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
72 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
73 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
74 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
75 HalfInstalled
=4,ConfigFiles
=5,Installed
=6};
80 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
81 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
86 // Memory mapped cache file
90 unsigned long sHash(string S
) const;
91 unsigned long sHash(const char *S
) const;
95 // Pointers to the arrays of items
99 PackageFile
*PkgFileP
;
103 StringItem
*StringItemP
;
106 virtual bool ReMap();
107 inline bool Sync() {return Map
.Sync();};
108 inline MMap
&GetMap() {return Map
;};
109 inline void *DataEnd() {return ((unsigned char *)Map
.Data()) + Map
.Size();};
111 // String hashing function (512 range)
112 inline unsigned long Hash(string S
) const {return sHash(S
);};
113 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
115 // Usefull transformation things
116 const char *Priority(unsigned char Priority
);
119 PkgIterator
FindPkg(string Name
);
120 Header
&Head() {return *HeaderP
;};
121 inline PkgIterator
PkgBegin();
122 inline PkgIterator
PkgEnd();
123 inline PkgFileIterator
FileBegin();
124 inline PkgFileIterator
FileEnd();
126 // Make me a function
127 pkgVersioningSystem
*VS
;
130 static const char *CompTypeDeb(unsigned char Comp
);
131 static const char *CompType(unsigned char Comp
);
132 static const char *DepType(unsigned char Dep
);
134 pkgCache(MMap
*Map
,bool DoMap
= true);
135 virtual ~pkgCache() {};
139 struct pkgCache::Header
141 // Signature information
142 unsigned long Signature
;
147 // Size of structure values
148 unsigned short HeaderSz
;
149 unsigned short PackageSz
;
150 unsigned short PackageFileSz
;
151 unsigned short VersionSz
;
152 unsigned short DependencySz
;
153 unsigned short ProvidesSz
;
154 unsigned short VerFileSz
;
157 unsigned long PackageCount
;
158 unsigned long VersionCount
;
159 unsigned long DependsCount
;
160 unsigned long PackageFileCount
;
161 unsigned long VerFileCount
;
162 unsigned long ProvidesCount
;
165 map_ptrloc FileList
; // struct PackageFile
166 map_ptrloc StringList
; // struct StringItem
167 map_ptrloc VerSysName
; // StringTable
168 map_ptrloc Architecture
; // StringTable
169 unsigned long MaxVerFileSize
;
171 /* Allocation pools, there should be one of these for each structure
172 excluding the header */
173 DynamicMMap::Pool Pools
[7];
175 // Rapid package name lookup
176 map_ptrloc HashTable
[2*1048];
178 bool CheckSizes(Header
&Against
) const;
182 struct pkgCache::Package
185 map_ptrloc Name
; // Stringtable
186 map_ptrloc VersionList
; // Version
187 map_ptrloc CurrentVer
; // Version
188 map_ptrloc Section
; // StringTable (StringItem)
191 map_ptrloc NextPackage
; // Package
192 map_ptrloc RevDepends
; // Dependency
193 map_ptrloc ProvidesList
; // Provides
195 // Install/Remove/Purge etc
196 unsigned char SelectedState
; // What
197 unsigned char InstState
; // Flags
198 unsigned char CurrentState
; // State
204 struct pkgCache::PackageFile
207 map_ptrloc FileName
; // Stringtable
208 map_ptrloc Archive
; // Stringtable
209 map_ptrloc Component
; // Stringtable
210 map_ptrloc Version
; // Stringtable
211 map_ptrloc Origin
; // Stringtable
212 map_ptrloc Label
; // Stringtable
213 map_ptrloc Architecture
; // Stringtable
214 map_ptrloc Site
; // Stringtable
215 map_ptrloc IndexType
; // Stringtable
220 map_ptrloc NextFile
; // PackageFile
222 time_t mtime
; // Modification time for the file
225 struct pkgCache::VerFile
227 map_ptrloc File
; // PackageFile
228 map_ptrloc NextFile
; // PkgVerFile
229 map_ptrloc Offset
; // File offset
233 struct pkgCache::Version
235 map_ptrloc VerStr
; // Stringtable
236 map_ptrloc Section
; // StringTable (StringItem)
237 map_ptrloc Arch
; // StringTable
240 map_ptrloc FileList
; // VerFile
241 map_ptrloc NextVer
; // Version
242 map_ptrloc DependsList
; // Dependency
243 map_ptrloc ParentPkg
; // Package
244 map_ptrloc ProvidesList
; // Provides
246 map_ptrloc Size
; // These are the .deb size
247 map_ptrloc InstalledSize
;
250 unsigned char Priority
;
253 struct pkgCache::Dependency
255 map_ptrloc Version
; // Stringtable
256 map_ptrloc Package
; // Package
257 map_ptrloc NextDepends
; // Dependency
258 map_ptrloc NextRevDepends
; // Dependency
259 map_ptrloc ParentVer
; // Version
261 // Specific types of depends
263 unsigned char CompareOp
;
267 struct pkgCache::Provides
269 map_ptrloc ParentPkg
; // Pacakge
270 map_ptrloc Version
; // Version
271 map_ptrloc ProvideVersion
; // Stringtable
272 map_ptrloc NextProvides
; // Provides
273 map_ptrloc NextPkgProv
; // Provides
276 struct pkgCache::StringItem
278 map_ptrloc String
; // Stringtable
279 map_ptrloc NextItem
; // StringItem
282 #include <apt-pkg/cacheiterators.h>
284 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
285 {return PkgIterator(*this);};
286 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
287 {return PkgIterator(*this,PkgP
);};
288 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
289 {return PkgFileIterator(*this,PkgFileP
+ HeaderP
->FileList
);};
290 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
291 {return PkgFileIterator(*this,PkgFileP
);};
293 // Oh I wish for Real Name Space Support
294 class pkgCache::Namespace
298 typedef pkgCache::PkgIterator PkgIterator
;
299 typedef pkgCache::VerIterator VerIterator
;
300 typedef pkgCache::DepIterator DepIterator
;
301 typedef pkgCache::PrvIterator PrvIterator
;
302 typedef pkgCache::PkgFileIterator PkgFileIterator
;
303 typedef pkgCache::VerFileIterator VerFileIterator
;
304 typedef pkgCache::Version Version
;
305 typedef pkgCache::Package Package
;
306 typedef pkgCache::Header Header
;
307 typedef pkgCache::Dep Dep
;
308 typedef pkgCache::Flag Flag
;