pkgcache.h 32 KB

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