]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgcache.h
Merge branch 'debian/sid' into debian/experimental
[apt.git] / apt-pkg / pkgcache.h
CommitLineData
578bfd0a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
94449d7c
DK
3/**\file pkgcache.h
4 \brief pkgCache - Structure definitions for the cache file
5
6 The goal of the cache file is two fold:
7 Firstly to speed loading and processing of the package file array and
8 secondly to reduce memory consumption of the package file array.
9
10 The implementation is aimed at an environment with many primary package
11 files, for instance someone that has a Package file for their CD-ROM, a
12 Package file for the latest version of the distribution on the CD-ROM and a
13 package file for the development version. Always present is the information
14 contained in the status file which might be considered a separate package
15 file.
16
17 Please understand, this is designed as a <b>Cache file</b> it is not meant to be
18 used on any system other than the one it was created for. It is not meant to
19 be authoritative either, i.e. if a system crash or software failure occurs it
20 must be perfectly acceptable for the cache file to be in an inconsistent
21 state. Furthermore at any time the cache file may be erased without losing
22 any information.
23
24 Also the structures and storage layout is optimized for use by the APT
25 and may not be suitable for all purposes. However it should be possible
26 to extend it with associate cache files that contain other information.
27
28 To keep memory use down the cache file only contains often used fields and
29 fields that are inexpensive to store, the Package file has a full list of
30 fields. Also the client may assume that all items are perfectly valid and
31 need not perform checks against their correctness. Removal of information
32 from the cache is possible, but blanks will be left in the file, and
33 unused strings will also be present. The recommended implementation is to
34 simply rebuild the cache each time any of the data files change. It is
35 possible to add a new package file to the cache without any negative side
36 effects.
37
38 <b>Note on Pointer access</b>
578bfd0a 39 Clients should always use the CacheIterators classes for access to the
94449d7c
DK
40 cache and the data in it. They also provide a simple STL-like method for
41 traversing the links of the datastructure.
42
43 Every item in every structure is stored as the index to that structure.
44 What this means is that once the files is mmaped every data access has to
45 go through a fix up stage to get a real memory pointer. This is done
46 by taking the index, multiplying it by the type size and then adding
47 it to the start address of the memory block. This sounds complex, but
48 in C it is a single array dereference. Because all items are aligned to
49 their size and indexes are stored as multiples of the size of the structure
50 the format is immediately portable to all possible architectures - BUT the
51 generated files are -NOT-.
52
53 This scheme allows code like this to be written:
54 <example>
55 void *Map = mmap(...);
56 Package *PkgList = (Package *)Map;
57 Header *Head = (Header *)Map;
58 char *Strings = (char *)Map;
59 cout << (Strings + PkgList[Head->HashTable[0]]->Name) << endl;
60 </example>
61 Notice the lack of casting or multiplication. The net result is to return
62 the name of the first package in the first hash bucket, without error
63 checks.
64
65 The generator uses allocation pools to group similarly sized structures in
66 large blocks to eliminate any alignment overhead. The generator also
67 assures that no structures overlap and all indexes are unique. Although
68 at first glance it may seem like there is the potential for two structures
69 to exist at the same point the generator never allows this to happen.
70 (See the discussion of free space pools)
71
72 See \ref pkgcachegen.h for more information about generating cache structures. */
578bfd0a 73 /*}}}*/
578bfd0a
AL
74#ifndef PKGLIB_PKGCACHE_H
75#define PKGLIB_PKGCACHE_H
76
a02db58f
DK
77#include <apt-pkg/mmap.h>
78#include <apt-pkg/macros.h>
79
578bfd0a
AL
80#include <string>
81#include <time.h>
4ad8619b 82#include <stdint.h>
0a843901 83
a4f6bdc8
DK
84#ifndef APT_8_CLEANER_HEADERS
85using std::string;
86#endif
87
4ad8619b
DK
88// storing file sizes of indexes, which are way below 4 GB for now
89typedef uint32_t map_filesize_t;
90// each package/group/dependency gets an id
91typedef uint32_t map_id_t;
92// some files get an id, too, but in far less absolute numbers
93typedef uint16_t map_fileid_t;
94// relative pointer from cache start
95typedef uint32_t map_pointer_t;
96// same as the previous, but documented to be to a string item
97typedef map_pointer_t map_stringitem_t;
98
b2e465d6 99class pkgVersioningSystem;
92fcbfc1 100class pkgCache /*{{{*/
578bfd0a
AL
101{
102 public:
103 // Cache element predeclarations
104 struct Header;
5bf15716 105 struct Group;
578bfd0a
AL
106 struct Package;
107 struct PackageFile;
108 struct Version;
a52f938b 109 struct Description;
578bfd0a
AL
110 struct Provides;
111 struct Dependency;
112 struct StringItem;
dcb79bae 113 struct VerFile;
a52f938b 114 struct DescFile;
578bfd0a
AL
115
116 // Iterators
773e2c1f 117 template<typename Str, typename Itr> class Iterator;
5bf15716 118 class GrpIterator;
578bfd0a
AL
119 class PkgIterator;
120 class VerIterator;
a52f938b 121 class DescIterator;
578bfd0a
AL
122 class DepIterator;
123 class PrvIterator;
124 class PkgFileIterator;
dcb79bae 125 class VerFileIterator;
a52f938b 126 class DescFileIterator;
b2e465d6
AL
127
128 class Namespace;
dcb79bae 129
f55a958f 130 // These are all the constants used in the cache structures
308c7d30
IJ
131
132 // WARNING - if you change these lists you must also edit
133 // the stringification in pkgcache.cc and also consider whether
134 // the cache file will become incompatible.
6c139d6e
AL
135 struct Dep
136 {
137 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
f8ae7e8b 138 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
94449d7c
DK
139 /** \brief available compare operators
140
141 The lower 4 bits are used to indicate what operator is being specified and
142 the upper 4 bits are flags. OR indicates that the next package is
143 or'd with the current package. */
6c139d6e
AL
144 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
145 Greater=0x4,Equals=0x5,NotEquals=0x6};
146 };
147
148 struct State
149 {
94449d7c
DK
150 /** \brief priority of a package version
151
152 Zero is used for unparsable or absent Priority fields. */
9005f08e 153 enum VerPriority {Required=1,Important=2,Standard=3,Optional=4,Extra=5};
6c139d6e
AL
154 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
155 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
156 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
9d06bc80
MV
157 HalfInstalled=4,ConfigFiles=5,Installed=6,
158 TriggersAwaited=7,TriggersPending=8};
6c139d6e
AL
159 };
160
161 struct Flag
162 {
138d4b3d 163 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
5ed56f93 164 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)};
6c139d6e 165 };
578bfd0a
AL
166
167 protected:
168
169 // Memory mapped cache file
8f3ba4e8 170 std::string CacheFile;
578bfd0a
AL
171 MMap &Map;
172
4ad8619b
DK
173 map_id_t sHash(const std::string &S) const APT_PURE;
174 map_id_t sHash(const char *S) const APT_PURE;
578bfd0a
AL
175
176 public:
177
178 // Pointers to the arrays of items
179 Header *HeaderP;
5bf15716 180 Group *GrpP;
578bfd0a 181 Package *PkgP;
dcb79bae 182 VerFile *VerFileP;
a52f938b 183 DescFile *DescFileP;
578bfd0a
AL
184 PackageFile *PkgFileP;
185 Version *VerP;
a52f938b 186 Description *DescP;
578bfd0a
AL
187 Provides *ProvideP;
188 Dependency *DepP;
189 StringItem *StringItemP;
190 char *StrP;
dcb79bae 191
a9fe5928 192 virtual bool ReMap(bool const &Errorchecks = true);
d3e8fbb3
DK
193 inline bool Sync() {return Map.Sync();}
194 inline MMap &GetMap() {return Map;}
195 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}
b2e465d6 196
578bfd0a 197 // String hashing function (512 range)
4ad8619b
DK
198 inline map_id_t Hash(const std::string &S) const {return sHash(S);}
199 inline map_id_t Hash(const char *S) const {return sHash(S);}
578bfd0a 200
94449d7c 201 // Useful transformation things
0149949b
AL
202 const char *Priority(unsigned char Priority);
203
578bfd0a 204 // Accessors
8f3ba4e8
DK
205 GrpIterator FindGrp(const std::string &Name);
206 PkgIterator FindPkg(const std::string &Name);
207 PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
5bf15716 208
d3e8fbb3 209 Header &Head() {return *HeaderP;}
25396fb0
DK
210 inline GrpIterator GrpBegin();
211 inline GrpIterator GrpEnd();
578bfd0a
AL
212 inline PkgIterator PkgBegin();
213 inline PkgIterator PkgEnd();
ad00ae81
AL
214 inline PkgFileIterator FileBegin();
215 inline PkgFileIterator FileEnd();
b2e465d6 216
d3e8fbb3 217 inline bool MultiArchCache() const { return MultiArchEnabled; }
d64e130a 218 inline char const * NativeArch();
8d4c859d 219
b2e465d6
AL
220 // Make me a function
221 pkgVersioningSystem *VS;
222
223 // Converters
a02db58f
DK
224 static const char *CompTypeDeb(unsigned char Comp) APT_CONST;
225 static const char *CompType(unsigned char Comp) APT_CONST;
b2e465d6 226 static const char *DepType(unsigned char Dep);
ad00ae81 227
b2e465d6 228 pkgCache(MMap *Map,bool DoMap = true);
d3e8fbb3 229 virtual ~pkgCache() {}
8d4c859d
DK
230
231private:
232 bool MultiArchEnabled;
8f3ba4e8 233 PkgIterator SingleArchFindPkg(const std::string &Name);
578bfd0a 234};
92fcbfc1
DK
235 /*}}}*/
236// Header structure /*{{{*/
578bfd0a
AL
237struct pkgCache::Header
238{
94449d7c
DK
239 /** \brief Signature information
240
241 This must contain the hex value 0x98FE76DC which is designed to
242 verify that the system loading the image has the same byte order
243 and byte size as the system saving the image */
578bfd0a 244 unsigned long Signature;
94449d7c 245 /** These contain the version of the cache file */
578bfd0a
AL
246 short MajorVersion;
247 short MinorVersion;
94449d7c
DK
248 /** \brief indicates if the cache should be erased
249
250 Dirty is true if the cache file was opened for reading, the client
251 expects to have written things to it and have not fully synced it.
252 The file should be erased and rebuilt if it is true. */
578bfd0a 253 bool Dirty;
94449d7c
DK
254
255 /** \brief Size of structure values
256
257 All *Sz variables contains the sizeof() that particular structure.
258 It is used as an extra consistency check on the structure of the file.
259
260 If any of the size values do not exactly match what the client expects
261 then the client should refuse the load the file. */
578bfd0a 262 unsigned short HeaderSz;
52c41485 263 unsigned short GroupSz;
578bfd0a
AL
264 unsigned short PackageSz;
265 unsigned short PackageFileSz;
266 unsigned short VersionSz;
a52f938b 267 unsigned short DescriptionSz;
578bfd0a
AL
268 unsigned short DependencySz;
269 unsigned short ProvidesSz;
dcb79bae 270 unsigned short VerFileSz;
a52f938b 271 unsigned short DescFileSz;
94449d7c
DK
272
273 /** \brief Structure counts
274
275 These indicate the number of each structure contained in the cache.
276 PackageCount is especially useful for generating user state structures.
277 See Package::Id for more info. */
4ad8619b
DK
278 map_id_t GroupCount;
279 map_id_t PackageCount;
280 map_id_t VersionCount;
281 map_id_t DescriptionCount;
282 map_id_t DependsCount;
283 map_fileid_t PackageFileCount;
284 map_fileid_t VerFileCount;
285 map_fileid_t DescFileCount;
286 map_id_t ProvidesCount;
94449d7c
DK
287
288 /** \brief index of the first PackageFile structure
289
290 The PackageFile structures are singly linked lists that represent
291 all package files that have been merged into the cache. */
4ad8619b 292 map_pointer_t FileList;
94449d7c
DK
293 /** \brief index of the first StringItem structure
294
295 The cache contains a list of all the unique strings (StringItems).
296 The parser reads this list into memory so it can match strings
297 against it.*/
4ad8619b 298 map_pointer_t StringList;
94449d7c 299 /** \brief String representing the version system used */
4ad8619b 300 map_pointer_t VerSysName;
7a223b93 301 /** \brief native architecture the cache was built against */
4ad8619b 302 map_pointer_t Architecture;
7a223b93 303 /** \brief all architectures the cache was built against */
4ad8619b 304 map_pointer_t Architectures;
94449d7c 305 /** \brief The maximum size of a raw entry from the original Package file */
4ad8619b 306 map_filesize_t MaxVerFileSize;
94449d7c 307 /** \brief The maximum size of a raw entry from the original Translation file */
4ad8619b 308 map_filesize_t MaxDescFileSize;
578bfd0a 309
94449d7c
DK
310 /** \brief The Pool structures manage the allocation pools that the generator uses
311
312 Start indicates the first byte of the pool, Count is the number of objects
313 remaining in the pool and ItemSize is the structure size (alignment factor)
314 of the pool. An ItemSize of 0 indicates the pool is empty. There should be
315 the same number of pools as there are structure types. The generator
316 stores this information so future additions can make use of any unused pool
317 blocks. */
5bf15716 318 DynamicMMap::Pool Pools[9];
e8a7b0b2 319
94449d7c
DK
320 /** \brief hash tables providing rapid group/package name lookup
321
e8a7b0b2 322 Each group/package name is inserted into a hash table using pkgCache::Hash(const &string)
94449d7c
DK
323 By iterating over each entry in the hash table it is possible to iterate over
324 the entire list of packages. Hash Collisions are handled with a singly linked
325 list of packages based at the hash item. The linked list contains only
326 packages that match the hashing function.
327 In the PkgHashTable is it possible that multiple packages have the same name -
328 these packages are stored as a sequence in the list.
e8a7b0b2
DK
329 The size of both tables is the same. */
330 unsigned int HashTableSize;
4ad8619b
DK
331 map_pointer_t * PkgHashTable() const { return (map_pointer_t*) (this + 1); }
332 map_pointer_t * GrpHashTable() const { return PkgHashTable() + HashTableSize; }
578bfd0a 333
0688ccd8 334 /** \brief Size of the complete cache file */
4ad8619b 335 unsigned long long CacheFileSize;
0688ccd8 336
a02db58f 337 bool CheckSizes(Header &Against) const APT_PURE;
578bfd0a
AL
338 Header();
339};
92fcbfc1 340 /*}}}*/
94449d7c
DK
341// Group structure /*{{{*/
342/** \brief groups architecture depending packages together
5bf15716 343
94449d7c
DK
344 On or more packages with the same name form a group, so we have
345 a simple way to access a package built for different architectures
346 Group exists in a singly linked list of group records starting at
347 the hash index of the name in the pkgCache::Header::GrpHashTable */
348struct pkgCache::Group
349{
350 /** \brief Name of the group */
4ad8619b 351 map_stringitem_t Name;
94449d7c
DK
352
353 // Linked List
52c41485 354 /** \brief Link to the first package which belongs to the group */
4ad8619b 355 map_pointer_t FirstPackage; // Package
52c41485 356 /** \brief Link to the last package which belongs to the group */
4ad8619b 357 map_pointer_t LastPackage; // Package
52c41485 358 /** \brief Link to the next Group */
4ad8619b 359 map_pointer_t Next; // Group
52c41485 360 /** \brief unique sequel ID */
4ad8619b 361 map_id_t ID;
52c41485 362
5bf15716
DK
363};
364 /*}}}*/
94449d7c
DK
365// Package structure /*{{{*/
366/** \brief contains information for a single unique package
367
368 There can be any number of versions of a given package.
369 Package exists in a singly linked list of package records starting at
370 the hash index of the name in the pkgCache::Header::PkgHashTable
371
372 A package can be created for every architecture so package names are
1e3f4083 373 not unique, but it is guaranteed that packages with the same name
94449d7c
DK
374 are sequencel ordered in the list. Packages with the same name can be
375 accessed with the Group.
376*/
377struct pkgCache::Package
578bfd0a 378{
94449d7c 379 /** \brief Name of the package */
4ad8619b 380 map_stringitem_t Name;
94449d7c 381 /** \brief Architecture of the package */
4ad8619b 382 map_stringitem_t Arch;
94449d7c
DK
383 /** \brief Base of a singly linked list of versions
384
385 Each structure represents a unique version of the package.
386 The version structures contain links into PackageFile and the
387 original text file as well as detailed information about the size
388 and dependencies of the specific package. In this way multiple
389 versions of a package can be cleanly handled by the system.
390 Furthermore, this linked list is guaranteed to be sorted
391 from Highest version to lowest version with no duplicate entries. */
4ad8619b 392 map_pointer_t VersionList; // Version
94449d7c 393 /** \brief index to the installed version */
4ad8619b 394 map_pointer_t CurrentVer; // Version
94449d7c 395 /** \brief index of the group this package belongs to */
4ad8619b 396 map_pointer_t Group; // Group the Package belongs to
94449d7c
DK
397
398 // Linked list
399 /** \brief Link to the next package in the same bucket */
4ad8619b 400 map_pointer_t Next; // Package
94449d7c 401 /** \brief List of all dependencies on this package */
4ad8619b 402 map_pointer_t RevDepends; // Dependency
94449d7c 403 /** \brief List of all "packages" this package provide */
4ad8619b 404 map_pointer_t ProvidesList; // Provides
a52f938b 405
578bfd0a 406 // Install/Remove/Purge etc
94449d7c 407 /** \brief state that the user wishes the package to be in */
578bfd0a 408 unsigned char SelectedState; // What
94449d7c
DK
409 /** \brief installation state of the package
410
411 This should be "ok" but in case the installation failed
412 it will be different.
413 */
578bfd0a 414 unsigned char InstState; // Flags
94449d7c 415 /** \brief indicates if the package is installed */
578bfd0a 416 unsigned char CurrentState; // State
94449d7c
DK
417
418 /** \brief unique sequel ID
419
420 ID is a unique value from 0 to Header->PackageCount assigned by the generator.
421 This allows clients to create an array of size PackageCount and use it to store
422 state information for the package map. For instance the status file emitter uses
423 this to track which packages have been emitted already. */
4ad8619b 424 map_id_t ID;
94449d7c 425 /** \brief some useful indicators of the package's state */
f55a958f 426 unsigned long Flags;
578bfd0a 427};
92fcbfc1 428 /*}}}*/
94449d7c
DK
429// Package File structure /*{{{*/
430/** \brief stores information about the files used to generate the cache
431
432 Package files are referenced by Version structures to be able to know
433 after the generation still from which Packages file includes this Version
434 as we need this information later on e.g. for pinning. */
435struct pkgCache::PackageFile
578bfd0a 436{
94449d7c 437 /** \brief physical disk file that this PackageFile represents */
4ad8619b 438 map_pointer_t FileName; // StringItem
94449d7c
DK
439 /** \brief the release information
440
441 Please see the files document for a description of what the
442 release information means. */
4ad8619b
DK
443 map_stringitem_t Archive;
444 map_stringitem_t Codename;
445 map_stringitem_t Component;
446 map_stringitem_t Version;
447 map_stringitem_t Origin;
448 map_stringitem_t Label;
449 map_stringitem_t Architecture;
94449d7c 450 /** \brief The site the index file was fetched from */
4ad8619b 451 map_stringitem_t Site;
94449d7c
DK
452 /** \brief indicates what sort of index file this is
453
454 @TODO enumerate at least the possible indexes */
4ad8619b 455 map_stringitem_t IndexType;
94449d7c
DK
456 /** \brief Size of the file
457
458 Used together with the modification time as a
459 simple check to ensure that the Packages
460 file has not been altered since Cache generation. */
4ad8619b 461 map_filesize_t Size;
94449d7c
DK
462 /** \brief Modification time for the file */
463 time_t mtime;
464
255c9e4b 465 /** @TODO document PackageFile::Flags */
3c124dde 466 unsigned long Flags;
94449d7c 467
578bfd0a 468 // Linked list
94449d7c 469 /** \brief Link to the next PackageFile in the Cache */
4ad8619b 470 map_pointer_t NextFile; // PackageFile
94449d7c 471 /** \brief unique sequel ID */
4ad8619b 472 map_fileid_t ID;
578bfd0a 473};
92fcbfc1 474 /*}}}*/
94449d7c
DK
475// VerFile structure /*{{{*/
476/** \brief associates a version with a PackageFile
477
478 This allows a full description of all Versions in all files
479 (and hence all sources) under consideration. */
480struct pkgCache::VerFile
dcb79bae 481{
94449d7c 482 /** \brief index of the package file that this version was found in */
4ad8619b 483 map_pointer_t File; // PackageFile
94449d7c 484 /** \brief next step in the linked list */
4ad8619b 485 map_pointer_t NextFile; // PkgVerFile
94449d7c 486 /** \brief position in the package file */
4ad8619b 487 map_filesize_t Offset; // File offset
255c9e4b 488 /** @TODO document pkgCache::VerFile::Size */
4ad8619b 489 map_filesize_t Size;
dcb79bae 490};
92fcbfc1 491 /*}}}*/
94449d7c
DK
492// DescFile structure /*{{{*/
493/** \brief associates a description with a Translation file */
494struct pkgCache::DescFile
a52f938b 495{
94449d7c 496 /** \brief index of the file that this description was found in */
4ad8619b 497 map_pointer_t File; // PackageFile
94449d7c 498 /** \brief next step in the linked list */
4ad8619b 499 map_pointer_t NextFile; // PkgVerFile
94449d7c 500 /** \brief position in the file */
4ad8619b 501 map_filesize_t Offset; // File offset
255c9e4b 502 /** @TODO document pkgCache::DescFile::Size */
4ad8619b 503 map_filesize_t Size;
a52f938b 504};
92fcbfc1 505 /*}}}*/
94449d7c
DK
506// Version structure /*{{{*/
507/** \brief information for a single version of a package
508
509 The version list is always sorted from highest version to lowest
510 version by the generator. Equal version numbers are either merged
511 or handled as separate versions based on the Hash value. */
512struct pkgCache::Version
578bfd0a 513{
94449d7c 514 /** \brief complete version string */
4ad8619b 515 map_stringitem_t VerStr;
94449d7c 516 /** \brief section this version is filled in */
4ad8619b 517 map_stringitem_t Section;
894d672e
DK
518
519 /** \brief Multi-Arch capabilities of a package version */
520 enum VerMultiArch { None = 0, /*!< is the default and doesn't trigger special behaviour */
521 All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
522 Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
523 Same = (1<<2), /*!< can be co-installed with itself from other architectures */
00b6a181
DK
524 Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
525 AllForeign = All | Foreign,
526 AllAllowed = All | Allowed };
94449d7c
DK
527 /** \brief stores the MultiArch capabilities of this version
528
894d672e
DK
529 Flags used are defined in pkgCache::Version::VerMultiArch
530 */
531 unsigned char MultiArch;
25396fb0 532
94449d7c
DK
533 /** \brief references all the PackageFile's that this version came from
534
535 FileList can be used to determine what distribution(s) the Version
536 applies to. If FileList is 0 then this is a blank version.
537 The structure should also have a 0 in all other fields excluding
538 pkgCache::Version::VerStr and Possibly pkgCache::Version::NextVer. */
4ad8619b 539 map_pointer_t FileList; // VerFile
94449d7c 540 /** \brief next (lower or equal) version in the linked list */
4ad8619b 541 map_pointer_t NextVer; // Version
94449d7c 542 /** \brief next description in the linked list */
4ad8619b 543 map_pointer_t DescriptionList; // Description
94449d7c 544 /** \brief base of the dependency list */
4ad8619b 545 map_pointer_t DependsList; // Dependency
94449d7c
DK
546 /** \brief links to the owning package
547
548 This allows reverse dependencies to determine the package */
4ad8619b 549 map_pointer_t ParentPkg; // Package
94449d7c 550 /** \brief list of pkgCache::Provides */
4ad8619b 551 map_pointer_t ProvidesList; // Provides
94449d7c
DK
552
553 /** \brief archive size for this version
554
555 For Debian this is the size of the .deb file. */
4ad8619b 556 uint64_t Size; // These are the .deb size
94449d7c 557 /** \brief uncompressed size for this version */
4ad8619b 558 uint64_t InstalledSize;
94449d7c
DK
559 /** \brief characteristic value representing this version
560
561 No two packages in existence should have the same VerStr
562 and Hash with different contents. */
204fbdcc 563 unsigned short Hash;
94449d7c 564 /** \brief unique sequel ID */
4ad8619b 565 map_id_t ID;
94449d7c 566 /** \brief parsed priority value */
578bfd0a
AL
567 unsigned char Priority;
568};
92fcbfc1 569 /*}}}*/
94449d7c
DK
570// Description structure /*{{{*/
571/** \brief datamember of a linked list of available description for a version */
572struct pkgCache::Description
a52f938b 573{
94449d7c
DK
574 /** \brief Language code of this description (translation)
575
576 If the value has a 0 length then this is read using the Package
577 file else the Translation-CODE file is used. */
4ad8619b 578 map_stringitem_t language_code;
94449d7c
DK
579 /** \brief MD5sum of the original description
580
581 Used to map Translations of a description to a version
582 and to check that the Translation is up-to-date. */
4ad8619b 583 map_stringitem_t md5sum;
a52f938b 584
255c9e4b 585 /** @TODO document pkgCache::Description::FileList */
4ad8619b 586 map_pointer_t FileList; // DescFile
94449d7c 587 /** \brief next translation for this description */
4ad8619b 588 map_pointer_t NextDesc; // Description
94449d7c 589 /** \brief the text is a description of this package */
4ad8619b 590 map_pointer_t ParentPkg; // Package
a52f938b 591
94449d7c 592 /** \brief unique sequel ID */
4ad8619b 593 map_id_t ID;
a52f938b 594};
92fcbfc1 595 /*}}}*/
94449d7c
DK
596// Dependency structure /*{{{*/
597/** \brief information for a single dependency record
598
599 The records are split up like this to ease processing by the client.
600 The base of the linked list is pkgCache::Version::DependsList.
601 All forms of dependencies are recorded here including Depends,
602 Recommends, Suggests, Enhances, Conflicts, Replaces and Breaks. */
603struct pkgCache::Dependency
578bfd0a 604{
94449d7c 605 /** \brief string of the version the dependency is applied against */
4ad8619b 606 map_stringitem_t Version; // StringItem
94449d7c
DK
607 /** \brief index of the package this depends applies to
608
609 The generator will - if the package does not already exist -
610 create a blank (no version records) package. */
4ad8619b 611 map_pointer_t Package; // Package
94449d7c 612 /** \brief next dependency of this version */
4ad8619b 613 map_pointer_t NextDepends; // Dependency
94449d7c 614 /** \brief next reverse dependency of this package */
4ad8619b 615 map_pointer_t NextRevDepends; // Dependency
94449d7c 616 /** \brief version of the package which has the reverse depends */
4ad8619b 617 map_pointer_t ParentVer; // Version
94449d7c
DK
618
619 /** \brief unique sequel ID */
4ad8619b 620 map_id_t ID;
94449d7c 621 /** \brief Dependency type - Depends, Recommends, Conflicts, etc */
578bfd0a 622 unsigned char Type;
94449d7c
DK
623 /** \brief comparison operator specified on the depends line
624
625 If the high bit is set then it is a logical OR with the previous record. */
578bfd0a 626 unsigned char CompareOp;
578bfd0a 627};
92fcbfc1 628 /*}}}*/
94449d7c
DK
629// Provides structure /*{{{*/
630/** \brief handles virtual packages
631
632 When a Provides: line is encountered a new provides record is added
633 associating the package with a virtual package name.
634 The provides structures are linked off the package structures.
635 This simplifies the analysis of dependencies and other aspects A provides
636 refers to a specific version of a specific package, not all versions need to
637 provide that provides.*/
638struct pkgCache::Provides
578bfd0a 639{
94449d7c 640 /** \brief index of the package providing this */
4ad8619b 641 map_pointer_t ParentPkg; // Package
94449d7c 642 /** \brief index of the version this provide line applies to */
4ad8619b 643 map_pointer_t Version; // Version
94449d7c
DK
644 /** \brief version in the provides line (if any)
645
646 This version allows dependencies to depend on specific versions of a
647 Provides, as well as allowing Provides to override existing packages.
648 This is experimental. Note that Debian doesn't allow versioned provides */
4ad8619b 649 map_stringitem_t ProvideVersion;
94449d7c 650 /** \brief next provides (based of package) */
4ad8619b 651 map_pointer_t NextProvides; // Provides
94449d7c 652 /** \brief next provides (based of version) */
4ad8619b 653 map_pointer_t NextPkgProv; // Provides
578bfd0a 654};
92fcbfc1 655 /*}}}*/
94449d7c
DK
656// StringItem structure /*{{{*/
657/** \brief used for generating single instances of strings
658
659 Some things like Section Name are are useful to have as unique tags.
660 It is part of a linked list based at pkgCache::Header::StringList
661
662 All strings are simply inlined any place in the file that is natural
663 for the writer. The client should make no assumptions about the positioning
664 of strings. All StringItems should be null-terminated. */
665struct pkgCache::StringItem
578bfd0a 666{
94449d7c 667 /** \brief string this refers to */
4ad8619b 668 map_stringitem_t String;
94449d7c 669 /** \brief Next link in the chain */
4ad8619b 670 map_stringitem_t NextItem;
578bfd0a 671};
92fcbfc1 672 /*}}}*/
959470da
DK
673
674
d64e130a 675inline char const * pkgCache::NativeArch()
d3e8fbb3 676 { return StrP + HeaderP->Architecture; }
959470da 677
094a497d 678#include <apt-pkg/cacheiterators.h>
578bfd0a 679
d3e8fbb3
DK
680inline pkgCache::GrpIterator pkgCache::GrpBegin()
681 {return GrpIterator(*this);}
682inline pkgCache::GrpIterator pkgCache::GrpEnd()
683 {return GrpIterator(*this,GrpP);}
684inline pkgCache::PkgIterator pkgCache::PkgBegin()
685 {return PkgIterator(*this);}
686inline pkgCache::PkgIterator pkgCache::PkgEnd()
687 {return PkgIterator(*this,PkgP);}
ad00ae81 688inline pkgCache::PkgFileIterator pkgCache::FileBegin()
d3e8fbb3 689 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}
ad00ae81 690inline pkgCache::PkgFileIterator pkgCache::FileEnd()
d3e8fbb3 691 {return PkgFileIterator(*this,PkgFileP);}
578bfd0a 692
b2e465d6 693// Oh I wish for Real Name Space Support
92fcbfc1 694class pkgCache::Namespace /*{{{*/
d3e8fbb3 695{
b2e465d6 696 public:
803ea2a8 697 typedef pkgCache::GrpIterator GrpIterator;
b2e465d6
AL
698 typedef pkgCache::PkgIterator PkgIterator;
699 typedef pkgCache::VerIterator VerIterator;
a52f938b 700 typedef pkgCache::DescIterator DescIterator;
b2e465d6
AL
701 typedef pkgCache::DepIterator DepIterator;
702 typedef pkgCache::PrvIterator PrvIterator;
703 typedef pkgCache::PkgFileIterator PkgFileIterator;
d3e8fbb3 704 typedef pkgCache::VerFileIterator VerFileIterator;
b2e465d6 705 typedef pkgCache::Version Version;
a52f938b 706 typedef pkgCache::Description Description;
b2e465d6
AL
707 typedef pkgCache::Package Package;
708 typedef pkgCache::Header Header;
709 typedef pkgCache::Dep Dep;
710 typedef pkgCache::Flag Flag;
711};
92fcbfc1 712 /*}}}*/
578bfd0a 713#endif