pkgcache.h 8.6 KB

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