pkgcache.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.2 1998/07/04 05:57:36 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. // Accessors
  80. PkgIterator FindPkg(string Name);
  81. Header &Head() {return *HeaderP;};
  82. inline PkgIterator PkgBegin();
  83. inline PkgIterator PkgEnd();
  84. pkgCache(MMap &Map);
  85. virtual ~pkgCache() {};
  86. };
  87. // Header structure
  88. struct pkgCache::Header
  89. {
  90. // Signature information
  91. unsigned long Signature;
  92. short MajorVersion;
  93. short MinorVersion;
  94. bool Dirty;
  95. // Size of structure values
  96. unsigned short HeaderSz;
  97. unsigned short PackageSz;
  98. unsigned short PackageFileSz;
  99. unsigned short VersionSz;
  100. unsigned short DependencySz;
  101. unsigned short ProvidesSz;
  102. // Structure counts
  103. unsigned long PackageCount;
  104. unsigned long VersionCount;
  105. unsigned long DependsCount;
  106. unsigned long PackageFileCount;
  107. // Offsets
  108. unsigned long FileList; // struct PackageFile
  109. unsigned long StringList; // struct StringItem
  110. /* Allocation pools, there should be one of these for each structure
  111. excluding the header */
  112. DynamicMMap::Pool Pools[6];
  113. // Rapid package name lookup
  114. unsigned long HashTable[512];
  115. bool CheckSizes(Header &Against) const;
  116. Header();
  117. };
  118. struct pkgCache::Package
  119. {
  120. // Pointers
  121. unsigned long Name; // Stringtable
  122. unsigned long VersionList; // Version
  123. unsigned long TargetVer; // Version
  124. unsigned long CurrentVer; // Version
  125. unsigned long TargetDist; // StringTable (StringItem)
  126. unsigned long Section; // StringTable (StringItem)
  127. // Linked list
  128. unsigned long NextPackage; // Package
  129. unsigned long RevDepends; // Dependency
  130. unsigned long ProvidesList; // Provides
  131. // Install/Remove/Purge etc
  132. unsigned char SelectedState; // What
  133. unsigned char InstState; // Flags
  134. unsigned char CurrentState; // State
  135. unsigned short ID;
  136. unsigned long Flags;
  137. };
  138. struct pkgCache::PackageFile
  139. {
  140. // Names
  141. unsigned long FileName; // Stringtable
  142. unsigned long Version; // Stringtable
  143. unsigned long Distribution; // Stringtable
  144. unsigned long Size;
  145. // Linked list
  146. unsigned long NextFile; // PackageFile
  147. unsigned short ID;
  148. unsigned long Flags;
  149. time_t mtime; // Modification time for the file
  150. };
  151. struct pkgCache::Version
  152. {
  153. unsigned long VerStr; // Stringtable
  154. unsigned long File; // PackageFile
  155. unsigned long Section; // StringTable (StringItem)
  156. // Lists
  157. unsigned long NextVer; // Version
  158. unsigned long DependsList; // Dependency
  159. unsigned long ParentPkg; // Package
  160. unsigned long ProvidesList; // Provides
  161. unsigned long Offset;
  162. unsigned long Size;
  163. unsigned long InstalledSize;
  164. unsigned short ID;
  165. unsigned char Priority;
  166. };
  167. struct pkgCache::Dependency
  168. {
  169. unsigned long Version; // Stringtable
  170. unsigned long Package; // Package
  171. unsigned long NextDepends; // Dependency
  172. unsigned long NextRevDepends; // Dependency
  173. unsigned long ParentVer; // Version
  174. // Specific types of depends
  175. unsigned char Type;
  176. unsigned char CompareOp;
  177. unsigned short ID;
  178. };
  179. struct pkgCache::Provides
  180. {
  181. unsigned long ParentPkg; // Pacakge
  182. unsigned long Version; // Version
  183. unsigned long ProvideVersion; // Stringtable
  184. unsigned long NextProvides; // Provides
  185. unsigned long NextPkgProv; // Provides
  186. };
  187. struct pkgCache::StringItem
  188. {
  189. unsigned long String; // Stringtable
  190. unsigned long NextItem; // StringItem
  191. };
  192. #include <pkglib/cacheiterators.h>
  193. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  194. {return PkgIterator(*this);};
  195. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  196. {return PkgIterator(*this,PkgP);};
  197. #endif