pkgcache.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.5 1998/07/07 04:17:03 jgg Exp $
  4. /* ######################################################################
  5. Cache - Structure definitions for the cache file
  6. Please see doc/pkglib/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 "pkglib/pkgcache.h"
  19. #endif
  20. #include <string>
  21. #include <time.h>
  22. #include <pkglib/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=5,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. bool Public;
  75. bool ReadOnly;
  76. static unsigned long sHash(string S);
  77. static unsigned long sHash(const char *S);
  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. // String hashing function (512 range)
  92. inline unsigned long Hash(string S) const {return sHash(S);};
  93. inline unsigned long Hash(const char *S) const {return sHash(S);};
  94. // Usefull transformation things
  95. const char *Priority(unsigned char Priority);
  96. // Accessors
  97. PkgIterator FindPkg(string Name);
  98. Header &Head() {return *HeaderP;};
  99. inline PkgIterator PkgBegin();
  100. inline PkgIterator PkgEnd();
  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. /* Allocation pools, there should be one of these for each structure
  129. excluding the header */
  130. DynamicMMap::Pool Pools[7];
  131. // Rapid package name lookup
  132. unsigned long HashTable[512];
  133. bool CheckSizes(Header &Against) const;
  134. Header();
  135. };
  136. struct pkgCache::Package
  137. {
  138. // Pointers
  139. unsigned long Name; // Stringtable
  140. unsigned long VersionList; // Version
  141. unsigned long TargetVer; // Version
  142. unsigned long CurrentVer; // Version
  143. unsigned long TargetDist; // StringTable (StringItem)
  144. unsigned long Section; // StringTable (StringItem)
  145. // Linked list
  146. unsigned long NextPackage; // Package
  147. unsigned long RevDepends; // Dependency
  148. unsigned long ProvidesList; // Provides
  149. // Install/Remove/Purge etc
  150. unsigned char SelectedState; // What
  151. unsigned char InstState; // Flags
  152. unsigned char CurrentState; // State
  153. unsigned short ID;
  154. unsigned long Flags;
  155. };
  156. struct pkgCache::PackageFile
  157. {
  158. // Names
  159. unsigned long FileName; // Stringtable
  160. unsigned long Version; // Stringtable
  161. unsigned long Distribution; // Stringtable
  162. unsigned long Size;
  163. // Linked list
  164. unsigned long NextFile; // PackageFile
  165. unsigned short ID;
  166. unsigned long Flags;
  167. time_t mtime; // Modification time for the file
  168. };
  169. struct pkgCache::VerFile
  170. {
  171. unsigned long File; // PackageFile
  172. unsigned long NextFile; // PkgVerFile
  173. unsigned long Offset;
  174. unsigned short Size;
  175. };
  176. struct pkgCache::Version
  177. {
  178. unsigned long VerStr; // Stringtable
  179. unsigned long Section; // StringTable (StringItem)
  180. // Lists
  181. unsigned long FileList; // VerFile
  182. unsigned long NextVer; // Version
  183. unsigned long DependsList; // Dependency
  184. unsigned long ParentPkg; // Package
  185. unsigned long ProvidesList; // Provides
  186. unsigned long Size;
  187. unsigned long InstalledSize;
  188. unsigned short ID;
  189. unsigned char Priority;
  190. };
  191. struct pkgCache::Dependency
  192. {
  193. unsigned long Version; // Stringtable
  194. unsigned long Package; // Package
  195. unsigned long NextDepends; // Dependency
  196. unsigned long NextRevDepends; // Dependency
  197. unsigned long ParentVer; // Version
  198. // Specific types of depends
  199. unsigned char Type;
  200. unsigned char CompareOp;
  201. unsigned short ID;
  202. };
  203. struct pkgCache::Provides
  204. {
  205. unsigned long ParentPkg; // Pacakge
  206. unsigned long Version; // Version
  207. unsigned long ProvideVersion; // Stringtable
  208. unsigned long NextProvides; // Provides
  209. unsigned long NextPkgProv; // Provides
  210. };
  211. struct pkgCache::StringItem
  212. {
  213. unsigned long String; // Stringtable
  214. unsigned long NextItem; // StringItem
  215. };
  216. #include <pkglib/cacheiterators.h>
  217. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  218. {return PkgIterator(*this);};
  219. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  220. {return PkgIterator(*this,PkgP);};
  221. #endif