]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
Drop the Arch information from the Version structure as we can get
[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
578bfd0a
AL
23#include <string>
24#include <time.h>
094a497d 25#include <apt-pkg/mmap.h>
0a843901
AL
26
27using std::string;
b2e465d6
AL
28
29class pkgVersioningSystem;
92fcbfc1 30class pkgCache /*{{{*/
578bfd0a
AL
31{
32 public:
33 // Cache element predeclarations
34 struct Header;
5bf15716 35 struct Group;
578bfd0a
AL
36 struct Package;
37 struct PackageFile;
38 struct Version;
a52f938b 39 struct Description;
578bfd0a
AL
40 struct Provides;
41 struct Dependency;
42 struct StringItem;
dcb79bae 43 struct VerFile;
a52f938b 44 struct DescFile;
578bfd0a
AL
45
46 // Iterators
773e2c1f 47 template<typename Str, typename Itr> class Iterator;
5bf15716 48 class GrpIterator;
578bfd0a
AL
49 class PkgIterator;
50 class VerIterator;
a52f938b 51 class DescIterator;
578bfd0a
AL
52 class DepIterator;
53 class PrvIterator;
54 class PkgFileIterator;
dcb79bae 55 class VerFileIterator;
a52f938b 56 class DescFileIterator;
b2e465d6
AL
57
58 class Namespace;
dcb79bae 59
f55a958f 60 // These are all the constants used in the cache structures
308c7d30
IJ
61
62 // WARNING - if you change these lists you must also edit
63 // the stringification in pkgcache.cc and also consider whether
64 // the cache file will become incompatible.
6c139d6e
AL
65 struct Dep
66 {
67 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
f8ae7e8b 68 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
6c139d6e
AL
69 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
70 Greater=0x4,Equals=0x5,NotEquals=0x6};
71 };
72
73 struct State
74 {
fbfb2a7c 75 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
76 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
77 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
78 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
9d06bc80
MV
79 HalfInstalled=4,ConfigFiles=5,Installed=6,
80 TriggersAwaited=7,TriggersPending=8};
6c139d6e
AL
81 };
82
83 struct Flag
84 {
138d4b3d 85 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
3c124dde 86 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
6c139d6e 87 };
578bfd0a
AL
88
89 protected:
90
91 // Memory mapped cache file
92 string CacheFile;
93 MMap &Map;
94
171c75f1 95 unsigned long sHash(const string &S) const;
f9eec0e7 96 unsigned long sHash(const char *S) const;
578bfd0a
AL
97
98 public:
99
100 // Pointers to the arrays of items
101 Header *HeaderP;
5bf15716 102 Group *GrpP;
578bfd0a 103 Package *PkgP;
dcb79bae 104 VerFile *VerFileP;
a52f938b 105 DescFile *DescFileP;
578bfd0a
AL
106 PackageFile *PkgFileP;
107 Version *VerP;
a52f938b 108 Description *DescP;
578bfd0a
AL
109 Provides *ProvideP;
110 Dependency *DepP;
111 StringItem *StringItemP;
112 char *StrP;
dcb79bae 113
578bfd0a
AL
114 virtual bool ReMap();
115 inline bool Sync() {return Map.Sync();};
981d20eb 116 inline MMap &GetMap() {return Map;};
b2e465d6
AL
117 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
118
578bfd0a 119 // String hashing function (512 range)
171c75f1 120 inline unsigned long Hash(const string &S) const {return sHash(S);};
578bfd0a
AL
121 inline unsigned long Hash(const char *S) const {return sHash(S);};
122
0149949b
AL
123 // Usefull transformation things
124 const char *Priority(unsigned char Priority);
125
578bfd0a 126 // Accessors
5bf15716 127 GrpIterator FindGrp(const string &Name);
25396fb0
DK
128 PkgIterator FindPkg(const string &Name);
129 PkgIterator FindPkg(const string &Name, string Arch);
5bf15716 130
578bfd0a 131 Header &Head() {return *HeaderP;};
25396fb0
DK
132 inline GrpIterator GrpBegin();
133 inline GrpIterator GrpEnd();
578bfd0a
AL
134 inline PkgIterator PkgBegin();
135 inline PkgIterator PkgEnd();
ad00ae81
AL
136 inline PkgFileIterator FileBegin();
137 inline PkgFileIterator FileEnd();
b2e465d6
AL
138
139 // Make me a function
140 pkgVersioningSystem *VS;
141
142 // Converters
143 static const char *CompTypeDeb(unsigned char Comp);
144 static const char *CompType(unsigned char Comp);
145 static const char *DepType(unsigned char Dep);
ad00ae81 146
b2e465d6 147 pkgCache(MMap *Map,bool DoMap = true);
578bfd0a
AL
148 virtual ~pkgCache() {};
149};
92fcbfc1
DK
150 /*}}}*/
151// Header structure /*{{{*/
578bfd0a
AL
152struct pkgCache::Header
153{
154 // Signature information
155 unsigned long Signature;
156 short MajorVersion;
157 short MinorVersion;
158 bool Dirty;
159
160 // Size of structure values
161 unsigned short HeaderSz;
162 unsigned short PackageSz;
163 unsigned short PackageFileSz;
164 unsigned short VersionSz;
a52f938b 165 unsigned short DescriptionSz;
578bfd0a
AL
166 unsigned short DependencySz;
167 unsigned short ProvidesSz;
dcb79bae 168 unsigned short VerFileSz;
a52f938b 169 unsigned short DescFileSz;
dcb79bae 170
578bfd0a 171 // Structure counts
5bf15716 172 unsigned long GroupCount;
578bfd0a
AL
173 unsigned long PackageCount;
174 unsigned long VersionCount;
a52f938b 175 unsigned long DescriptionCount;
578bfd0a
AL
176 unsigned long DependsCount;
177 unsigned long PackageFileCount;
a7e66b17 178 unsigned long VerFileCount;
a52f938b 179 unsigned long DescFileCount;
a7e66b17 180 unsigned long ProvidesCount;
578bfd0a
AL
181
182 // Offsets
349cd3b8
AL
183 map_ptrloc FileList; // struct PackageFile
184 map_ptrloc StringList; // struct StringItem
b2e465d6
AL
185 map_ptrloc VerSysName; // StringTable
186 map_ptrloc Architecture; // StringTable
ad00ae81 187 unsigned long MaxVerFileSize;
a52f938b 188 unsigned long MaxDescFileSize;
578bfd0a
AL
189
190 /* Allocation pools, there should be one of these for each structure
191 excluding the header */
5bf15716 192 DynamicMMap::Pool Pools[9];
578bfd0a 193
5bf15716
DK
194 // Rapid package and group name lookup
195 // Notice: Increase only both table sizes as the
196 // hashmethod assume the size of the Pkg one
197 map_ptrloc PkgHashTable[2*1048];
198 map_ptrloc GrpHashTable[2*1048];
578bfd0a
AL
199
200 bool CheckSizes(Header &Against) const;
201 Header();
202};
92fcbfc1 203 /*}}}*/
5bf15716
DK
204struct pkgCache::Group { /*{{{*/
205 map_ptrloc Name; // Stringtable
206
207 // Linked List
208 map_ptrloc FirstPackage;// Package
209 map_ptrloc LastPackage; // Package
210 map_ptrloc Next; // Group
211};
212 /*}}}*/
92fcbfc1 213struct pkgCache::Package /*{{{*/
578bfd0a
AL
214{
215 // Pointers
349cd3b8 216 map_ptrloc Name; // Stringtable
5bf15716 217 map_ptrloc Arch; // StringTable (StringItem)
349cd3b8 218 map_ptrloc VersionList; // Version
349cd3b8 219 map_ptrloc CurrentVer; // Version
349cd3b8 220 map_ptrloc Section; // StringTable (StringItem)
5bf15716 221 map_ptrloc Group; // Group the Package belongs to
578bfd0a
AL
222
223 // Linked list
349cd3b8
AL
224 map_ptrloc NextPackage; // Package
225 map_ptrloc RevDepends; // Dependency
226 map_ptrloc ProvidesList; // Provides
a52f938b 227
578bfd0a
AL
228 // Install/Remove/Purge etc
229 unsigned char SelectedState; // What
230 unsigned char InstState; // Flags
231 unsigned char CurrentState; // State
232
09fab244 233 unsigned int ID;
f55a958f 234 unsigned long Flags;
578bfd0a 235};
92fcbfc1
DK
236 /*}}}*/
237struct pkgCache::PackageFile /*{{{*/
578bfd0a
AL
238{
239 // Names
349cd3b8
AL
240 map_ptrloc FileName; // Stringtable
241 map_ptrloc Archive; // Stringtable
efc487fb 242 map_ptrloc Codename; // Stringtable
349cd3b8
AL
243 map_ptrloc Component; // Stringtable
244 map_ptrloc Version; // Stringtable
245 map_ptrloc Origin; // Stringtable
246 map_ptrloc Label; // Stringtable
247 map_ptrloc Architecture; // Stringtable
b2e465d6
AL
248 map_ptrloc Site; // Stringtable
249 map_ptrloc IndexType; // Stringtable
b0b4efb9 250 unsigned long Size;
3c124dde 251 unsigned long Flags;
578bfd0a
AL
252
253 // Linked list
349cd3b8 254 map_ptrloc NextFile; // PackageFile
09fab244 255 unsigned int ID;
578bfd0a
AL
256 time_t mtime; // Modification time for the file
257};
92fcbfc1
DK
258 /*}}}*/
259struct pkgCache::VerFile /*{{{*/
dcb79bae 260{
349cd3b8
AL
261 map_ptrloc File; // PackageFile
262 map_ptrloc NextFile; // PkgVerFile
263 map_ptrloc Offset; // File offset
6d3176fb 264 unsigned long Size;
dcb79bae 265};
92fcbfc1
DK
266 /*}}}*/
267struct pkgCache::DescFile /*{{{*/
a52f938b
OS
268{
269 map_ptrloc File; // PackageFile
270 map_ptrloc NextFile; // PkgVerFile
271 map_ptrloc Offset; // File offset
6d3176fb 272 unsigned long Size;
a52f938b 273};
92fcbfc1
DK
274 /*}}}*/
275struct pkgCache::Version /*{{{*/
578bfd0a 276{
349cd3b8
AL
277 map_ptrloc VerStr; // Stringtable
278 map_ptrloc Section; // StringTable (StringItem)
25396fb0
DK
279 enum {None, All, Foreign, Same, Allowed} MultiArch;
280
578bfd0a 281 // Lists
349cd3b8
AL
282 map_ptrloc FileList; // VerFile
283 map_ptrloc NextVer; // Version
a52f938b 284 map_ptrloc DescriptionList; // Description
349cd3b8
AL
285 map_ptrloc DependsList; // Dependency
286 map_ptrloc ParentPkg; // Package
287 map_ptrloc ProvidesList; // Provides
578bfd0a 288
349cd3b8
AL
289 map_ptrloc Size; // These are the .deb size
290 map_ptrloc InstalledSize;
204fbdcc 291 unsigned short Hash;
09fab244 292 unsigned int ID;
578bfd0a
AL
293 unsigned char Priority;
294};
92fcbfc1
DK
295 /*}}}*/
296struct pkgCache::Description /*{{{*/
a52f938b
OS
297{
298 // Language Code store the description translation language code. If
299 // the value has a 0 lenght then this is readed using the Package
300 // file else the Translation-CODE are used.
301 map_ptrloc language_code; // StringTable
302 map_ptrloc md5sum; // StringTable
303
304 // Linked list
305 map_ptrloc FileList; // DescFile
306 map_ptrloc NextDesc; // Description
307 map_ptrloc ParentPkg; // Package
308
09fab244 309 unsigned int ID;
a52f938b 310};
92fcbfc1
DK
311 /*}}}*/
312struct pkgCache::Dependency /*{{{*/
578bfd0a 313{
349cd3b8
AL
314 map_ptrloc Version; // Stringtable
315 map_ptrloc Package; // Package
316 map_ptrloc NextDepends; // Dependency
317 map_ptrloc NextRevDepends; // Dependency
318 map_ptrloc ParentVer; // Version
578bfd0a
AL
319
320 // Specific types of depends
6a3da7a6 321 map_ptrloc ID;
578bfd0a
AL
322 unsigned char Type;
323 unsigned char CompareOp;
578bfd0a 324};
92fcbfc1
DK
325 /*}}}*/
326struct pkgCache::Provides /*{{{*/
578bfd0a 327{
349cd3b8
AL
328 map_ptrloc ParentPkg; // Pacakge
329 map_ptrloc Version; // Version
330 map_ptrloc ProvideVersion; // Stringtable
331 map_ptrloc NextProvides; // Provides
332 map_ptrloc NextPkgProv; // Provides
578bfd0a 333};
92fcbfc1
DK
334 /*}}}*/
335struct pkgCache::StringItem /*{{{*/
578bfd0a 336{
349cd3b8
AL
337 map_ptrloc String; // Stringtable
338 map_ptrloc NextItem; // StringItem
578bfd0a 339};
92fcbfc1 340 /*}}}*/
094a497d 341#include <apt-pkg/cacheiterators.h>
578bfd0a 342
25396fb0
DK
343inline pkgCache::GrpIterator pkgCache::GrpBegin()
344 {return GrpIterator(*this);};
345inline pkgCache::GrpIterator pkgCache::GrpEnd()
346 {return GrpIterator(*this,GrpP);};
578bfd0a
AL
347inline pkgCache::PkgIterator pkgCache::PkgBegin()
348 {return PkgIterator(*this);};
349inline pkgCache::PkgIterator pkgCache::PkgEnd()
350 {return PkgIterator(*this,PkgP);};
ad00ae81 351inline pkgCache::PkgFileIterator pkgCache::FileBegin()
b2e465d6 352 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
ad00ae81
AL
353inline pkgCache::PkgFileIterator pkgCache::FileEnd()
354 {return PkgFileIterator(*this,PkgFileP);};
578bfd0a 355
b2e465d6 356// Oh I wish for Real Name Space Support
92fcbfc1 357class pkgCache::Namespace /*{{{*/
b2e465d6
AL
358{
359 public:
360
361 typedef pkgCache::PkgIterator PkgIterator;
362 typedef pkgCache::VerIterator VerIterator;
a52f938b 363 typedef pkgCache::DescIterator DescIterator;
b2e465d6
AL
364 typedef pkgCache::DepIterator DepIterator;
365 typedef pkgCache::PrvIterator PrvIterator;
366 typedef pkgCache::PkgFileIterator PkgFileIterator;
367 typedef pkgCache::VerFileIterator VerFileIterator;
368 typedef pkgCache::Version Version;
a52f938b 369 typedef pkgCache::Description Description;
b2e465d6
AL
370 typedef pkgCache::Package Package;
371 typedef pkgCache::Header Header;
372 typedef pkgCache::Dep Dep;
373 typedef pkgCache::Flag Flag;
374};
92fcbfc1 375 /*}}}*/
578bfd0a 376#endif