pkgcache.h 8.6 KB

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