pkgcache.h 7.8 KB

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