pkgcache.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.22 1999/07/30 02:54:25 jgg Exp $
  4. /* ######################################################################
  5. Cache - Structure definitions for the cache file
  6. Please see doc/apt-pkg/cache.sgml for a more detailed description of
  7. this format. Also be sure to keep that file up-to-date!!
  8. Clients should always use the CacheIterators classes for access to the
  9. cache. They provide a simple STL-like method for traversing the links
  10. of the datastructure.
  11. See pkgcachegen.h for information about generating cache structures.
  12. ##################################################################### */
  13. /*}}}*/
  14. // Header section: pkglib
  15. #ifndef PKGLIB_PKGCACHE_H
  16. #define PKGLIB_PKGCACHE_H
  17. #ifdef __GNUG__
  18. #pragma interface "apt-pkg/pkgcache.h"
  19. #endif
  20. #include <string>
  21. #include <time.h>
  22. #include <apt-pkg/mmap.h>
  23. class pkgCache
  24. {
  25. public:
  26. // Cache element predeclarations
  27. struct Header;
  28. struct Package;
  29. struct PackageFile;
  30. struct Version;
  31. struct Provides;
  32. struct Dependency;
  33. struct StringItem;
  34. struct VerFile;
  35. // Iterators
  36. class PkgIterator;
  37. class VerIterator;
  38. class DepIterator;
  39. class PrvIterator;
  40. class PkgFileIterator;
  41. class VerFileIterator;
  42. friend PkgIterator;
  43. friend VerIterator;
  44. friend DepIterator;
  45. friend PrvIterator;
  46. friend PkgFileIterator;
  47. friend VerFileIterator;
  48. // These are all the constants used in the cache structures
  49. struct Dep
  50. {
  51. enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  52. Conflicts=5,Replaces=6};
  53. enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  54. Greater=0x4,Equals=0x5,NotEquals=0x6};
  55. };
  56. struct State
  57. {
  58. enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
  59. enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  60. enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  61. enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  62. HalfInstalled=4,ConfigFiles=5,Installed=6};
  63. };
  64. struct Flag
  65. {
  66. enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
  67. enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
  68. };
  69. protected:
  70. // Memory mapped cache file
  71. string CacheFile;
  72. MMap &Map;
  73. unsigned long sHash(string S) const;
  74. unsigned long sHash(const char *S) const;
  75. public:
  76. // Pointers to the arrays of items
  77. Header *HeaderP;
  78. Package *PkgP;
  79. VerFile *VerFileP;
  80. PackageFile *PkgFileP;
  81. Version *VerP;
  82. Provides *ProvideP;
  83. Dependency *DepP;
  84. StringItem *StringItemP;
  85. char *StrP;
  86. virtual bool ReMap();
  87. inline bool Sync() {return Map.Sync();};
  88. inline MMap &GetMap() {return Map;};
  89. // String hashing function (512 range)
  90. inline unsigned long Hash(string S) const {return sHash(S);};
  91. inline unsigned long Hash(const char *S) const {return sHash(S);};
  92. // Usefull transformation things
  93. const char *Priority(unsigned char Priority);
  94. // Accessors
  95. PkgIterator FindPkg(string Name);
  96. Header &Head() {return *HeaderP;};
  97. inline PkgIterator PkgBegin();
  98. inline PkgIterator PkgEnd();
  99. inline PkgFileIterator FileBegin();
  100. inline PkgFileIterator FileEnd();
  101. VerIterator GetCandidateVer(PkgIterator Pkg,bool AllowCurrent = true);
  102. pkgCache(MMap &Map);
  103. virtual ~pkgCache() {};
  104. };
  105. // Header structure
  106. struct pkgCache::Header
  107. {
  108. // Signature information
  109. unsigned long Signature;
  110. short MajorVersion;
  111. short MinorVersion;
  112. bool Dirty;
  113. // Size of structure values
  114. unsigned short HeaderSz;
  115. unsigned short PackageSz;
  116. unsigned short PackageFileSz;
  117. unsigned short VersionSz;
  118. unsigned short DependencySz;
  119. unsigned short ProvidesSz;
  120. unsigned short VerFileSz;
  121. // Structure counts
  122. unsigned long PackageCount;
  123. unsigned long VersionCount;
  124. unsigned long DependsCount;
  125. unsigned long PackageFileCount;
  126. unsigned long VerFileCount;
  127. unsigned long ProvidesCount;
  128. // Offsets
  129. map_ptrloc FileList; // struct PackageFile
  130. map_ptrloc StringList; // struct StringItem
  131. unsigned long MaxVerFileSize;
  132. /* Allocation pools, there should be one of these for each structure
  133. excluding the header */
  134. DynamicMMap::Pool Pools[7];
  135. // Rapid package name lookup
  136. map_ptrloc HashTable[2*1048];
  137. bool CheckSizes(Header &Against) const;
  138. Header();
  139. };
  140. struct pkgCache::Package
  141. {
  142. // Pointers
  143. map_ptrloc Name; // Stringtable
  144. map_ptrloc VersionList; // Version
  145. map_ptrloc TargetVer; // Version
  146. map_ptrloc CurrentVer; // Version
  147. map_ptrloc TargetDist; // StringTable (StringItem)
  148. map_ptrloc Section; // StringTable (StringItem)
  149. // Linked list
  150. map_ptrloc NextPackage; // Package
  151. map_ptrloc RevDepends; // Dependency
  152. map_ptrloc ProvidesList; // Provides
  153. // Install/Remove/Purge etc
  154. unsigned char SelectedState; // What
  155. unsigned char InstState; // Flags
  156. unsigned char CurrentState; // State
  157. unsigned short ID;
  158. unsigned long Flags;
  159. };
  160. struct pkgCache::PackageFile
  161. {
  162. // Names
  163. map_ptrloc FileName; // Stringtable
  164. map_ptrloc Archive; // Stringtable
  165. map_ptrloc Component; // Stringtable
  166. map_ptrloc Version; // Stringtable
  167. map_ptrloc Origin; // Stringtable
  168. map_ptrloc Label; // Stringtable
  169. map_ptrloc Architecture; // Stringtable
  170. unsigned long Size;
  171. unsigned long Flags;
  172. // Linked list
  173. map_ptrloc NextFile; // PackageFile
  174. unsigned short ID;
  175. time_t mtime; // Modification time for the file
  176. };
  177. struct pkgCache::VerFile
  178. {
  179. map_ptrloc File; // PackageFile
  180. map_ptrloc NextFile; // PkgVerFile
  181. map_ptrloc Offset; // File offset
  182. unsigned short Size;
  183. };
  184. struct pkgCache::Version
  185. {
  186. map_ptrloc VerStr; // Stringtable
  187. map_ptrloc Section; // StringTable (StringItem)
  188. map_ptrloc Arch; // StringTable
  189. // Lists
  190. map_ptrloc FileList; // VerFile
  191. map_ptrloc NextVer; // Version
  192. map_ptrloc DependsList; // Dependency
  193. map_ptrloc ParentPkg; // Package
  194. map_ptrloc ProvidesList; // Provides
  195. map_ptrloc Size; // These are the .deb size
  196. map_ptrloc InstalledSize;
  197. unsigned short Hash;
  198. unsigned short ID;
  199. unsigned char Priority;
  200. };
  201. struct pkgCache::Dependency
  202. {
  203. map_ptrloc Version; // Stringtable
  204. map_ptrloc Package; // Package
  205. map_ptrloc NextDepends; // Dependency
  206. map_ptrloc NextRevDepends; // Dependency
  207. map_ptrloc ParentVer; // Version
  208. // Specific types of depends
  209. unsigned char Type;
  210. unsigned char CompareOp;
  211. unsigned short ID;
  212. };
  213. struct pkgCache::Provides
  214. {
  215. map_ptrloc ParentPkg; // Pacakge
  216. map_ptrloc Version; // Version
  217. map_ptrloc ProvideVersion; // Stringtable
  218. map_ptrloc NextProvides; // Provides
  219. map_ptrloc NextPkgProv; // Provides
  220. };
  221. struct pkgCache::StringItem
  222. {
  223. map_ptrloc String; // Stringtable
  224. map_ptrloc NextItem; // StringItem
  225. };
  226. #include <apt-pkg/cacheiterators.h>
  227. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  228. {return PkgIterator(*this);};
  229. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  230. {return PkgIterator(*this,PkgP);};
  231. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  232. {return PkgFileIterator(*this);};
  233. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  234. {return PkgFileIterator(*this,PkgFileP);};
  235. #endif