pkgcache.h 30 KB

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