1 // -*- mode: cpp; mode: fold -*-
3 // $Id: pkgcache.h,v 1.3 1998/07/04 22:32:12 jgg Exp $
4 /* ######################################################################
6 Cache - Structure definitions for the cache file
8 Please see doc/pkglib/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
25 #include <pkglib/mmap.h>
30 // Cache element predeclarations
44 class PkgFileIterator
;
49 friend PkgFileIterator
;
51 // These are all the constants used in the cache structures
52 enum DepType
{Depends
=1,PreDepends
=2,Suggests
=3,Recommends
=4,
53 Conflicts
=5,Replaces
=6};
54 enum VerPriority
{Important
=1,Required
=2,Standard
=3,Optional
=5,Extra
=5};
55 enum PkgSelectedState
{Unknown
=0,Install
=1,Hold
=2,DeInstall
=3,Purge
=4};
56 enum PkgFlags
{Auto
=(1<<0),New
=(1<<1),Obsolete
=(1<<2),Essential
=(1<<3),
57 ImmediateConf
=(1<<4)};
58 enum PkgInstState
{Ok
=0,ReInstReq
=1,HoldInst
=2,HoldReInstReq
=3};
59 enum PkgCurrentState
{NotInstalled
=0,UnPacked
=1,HalfConfigured
=2,
60 UnInstalled
=3,HalfInstalled
=4,ConfigFiles
=5,
62 enum PkgFFlags
{NotSource
=(1<<0)};
63 enum DepCompareOp
{Or
=0x10,LessEq
=0x1,GreaterEq
=0x2,Less
=0x3,
64 Greater
=0x4,Equals
=0x5,NotEquals
=0x6};
68 // Memory mapped cache file
75 static unsigned long sHash(string S
);
76 static unsigned long sHash(const char *S
);
80 // Pointers to the arrays of items
83 PackageFile
*PkgFileP
;
87 StringItem
*StringItemP
;
91 inline bool Sync() {return Map
.Sync();};
93 // String hashing function (512 range)
94 inline unsigned long Hash(string S
) const {return sHash(S
);};
95 inline unsigned long Hash(const char *S
) const {return sHash(S
);};
97 // Usefull transformation things
98 const char *Priority(unsigned char Priority
);
101 PkgIterator
FindPkg(string Name
);
102 Header
&Head() {return *HeaderP
;};
103 inline PkgIterator
PkgBegin();
104 inline PkgIterator
PkgEnd();
107 virtual ~pkgCache() {};
111 struct pkgCache::Header
113 // Signature information
114 unsigned long Signature
;
119 // Size of structure values
120 unsigned short HeaderSz
;
121 unsigned short PackageSz
;
122 unsigned short PackageFileSz
;
123 unsigned short VersionSz
;
124 unsigned short DependencySz
;
125 unsigned short ProvidesSz
;
128 unsigned long PackageCount
;
129 unsigned long VersionCount
;
130 unsigned long DependsCount
;
131 unsigned long PackageFileCount
;
134 unsigned long FileList
; // struct PackageFile
135 unsigned long StringList
; // struct StringItem
137 /* Allocation pools, there should be one of these for each structure
138 excluding the header */
139 DynamicMMap::Pool Pools
[6];
141 // Rapid package name lookup
142 unsigned long HashTable
[512];
144 bool CheckSizes(Header
&Against
) const;
148 struct pkgCache::Package
151 unsigned long Name
; // Stringtable
152 unsigned long VersionList
; // Version
153 unsigned long TargetVer
; // Version
154 unsigned long CurrentVer
; // Version
155 unsigned long TargetDist
; // StringTable (StringItem)
156 unsigned long Section
; // StringTable (StringItem)
159 unsigned long NextPackage
; // Package
160 unsigned long RevDepends
; // Dependency
161 unsigned long ProvidesList
; // Provides
163 // Install/Remove/Purge etc
164 unsigned char SelectedState
; // What
165 unsigned char InstState
; // Flags
166 unsigned char CurrentState
; // State
172 struct pkgCache::PackageFile
175 unsigned long FileName
; // Stringtable
176 unsigned long Version
; // Stringtable
177 unsigned long Distribution
; // Stringtable
181 unsigned long NextFile
; // PackageFile
184 time_t mtime
; // Modification time for the file
187 struct pkgCache::Version
189 unsigned long VerStr
; // Stringtable
190 unsigned long File
; // PackageFile
191 unsigned long Section
; // StringTable (StringItem)
194 unsigned long NextVer
; // Version
195 unsigned long DependsList
; // Dependency
196 unsigned long ParentPkg
; // Package
197 unsigned long ProvidesList
; // Provides
199 unsigned long Offset
;
201 unsigned long InstalledSize
;
203 unsigned char Priority
;
206 struct pkgCache::Dependency
208 unsigned long Version
; // Stringtable
209 unsigned long Package
; // Package
210 unsigned long NextDepends
; // Dependency
211 unsigned long NextRevDepends
; // Dependency
212 unsigned long ParentVer
; // Version
214 // Specific types of depends
216 unsigned char CompareOp
;
220 struct pkgCache::Provides
222 unsigned long ParentPkg
; // Pacakge
223 unsigned long Version
; // Version
224 unsigned long ProvideVersion
; // Stringtable
225 unsigned long NextProvides
; // Provides
226 unsigned long NextPkgProv
; // Provides
229 struct pkgCache::StringItem
231 unsigned long String
; // Stringtable
232 unsigned long NextItem
; // StringItem
235 #include <pkglib/cacheiterators.h>
237 inline pkgCache::PkgIterator
pkgCache::PkgBegin()
238 {return PkgIterator(*this);};
239 inline pkgCache::PkgIterator
pkgCache::PkgEnd()
240 {return PkgIterator(*this,PkgP
);};