pkgcache.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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);
  105. PkgIterator FindPkg(const string &Name, const string &Arch);
  106. Header &Head() {return *HeaderP;};
  107. inline GrpIterator GrpBegin();
  108. inline GrpIterator GrpEnd();
  109. inline PkgIterator PkgBegin();
  110. inline PkgIterator PkgEnd();
  111. inline PkgFileIterator FileBegin();
  112. inline PkgFileIterator FileEnd();
  113. inline bool MultiArchCache() const { return MultiArchEnabled; };
  114. // Make me a function
  115. pkgVersioningSystem *VS;
  116. // Converters
  117. static const char *CompTypeDeb(unsigned char Comp);
  118. static const char *CompType(unsigned char Comp);
  119. static const char *DepType(unsigned char Dep);
  120. pkgCache(MMap *Map,bool DoMap = true);
  121. virtual ~pkgCache() {};
  122. private:
  123. bool MultiArchEnabled;
  124. PkgIterator SingleArchFindPkg(const string &Name);
  125. };
  126. /*}}}*/
  127. // Header structure /*{{{*/
  128. struct pkgCache::Header
  129. {
  130. // Signature information
  131. unsigned long Signature;
  132. short MajorVersion;
  133. short MinorVersion;
  134. bool Dirty;
  135. // Size of structure values
  136. unsigned short HeaderSz;
  137. unsigned short PackageSz;
  138. unsigned short PackageFileSz;
  139. unsigned short VersionSz;
  140. unsigned short DescriptionSz;
  141. unsigned short DependencySz;
  142. unsigned short ProvidesSz;
  143. unsigned short VerFileSz;
  144. unsigned short DescFileSz;
  145. // Structure counts
  146. unsigned long GroupCount;
  147. unsigned long PackageCount;
  148. unsigned long VersionCount;
  149. unsigned long DescriptionCount;
  150. unsigned long DependsCount;
  151. unsigned long PackageFileCount;
  152. unsigned long VerFileCount;
  153. unsigned long DescFileCount;
  154. unsigned long ProvidesCount;
  155. // Offsets
  156. map_ptrloc FileList; // struct PackageFile
  157. map_ptrloc StringList; // struct StringItem
  158. map_ptrloc VerSysName; // StringTable
  159. map_ptrloc Architecture; // StringTable
  160. unsigned long MaxVerFileSize;
  161. unsigned long MaxDescFileSize;
  162. /* Allocation pools, there should be one of these for each structure
  163. excluding the header */
  164. DynamicMMap::Pool Pools[9];
  165. // Rapid package and group name lookup
  166. // Notice: Increase only both table sizes as the
  167. // hashmethod assume the size of the Pkg one
  168. map_ptrloc PkgHashTable[2*1048];
  169. map_ptrloc GrpHashTable[2*1048];
  170. bool CheckSizes(Header &Against) const;
  171. Header();
  172. };
  173. /*}}}*/
  174. struct pkgCache::Group { /*{{{*/
  175. map_ptrloc Name; // Stringtable
  176. // Linked List
  177. map_ptrloc FirstPackage;// Package
  178. map_ptrloc LastPackage; // Package
  179. map_ptrloc Next; // Group
  180. };
  181. /*}}}*/
  182. struct pkgCache::Package /*{{{*/
  183. {
  184. // Pointers
  185. map_ptrloc Name; // Stringtable
  186. map_ptrloc Arch; // StringTable (StringItem)
  187. map_ptrloc VersionList; // Version
  188. map_ptrloc CurrentVer; // Version
  189. map_ptrloc Section; // StringTable (StringItem)
  190. map_ptrloc Group; // Group the Package belongs to
  191. // Linked list
  192. map_ptrloc NextPackage; // Package
  193. map_ptrloc RevDepends; // Dependency
  194. map_ptrloc ProvidesList; // Provides
  195. // Install/Remove/Purge etc
  196. unsigned char SelectedState; // What
  197. unsigned char InstState; // Flags
  198. unsigned char CurrentState; // State
  199. unsigned int ID;
  200. unsigned long Flags;
  201. };
  202. /*}}}*/
  203. struct pkgCache::PackageFile /*{{{*/
  204. {
  205. // Names
  206. map_ptrloc FileName; // Stringtable
  207. map_ptrloc Archive; // Stringtable
  208. map_ptrloc Codename; // Stringtable
  209. map_ptrloc Component; // Stringtable
  210. map_ptrloc Version; // Stringtable
  211. map_ptrloc Origin; // Stringtable
  212. map_ptrloc Label; // Stringtable
  213. map_ptrloc Architecture; // Stringtable
  214. map_ptrloc Site; // Stringtable
  215. map_ptrloc IndexType; // Stringtable
  216. unsigned long Size;
  217. unsigned long Flags;
  218. // Linked list
  219. map_ptrloc NextFile; // PackageFile
  220. unsigned int ID;
  221. time_t mtime; // Modification time for the file
  222. };
  223. /*}}}*/
  224. struct pkgCache::VerFile /*{{{*/
  225. {
  226. map_ptrloc File; // PackageFile
  227. map_ptrloc NextFile; // PkgVerFile
  228. map_ptrloc Offset; // File offset
  229. unsigned long Size;
  230. };
  231. /*}}}*/
  232. struct pkgCache::DescFile /*{{{*/
  233. {
  234. map_ptrloc File; // PackageFile
  235. map_ptrloc NextFile; // PkgVerFile
  236. map_ptrloc Offset; // File offset
  237. unsigned long Size;
  238. };
  239. /*}}}*/
  240. struct pkgCache::Version /*{{{*/
  241. {
  242. map_ptrloc VerStr; // Stringtable
  243. map_ptrloc Section; // StringTable (StringItem)
  244. enum {None, All, Foreign, Same, Allowed} MultiArch;
  245. // Lists
  246. map_ptrloc FileList; // VerFile
  247. map_ptrloc NextVer; // Version
  248. map_ptrloc DescriptionList; // Description
  249. map_ptrloc DependsList; // Dependency
  250. map_ptrloc ParentPkg; // Package
  251. map_ptrloc ProvidesList; // Provides
  252. map_ptrloc Size; // These are the .deb size
  253. map_ptrloc InstalledSize;
  254. unsigned short Hash;
  255. unsigned int ID;
  256. unsigned char Priority;
  257. };
  258. /*}}}*/
  259. struct pkgCache::Description /*{{{*/
  260. {
  261. // Language Code store the description translation language code. If
  262. // the value has a 0 lenght then this is readed using the Package
  263. // file else the Translation-CODE are used.
  264. map_ptrloc language_code; // StringTable
  265. map_ptrloc md5sum; // StringTable
  266. // Linked list
  267. map_ptrloc FileList; // DescFile
  268. map_ptrloc NextDesc; // Description
  269. map_ptrloc ParentPkg; // Package
  270. unsigned int ID;
  271. };
  272. /*}}}*/
  273. struct pkgCache::Dependency /*{{{*/
  274. {
  275. map_ptrloc Version; // Stringtable
  276. map_ptrloc Package; // Package
  277. map_ptrloc NextDepends; // Dependency
  278. map_ptrloc NextRevDepends; // Dependency
  279. map_ptrloc ParentVer; // Version
  280. // Specific types of depends
  281. map_ptrloc ID;
  282. unsigned char Type;
  283. unsigned char CompareOp;
  284. };
  285. /*}}}*/
  286. struct pkgCache::Provides /*{{{*/
  287. {
  288. map_ptrloc ParentPkg; // Pacakge
  289. map_ptrloc Version; // Version
  290. map_ptrloc ProvideVersion; // Stringtable
  291. map_ptrloc NextProvides; // Provides
  292. map_ptrloc NextPkgProv; // Provides
  293. };
  294. /*}}}*/
  295. struct pkgCache::StringItem /*{{{*/
  296. {
  297. map_ptrloc String; // Stringtable
  298. map_ptrloc NextItem; // StringItem
  299. };
  300. /*}}}*/
  301. #include <apt-pkg/cacheiterators.h>
  302. inline pkgCache::GrpIterator pkgCache::GrpBegin()
  303. {return GrpIterator(*this);};
  304. inline pkgCache::GrpIterator pkgCache::GrpEnd()
  305. {return GrpIterator(*this,GrpP);};
  306. inline pkgCache::PkgIterator pkgCache::PkgBegin()
  307. {return PkgIterator(*this);};
  308. inline pkgCache::PkgIterator pkgCache::PkgEnd()
  309. {return PkgIterator(*this,PkgP);};
  310. inline pkgCache::PkgFileIterator pkgCache::FileBegin()
  311. {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
  312. inline pkgCache::PkgFileIterator pkgCache::FileEnd()
  313. {return PkgFileIterator(*this,PkgFileP);};
  314. // Oh I wish for Real Name Space Support
  315. class pkgCache::Namespace /*{{{*/
  316. {
  317. public:
  318. typedef pkgCache::GrpIterator GrpIterator;
  319. typedef pkgCache::PkgIterator PkgIterator;
  320. typedef pkgCache::VerIterator VerIterator;
  321. typedef pkgCache::DescIterator DescIterator;
  322. typedef pkgCache::DepIterator DepIterator;
  323. typedef pkgCache::PrvIterator PrvIterator;
  324. typedef pkgCache::PkgFileIterator PkgFileIterator;
  325. typedef pkgCache::VerFileIterator VerFileIterator;
  326. typedef pkgCache::Version Version;
  327. typedef pkgCache::Description Description;
  328. typedef pkgCache::Package Package;
  329. typedef pkgCache::Header Header;
  330. typedef pkgCache::Dep Dep;
  331. typedef pkgCache::Flag Flag;
  332. };
  333. /*}}}*/
  334. #endif