pkgcache.h 8.7 KB

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