]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
* merged with mainline
[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};
6c139d6e
AL
78 };
79
80 struct Flag
81 {
138d4b3d 82 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 83 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 84 };
578bfd0a
AL
85
86 protected:
87
88 // Memory mapped cache file
89 string CacheFile;
90 MMap &Map;
91
171c75f1 92 unsigned long sHash(const string &S) const;
f9eec0e7 93 unsigned long sHash(const char *S) const;
578bfd0a
AL
94
95 public:
96
97 // Pointers to the arrays of items
98 Header *HeaderP;
99 Package *PkgP;
dcb79bae 100 VerFile *VerFileP;
578bfd0a
AL
101 PackageFile *PkgFileP;
102 Version *VerP;
103 Provides *ProvideP;
104 Dependency *DepP;
105 StringItem *StringItemP;
106 char *StrP;
dcb79bae 107
578bfd0a
AL
108 virtual bool ReMap();
109 inline bool Sync() {return Map.Sync();};
981d20eb 110 inline MMap &GetMap() {return Map;};
b2e465d6
AL
111 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
112
578bfd0a 113 // String hashing function (512 range)
171c75f1 114 inline unsigned long Hash(const string &S) const {return sHash(S);};
578bfd0a
AL
115 inline unsigned long Hash(const char *S) const {return sHash(S);};
116
0149949b
AL
117 // Usefull transformation things
118 const char *Priority(unsigned char Priority);
119
578bfd0a 120 // Accessors
171c75f1 121 PkgIterator FindPkg(const string &Name);
578bfd0a
AL
122 Header &Head() {return *HeaderP;};
123 inline PkgIterator PkgBegin();
124 inline PkgIterator PkgEnd();
ad00ae81
AL
125 inline PkgFileIterator FileBegin();
126 inline PkgFileIterator FileEnd();
b2e465d6
AL
127
128 // Make me a function
129 pkgVersioningSystem *VS;
130
131 // Converters
132 static const char *CompTypeDeb(unsigned char Comp);
133 static const char *CompType(unsigned char Comp);
134 static const char *DepType(unsigned char Dep);
ad00ae81 135
b2e465d6 136 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a
AL
137 virtual ~pkgCache() {};
138};
139
140// Header structure
141struct pkgCache::Header
142{
143 // Signature information
144 unsigned long Signature;
145 short MajorVersion;
146 short MinorVersion;
147 bool Dirty;
148
149 // Size of structure values
150 unsigned short HeaderSz;
151 unsigned short PackageSz;
152 unsigned short PackageFileSz;
153 unsigned short VersionSz;
154 unsigned short DependencySz;
155 unsigned short ProvidesSz;
dcb79bae
AL
156 unsigned short VerFileSz;
157
578bfd0a
AL
158 // Structure counts
159 unsigned long PackageCount;
160 unsigned long VersionCount;
161 unsigned long DependsCount;
162 unsigned long PackageFileCount;
a7e66b17
AL
163 unsigned long VerFileCount;
164 unsigned long ProvidesCount;
578bfd0a
AL
165
166 // Offsets
349cd3b8
AL
167 map_ptrloc FileList; // struct PackageFile
168 map_ptrloc StringList; // struct StringItem
b2e465d6
AL
169 map_ptrloc VerSysName; // StringTable
170 map_ptrloc Architecture; // StringTable
ad00ae81 171 unsigned long MaxVerFileSize;
578bfd0a
AL
172
173 /* Allocation pools, there should be one of these for each structure
174 excluding the header */
dcb79bae 175 DynamicMMap::Pool Pools[7];
578bfd0a
AL
176
177 // Rapid package name lookup
349cd3b8 178 map_ptrloc HashTable[2*1048];
578bfd0a
AL
179
180 bool CheckSizes(Header &Against) const;
181 Header();
182};
183
184struct pkgCache::Package
185{
186 // Pointers
349cd3b8
AL
187 map_ptrloc Name; // Stringtable
188 map_ptrloc VersionList; // Version
349cd3b8 189 map_ptrloc CurrentVer; // Version
349cd3b8 190 map_ptrloc Section; // StringTable (StringItem)
578bfd0a
AL
191
192 // Linked list
349cd3b8
AL
193 map_ptrloc NextPackage; // Package
194 map_ptrloc RevDepends; // Dependency
195 map_ptrloc ProvidesList; // Provides
578bfd0a
AL
196
197 // Install/Remove/Purge etc
198 unsigned char SelectedState; // What
199 unsigned char InstState; // Flags
200 unsigned char CurrentState; // State
201
202 unsigned short ID;
f55a958f 203 unsigned long Flags;
578bfd0a
AL
204};
205
206struct pkgCache::PackageFile
207{
208 // Names
349cd3b8
AL
209 map_ptrloc FileName; // Stringtable
210 map_ptrloc Archive; // Stringtable
211 map_ptrloc Component; // Stringtable
212 map_ptrloc Version; // Stringtable
213 map_ptrloc Origin; // Stringtable
214 map_ptrloc Label; // Stringtable
215 map_ptrloc Architecture; // Stringtable
b2e465d6
AL
216 map_ptrloc Site; // Stringtable
217 map_ptrloc IndexType; // Stringtable
b0b4efb9 218 unsigned long Size;
3c124dde 219 unsigned long Flags;
578bfd0a
AL
220
221 // Linked list
349cd3b8 222 map_ptrloc NextFile; // PackageFile
578bfd0a 223 unsigned short ID;
578bfd0a
AL
224 time_t mtime; // Modification time for the file
225};
226
dcb79bae
AL
227struct pkgCache::VerFile
228{
349cd3b8
AL
229 map_ptrloc File; // PackageFile
230 map_ptrloc NextFile; // PkgVerFile
231 map_ptrloc Offset; // File offset
dcb79bae
AL
232 unsigned short Size;
233};
234
578bfd0a
AL
235struct pkgCache::Version
236{
349cd3b8
AL
237 map_ptrloc VerStr; // Stringtable
238 map_ptrloc Section; // StringTable (StringItem)
239 map_ptrloc Arch; // StringTable
17caf1b1 240
578bfd0a 241 // Lists
349cd3b8
AL
242 map_ptrloc FileList; // VerFile
243 map_ptrloc NextVer; // Version
244 map_ptrloc DependsList; // Dependency
245 map_ptrloc ParentPkg; // Package
246 map_ptrloc ProvidesList; // Provides
578bfd0a 247
349cd3b8
AL
248 map_ptrloc Size; // These are the .deb size
249 map_ptrloc InstalledSize;
204fbdcc 250 unsigned short Hash;
578bfd0a
AL
251 unsigned short ID;
252 unsigned char Priority;
253};
254
255struct pkgCache::Dependency
256{
349cd3b8
AL
257 map_ptrloc Version; // Stringtable
258 map_ptrloc Package; // Package
259 map_ptrloc NextDepends; // Dependency
260 map_ptrloc NextRevDepends; // Dependency
261 map_ptrloc ParentVer; // Version
578bfd0a
AL
262
263 // Specific types of depends
6a3da7a6 264 map_ptrloc ID;
578bfd0a
AL
265 unsigned char Type;
266 unsigned char CompareOp;
578bfd0a
AL
267};
268
269struct pkgCache::Provides
270{
349cd3b8
AL
271 map_ptrloc ParentPkg; // Pacakge
272 map_ptrloc Version; // Version
273 map_ptrloc ProvideVersion; // Stringtable
274 map_ptrloc NextProvides; // Provides
275 map_ptrloc NextPkgProv; // Provides
578bfd0a
AL
276};
277
278struct pkgCache::StringItem
279{
349cd3b8
AL
280 map_ptrloc String; // Stringtable
281 map_ptrloc NextItem; // StringItem
578bfd0a
AL
282};
283
094a497d 284#include <apt-pkg/cacheiterators.h>
578bfd0a
AL
285
286inline pkgCache::PkgIterator pkgCache::PkgBegin()
287 {return PkgIterator(*this);};
288inline pkgCache::PkgIterator pkgCache::PkgEnd()
289 {return PkgIterator(*this,PkgP);};
ad00ae81 290inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 291 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
292inline pkgCache::PkgFileIterator pkgCache::FileEnd()
293 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 294
b2e465d6
AL
295// Oh I wish for Real Name Space Support
296class pkgCache::Namespace
297{
298 public:
299
300 typedef pkgCache::PkgIterator PkgIterator;
301 typedef pkgCache::VerIterator VerIterator;
302 typedef pkgCache::DepIterator DepIterator;
303 typedef pkgCache::PrvIterator PrvIterator;
304 typedef pkgCache::PkgFileIterator PkgFileIterator;
305 typedef pkgCache::VerFileIterator VerFileIterator;
306 typedef pkgCache::Version Version;
307 typedef pkgCache::Package Package;
308 typedef pkgCache::Header Header;
309 typedef pkgCache::Dep Dep;
310 typedef pkgCache::Flag Flag;
311};
312
578bfd0a 313#endif