apt  0.9.12.1
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
map_ptrloc FileList
references all the PackageFile's that this version came from
Definition: pkgcache.h:528
map_ptrloc Archive
the release information
Definition: pkgcache.h:432
Definition: cacheiterators.h:136
Definition: cacheiterators.h:315
map_ptrloc NextFile
next step in the linked list
Definition: pkgcache.h:474
map_ptrloc Package
index of the package this depends applies to
Definition: pkgcache.h:600
map_ptrloc StringList
index of the first StringItem structure
Definition: pkgcache.h:284
information for a single version of a package
Definition: pkgcache.h:501
map_ptrloc ProvidesList
List of all "packages" this package provide.
Definition: pkgcache.h:393
map_ptrloc DependsList
base of the dependency list
Definition: pkgcache.h:534
map_ptrloc NextProvides
next provides (based of package)
Definition: pkgcache.h:640
map_ptrloc Offset
position in the file
Definition: pkgcache.h:490
unsigned int ID
unique sequel ID
Definition: pkgcache.h:582
Definition: cacheiterators.h:39
unsigned int ID
unique sequel ID
Definition: pkgcache.h:413
Definition: cacheiterators.h:95
Definition: pkgcache.h:121
VerMultiArch
Multi-Arch capabilities of a package version.
Definition: pkgcache.h:509
handles virtual packages
Definition: pkgcache.h:627
map_ptrloc Section
indicates the deduced section
Definition: pkgcache.h:383
information for a single dependency record
Definition: pkgcache.h:592
groups architecture depending packages together
Definition: pkgcache.h:332
map_ptrloc Offset
position in the package file
Definition: pkgcache.h:476
map_ptrloc VerSysName
String representing the version system used.
Definition: pkgcache.h:286
Definition: pkgcache.h:147
map_ptrloc Site
The site the index file was fetched from.
Definition: pkgcache.h:440
unsigned int ID
unique sequel ID
Definition: pkgcache.h:554
unsigned long long Size
archive size for this version
Definition: pkgcache.h:545
map_ptrloc ParentPkg
the text is a description of this package
Definition: pkgcache.h:579
map_ptrloc FileList
index of the first PackageFile structure
Definition: pkgcache.h:278
map_ptrloc File
index of the file that this description was found in
Definition: pkgcache.h:486
unsigned short Hash
characteristic value representing this version
Definition: pkgcache.h:552
used for generating single instances of strings
Definition: pkgcache.h:654
map_ptrloc Name
Name of the package.
Definition: pkgcache.h:364
map_ptrloc IndexType
indicates what sort of index file this is
Definition: pkgcache.h:444
map_ptrloc NextItem
Next link in the chain.
Definition: pkgcache.h:659
map_ptrloc NextDepends
next dependency of this version
Definition: pkgcache.h:602
Definition: pkgcache.h:86
contains information for a single unique package
Definition: pkgcache.h:361
map_ptrloc Version
index of the version this provide line applies to
Definition: pkgcache.h:632
map_ptrloc FileName
physical disk file that this PackageFile represents
Definition: pkgcache.h:427
map_ptrloc Next
Link to the next Group.
Definition: pkgcache.h:343
map_ptrloc NextRevDepends
next reverse dependency of this package
Definition: pkgcache.h:604
unsigned long long InstalledSize
uncompressed size for this version
Definition: pkgcache.h:547
unsigned long Size
Size of the file.
Definition: pkgcache.h:450
unsigned long MaxDescFileSize
The maximum size of a raw entry from the original Translation file.
Definition: pkgcache.h:292
Definition: version.h:30
associates a version with a PackageFile
Definition: pkgcache.h:469
map_ptrloc Group
index of the group this package belongs to
Definition: pkgcache.h:385
map_ptrloc ParentVer
version of the package which has the reverse depends
Definition: pkgcache.h:606
Definition: cacheiterators.h:264
Definition: cacheiterators.h:352
map_ptrloc LastPackage
Link to the last package which belongs to the group.
Definition: pkgcache.h:341
Definition: cacheiterators.h:404
unsigned long CacheFileSize
Size of the complete cache file.
Definition: pkgcache.h:319
unsigned long GroupCount
Structure counts.
Definition: pkgcache.h:264
map_ptrloc Version
string of the version the dependency is applied against
Definition: pkgcache.h:595
map_ptrloc ParentPkg
index of the package providing this
Definition: pkgcache.h:630
map_ptrloc RevDepends
List of all dependencies on this package.
Definition: pkgcache.h:391
map_ptrloc NextVer
next (lower or equal) version in the linked list
Definition: pkgcache.h:530
DepCompareOp
available compare operators
Definition: pkgcache.h:130
Definition: pkgcache.h:683
map_ptrloc NextPkgProv
next provides (based of version)
Definition: pkgcache.h:642
map_ptrloc language_code
Language code of this description (translation)
Definition: pkgcache.h:567
unsigned char MultiArch
stores the MultiArch capabilities of this version
Definition: pkgcache.h:520
Definition: cacheiterators.h:185
associates a description with a Translation file
Definition: pkgcache.h:483
unsigned char Priority
parsed priority value
Definition: pkgcache.h:556
unsigned long Flags
some useful indicators of the package's state
Definition: pkgcache.h:415
map_ptrloc String
string this refers to
Definition: pkgcache.h:657
Definition: mmap.h:43
unsigned long Signature
Signature information.
Definition: pkgcache.h:230
VerPriority
priority of a package version
Definition: pkgcache.h:139
map_ptrloc ProvideVersion
version in the provides line (if any)
Definition: pkgcache.h:638
map_ptrloc NextDesc
next translation for this description
Definition: pkgcache.h:577
map_ptrloc File
index of the package file that this version was found in
Definition: pkgcache.h:472
map_ptrloc NextFile
next step in the linked list
Definition: pkgcache.h:488
Definition: cacheiterators.h:237
map_ptrloc ID
unique sequel ID
Definition: pkgcache.h:609
unsigned char InstState
installation state of the package
Definition: pkgcache.h:403
unsigned char CompareOp
comparison operator specified on the depends line
Definition: pkgcache.h:615
Definition: pkgcache.h:223
unsigned char CurrentState
indicates if the package is installed
Definition: pkgcache.h:405
map_ptrloc Name
Name of the group.
Definition: pkgcache.h:335
Definition: pkgcache.h:134
map_ptrloc Section
section this version is filled in
Definition: pkgcache.h:506
unsigned char SelectedState
state that the user wishes the package to be in
Definition: pkgcache.h:397
map_ptrloc NextPackage
Link to the next package in the same bucket.
Definition: pkgcache.h:389
map_ptrloc md5sum
MD5sum of the original description.
Definition: pkgcache.h:572
unsigned long MaxVerFileSize
The maximum size of a raw entry from the original Package file.
Definition: pkgcache.h:290
map_ptrloc ParentPkg
links to the owning package
Definition: pkgcache.h:538
map_ptrloc NextFile
Link to the next PackageFile in the Cache.
Definition: pkgcache.h:459
unsigned char Type
Dependency type - Depends, Recommends, Conflicts, etc.
Definition: pkgcache.h:611
bool Dirty
indicates if the cache should be erased
Definition: pkgcache.h:239
map_ptrloc DescriptionList
next description in the linked list
Definition: pkgcache.h:532
unsigned short HeaderSz
Size of structure values.
Definition: pkgcache.h:248
map_ptrloc VersionList
Base of a singly linked list of versions.
Definition: pkgcache.h:376
map_ptrloc ProvidesList
list of pkgCache::Provides
Definition: pkgcache.h:540
Definition: mmap.h:85
time_t mtime
Modification time for the file.
Definition: pkgcache.h:452
map_ptrloc CurrentVer
index to the installed version
Definition: pkgcache.h:378
short MajorVersion
Definition: pkgcache.h:232
map_ptrloc Architecture
Architecture(s) the cache was built against.
Definition: pkgcache.h:288
Definition: cacheiterators.h:385
map_ptrloc Arch
Architecture of the package.
Definition: pkgcache.h:366
stores information about the files used to generate the cache
Definition: pkgcache.h:424
datamember of a linked list of available description for a version
Definition: pkgcache.h:561
unsigned int ID
unique sequel ID
Definition: pkgcache.h:461
map_ptrloc FirstPackage
Link to the first package which belongs to the group.
Definition: pkgcache.h:339
map_ptrloc VerStr
complete version string
Definition: pkgcache.h:504
unsigned int ID
unique sequel ID
Definition: pkgcache.h:345