1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcache.h,v 1.22 1999/07/30 02:54:25 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>
34 // Cache element predeclarations
49 class PkgFileIterator
;
50 class VerFileIterator
;
55 friend PkgFileIterator
;
56 friend VerFileIterator
;
58 // These are all the constants used in the cache structures
61 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
62 Conflicts
=5,Replaces
=6};
63 enum DepCompareOp
{Or
=0x10,NoOp
=0,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
64 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
69 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=4,Extra
=5};
70 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
71 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
72 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
73 HalfInstalled
=4,ConfigFiles
=5,Installed
=6};
78 enum PkgFlags
{Auto
=(1<<0),Essential
=(1<<3),Important
=(1<<4)};
79 enum PkgFFlags
{NotSource
=(1<<0),NotAutomatic
=(1<<1)};
84 // Memory mapped cache file
88 unsigned long sHash(string S
) const;
89 unsigned long sHash(const char *S
) const;
93 // Pointers to the arrays of items
97 PackageFile
*PkgFileP
;
101 StringItem
*StringItemP
;
104 virtual bool ReMap();
105 inline bool Sync() {return Map
.Sync();};
106 inline MMap
&GetMap() {return Map
;};
108 // String hashing function (512 range)
109 inline unsigned long Hash(string S
) const {return sHash(S
);};
110 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
112 // Usefull transformation things
113 const char *Priority(unsigned char Priority
);
116 PkgIterator
FindPkg(string Name
);
117 Header
&Head() {return *HeaderP
;};
118 inline PkgIterator
PkgBegin();
119 inline PkgIterator
PkgEnd();
120 inline PkgFileIterator
FileBegin();
121 inline PkgFileIterator
FileEnd();
122 VerIterator
GetCandidateVer(PkgIterator Pkg
,bool AllowCurrent
= true);
125 virtual ~pkgCache() {};
129 struct pkgCache::Header
131 // Signature information
132 unsigned long Signature
;
137 // Size of structure values
138 unsigned short HeaderSz
;
139 unsigned short PackageSz
;
140 unsigned short PackageFileSz
;
141 unsigned short VersionSz
;
142 unsigned short DependencySz
;
143 unsigned short ProvidesSz
;
144 unsigned short VerFileSz
;
147 unsigned long PackageCount
;
148 unsigned long VersionCount
;
149 unsigned long DependsCount
;
150 unsigned long PackageFileCount
;
151 unsigned long VerFileCount
;
152 unsigned long ProvidesCount
;
155 map_ptrloc FileList
; // struct PackageFile
156 map_ptrloc StringList
; // struct StringItem
157 unsigned long MaxVerFileSize
;
159 /* Allocation pools, there should be one of these for each structure
160 excluding the header */
161 DynamicMMap::Pool Pools
[7];
163 // Rapid package name lookup
164 map_ptrloc HashTable
[2*1048];
166 bool CheckSizes(Header
&Against
) const;
170 struct pkgCache::Package
173 map_ptrloc Name
; // Stringtable
174 map_ptrloc VersionList
; // Version
175 map_ptrloc TargetVer
; // Version
176 map_ptrloc CurrentVer
; // Version
177 map_ptrloc TargetDist
; // StringTable (StringItem)
178 map_ptrloc Section
; // StringTable (StringItem)
181 map_ptrloc NextPackage
; // Package
182 map_ptrloc RevDepends
; // Dependency
183 map_ptrloc ProvidesList
; // Provides
185 // Install/Remove/Purge etc
186 unsigned char SelectedState
; // What
187 unsigned char InstState
; // Flags
188 unsigned char CurrentState
; // State
194 struct pkgCache::PackageFile
197 map_ptrloc FileName
; // Stringtable
198 map_ptrloc Archive
; // Stringtable
199 map_ptrloc Component
; // Stringtable
200 map_ptrloc Version
; // Stringtable
201 map_ptrloc Origin
; // Stringtable
202 map_ptrloc Label
; // Stringtable
203 map_ptrloc Architecture
; // Stringtable
208 map_ptrloc NextFile
; // PackageFile
210 time_t mtime
; // Modification time for the file
213 struct pkgCache::VerFile
215 map_ptrloc File
; // PackageFile
216 map_ptrloc NextFile
; // PkgVerFile
217 map_ptrloc Offset
; // File offset
221 struct pkgCache::Version
223 map_ptrloc VerStr
; // Stringtable
224 map_ptrloc Section
; // StringTable (StringItem)
225 map_ptrloc Arch
; // StringTable
228 map_ptrloc FileList
; // VerFile
229 map_ptrloc NextVer
; // Version
230 map_ptrloc DependsList
; // Dependency
231 map_ptrloc ParentPkg
; // Package
232 map_ptrloc ProvidesList
; // Provides
234 map_ptrloc Size
; // These are the .deb size
235 map_ptrloc InstalledSize
;
238 unsigned char Priority
;
241 struct pkgCache::Dependency
243 map_ptrloc Version
; // Stringtable
244 map_ptrloc Package
; // Package
245 map_ptrloc NextDepends
; // Dependency
246 map_ptrloc NextRevDepends
; // Dependency
247 map_ptrloc ParentVer
; // Version
249 // Specific types of depends
251 unsigned char CompareOp
;
255 struct pkgCache::Provides
257 map_ptrloc ParentPkg
; // Pacakge
258 map_ptrloc Version
; // Version
259 map_ptrloc ProvideVersion
; // Stringtable
260 map_ptrloc NextProvides
; // Provides
261 map_ptrloc NextPkgProv
; // Provides
264 struct pkgCache::StringItem
266 map_ptrloc String
; // Stringtable
267 map_ptrloc NextItem
; // StringItem
270 #include <apt-pkg/cacheiterators.h>
272 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
273 {return PkgIterator(*this);};
274 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
275 {return PkgIterator(*this,PkgP
);};
276 inline pkgCache::PkgFileIterator
pkgCache::FileBegin()
277 {return PkgFileIterator(*this);};
278 inline pkgCache::PkgFileIterator
pkgCache::FileEnd()
279 {return PkgFileIterator(*this,PkgFileP
);};