pkgcache.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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_MSG("Not used anymore in cache generation and without a replacement") 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. APT_HIDDEN uint32_t CacheHash();
  197. // Useful transformation things
  198. static const char *Priority(unsigned char Priority);
  199. // Accessors
  200. GrpIterator FindGrp(const std::string &Name);
  201. PkgIterator FindPkg(const std::string &Name);
  202. PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
  203. Header &Head() {return *HeaderP;}
  204. inline GrpIterator GrpBegin();
  205. inline GrpIterator GrpEnd();
  206. inline PkgIterator PkgBegin();
  207. inline PkgIterator PkgEnd();
  208. inline PkgFileIterator FileBegin();
  209. inline PkgFileIterator FileEnd();
  210. inline RlsFileIterator RlsFileBegin();
  211. inline RlsFileIterator RlsFileEnd();
  212. inline bool MultiArchCache() const { return MultiArchEnabled; }
  213. inline char const * NativeArch();
  214. // Make me a function
  215. pkgVersioningSystem *VS;
  216. // Converters
  217. static const char *CompTypeDeb(unsigned char Comp) APT_CONST;
  218. static const char *CompType(unsigned char Comp) APT_CONST;
  219. static const char *DepType(unsigned char Dep);
  220. pkgCache(MMap *Map,bool DoMap = true);
  221. virtual ~pkgCache();
  222. private:
  223. void * const d;
  224. bool MultiArchEnabled;
  225. };
  226. /*}}}*/
  227. // Header structure /*{{{*/
  228. struct pkgCache::Header
  229. {
  230. /** \brief Signature information
  231. This must contain the hex value 0x98FE76DC which is designed to
  232. verify that the system loading the image has the same byte order
  233. and byte size as the system saving the image */
  234. uint32_t Signature;
  235. /** These contain the version of the cache file */
  236. map_number_t MajorVersion;
  237. map_number_t MinorVersion;
  238. /** \brief indicates if the cache should be erased
  239. Dirty is true if the cache file was opened for reading, the client
  240. expects to have written things to it and have not fully synced it.
  241. The file should be erased and rebuilt if it is true. */
  242. bool Dirty;
  243. /** \brief Size of structure values
  244. All *Sz variables contains the sizeof() that particular structure.
  245. It is used as an extra consistency check on the structure of the file.
  246. If any of the size values do not exactly match what the client expects
  247. then the client should refuse the load the file. */
  248. uint16_t HeaderSz;
  249. map_number_t GroupSz;
  250. map_number_t PackageSz;
  251. map_number_t ReleaseFileSz;
  252. map_number_t PackageFileSz;
  253. map_number_t VersionSz;
  254. map_number_t DescriptionSz;
  255. map_number_t DependencySz;
  256. map_number_t DependencyDataSz;
  257. map_number_t ProvidesSz;
  258. map_number_t VerFileSz;
  259. map_number_t DescFileSz;
  260. /** \brief Structure counts
  261. These indicate the number of each structure contained in the cache.
  262. PackageCount is especially useful for generating user state structures.
  263. See Package::Id for more info. */
  264. map_id_t GroupCount;
  265. map_id_t PackageCount;
  266. map_id_t VersionCount;
  267. map_id_t DescriptionCount;
  268. map_id_t DependsCount;
  269. map_id_t DependsDataCount;
  270. map_fileid_t ReleaseFileCount;
  271. map_fileid_t PackageFileCount;
  272. map_fileid_t VerFileCount;
  273. map_fileid_t DescFileCount;
  274. map_id_t ProvidesCount;
  275. /** \brief index of the first PackageFile structure
  276. The PackageFile structures are singly linked lists that represent
  277. all package files that have been merged into the cache. */
  278. map_pointer_t FileList;
  279. /** \brief index of the first ReleaseFile structure */
  280. map_pointer_t RlsFileList;
  281. /** \brief String representing the version system used */
  282. map_pointer_t VerSysName;
  283. /** \brief native architecture the cache was built against */
  284. map_pointer_t Architecture;
  285. /** \brief all architectures the cache was built against */
  286. map_pointer_t Architectures;
  287. /** \brief The maximum size of a raw entry from the original Package file */
  288. map_filesize_t MaxVerFileSize;
  289. /** \brief The maximum size of a raw entry from the original Translation file */
  290. map_filesize_t MaxDescFileSize;
  291. /** \brief The Pool structures manage the allocation pools that the generator uses
  292. Start indicates the first byte of the pool, Count is the number of objects
  293. remaining in the pool and ItemSize is the structure size (alignment factor)
  294. of the pool. An ItemSize of 0 indicates the pool is empty. There should be
  295. the same number of pools as there are structure types. The generator
  296. stores this information so future additions can make use of any unused pool
  297. blocks. */
  298. DynamicMMap::Pool Pools[12];
  299. /** \brief hash tables providing rapid group/package name lookup
  300. Each group/package name is inserted into a hash table using pkgCache::Hash(const &string)
  301. By iterating over each entry in the hash table it is possible to iterate over
  302. the entire list of packages. Hash Collisions are handled with a singly linked
  303. list of packages based at the hash item. The linked list contains only
  304. packages that match the hashing function.
  305. In the PkgHashTable is it possible that multiple packages have the same name -
  306. these packages are stored as a sequence in the list.
  307. The size of both tables is the same. */
  308. uint32_t HashTableSize;
  309. uint32_t GetHashTableSize() const { return HashTableSize; }
  310. void SetHashTableSize(unsigned int const sz) { HashTableSize = sz; }
  311. map_pointer_t GetArchitectures() const { return Architectures; }
  312. void SetArchitectures(map_pointer_t const idx) { Architectures = idx; }
  313. map_pointer_t * PkgHashTableP() const { return (map_pointer_t*) (this + 1); }
  314. map_pointer_t * GrpHashTableP() const { return PkgHashTableP() + GetHashTableSize(); }
  315. /** \brief Hash of the file (TODO: Rename) */
  316. map_filesize_small_t CacheFileSize;
  317. bool CheckSizes(Header &Against) const APT_PURE;
  318. Header();
  319. };
  320. /*}}}*/
  321. // Group structure /*{{{*/
  322. /** \brief groups architecture depending packages together
  323. On or more packages with the same name form a group, so we have
  324. a simple way to access a package built for different architectures
  325. Group exists in a singly linked list of group records starting at
  326. the hash index of the name in the pkgCache::Header::GrpHashTable */
  327. struct pkgCache::Group
  328. {
  329. /** \brief Name of the group */
  330. map_stringitem_t Name;
  331. // Linked List
  332. /** \brief Link to the first package which belongs to the group */
  333. map_pointer_t FirstPackage; // Package
  334. /** \brief Link to the last package which belongs to the group */
  335. map_pointer_t LastPackage; // Package
  336. /** \brief Link to the next Group */
  337. map_pointer_t Next; // Group
  338. /** \brief unique sequel ID */
  339. map_id_t ID;
  340. };
  341. /*}}}*/
  342. // Package structure /*{{{*/
  343. /** \brief contains information for a single unique package
  344. There can be any number of versions of a given package.
  345. Package exists in a singly linked list of package records starting at
  346. the hash index of the name in the pkgCache::Header::PkgHashTable
  347. A package can be created for every architecture so package names are
  348. not unique, but it is guaranteed that packages with the same name
  349. are sequencel ordered in the list. Packages with the same name can be
  350. accessed with the Group.
  351. */
  352. struct pkgCache::Package
  353. {
  354. /** \brief Name of the package
  355. * Note that the access method Name() will remain. It is just this data member
  356. * deprecated as this information is already stored and available via the
  357. * associated Group – so it is wasting precious binary cache space */
  358. APT_DEPRECATED_MSG("Use the .Name() method instead of accessing the member directly") map_stringitem_t Name;
  359. /** \brief Architecture of the package */
  360. map_stringitem_t Arch;
  361. /** \brief Base of a singly linked list of versions
  362. Each structure represents a unique version of the package.
  363. The version structures contain links into PackageFile and the
  364. original text file as well as detailed information about the size
  365. and dependencies of the specific package. In this way multiple
  366. versions of a package can be cleanly handled by the system.
  367. Furthermore, this linked list is guaranteed to be sorted
  368. from Highest version to lowest version with no duplicate entries. */
  369. map_pointer_t VersionList; // Version
  370. /** \brief index to the installed version */
  371. map_pointer_t CurrentVer; // Version
  372. /** \brief index of the group this package belongs to */
  373. map_pointer_t Group; // Group the Package belongs to
  374. // Linked list
  375. /** \brief Link to the next package in the same bucket */
  376. map_pointer_t NextPackage; // Package
  377. /** \brief List of all dependencies on this package */
  378. map_pointer_t RevDepends; // Dependency
  379. /** \brief List of all "packages" this package provide */
  380. map_pointer_t ProvidesList; // Provides
  381. // Install/Remove/Purge etc
  382. /** \brief state that the user wishes the package to be in */
  383. map_number_t SelectedState; // What
  384. /** \brief installation state of the package
  385. This should be "ok" but in case the installation failed
  386. it will be different.
  387. */
  388. map_number_t InstState; // Flags
  389. /** \brief indicates if the package is installed */
  390. map_number_t CurrentState; // State
  391. /** \brief unique sequel ID
  392. ID is a unique value from 0 to Header->PackageCount assigned by the generator.
  393. This allows clients to create an array of size PackageCount and use it to store
  394. state information for the package map. For instance the status file emitter uses
  395. this to track which packages have been emitted already. */
  396. map_id_t ID;
  397. /** \brief some useful indicators of the package's state */
  398. map_flags_t Flags;
  399. };
  400. /*}}}*/
  401. // Release File structure /*{{{*/
  402. /** \brief stores information about the release files used to generate the cache
  403. PackageFiles reference ReleaseFiles as we need to keep record of which
  404. version belongs to which release e.g. for pinning. */
  405. struct pkgCache::ReleaseFile
  406. {
  407. /** \brief physical disk file that this ReleaseFile represents */
  408. map_stringitem_t FileName;
  409. /** \brief the release information
  410. Please see the files document for a description of what the
  411. release information means. */
  412. map_stringitem_t Archive;
  413. map_stringitem_t Codename;
  414. map_stringitem_t Version;
  415. map_stringitem_t Origin;
  416. map_stringitem_t Label;
  417. /** \brief The site the index file was fetched from */
  418. map_stringitem_t Site;
  419. /** \brief Size of the file
  420. Used together with the modification time as a
  421. simple check to ensure that the Packages
  422. file has not been altered since Cache generation. */
  423. map_filesize_t Size;
  424. /** \brief Modification time for the file */
  425. time_t mtime;
  426. /** @TODO document PackageFile::Flags */
  427. map_flags_t Flags;
  428. // Linked list
  429. /** \brief Link to the next ReleaseFile in the Cache */
  430. map_pointer_t NextFile;
  431. /** \brief unique sequel ID */
  432. map_fileid_t ID;
  433. };
  434. /*}}}*/
  435. // Package File structure /*{{{*/
  436. /** \brief stores information about the files used to generate the cache
  437. Package files are referenced by Version structures to be able to know
  438. after the generation still from which Packages file includes this Version
  439. as we need this information later on e.g. for pinning. */
  440. struct pkgCache::PackageFile
  441. {
  442. /** \brief physical disk file that this PackageFile represents */
  443. map_stringitem_t FileName;
  444. /** \brief the release information */
  445. map_pointer_t Release;
  446. map_stringitem_t Component;
  447. map_stringitem_t Architecture;
  448. /** \brief indicates what sort of index file this is
  449. @TODO enumerate at least the possible indexes */
  450. map_stringitem_t IndexType;
  451. /** \brief Size of the file
  452. Used together with the modification time as a
  453. simple check to ensure that the Packages
  454. file has not been altered since Cache generation. */
  455. map_filesize_t Size;
  456. /** \brief Modification time for the file */
  457. time_t mtime;
  458. /** @TODO document PackageFile::Flags */
  459. map_flags_t Flags;
  460. // Linked list
  461. /** \brief Link to the next PackageFile in the Cache */
  462. map_pointer_t NextFile; // PackageFile
  463. /** \brief unique sequel ID */
  464. map_fileid_t ID;
  465. };
  466. /*}}}*/
  467. // VerFile structure /*{{{*/
  468. /** \brief associates a version with a PackageFile
  469. This allows a full description of all Versions in all files
  470. (and hence all sources) under consideration. */
  471. struct pkgCache::VerFile
  472. {
  473. /** \brief index of the package file that this version was found in */
  474. map_pointer_t File; // PackageFile
  475. /** \brief next step in the linked list */
  476. map_pointer_t NextFile; // PkgVerFile
  477. /** \brief position in the package file */
  478. map_filesize_t Offset; // File offset
  479. /** @TODO document pkgCache::VerFile::Size */
  480. map_filesize_t Size;
  481. };
  482. /*}}}*/
  483. // DescFile structure /*{{{*/
  484. /** \brief associates a description with a Translation file */
  485. struct pkgCache::DescFile
  486. {
  487. /** \brief index of the file that this description was found in */
  488. map_pointer_t File; // PackageFile
  489. /** \brief next step in the linked list */
  490. map_pointer_t NextFile; // PkgVerFile
  491. /** \brief position in the file */
  492. map_filesize_t Offset; // File offset
  493. /** @TODO document pkgCache::DescFile::Size */
  494. map_filesize_t Size;
  495. };
  496. /*}}}*/
  497. // Version structure /*{{{*/
  498. /** \brief information for a single version of a package
  499. The version list is always sorted from highest version to lowest
  500. version by the generator. Equal version numbers are either merged
  501. or handled as separate versions based on the Hash value. */
  502. APT_IGNORE_DEPRECATED_PUSH
  503. struct pkgCache::Version
  504. {
  505. /** \brief complete version string */
  506. map_stringitem_t VerStr;
  507. /** \brief section this version is filled in */
  508. map_stringitem_t Section;
  509. /** \brief source package name this version comes from
  510. Always contains the name, even if it is the same as the binary name */
  511. map_stringitem_t SourcePkgName;
  512. /** \brief source version this version comes from
  513. Always contains the version string, even if it is the same as the binary version */
  514. map_stringitem_t SourceVerStr;
  515. /** \brief Multi-Arch capabilities of a package version */
  516. enum VerMultiArch { No = 0, /*!< is the default and doesn't trigger special behaviour */
  517. All = (1<<0), /*!< will cause that Ver.Arch() will report "all" */
  518. Foreign = (1<<1), /*!< can satisfy dependencies in another architecture */
  519. Same = (1<<2), /*!< can be co-installed with itself from other architectures */
  520. Allowed = (1<<3), /*!< other packages are allowed to depend on thispkg:any */
  521. AllForeign = All | Foreign,
  522. AllAllowed = All | Allowed };
  523. /** \brief deprecated variant of No */
  524. static const APT_DEPRECATED_MSG("The default value of the Multi-Arch field is no, not none") VerMultiArch None = No;
  525. /** \brief stores the MultiArch capabilities of this version
  526. Flags used are defined in pkgCache::Version::VerMultiArch
  527. */
  528. map_number_t MultiArch;
  529. /** \brief references all the PackageFile's that this version came from
  530. FileList can be used to determine what distribution(s) the Version
  531. applies to. If FileList is 0 then this is a blank version.
  532. The structure should also have a 0 in all other fields excluding
  533. pkgCache::Version::VerStr and Possibly pkgCache::Version::NextVer. */
  534. map_pointer_t FileList; // VerFile
  535. /** \brief next (lower or equal) version in the linked list */
  536. map_pointer_t NextVer; // Version
  537. /** \brief next description in the linked list */
  538. map_pointer_t DescriptionList; // Description
  539. /** \brief base of the dependency list */
  540. map_pointer_t DependsList; // Dependency
  541. /** \brief links to the owning package
  542. This allows reverse dependencies to determine the package */
  543. map_pointer_t ParentPkg; // Package
  544. /** \brief list of pkgCache::Provides */
  545. map_pointer_t ProvidesList; // Provides
  546. /** \brief archive size for this version
  547. For Debian this is the size of the .deb file. */
  548. map_filesize_t Size; // These are the .deb size
  549. /** \brief uncompressed size for this version */
  550. map_filesize_t InstalledSize;
  551. /** \brief characteristic value representing this version
  552. No two packages in existence should have the same VerStr
  553. and Hash with different contents. */
  554. unsigned short Hash;
  555. /** \brief unique sequel ID */
  556. map_id_t ID;
  557. /** \brief parsed priority value */
  558. map_number_t Priority;
  559. };
  560. APT_IGNORE_DEPRECATED_POP
  561. /*}}}*/
  562. // Description structure /*{{{*/
  563. /** \brief datamember of a linked list of available description for a version */
  564. struct pkgCache::Description
  565. {
  566. /** \brief Language code of this description (translation)
  567. If the value has a 0 length then this is read using the Package
  568. file else the Translation-CODE file is used. */
  569. map_stringitem_t language_code;
  570. /** \brief MD5sum of the original description
  571. Used to map Translations of a description to a version
  572. and to check that the Translation is up-to-date. */
  573. map_stringitem_t md5sum;
  574. /** @TODO document pkgCache::Description::FileList */
  575. map_pointer_t FileList; // DescFile
  576. /** \brief next translation for this description */
  577. map_pointer_t NextDesc; // Description
  578. /** \brief the text is a description of this package */
  579. map_pointer_t ParentPkg; // Package
  580. /** \brief unique sequel ID */
  581. map_id_t ID;
  582. };
  583. /*}}}*/
  584. // Dependency structure /*{{{*/
  585. /** \brief information for a single dependency record
  586. The records are split up like this to ease processing by the client.
  587. The base of the linked list is pkgCache::Version::DependsList.
  588. All forms of dependencies are recorded here including Depends,
  589. Recommends, Suggests, Enhances, Conflicts, Replaces and Breaks. */
  590. struct pkgCache::DependencyData
  591. {
  592. /** \brief string of the version the dependency is applied against */
  593. map_stringitem_t Version;
  594. /** \brief index of the package this depends applies to
  595. The generator will - if the package does not already exist -
  596. create a blank (no version records) package. */
  597. map_pointer_t Package; // Package
  598. /** \brief Dependency type - Depends, Recommends, Conflicts, etc */
  599. map_number_t Type;
  600. /** \brief comparison operator specified on the depends line
  601. If the high bit is set then it is a logical OR with the previous record. */
  602. map_flags_t CompareOp;
  603. map_pointer_t NextData;
  604. };
  605. struct pkgCache::Dependency
  606. {
  607. map_pointer_t DependencyData; // DependencyData
  608. /** \brief version of the package which has the depends */
  609. map_pointer_t ParentVer; // Version
  610. /** \brief next reverse dependency of this package */
  611. map_pointer_t NextRevDepends; // Dependency
  612. /** \brief next dependency of this version */
  613. map_pointer_t NextDepends; // Dependency
  614. /** \brief unique sequel ID */
  615. map_id_t ID;
  616. };
  617. /*}}}*/
  618. // Provides structure /*{{{*/
  619. /** \brief handles virtual packages
  620. When a Provides: line is encountered a new provides record is added
  621. associating the package with a virtual package name.
  622. The provides structures are linked off the package structures.
  623. This simplifies the analysis of dependencies and other aspects A provides
  624. refers to a specific version of a specific package, not all versions need to
  625. provide that provides.*/
  626. struct pkgCache::Provides
  627. {
  628. /** \brief index of the package providing this */
  629. map_pointer_t ParentPkg; // Package
  630. /** \brief index of the version this provide line applies to */
  631. map_pointer_t Version; // Version
  632. /** \brief version in the provides line (if any)
  633. This version allows dependencies to depend on specific versions of a
  634. Provides, as well as allowing Provides to override existing packages. */
  635. map_stringitem_t ProvideVersion;
  636. map_flags_t Flags;
  637. /** \brief next provides (based of package) */
  638. map_pointer_t NextProvides; // Provides
  639. /** \brief next provides (based of version) */
  640. map_pointer_t NextPkgProv; // Provides
  641. };
  642. /*}}}*/
  643. // UNUSED StringItem structure /*{{{*/
  644. struct APT_DEPRECATED_MSG("No longer used in cache generation without a replacement") pkgCache::StringItem
  645. {
  646. /** \brief string this refers to */
  647. map_ptrloc String; // StringItem
  648. /** \brief Next link in the chain */
  649. map_ptrloc NextItem; // StringItem
  650. };
  651. /*}}}*/
  652. inline char const * pkgCache::NativeArch()
  653. { return StrP + HeaderP->Architecture; }
  654. #include <apt-pkg/cacheiterators.h>
  655. inline pkgCache::GrpIterator pkgCache::GrpBegin()
  656. {return GrpIterator(*this);}
  657. inline pkgCache::GrpIterator pkgCache::GrpEnd()
  658. {return GrpIterator(*this,GrpP);}
  659. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  660. {return PkgIterator(*this);}
  661. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  662. {return PkgIterator(*this,PkgP);}
  663. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  664. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}
  665. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  666. {return PkgFileIterator(*this,PkgFileP);}
  667. inline pkgCache::RlsFileIterator pkgCache::RlsFileBegin()
  668. {return RlsFileIterator(*this,RlsFileP + HeaderP->RlsFileList);}
  669. inline pkgCache::RlsFileIterator pkgCache::RlsFileEnd()
  670. {return RlsFileIterator(*this,RlsFileP);}
  671. // Oh I wish for Real Name Space Support
  672. class pkgCache::Namespace /*{{{*/
  673. {
  674. public:
  675. typedef pkgCache::GrpIterator GrpIterator;
  676. typedef pkgCache::PkgIterator PkgIterator;
  677. typedef pkgCache::VerIterator VerIterator;
  678. typedef pkgCache::DescIterator DescIterator;
  679. typedef pkgCache::DepIterator DepIterator;
  680. typedef pkgCache::PrvIterator PrvIterator;
  681. typedef pkgCache::RlsFileIterator RlsFileIterator;
  682. typedef pkgCache::PkgFileIterator PkgFileIterator;
  683. typedef pkgCache::VerFileIterator VerFileIterator;
  684. typedef pkgCache::Version Version;
  685. typedef pkgCache::Description Description;
  686. typedef pkgCache::Package Package;
  687. typedef pkgCache::Header Header;
  688. typedef pkgCache::Dep Dep;
  689. typedef pkgCache::Flag Flag;
  690. };
  691. /*}}}*/
  692. #endif