1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcache.h,v 1.15 1998/12/14 08:07:29 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 // Header section: pkglib
20 #ifndef PKGLIB_PKGCACHE_H
21 #define PKGLIB_PKGCACHE_H
24 #pragma interface "apt-pkg/pkgcache.h"
29 #include <apt-pkg/mmap.h>
31 /* This should be a 32 bit type, larger tyes use too much ram and smaller
32 types are too small. Where ever possible 'unsigned long' should be used
33 instead of this internal type */
34 typedef unsigned int __apt_ptrloc
;
39 // Cache element predeclarations
54 class PkgFileIterator
;
55 class VerFileIterator
;
60 friend PkgFileIterator
;
61 friend VerFileIterator
;
63 // These are all the constants used in the cache structures
66 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
67 Conflicts
=5,Replaces
=6};
68 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
69 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
74 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
75 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
76 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
77 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
78 UnInstalled
=3,HalfInstalled
=4,ConfigFiles
=5,Installed
=6};
83 enum PkgFlags
{Auto
=(1<<0),New
=(1<<1),Obsolete
=(1<<2),Essential
=(1<<3),
84 ImmediateConf
=(1<<4)};
85 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
90 // Memory mapped cache file
94 static unsigned long sHash(string S
);
95 static unsigned long sHash(const char *S
);
99 // Pointers to the arrays of items
103 PackageFile
*PkgFileP
;
107 StringItem
*StringItemP
;
110 virtual bool ReMap();
111 inline bool Sync() {return Map
.Sync();};
112 inline MMap
&GetMap() {return Map
;};
114 // String hashing function (512 range)
115 inline unsigned long Hash(string S
) const {return sHash(S
);};
116 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
118 // Usefull transformation things
119 const char *Priority(unsigned char Priority
);
122 PkgIterator
FindPkg(string Name
);
123 Header
&Head() {return *HeaderP
;};
124 inline PkgIterator
PkgBegin();
125 inline PkgIterator
PkgEnd();
126 inline PkgFileIterator
FileBegin();
127 inline PkgFileIterator
FileEnd();
130 virtual ~pkgCache() {};
134 struct pkgCache::Header
136 // Signature information
137 unsigned long Signature
;
142 // Size of structure values
143 unsigned short HeaderSz
;
144 unsigned short PackageSz
;
145 unsigned short PackageFileSz
;
146 unsigned short VersionSz
;
147 unsigned short DependencySz
;
148 unsigned short ProvidesSz
;
149 unsigned short VerFileSz
;
152 unsigned long PackageCount
;
153 unsigned long VersionCount
;
154 unsigned long DependsCount
;
155 unsigned long PackageFileCount
;
156 unsigned long VerFileCount
;
157 unsigned long ProvidesCount
;
160 __apt_ptrloc FileList
; // struct PackageFile
161 __apt_ptrloc StringList
; // struct StringItem
162 unsigned long MaxVerFileSize
;
164 /* Allocation pools, there should be one of these for each structure
165 excluding the header */
166 DynamicMMap::Pool Pools
[7];
168 // Rapid package name lookup
169 __apt_ptrloc HashTable
[2048];
171 bool CheckSizes(Header
&Against
) const;
175 struct pkgCache::Package
178 __apt_ptrloc Name
; // Stringtable
179 __apt_ptrloc VersionList
; // Version
180 __apt_ptrloc TargetVer
; // Version
181 __apt_ptrloc CurrentVer
; // Version
182 __apt_ptrloc TargetDist
; // StringTable (StringItem)
183 __apt_ptrloc Section
; // StringTable (StringItem)
186 __apt_ptrloc NextPackage
; // Package
187 __apt_ptrloc RevDepends
; // Dependency
188 __apt_ptrloc ProvidesList
; // Provides
190 // Install/Remove/Purge etc
191 unsigned char SelectedState
; // What
192 unsigned char InstState
; // Flags
193 unsigned char CurrentState
; // State
199 struct pkgCache::PackageFile
202 __apt_ptrloc FileName
; // Stringtable
203 __apt_ptrloc Archive
; // Stringtable
204 __apt_ptrloc Component
; // Stringtable
205 __apt_ptrloc Version
; // Stringtable
206 __apt_ptrloc Origin
; // Stringtable
207 __apt_ptrloc Label
; // Stringtable
208 __apt_ptrloc Architecture
; // Stringtable
213 __apt_ptrloc NextFile
; // PackageFile
215 time_t mtime
; // Modification time for the file
218 struct pkgCache::VerFile
220 __apt_ptrloc File
; // PackageFile
221 __apt_ptrloc NextFile
; // PkgVerFile
222 __apt_ptrloc Offset
; // File offset
226 struct pkgCache::Version
228 __apt_ptrloc VerStr
; // Stringtable
229 __apt_ptrloc Section
; // StringTable (StringItem)
232 __apt_ptrloc FileList
; // VerFile
233 __apt_ptrloc NextVer
; // Version
234 __apt_ptrloc DependsList
; // Dependency
235 __apt_ptrloc ParentPkg
; // Package
236 __apt_ptrloc ProvidesList
; // Provides
238 __apt_ptrloc Size
; // These are the .deb size
239 __apt_ptrloc InstalledSize
;
241 unsigned char Priority
;
244 struct pkgCache::Dependency
246 __apt_ptrloc Version
; // Stringtable
247 __apt_ptrloc Package
; // Package
248 __apt_ptrloc NextDepends
; // Dependency
249 __apt_ptrloc NextRevDepends
; // Dependency
250 __apt_ptrloc ParentVer
; // Version
252 // Specific types of depends
254 unsigned char CompareOp
;
258 struct pkgCache::Provides
260 __apt_ptrloc ParentPkg
; // Pacakge
261 __apt_ptrloc Version
; // Version
262 __apt_ptrloc ProvideVersion
; // Stringtable
263 __apt_ptrloc NextProvides
; // Provides
264 __apt_ptrloc NextPkgProv
; // Provides
267 struct pkgCache::StringItem
269 __apt_ptrloc String
; // Stringtable
270 __apt_ptrloc NextItem
; // StringItem
273 #include <apt-pkg/cacheiterators.h>
275 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
276 {return PkgIterator(*this);};
277 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
278 {return PkgIterator(*this,PkgP
);};
279 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
280 {return PkgFileIterator(*this);};
281 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
282 {return PkgFileIterator(*this,PkgFileP
);};