pkgcache.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.1 1998/07/02 02:58: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. // Definitions for Depends::Type
  21. #define pkgDEP_Depends 1
  22. #define pkgDEP_PreDepends 2
  23. #define pkgDEP_Suggests 3
  24. #define pkgDEP_Recommends 4
  25. #define pkgDEP_Conflicts 5
  26. #define pkgDEP_Replaces 6
  27. // Definitions for Version::Priority
  28. #define pkgPRIO_Important 1
  29. #define pkgPRIO_Required 2
  30. #define pkgPRIO_Standard 3
  31. #define pkgPRIO_Optional 4
  32. #define pkgPRIO_Extra 5
  33. // Definitions for Package::SelectedState
  34. #define pkgSTATE_Unkown 0
  35. #define pkgSTATE_Install 1
  36. #define pkgSTATE_Hold 2
  37. #define pkgSTATE_DeInstall 3
  38. #define pkgSTATE_Purge 4
  39. // Definitions for Package::Flags
  40. #define pkgFLAG_Auto (1 << 0)
  41. #define pkgFLAG_New (1 << 1)
  42. #define pkgFLAG_Obsolete (1 << 2)
  43. #define pkgFLAG_Essential (1 << 3)
  44. #define pkgFLAG_ImmediateConf (1 << 4)
  45. // Definitions for Package::InstState
  46. #define pkgSTATE_Ok 0
  47. #define pkgSTATE_ReInstReq 1
  48. #define pkgSTATE_Hold 2
  49. #define pkgSTATE_HoldReInstReq 3
  50. // Definitions for Package::CurrentState
  51. #define pkgSTATE_NotInstalled 0
  52. #define pkgSTATE_UnPacked 1
  53. #define pkgSTATE_HalfConfigured 2
  54. #define pkgSTATE_UnInstalled 3
  55. #define pkgSTATE_HalfInstalled 4
  56. #define pkgSTATE_ConfigFiles 5
  57. #define pkgSTATE_Installed 6
  58. // Definitions for PackageFile::Flags
  59. #define pkgFLAG_NotSource (1 << 0)
  60. // Definitions for Dependency::CompareOp
  61. #define pkgOP_OR 0x10
  62. #define pkgOP_LESSEQ 0x1
  63. #define pkgOP_GREATEREQ 0x2
  64. #define pkgOP_LESS 0x3
  65. #define pkgOP_GREATER 0x4
  66. #define pkgOP_EQUALS 0x5
  67. #define pkgOP_NOTEQUALS 0x6
  68. class pkgCache
  69. {
  70. public:
  71. // Cache element predeclarations
  72. struct Header;
  73. struct Package;
  74. struct PackageFile;
  75. struct Version;
  76. struct Provides;
  77. struct Dependency;
  78. struct StringItem;
  79. // Iterators
  80. class PkgIterator;
  81. class VerIterator;
  82. class DepIterator;
  83. class PrvIterator;
  84. class PkgFileIterator;
  85. friend PkgIterator;
  86. friend VerIterator;
  87. friend DepIterator;
  88. friend PrvIterator;
  89. friend PkgFileIterator;
  90. protected:
  91. // Memory mapped cache file
  92. string CacheFile;
  93. MMap &Map;
  94. bool Public;
  95. bool ReadOnly;
  96. static unsigned long sHash(string S);
  97. static unsigned long sHash(const char *S);
  98. public:
  99. // Pointers to the arrays of items
  100. Header *HeaderP;
  101. Package *PkgP;
  102. PackageFile *PkgFileP;
  103. Version *VerP;
  104. Provides *ProvideP;
  105. Dependency *DepP;
  106. StringItem *StringItemP;
  107. char *StrP;
  108. virtual bool ReMap();
  109. inline bool Sync() {return Map.Sync();};
  110. // String hashing function (512 range)
  111. inline unsigned long Hash(string S) const {return sHash(S);};
  112. inline unsigned long Hash(const char *S) const {return sHash(S);};
  113. // Accessors
  114. PkgIterator FindPkg(string Name);
  115. Header &Head() {return *HeaderP;};
  116. inline PkgIterator PkgBegin();
  117. inline PkgIterator PkgEnd();
  118. pkgCache(MMap &Map);
  119. virtual ~pkgCache() {};
  120. };
  121. // Header structure
  122. struct pkgCache::Header
  123. {
  124. // Signature information
  125. unsigned long Signature;
  126. short MajorVersion;
  127. short MinorVersion;
  128. bool Dirty;
  129. // Size of structure values
  130. unsigned short HeaderSz;
  131. unsigned short PackageSz;
  132. unsigned short PackageFileSz;
  133. unsigned short VersionSz;
  134. unsigned short DependencySz;
  135. unsigned short ProvidesSz;
  136. // Structure counts
  137. unsigned long PackageCount;
  138. unsigned long VersionCount;
  139. unsigned long DependsCount;
  140. unsigned long PackageFileCount;
  141. // Offsets
  142. unsigned long FileList; // struct PackageFile
  143. unsigned long StringList; // struct StringItem
  144. /* Allocation pools, there should be one of these for each structure
  145. excluding the header */
  146. DynamicMMap::Pool Pools[6];
  147. // Rapid package name lookup
  148. unsigned long HashTable[512];
  149. bool CheckSizes(Header &Against) const;
  150. Header();
  151. };
  152. struct pkgCache::Package
  153. {
  154. // Pointers
  155. unsigned long Name; // Stringtable
  156. unsigned long VersionList; // Version
  157. unsigned long TargetVer; // Version
  158. unsigned long CurrentVer; // Version
  159. unsigned long TargetDist; // StringTable (StringItem)
  160. unsigned long Section; // StringTable (StringItem)
  161. // Linked list
  162. unsigned long NextPackage; // Package
  163. unsigned long RevDepends; // Dependency
  164. unsigned long ProvidesList; // Provides
  165. // Install/Remove/Purge etc
  166. unsigned char SelectedState; // What
  167. unsigned char InstState; // Flags
  168. unsigned char CurrentState; // State
  169. unsigned short ID;
  170. unsigned short Flags;
  171. };
  172. struct pkgCache::PackageFile
  173. {
  174. // Names
  175. unsigned long FileName; // Stringtable
  176. unsigned long Version; // Stringtable
  177. unsigned long Distribution; // Stringtable
  178. unsigned long Size;
  179. // Linked list
  180. unsigned long NextFile; // PackageFile
  181. unsigned short ID;
  182. unsigned short Flags;
  183. time_t mtime; // Modification time for the file
  184. };
  185. struct pkgCache::Version
  186. {
  187. unsigned long VerStr; // Stringtable
  188. unsigned long File; // PackageFile
  189. unsigned long Section; // StringTable (StringItem)
  190. // Lists
  191. unsigned long NextVer; // Version
  192. unsigned long DependsList; // Dependency
  193. unsigned long ParentPkg; // Package
  194. unsigned long ProvidesList; // Provides
  195. unsigned long Offset;
  196. unsigned long Size;
  197. unsigned long InstalledSize;
  198. unsigned short ID;
  199. unsigned char Priority;
  200. };
  201. struct pkgCache::Dependency
  202. {
  203. unsigned long Version; // Stringtable
  204. unsigned long Package; // Package
  205. unsigned long NextDepends; // Dependency
  206. unsigned long NextRevDepends; // Dependency
  207. unsigned long ParentVer; // Version
  208. // Specific types of depends
  209. unsigned char Type;
  210. unsigned char CompareOp;
  211. unsigned short ID;
  212. };
  213. struct pkgCache::Provides
  214. {
  215. unsigned long ParentPkg; // Pacakge
  216. unsigned long Version; // Version
  217. unsigned long ProvideVersion; // Stringtable
  218. unsigned long NextProvides; // Provides
  219. unsigned long NextPkgProv; // Provides
  220. };
  221. struct pkgCache::StringItem
  222. {
  223. unsigned long String; // Stringtable
  224. unsigned long NextItem; // StringItem
  225. };
  226. #include <pkglib/cacheiterators.h>
  227. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  228. {return PkgIterator(*this);};
  229. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  230. {return PkgIterator(*this,PkgP);};
  231. #endif