pkgcache.h 6.9 KB

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