pkgcache.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.15 1998/12/14 08:07:29 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),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3),
  71. ImmediateConf=(1<<4)};
  72. enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
  73. };
  74. protected:
  75. // Memory mapped cache file
  76. string CacheFile;
  77. MMap &Map;
  78. static unsigned long sHash(string S);
  79. static unsigned long sHash(const char *S);
  80. public:
  81. // Pointers to the arrays of items
  82. Header *HeaderP;
  83. Package *PkgP;
  84. VerFile *VerFileP;
  85. PackageFile *PkgFileP;
  86. Version *VerP;
  87. Provides *ProvideP;
  88. Dependency *DepP;
  89. StringItem *StringItemP;
  90. char *StrP;
  91. virtual bool ReMap();
  92. inline bool Sync() {return Map.Sync();};
  93. inline MMap &GetMap() {return Map;};
  94. // String hashing function (512 range)
  95. inline unsigned long Hash(string S) const {return sHash(S);};
  96. inline unsigned long Hash(const char *S) const {return sHash(S);};
  97. // Usefull transformation things
  98. const char *Priority(unsigned char Priority);
  99. // Accessors
  100. PkgIterator FindPkg(string Name);
  101. Header &Head() {return *HeaderP;};
  102. inline PkgIterator PkgBegin();
  103. inline PkgIterator PkgEnd();
  104. inline PkgFileIterator FileBegin();
  105. inline PkgFileIterator FileEnd();
  106. pkgCache(MMap &Map);
  107. virtual ~pkgCache() {};
  108. };
  109. // Header structure
  110. struct pkgCache::Header
  111. {
  112. // Signature information
  113. unsigned long Signature;
  114. short MajorVersion;
  115. short MinorVersion;
  116. bool Dirty;
  117. // Size of structure values
  118. unsigned short HeaderSz;
  119. unsigned short PackageSz;
  120. unsigned short PackageFileSz;
  121. unsigned short VersionSz;
  122. unsigned short DependencySz;
  123. unsigned short ProvidesSz;
  124. unsigned short VerFileSz;
  125. // Structure counts
  126. unsigned long PackageCount;
  127. unsigned long VersionCount;
  128. unsigned long DependsCount;
  129. unsigned long PackageFileCount;
  130. unsigned long VerFileCount;
  131. unsigned long ProvidesCount;
  132. // Offsets
  133. __apt_ptrloc FileList; // struct PackageFile
  134. __apt_ptrloc StringList; // struct StringItem
  135. unsigned long MaxVerFileSize;
  136. /* Allocation pools, there should be one of these for each structure
  137. excluding the header */
  138. DynamicMMap::Pool Pools[7];
  139. // Rapid package name lookup
  140. __apt_ptrloc HashTable[2048];
  141. bool CheckSizes(Header &Against) const;
  142. Header();
  143. };
  144. struct pkgCache::Package
  145. {
  146. // Pointers
  147. __apt_ptrloc Name; // Stringtable
  148. __apt_ptrloc VersionList; // Version
  149. __apt_ptrloc TargetVer; // Version
  150. __apt_ptrloc CurrentVer; // Version
  151. __apt_ptrloc TargetDist; // StringTable (StringItem)
  152. __apt_ptrloc Section; // StringTable (StringItem)
  153. // Linked list
  154. __apt_ptrloc NextPackage; // Package
  155. __apt_ptrloc RevDepends; // Dependency
  156. __apt_ptrloc ProvidesList; // Provides
  157. // Install/Remove/Purge etc
  158. unsigned char SelectedState; // What
  159. unsigned char InstState; // Flags
  160. unsigned char CurrentState; // State
  161. unsigned short ID;
  162. unsigned long Flags;
  163. };
  164. struct pkgCache::PackageFile
  165. {
  166. // Names
  167. __apt_ptrloc FileName; // Stringtable
  168. __apt_ptrloc Archive; // Stringtable
  169. __apt_ptrloc Component; // Stringtable
  170. __apt_ptrloc Version; // Stringtable
  171. __apt_ptrloc Origin; // Stringtable
  172. __apt_ptrloc Label; // Stringtable
  173. __apt_ptrloc Architecture; // Stringtable
  174. unsigned long Size;
  175. unsigned long Flags;
  176. // Linked list
  177. __apt_ptrloc NextFile; // PackageFile
  178. unsigned short ID;
  179. time_t mtime; // Modification time for the file
  180. };
  181. struct pkgCache::VerFile
  182. {
  183. __apt_ptrloc File; // PackageFile
  184. __apt_ptrloc NextFile; // PkgVerFile
  185. __apt_ptrloc Offset; // File offset
  186. unsigned short Size;
  187. };
  188. struct pkgCache::Version
  189. {
  190. __apt_ptrloc VerStr; // Stringtable
  191. __apt_ptrloc Section; // StringTable (StringItem)
  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