pkgcache.h 8.6 KB

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