pkgcache.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $
  4. /* ######################################################################
  5. Cache - Structure definitions for the cache file
  6. Please see doc/apt-pkg/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. #ifndef PKGLIB_PKGCACHE_H
  15. #define PKGLIB_PKGCACHE_H
  16. #include <string>
  17. #include <time.h>
  18. #include <apt-pkg/mmap.h>
  19. using std::string;
  20. class pkgVersioningSystem;
  21. class pkgCache /*{{{*/
  22. {
  23. public:
  24. // Cache element predeclarations
  25. struct Header;
  26. struct Group;
  27. struct Package;
  28. struct PackageFile;
  29. struct Version;
  30. struct Description;
  31. struct Provides;
  32. struct Dependency;
  33. struct StringItem;
  34. struct VerFile;
  35. struct DescFile;
  36. // Iterators
  37. template<typename Str, typename Itr> class Iterator;
  38. class GrpIterator;
  39. class PkgIterator;
  40. class VerIterator;
  41. class DescIterator;
  42. class DepIterator;
  43. class PrvIterator;
  44. class PkgFileIterator;
  45. class VerFileIterator;
  46. class DescFileIterator;
  47. class Namespace;
  48. // These are all the constants used in the cache structures
  49. // WARNING - if you change these lists you must also edit
  50. // the stringification in pkgcache.cc and also consider whether
  51. // the cache file will become incompatible.
  52. struct Dep
  53. {
  54. enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
  55. Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
  56. enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
  57. Greater=0x4,Equals=0x5,NotEquals=0x6};
  58. };
  59. struct State
  60. {
  61. enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
  62. enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
  63. enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
  64. enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
  65. HalfInstalled=4,ConfigFiles=5,Installed=6,
  66. TriggersAwaited=7,TriggersPending=8};
  67. };
  68. struct Flag
  69. {
  70. enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
  71. enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
  72. };
  73. protected:
  74. // Memory mapped cache file
  75. string CacheFile;
  76. MMap &Map;
  77. unsigned long sHash(const string &S) const;
  78. unsigned long sHash(const char *S) const;
  79. public:
  80. // Pointers to the arrays of items
  81. Header *HeaderP;
  82. Group *GrpP;
  83. Package *PkgP;
  84. VerFile *VerFileP;
  85. DescFile *DescFileP;
  86. PackageFile *PkgFileP;
  87. Version *VerP;
  88. Description *DescP;
  89. Provides *ProvideP;
  90. Dependency *DepP;
  91. StringItem *StringItemP;
  92. char *StrP;
  93. virtual bool ReMap();
  94. inline bool Sync() {return Map.Sync();};
  95. inline MMap &GetMap() {return Map;};
  96. inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
  97. // String hashing function (512 range)
  98. inline unsigned long Hash(const string &S) const {return sHash(S);};
  99. inline unsigned long Hash(const char *S) const {return sHash(S);};
  100. // Usefull transformation things
  101. const char *Priority(unsigned char Priority);
  102. // Accessors
  103. GrpIterator FindGrp(const string &Name);
  104. PkgIterator FindPkg(const string &Name, string Arch = "native");
  105. Header &Head() {return *HeaderP;};
  106. inline PkgIterator PkgBegin();
  107. inline PkgIterator PkgEnd();
  108. inline PkgFileIterator FileBegin();
  109. inline PkgFileIterator FileEnd();
  110. // Make me a function
  111. pkgVersioningSystem *VS;
  112. // Converters
  113. static const char *CompTypeDeb(unsigned char Comp);
  114. static const char *CompType(unsigned char Comp);
  115. static const char *DepType(unsigned char Dep);
  116. pkgCache(MMap *Map,bool DoMap = true);
  117. virtual ~pkgCache() {};
  118. };
  119. /*}}}*/
  120. // Header structure /*{{{*/
  121. struct pkgCache::Header
  122. {
  123. // Signature information
  124. unsigned long Signature;
  125. short MajorVersion;
  126. short MinorVersion;
  127. bool Dirty;
  128. // Size of structure values
  129. unsigned short HeaderSz;
  130. unsigned short PackageSz;
  131. unsigned short PackageFileSz;
  132. unsigned short VersionSz;
  133. unsigned short DescriptionSz;
  134. unsigned short DependencySz;
  135. unsigned short ProvidesSz;
  136. unsigned short VerFileSz;
  137. unsigned short DescFileSz;
  138. // Structure counts
  139. unsigned long GroupCount;
  140. unsigned long PackageCount;
  141. unsigned long VersionCount;
  142. unsigned long DescriptionCount;
  143. unsigned long DependsCount;
  144. unsigned long PackageFileCount;
  145. unsigned long VerFileCount;
  146. unsigned long DescFileCount;
  147. unsigned long ProvidesCount;
  148. // Offsets
  149. map_ptrloc FileList; // struct PackageFile
  150. map_ptrloc StringList; // struct StringItem
  151. map_ptrloc VerSysName; // StringTable
  152. map_ptrloc Architecture; // StringTable
  153. unsigned long MaxVerFileSize;
  154. unsigned long MaxDescFileSize;
  155. /* Allocation pools, there should be one of these for each structure
  156. excluding the header */
  157. DynamicMMap::Pool Pools[9];
  158. // Rapid package and group name lookup
  159. // Notice: Increase only both table sizes as the
  160. // hashmethod assume the size of the Pkg one
  161. map_ptrloc PkgHashTable[2*1048];
  162. map_ptrloc GrpHashTable[2*1048];
  163. bool CheckSizes(Header &Against) const;
  164. Header();
  165. };
  166. /*}}}*/
  167. struct pkgCache::Group { /*{{{*/
  168. map_ptrloc Name; // Stringtable
  169. // Linked List
  170. map_ptrloc FirstPackage;// Package
  171. map_ptrloc LastPackage; // Package
  172. map_ptrloc Next; // Group
  173. };
  174. /*}}}*/
  175. struct pkgCache::Package /*{{{*/
  176. {
  177. // Pointers
  178. map_ptrloc Name; // Stringtable
  179. map_ptrloc Arch; // StringTable (StringItem)
  180. map_ptrloc VersionList; // Version
  181. map_ptrloc CurrentVer; // Version
  182. map_ptrloc Section; // StringTable (StringItem)
  183. map_ptrloc Group; // Group the Package belongs to
  184. // Linked list
  185. map_ptrloc NextPackage; // Package
  186. map_ptrloc RevDepends; // Dependency
  187. map_ptrloc ProvidesList; // Provides
  188. // Install/Remove/Purge etc
  189. unsigned char SelectedState; // What
  190. unsigned char InstState; // Flags
  191. unsigned char CurrentState; // State
  192. unsigned int ID;
  193. unsigned long Flags;
  194. };
  195. /*}}}*/
  196. struct pkgCache::PackageFile /*{{{*/
  197. {
  198. // Names
  199. map_ptrloc FileName; // Stringtable
  200. map_ptrloc Archive; // Stringtable
  201. map_ptrloc Codename; // Stringtable
  202. map_ptrloc Component; // Stringtable
  203. map_ptrloc Version; // Stringtable
  204. map_ptrloc Origin; // Stringtable
  205. map_ptrloc Label; // Stringtable
  206. map_ptrloc Architecture; // Stringtable
  207. map_ptrloc Site; // Stringtable
  208. map_ptrloc IndexType; // Stringtable
  209. unsigned long Size;
  210. unsigned long Flags;
  211. // Linked list
  212. map_ptrloc NextFile; // PackageFile
  213. unsigned int ID;
  214. time_t mtime; // Modification time for the file
  215. };
  216. /*}}}*/
  217. struct pkgCache::VerFile /*{{{*/
  218. {
  219. map_ptrloc File; // PackageFile
  220. map_ptrloc NextFile; // PkgVerFile
  221. map_ptrloc Offset; // File offset
  222. unsigned long Size;
  223. };
  224. /*}}}*/
  225. struct pkgCache::DescFile /*{{{*/
  226. {
  227. map_ptrloc File; // PackageFile
  228. map_ptrloc NextFile; // PkgVerFile
  229. map_ptrloc Offset; // File offset
  230. unsigned long Size;
  231. };
  232. /*}}}*/
  233. struct pkgCache::Version /*{{{*/
  234. {
  235. map_ptrloc VerStr; // Stringtable
  236. map_ptrloc Section; // StringTable (StringItem)
  237. map_ptrloc Arch; // StringTable
  238. // Lists
  239. map_ptrloc FileList; // VerFile
  240. map_ptrloc NextVer; // Version
  241. map_ptrloc DescriptionList; // Description
  242. map_ptrloc DependsList; // Dependency
  243. map_ptrloc ParentPkg; // Package
  244. map_ptrloc ProvidesList; // Provides
  245. map_ptrloc Size; // These are the .deb size
  246. map_ptrloc InstalledSize;
  247. unsigned short Hash;
  248. unsigned int ID;
  249. unsigned char Priority;
  250. };
  251. /*}}}*/
  252. struct pkgCache::Description /*{{{*/
  253. {
  254. // Language Code store the description translation language code. If
  255. // the value has a 0 lenght then this is readed using the Package
  256. // file else the Translation-CODE are used.
  257. map_ptrloc language_code; // StringTable
  258. map_ptrloc md5sum; // StringTable
  259. // Linked list
  260. map_ptrloc FileList; // DescFile
  261. map_ptrloc NextDesc; // Description
  262. map_ptrloc ParentPkg; // Package
  263. unsigned int ID;
  264. };
  265. /*}}}*/
  266. struct pkgCache::Dependency /*{{{*/
  267. {
  268. map_ptrloc Version; // Stringtable
  269. map_ptrloc Package; // Package
  270. map_ptrloc NextDepends; // Dependency
  271. map_ptrloc NextRevDepends; // Dependency
  272. map_ptrloc ParentVer; // Version
  273. // Specific types of depends
  274. map_ptrloc ID;
  275. unsigned char Type;
  276. unsigned char CompareOp;
  277. };
  278. /*}}}*/
  279. struct pkgCache::Provides /*{{{*/
  280. {
  281. map_ptrloc ParentPkg; // Pacakge
  282. map_ptrloc Version; // Version
  283. map_ptrloc ProvideVersion; // Stringtable
  284. map_ptrloc NextProvides; // Provides
  285. map_ptrloc NextPkgProv; // Provides
  286. };
  287. /*}}}*/
  288. struct pkgCache::StringItem /*{{{*/
  289. {
  290. map_ptrloc String; // Stringtable
  291. map_ptrloc NextItem; // StringItem
  292. };
  293. /*}}}*/
  294. #include <apt-pkg/cacheiterators.h>
  295. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  296. {return PkgIterator(*this);};
  297. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  298. {return PkgIterator(*this,PkgP);};
  299. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  300. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
  301. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  302. {return PkgFileIterator(*this,PkgFileP);};
  303. // Oh I wish for Real Name Space Support
  304. class pkgCache::Namespace /*{{{*/
  305. {
  306. public:
  307. typedef pkgCache::PkgIterator PkgIterator;
  308. typedef pkgCache::VerIterator VerIterator;
  309. typedef pkgCache::DescIterator DescIterator;
  310. typedef pkgCache::DepIterator DepIterator;
  311. typedef pkgCache::PrvIterator PrvIterator;
  312. typedef pkgCache::PkgFileIterator PkgFileIterator;
  313. typedef pkgCache::VerFileIterator VerFileIterator;
  314. typedef pkgCache::Version Version;
  315. typedef pkgCache::Description Description;
  316. typedef pkgCache::Package Package;
  317. typedef pkgCache::Header Header;
  318. typedef pkgCache::Dep Dep;
  319. typedef pkgCache::Flag Flag;
  320. };
  321. /*}}}*/
  322. #endif