You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

832 lines
32 KiB

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