apt  0.9.11.4
pkgcache.h
Go to the documentation of this file.
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
73  /*}}}*/
74 #ifndef PKGLIB_PKGCACHE_H
75 #define PKGLIB_PKGCACHE_H
76 
77 #include <string>
78 #include <time.h>
79 #include <apt-pkg/mmap.h>
80 
81 #ifndef APT_8_CLEANER_HEADERS
82 using std::string;
83 #endif
84 
86 class pkgCache /*{{{*/
87 {
88  public:
89  // Cache element predeclarations
90  struct Header;
91  struct Group;
92  struct Package;
93  struct PackageFile;
94  struct Version;
95  struct Description;
96  struct Provides;
97  struct Dependency;
98  struct StringItem;
99  struct VerFile;
100  struct DescFile;
101 
102  // Iterators
103  template<typename Str, typename Itr> class Iterator;
104  class GrpIterator;
105  class PkgIterator;
106  class VerIterator;
107  class DescIterator;
108  class DepIterator;
109  class PrvIterator;
110  class PkgFileIterator;
111  class VerFileIterator;
112  class DescFileIterator;
113 
114  class Namespace;
115 
116  // These are all the constants used in the cache structures
117 
118  // WARNING - if you change these lists you must also edit
119  // the stringification in pkgcache.cc and also consider whether
120  // the cache file will become incompatible.
121  struct Dep
122  {
123  enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
124  Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
130  enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
131  Greater=0x4,Equals=0x5,NotEquals=0x6};
132  };
133 
134  struct State
135  {
139  enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
140  enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
141  enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
142  enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
143  HalfInstalled=4,ConfigFiles=5,Installed=6,
144  TriggersAwaited=7,TriggersPending=8};
145  };
146 
147  struct Flag
148  {
149  enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
150  enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1),ButAutomaticUpgrades=(1<<2)};
151  };
152 
153  protected:
154 
155  // Memory mapped cache file
156  std::string CacheFile;
157  MMap &Map;
158 
159  unsigned long sHash(const std::string &S) const;
160  unsigned long sHash(const char *S) const;
161 
162  public:
163 
164  // Pointers to the arrays of items
165  Header *HeaderP;
166  Group *GrpP;
167  Package *PkgP;
168  VerFile *VerFileP;
169  DescFile *DescFileP;
170  PackageFile *PkgFileP;
171  Version *VerP;
172  Description *DescP;
173  Provides *ProvideP;
174  Dependency *DepP;
175  StringItem *StringItemP;
176  char *StrP;
177 
178  virtual bool ReMap(bool const &Errorchecks = true);
179  inline bool Sync() {return Map.Sync();};
180  inline MMap &GetMap() {return Map;};
181  inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
182 
183  // String hashing function (512 range)
184  inline unsigned long Hash(const std::string &S) const {return sHash(S);};
185  inline unsigned long Hash(const char *S) const {return sHash(S);};
186 
187  // Useful transformation things
188  const char *Priority(unsigned char Priority);
189 
190  // Accessors
191  GrpIterator FindGrp(const std::string &Name);
192  PkgIterator FindPkg(const std::string &Name);
193  PkgIterator FindPkg(const std::string &Name, const std::string &Arch);
194 
195  Header &Head() {return *HeaderP;};
196  inline GrpIterator GrpBegin();
197  inline GrpIterator GrpEnd();
198  inline PkgIterator PkgBegin();
199  inline PkgIterator PkgEnd();
200  inline PkgFileIterator FileBegin();
201  inline PkgFileIterator FileEnd();
202 
203  inline bool MultiArchCache() const { return MultiArchEnabled; };
204  inline char const * const NativeArch() const;
205 
206  // Make me a function
208 
209  // Converters
210  static const char *CompTypeDeb(unsigned char Comp);
211  static const char *CompType(unsigned char Comp);
212  static const char *DepType(unsigned char Dep);
213 
214  pkgCache(MMap *Map,bool DoMap = true);
215  virtual ~pkgCache() {};
216 
217 private:
218  bool MultiArchEnabled;
219  PkgIterator SingleArchFindPkg(const std::string &Name);
220 };
221  /*}}}*/
222 // Header structure /*{{{*/
224 {
230  unsigned long Signature;
233  short MinorVersion;
239  bool Dirty;
240 
248  unsigned short HeaderSz;
249  unsigned short GroupSz;
250  unsigned short PackageSz;
251  unsigned short PackageFileSz;
252  unsigned short VersionSz;
253  unsigned short DescriptionSz;
254  unsigned short DependencySz;
255  unsigned short ProvidesSz;
256  unsigned short VerFileSz;
257  unsigned short DescFileSz;
258 
264  unsigned long GroupCount;
265  unsigned long PackageCount;
266  unsigned long VersionCount;
267  unsigned long DescriptionCount;
268  unsigned long DependsCount;
269  unsigned long PackageFileCount;
270  unsigned long VerFileCount;
271  unsigned long DescFileCount;
272  unsigned long ProvidesCount;
273 
278  map_ptrloc FileList;
284  map_ptrloc StringList;
286  map_ptrloc VerSysName;
288  map_ptrloc Architecture;
290  unsigned long MaxVerFileSize;
292  unsigned long MaxDescFileSize;
293 
303 
315  map_ptrloc PkgHashTable[2*1048];
316  map_ptrloc GrpHashTable[2*1048];
317 
319  unsigned long CacheFileSize;
320 
321  bool CheckSizes(Header &Against) const;
322  Header();
323 };
324  /*}}}*/
325 // Group structure /*{{{*/
333 {
335  map_ptrloc Name; // StringItem
336 
337  // Linked List
339  map_ptrloc FirstPackage; // Package
341  map_ptrloc LastPackage; // Package
343  map_ptrloc Next; // Group
345  unsigned int ID;
346 
347 };
348  /*}}}*/
349 // Package structure /*{{{*/
362 {
364  map_ptrloc Name; // StringItem
366  map_ptrloc Arch; // StringItem
376  map_ptrloc VersionList; // Version
378  map_ptrloc CurrentVer; // Version
383  map_ptrloc Section; // StringItem
385  map_ptrloc Group; // Group the Package belongs to
386 
387  // Linked list
389  map_ptrloc NextPackage; // Package
391  map_ptrloc RevDepends; // Dependency
393  map_ptrloc ProvidesList; // Provides
394 
395  // Install/Remove/Purge etc
397  unsigned char SelectedState; // What
403  unsigned char InstState; // Flags
405  unsigned char CurrentState; // State
406 
413  unsigned int ID;
415  unsigned long Flags;
416 };
417  /*}}}*/
418 // Package File structure /*{{{*/
425 {
427  map_ptrloc FileName; // StringItem
432  map_ptrloc Archive; // StringItem
433  map_ptrloc Codename; // StringItem
434  map_ptrloc Component; // StringItem
435  map_ptrloc Version; // StringItem
436  map_ptrloc Origin; // StringItem
437  map_ptrloc Label; // StringItem
438  map_ptrloc Architecture; // StringItem
440  map_ptrloc Site; // StringItem
444  map_ptrloc IndexType; // StringItem
450  unsigned long Size;
452  time_t mtime;
453 
454  /* @TODO document PackageFile::Flags */
455  unsigned long Flags;
456 
457  // Linked list
459  map_ptrloc NextFile; // PackageFile
461  unsigned int ID;
462 };
463  /*}}}*/
464 // VerFile structure /*{{{*/
470 {
472  map_ptrloc File; // PackageFile
474  map_ptrloc NextFile; // PkgVerFile
476  map_ptrloc Offset; // File offset
477  /* @TODO document pkgCache::VerFile::Size */
478  unsigned long Size;
479 };
480  /*}}}*/
481 // DescFile structure /*{{{*/
484 {
486  map_ptrloc File; // PackageFile
488  map_ptrloc NextFile; // PkgVerFile
490  map_ptrloc Offset; // File offset
491  /* @TODO document pkgCache::DescFile::Size */
492  unsigned long Size;
493 };
494  /*}}}*/
495 // Version structure /*{{{*/
502 {
504  map_ptrloc VerStr; // StringItem
506  map_ptrloc Section; // StringItem
507 
509  enum VerMultiArch { None = 0,
510  All = (1<<0),
511  Foreign = (1<<1),
512  Same = (1<<2),
513  Allowed = (1<<3),
514  AllForeign = All | Foreign,
515  AllAllowed = All | Allowed };
520  unsigned char MultiArch;
521 
528  map_ptrloc FileList; // VerFile
530  map_ptrloc NextVer; // Version
532  map_ptrloc DescriptionList; // Description
534  map_ptrloc DependsList; // Dependency
538  map_ptrloc ParentPkg; // Package
540  map_ptrloc ProvidesList; // Provides
541 
545  unsigned long long Size; // These are the .deb size
547  unsigned long long InstalledSize;
552  unsigned short Hash;
554  unsigned int ID;
556  unsigned char Priority;
557 };
558  /*}}}*/
559 // Description structure /*{{{*/
562 {
567  map_ptrloc language_code; // StringItem
572  map_ptrloc md5sum; // StringItem
573 
574  /* @TODO document pkgCache::Description::FileList */
575  map_ptrloc FileList; // DescFile
577  map_ptrloc NextDesc; // Description
579  map_ptrloc ParentPkg; // Package
580 
582  unsigned int ID;
583 };
584  /*}}}*/
585 // Dependency structure /*{{{*/
593 {
595  map_ptrloc Version; // StringItem
600  map_ptrloc Package; // Package
602  map_ptrloc NextDepends; // Dependency
604  map_ptrloc NextRevDepends; // Dependency
606  map_ptrloc ParentVer; // Version
607 
609  map_ptrloc ID;
611  unsigned char Type;
615  unsigned char CompareOp;
616 };
617  /*}}}*/
618 // Provides structure /*{{{*/
628 {
630  map_ptrloc ParentPkg; // Package
632  map_ptrloc Version; // Version
638  map_ptrloc ProvideVersion; // StringItem
640  map_ptrloc NextProvides; // Provides
642  map_ptrloc NextPkgProv; // Provides
643 };
644  /*}}}*/
645 // StringItem structure /*{{{*/
655 {
657  map_ptrloc String; // StringItem
659  map_ptrloc NextItem; // StringItem
660 };
661  /*}}}*/
662 
663 
664 inline char const * const pkgCache::NativeArch() const
665  { return StrP + HeaderP->Architecture; };
666 
667 #include <apt-pkg/cacheiterators.h>
668 
669 inline pkgCache::GrpIterator pkgCache::GrpBegin()
670  {return GrpIterator(*this);};
671 inline pkgCache::GrpIterator pkgCache::GrpEnd()
672  {return GrpIterator(*this,GrpP);};
673 inline pkgCache::PkgIterator pkgCache::PkgBegin()
674  {return PkgIterator(*this);};
675 inline pkgCache::PkgIterator pkgCache::PkgEnd()
676  {return PkgIterator(*this,PkgP);};
677 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
678  {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
679 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
680  {return PkgFileIterator(*this,PkgFileP);};
681 
682 // Oh I wish for Real Name Space Support
683 class pkgCache::Namespace /*{{{*/
684 {
685  public:
694  typedef pkgCache::Version Version;
696  typedef pkgCache::Package Package;
697  typedef pkgCache::Header Header;
698  typedef pkgCache::Dep Dep;
699  typedef pkgCache::Flag Flag;
700 };
701  /*}}}*/
702 #endif