]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
* merged with apt--main and apt--fixes
[apt.git] / apt-pkg / pkgcache.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
6a3da7a6 3// $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $
578bfd0a
AL
4/* ######################################################################
5
6 Cache - Structure definitions for the cache file
7
094a497d 8 Please see doc/apt-pkg/cache.sgml for a more detailed description of
578bfd0a
AL
9 this format. Also be sure to keep that file up-to-date!!
10
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
13 of the datastructure.
14
15 See pkgcachegen.h for information about generating cache structures.
16
17 ##################################################################### */
18 /*}}}*/
578bfd0a
AL
19#ifndef PKGLIB_PKGCACHE_H
20#define PKGLIB_PKGCACHE_H
21
6c139d6e 22#ifdef __GNUG__
094a497d 23#pragma interface "apt-pkg/pkgcache.h"
6c139d6e
AL
24#endif
25
578bfd0a
AL
26#include <string>
27#include <time.h>
094a497d 28#include <apt-pkg/mmap.h>
0a843901
AL
29
30using std::string;
b2e465d6
AL
31
32class pkgVersioningSystem;
578bfd0a
AL
33class pkgCache
34{
35 public:
36 // Cache element predeclarations
37 struct Header;
38 struct Package;
39 struct PackageFile;
40 struct Version;
41 struct Provides;
42 struct Dependency;
43 struct StringItem;
dcb79bae 44 struct VerFile;
578bfd0a
AL
45
46 // Iterators
47 class PkgIterator;
48 class VerIterator;
49 class DepIterator;
50 class PrvIterator;
51 class PkgFileIterator;
dcb79bae 52 class VerFileIterator;
b2e465d6
AL
53 friend class PkgIterator;
54 friend class VerIterator;
55 friend class DepIterator;
56 friend class PrvIterator;
57 friend class PkgFileIterator;
58 friend class VerFileIterator;
59
60 class Namespace;
dcb79bae 61
f55a958f 62 // These are all the constants used in the cache structures
6c139d6e
AL
63 struct Dep
64 {
65 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
b2e465d6 66 Conflicts=5,Replaces=6,Obsoletes=7};
6c139d6e
AL
67 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
68 Greater=0x4,Equals=0x5,NotEquals=0x6};
69 };
70
71 struct State
72 {
fbfb2a7c 73 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
74 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
75 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
76 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
a005475e 77 HalfInstalled=4,ConfigFiles=5,Installed=6};
afb1e2e3 78 enum PkgRemoveState {RemoveUnknown=0, RemoveManual=1,RemoveSuggested=2,RemoveRecommended=3,RemoveRequired=4};
6c139d6e
AL
79 };
80
81 struct Flag
82 {
138d4b3d 83 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 84 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 85 };
578bfd0a
AL
86
87 protected:
88
89 // Memory mapped cache file
90 string CacheFile;
91 MMap &Map;
92
f9eec0e7
AL
93 unsigned long sHash(string S) const;
94 unsigned long sHash(const char *S) const;
578bfd0a
AL
95
96 public:
97
98 // Pointers to the arrays of items
99 Header *HeaderP;
100 Package *PkgP;
dcb79bae 101 VerFile *VerFileP;
578bfd0a
AL
102 PackageFile *PkgFileP;
103 Version *VerP;
104 Provides *ProvideP;
105 Dependency *DepP;
106 StringItem *StringItemP;
107 char *StrP;
dcb79bae 108
578bfd0a
AL
109 virtual bool ReMap();
110 inline bool Sync() {return Map.Sync();};
981d20eb 111 inline MMap &GetMap() {return Map;};
b2e465d6
AL
112 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
113
578bfd0a
AL
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);};
117
0149949b
AL
118 // Usefull transformation things
119 const char *Priority(unsigned char Priority);
120
578bfd0a
AL
121 // Accessors
122 PkgIterator FindPkg(string Name);
123 Header &Head() {return *HeaderP;};
124 inline PkgIterator PkgBegin();
125 inline PkgIterator PkgEnd();
ad00ae81
AL
126 inline PkgFileIterator FileBegin();
127 inline PkgFileIterator FileEnd();
b2e465d6
AL
128
129 // Make me a function
130 pkgVersioningSystem *VS;
131
132 // Converters
133 static const char *CompTypeDeb(unsigned char Comp);
134 static const char *CompType(unsigned char Comp);
135 static const char *DepType(unsigned char Dep);
ad00ae81 136
b2e465d6 137 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a
AL
138 virtual ~pkgCache() {};
139};
140
141// Header structure
142struct pkgCache::Header
143{
144 // Signature information
145 unsigned long Signature;
146 short MajorVersion;
147 short MinorVersion;
148 bool Dirty;
149
150 // Size of structure values
151 unsigned short HeaderSz;
152 unsigned short PackageSz;
153 unsigned short PackageFileSz;
154 unsigned short VersionSz;
155 unsigned short DependencySz;
156 unsigned short ProvidesSz;
dcb79bae
AL
157 unsigned short VerFileSz;
158
578bfd0a
AL
159 // Structure counts
160 unsigned long PackageCount;
161 unsigned long VersionCount;
162 unsigned long DependsCount;
163 unsigned long PackageFileCount;
a7e66b17
AL
164 unsigned long VerFileCount;
165 unsigned long ProvidesCount;
578bfd0a
AL
166
167 // Offsets
349cd3b8
AL
168 map_ptrloc FileList; // struct PackageFile
169 map_ptrloc StringList; // struct StringItem
b2e465d6
AL
170 map_ptrloc VerSysName; // StringTable
171 map_ptrloc Architecture; // StringTable
ad00ae81 172 unsigned long MaxVerFileSize;
578bfd0a
AL
173
174 /* Allocation pools, there should be one of these for each structure
175 excluding the header */
dcb79bae 176 DynamicMMap::Pool Pools[7];
578bfd0a
AL
177
178 // Rapid package name lookup
349cd3b8 179 map_ptrloc HashTable[2*1048];
578bfd0a
AL
180
181 bool CheckSizes(Header &Against) const;
182 Header();
183};
184
185struct pkgCache::Package
186{
187 // Pointers
349cd3b8
AL
188 map_ptrloc Name; // Stringtable
189 map_ptrloc VersionList; // Version
349cd3b8 190 map_ptrloc CurrentVer; // Version
349cd3b8 191 map_ptrloc Section; // StringTable (StringItem)
578bfd0a
AL
192
193 // Linked list
349cd3b8
AL
194 map_ptrloc NextPackage; // Package
195 map_ptrloc RevDepends; // Dependency
196 map_ptrloc ProvidesList; // Provides
578bfd0a
AL
197
198 // Install/Remove/Purge etc
199 unsigned char SelectedState; // What
200 unsigned char InstState; // Flags
201 unsigned char CurrentState; // State
202
203 unsigned short ID;
f55a958f 204 unsigned long Flags;
578bfd0a
AL
205};
206
207struct pkgCache::PackageFile
208{
209 // Names
349cd3b8
AL
210 map_ptrloc FileName; // Stringtable
211 map_ptrloc Archive; // Stringtable
212 map_ptrloc Component; // Stringtable
213 map_ptrloc Version; // Stringtable
214 map_ptrloc Origin; // Stringtable
215 map_ptrloc Label; // Stringtable
216 map_ptrloc Architecture; // Stringtable
b2e465d6
AL
217 map_ptrloc Site; // Stringtable
218 map_ptrloc IndexType; // Stringtable
b0b4efb9 219 unsigned long Size;
3c124dde 220 unsigned long Flags;
578bfd0a
AL
221
222 // Linked list
349cd3b8 223 map_ptrloc NextFile; // PackageFile
578bfd0a 224 unsigned short ID;
578bfd0a
AL
225 time_t mtime; // Modification time for the file
226};
227
dcb79bae
AL
228struct pkgCache::VerFile
229{
349cd3b8
AL
230 map_ptrloc File; // PackageFile
231 map_ptrloc NextFile; // PkgVerFile
232 map_ptrloc Offset; // File offset
dcb79bae
AL
233 unsigned short Size;
234};
235
578bfd0a
AL
236struct pkgCache::Version
237{
349cd3b8
AL
238 map_ptrloc VerStr; // Stringtable
239 map_ptrloc Section; // StringTable (StringItem)
240 map_ptrloc Arch; // StringTable
17caf1b1 241
578bfd0a 242 // Lists
349cd3b8
AL
243 map_ptrloc FileList; // VerFile
244 map_ptrloc NextVer; // Version
245 map_ptrloc DependsList; // Dependency
246 map_ptrloc ParentPkg; // Package
247 map_ptrloc ProvidesList; // Provides
578bfd0a 248
349cd3b8
AL
249 map_ptrloc Size; // These are the .deb size
250 map_ptrloc InstalledSize;
204fbdcc 251 unsigned short Hash;
578bfd0a
AL
252 unsigned short ID;
253 unsigned char Priority;
254};
255
256struct pkgCache::Dependency
257{
349cd3b8
AL
258 map_ptrloc Version; // Stringtable
259 map_ptrloc Package; // Package
260 map_ptrloc NextDepends; // Dependency
261 map_ptrloc NextRevDepends; // Dependency
262 map_ptrloc ParentVer; // Version
578bfd0a
AL
263
264 // Specific types of depends
6a3da7a6 265 map_ptrloc ID;
578bfd0a
AL
266 unsigned char Type;
267 unsigned char CompareOp;
578bfd0a
AL
268};
269
270struct pkgCache::Provides
271{
349cd3b8
AL
272 map_ptrloc ParentPkg; // Pacakge
273 map_ptrloc Version; // Version
274 map_ptrloc ProvideVersion; // Stringtable
275 map_ptrloc NextProvides; // Provides
276 map_ptrloc NextPkgProv; // Provides
578bfd0a
AL
277};
278
279struct pkgCache::StringItem
280{
349cd3b8
AL
281 map_ptrloc String; // Stringtable
282 map_ptrloc NextItem; // StringItem
578bfd0a
AL
283};
284
094a497d 285#include <apt-pkg/cacheiterators.h>
578bfd0a
AL
286
287inline pkgCache::PkgIterator pkgCache::PkgBegin()
288 {return PkgIterator(*this);};
289inline pkgCache::PkgIterator pkgCache::PkgEnd()
290 {return PkgIterator(*this,PkgP);};
ad00ae81 291inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 292 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
293inline pkgCache::PkgFileIterator pkgCache::FileEnd()
294 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 295
b2e465d6
AL
296// Oh I wish for Real Name Space Support
297class pkgCache::Namespace
298{
299 public:
300
301 typedef pkgCache::PkgIterator PkgIterator;
302 typedef pkgCache::VerIterator VerIterator;
303 typedef pkgCache::DepIterator DepIterator;
304 typedef pkgCache::PrvIterator PrvIterator;
305 typedef pkgCache::PkgFileIterator PkgFileIterator;
306 typedef pkgCache::VerFileIterator VerFileIterator;
307 typedef pkgCache::Version Version;
308 typedef pkgCache::Package Package;
309 typedef pkgCache::Header Header;
310 typedef pkgCache::Dep Dep;
311 typedef pkgCache::Flag Flag;
312};
313
578bfd0a 314#endif