pkgcache.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.9 1998/11/08 23:29:18 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. 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 PkgIterator;
  43. friend VerIterator;
  44. friend DepIterator;
  45. friend PrvIterator;
  46. friend PkgFileIterator;
  47. friend VerFileIterator;
  48. // These are all the constants used in the cache structures
  49. struct Dep
  50. {
  51. enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  52. Conflicts=5,Replaces=6};
  53. enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  54. Greater=0x4,Equals=0x5,NotEquals=0x6};
  55. };
  56. struct State
  57. {
  58. enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
  59. enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  60. enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  61. enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  62. UnInstalled=3,HalfInstalled=4,ConfigFiles=5,Installed=6};
  63. };
  64. struct Flag
  65. {
  66. enum PkgFlags {Auto=(1<<0),New=(1<<1),Obsolete=(1<<2),Essential=(1<<3),
  67. ImmediateConf=(1<<4)};
  68. enum PkgFFlags {NotSource=(1<<0)};
  69. };
  70. protected:
  71. // Memory mapped cache file
  72. string CacheFile;
  73. MMap &Map;
  74. static unsigned long sHash(string S);
  75. static unsigned long sHash(const char *S);
  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. // String hashing function (512 range)
  90. inline unsigned long Hash(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(string Name);
  96. Header &Head() {return *HeaderP;};
  97. inline PkgIterator PkgBegin();
  98. inline PkgIterator PkgEnd();
  99. inline PkgFileIterator FileBegin();
  100. inline PkgFileIterator FileEnd();
  101. pkgCache(MMap &Map);
  102. virtual ~pkgCache() {};
  103. };
  104. // Header structure
  105. struct pkgCache::Header
  106. {
  107. // Signature information
  108. unsigned long Signature;
  109. short MajorVersion;
  110. short MinorVersion;
  111. bool Dirty;
  112. // Size of structure values
  113. unsigned short HeaderSz;
  114. unsigned short PackageSz;
  115. unsigned short PackageFileSz;
  116. unsigned short VersionSz;
  117. unsigned short DependencySz;
  118. unsigned short ProvidesSz;
  119. unsigned short VerFileSz;
  120. // Structure counts
  121. unsigned long PackageCount;
  122. unsigned long VersionCount;
  123. unsigned long DependsCount;
  124. unsigned long PackageFileCount;
  125. // Offsets
  126. unsigned long FileList; // struct PackageFile
  127. unsigned long StringList; // struct StringItem
  128. unsigned long MaxVerFileSize;
  129. /* Allocation pools, there should be one of these for each structure
  130. excluding the header */
  131. DynamicMMap::Pool Pools[7];
  132. // Rapid package name lookup
  133. unsigned long HashTable[512];
  134. bool CheckSizes(Header &Against) const;
  135. Header();
  136. };
  137. struct pkgCache::Package
  138. {
  139. // Pointers
  140. unsigned long Name; // Stringtable
  141. unsigned long VersionList; // Version
  142. unsigned long TargetVer; // Version
  143. unsigned long CurrentVer; // Version
  144. unsigned long TargetDist; // StringTable (StringItem)
  145. unsigned long Section; // StringTable (StringItem)
  146. // Linked list
  147. unsigned long NextPackage; // Package
  148. unsigned long RevDepends; // Dependency
  149. unsigned long ProvidesList; // Provides
  150. // Install/Remove/Purge etc
  151. unsigned char SelectedState; // What
  152. unsigned char InstState; // Flags
  153. unsigned char CurrentState; // State
  154. unsigned short ID;
  155. unsigned long Flags;
  156. };
  157. struct pkgCache::PackageFile
  158. {
  159. // Names
  160. unsigned long FileName; // Stringtable
  161. unsigned long Version; // Stringtable
  162. unsigned long Distribution; // Stringtable
  163. unsigned long Size;
  164. // Linked list
  165. unsigned long NextFile; // PackageFile
  166. unsigned short ID;
  167. unsigned long Flags;
  168. time_t mtime; // Modification time for the file
  169. };
  170. struct pkgCache::VerFile
  171. {
  172. unsigned long File; // PackageFile
  173. unsigned long NextFile; // PkgVerFile
  174. unsigned long Offset;
  175. unsigned short Size;
  176. };
  177. struct pkgCache::Version
  178. {
  179. unsigned long VerStr; // Stringtable
  180. unsigned long Section; // StringTable (StringItem)
  181. // Lists
  182. unsigned long FileList; // VerFile
  183. unsigned long NextVer; // Version
  184. unsigned long DependsList; // Dependency
  185. unsigned long ParentPkg; // Package
  186. unsigned long ProvidesList; // Provides
  187. unsigned long Size;
  188. unsigned long InstalledSize;
  189. unsigned short ID;
  190. unsigned char Priority;
  191. };
  192. struct pkgCache::Dependency
  193. {
  194. unsigned long Version; // Stringtable
  195. unsigned long Package; // Package
  196. unsigned long NextDepends; // Dependency
  197. unsigned long NextRevDepends; // Dependency
  198. unsigned long ParentVer; // Version
  199. // Specific types of depends
  200. unsigned char Type;
  201. unsigned char CompareOp;
  202. unsigned short ID;
  203. };
  204. struct pkgCache::Provides
  205. {
  206. unsigned long ParentPkg; // Pacakge
  207. unsigned long Version; // Version
  208. unsigned long ProvideVersion; // Stringtable
  209. unsigned long NextProvides; // Provides
  210. unsigned long NextPkgProv; // Provides
  211. };
  212. struct pkgCache::StringItem
  213. {
  214. unsigned long String; // Stringtable
  215. unsigned long NextItem; // StringItem
  216. };
  217. #include <apt-pkg/cacheiterators.h>
  218. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  219. {return PkgIterator(*this);};
  220. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  221. {return PkgIterator(*this,PkgP);};
  222. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  223. {return PkgFileIterator(*this);};
  224. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  225. {return PkgFileIterator(*this,PkgFileP);};
  226. #endif