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