pkgcache.h 6.6 KB

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