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.
 
 
 
 
 
 

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