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