apt 3.0.3
commandline package manager
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#define __PKGLIB_IN_PKGCACHE_H
77#include <apt-pkg/macros.h>
78#include <apt-pkg/mmap.h>
79
80#include <cstddef> // required for nullptr_t
81#include <cstdint>
82#include <ctime>
83#include <string>
84#include <string_view>
85
86
87
88// size of (potentially big) files like debs or the install size of them
89typedef uint64_t map_filesize_t;
90// storing file sizes of indexes, which are way below 4 GB for now
91typedef uint32_t map_filesize_small_t;
92// each package/group/dependency gets an id
93typedef uint32_t map_id_t;
94// some files get an id, too, but in far less absolute numbers
95typedef uint16_t map_fileid_t;
96
97// relative pointer from cache start
98template <typename T> class map_pointer {
99 uint32_t val;
100public:
101 map_pointer() noexcept : val(0) {}
102 map_pointer(std::nullptr_t) noexcept : val(0) {}
103 explicit map_pointer(uint32_t n) noexcept : val(n) {}
104 explicit operator uint32_t() noexcept { return val; }
105 explicit operator bool() noexcept { return val != 0; }
106};
107
108template<typename T> inline T *operator +(T *p, map_pointer<T> m) { return p + uint32_t(m); }
109template<typename T> inline bool operator ==(map_pointer<T> u, map_pointer<T> m) { return uint32_t(u) == uint32_t(m); }
110template<typename T> inline bool operator !=(map_pointer<T> u, map_pointer<T> m) { return uint32_t(u) != uint32_t(m); }
111template<typename T> inline bool operator <(map_pointer<T> u, map_pointer<T> m) { return uint32_t(u) < uint32_t(m); }
112template<typename T> inline bool operator >(map_pointer<T> u, map_pointer<T> m) { return uint32_t(u) > uint32_t(m); }
113template<typename T> inline uint32_t operator -(map_pointer<T> u, map_pointer<T> m) { return uint32_t(u) - uint32_t(m); }
114template<typename T> bool operator ==(map_pointer<T> m, std::nullptr_t) { return uint32_t(m) == 0; }
115template<typename T> bool operator !=(map_pointer<T> m, std::nullptr_t) { return uint32_t(m) != 0; }
116
117// same as the previous, but documented to be to a string item
119
120// we have only a small amount of flags for each item
121typedef uint8_t map_flags_t;
122typedef uint8_t map_number_t;
123
125class APT_PUBLIC pkgCache /*{{{*/
126{
127 public:
128 // Cache element predeclarations
129 struct Header;
130 struct Group;
131 struct Package;
132 struct ReleaseFile;
133 struct PackageFile;
134 struct SourceVersion;
135 struct Version;
136 struct Description;
137 struct Provides;
138 struct Dependency;
139 struct DependencyData;
140 struct StringItem;
141 struct VerFile;
142 struct DescFile;
143
144 // Iterators
145 template<typename Str, typename Itr> class Iterator;
146 class GrpIterator;
147 class PkgIterator;
148 class VerIterator;
149 class SrcVerIterator;
150 class DescIterator;
151 class DepIterator;
152 class PrvIterator;
153 class RlsFileIterator;
154 class PkgFileIterator;
155 class VerFileIterator;
156 class DescFileIterator;
157
158 class Namespace;
159
160 // These are all the constants used in the cache structures
161
162 // WARNING - if you change these lists you must also edit
163 // the stringification in pkgcache.cc and also consider whether
164 // the cache file will become incompatible.
165 struct Dep
166 {
167 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
168 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8,Enhances=9};
174 enum DepCompareOp {NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
175 Greater=0x4,Equals=0x5,NotEquals=0x6,
176 Or=0x10,
177 MultiArchImplicit=0x20,
178 ArchSpecific=0x40
179 };
180 };
181
182 struct State
183 {
187 enum VerPriority {Required=1,Important=2,Standard=3,Optional=4,Extra=5};
188 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
189 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
190 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
191 HalfInstalled=4,ConfigFiles=5,Installed=6,
192 TriggersAwaited=7,TriggersPending=8};
193 };
194
195 struct Flag
196 {
197 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
199 NotSource=(1<<0),
200 LocalSource=(1<<1),
201 NoPackages=(1<<2),
202 };
204 NotAutomatic=(1<<0),
205 ButAutomaticUpgrades=(1<<1),
206 };
211 };
212
213 protected:
214
215 // Memory mapped cache file
216 std::string CacheFile;
217 MMap &Map;
218 map_id_t sHash(std::string_view S) const APT_PURE;
219
220 public:
221
222 // Pointers to the arrays of items
223 Header *HeaderP;
224 Group *GrpP;
225 Package *PkgP;
226 VerFile *VerFileP;
227 DescFile *DescFileP;
228 ReleaseFile *RlsFileP;
229 PackageFile *PkgFileP;
230 SourceVersion *SrcVerP; // reserved for SourceVersion objects
231 Version *VerP;
232 Description *DescP;
233 Provides *ProvideP;
234 Dependency *DepP;
235 DependencyData *DepDataP;
236 char *StrP;
237 void *reserved[13];
238
239 virtual bool ReMap(bool const &Errorchecks = true);
240 inline bool Sync() {return Map.Sync();}
241 inline MMap &GetMap() {return Map;}
242 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();}
243
244 // String hashing function (512 range)
245 inline map_id_t Hash(std::string_view S) const {return sHash(S);}
246
247 APT_HIDDEN uint32_t CacheHash();
248
249 // Useful transformation things
250 static const char *Priority(unsigned char Priority);
251 static std::string_view Priority_NoL10n(unsigned char Prio);
252
253 // Accessors
254 GrpIterator FindGrp(std::string_view Name);
255 PkgIterator FindPkg(std::string_view Name);
256 PkgIterator FindPkg(std::string_view Name, std::string_view Arch);
257
258 std::string_view ViewString(map_stringitem_t idx) const
259 {
260 char *name = StrP + idx;
261 size_t len = *reinterpret_cast<const uint16_t*>(name - sizeof(uint16_t));
262 return {name, len};
263 }
264
265 Header &Head() {return *HeaderP;}
266 inline GrpIterator GrpBegin();
267 inline GrpIterator GrpEnd();
268 inline PkgIterator PkgBegin();
269 inline PkgIterator PkgEnd();
270 inline PkgFileIterator FileBegin();
271 inline PkgFileIterator FileEnd();
272 inline RlsFileIterator RlsFileBegin();
273 inline RlsFileIterator RlsFileEnd();
274
275 inline bool MultiArchCache() const { return MultiArchEnabled; }
276 inline char const * NativeArch();
277
278 // Make me a function
280
281 // Converters
282 static const char *CompTypeDeb(unsigned char Comp) APT_PURE;
283 static const char *CompType(unsigned char Comp) APT_PURE;
284 static const char *DepType(unsigned char Dep);
285 static std::string_view DepType_NoL10n(unsigned char Dep);
286
287 pkgCache(MMap *Map,bool DoMap = true);
288 virtual ~pkgCache();
289
290private:
291 void * const d;
292 bool MultiArchEnabled;
293};
294 /*}}}*/
295// Header structure /*{{{*/
297{
303 uint32_t Signature;
305 map_number_t MajorVersion;
306 map_number_t MinorVersion;
312 bool Dirty;
313
321 uint16_t HeaderSz;
322 map_number_t GroupSz;
323 map_number_t PackageSz;
324 map_number_t ReleaseFileSz;
325 map_number_t PackageFileSz;
326 map_number_t VersionSz;
327 map_number_t SourceVersionSz;
328 map_number_t DescriptionSz;
329 map_number_t DependencySz;
330 map_number_t DependencyDataSz;
331 map_number_t ProvidesSz;
332 map_number_t VerFileSz;
333 map_number_t DescFileSz;
334
340 map_id_t GroupCount;
341 map_id_t PackageCount;
342 map_id_t VersionCount;
343 map_id_t SourceVersionCount;
344 map_id_t DescriptionCount;
345 map_id_t DependsCount;
346 map_id_t DependsDataCount;
347 map_fileid_t ReleaseFileCount;
348 map_fileid_t PackageFileCount;
349 map_id_t VerFileCount;
350 map_id_t DescFileCount;
351 map_id_t ProvidesCount;
352
360
368 map_filesize_t MaxVerFileSize;
370 map_filesize_t MaxDescFileSize;
371
381
393 uint32_t GetHashTableSize() const { return HashTableSize; }
394 void SetHashTableSize(unsigned int const sz) { HashTableSize = sz; }
395 map_stringitem_t GetArchitectures() const { return Architectures; }
396 void SetArchitectures(map_stringitem_t const idx) { Architectures = idx; }
397
398#ifdef APT_COMPILING_APT
399 map_pointer<Group> * GrpHashTableP() const { return (map_pointer<Group>*) (this + 1); }
400 map_pointer<Package> * PkgHashTableP() const { return reinterpret_cast<map_pointer<Package> *>(GrpHashTableP() + GetHashTableSize()); }
401#endif
402
404 map_filesize_small_t CacheFileSize;
405
406 bool CheckSizes(Header &Against) const APT_PURE;
407 Header();
408};
409 /*}}}*/
410// Group structure /*{{{*/
446 /*}}}*/
447// Package structure /*{{{*/
511 /*}}}*/
512// Release File structure /*{{{*/
554 /*}}}*/
555// Package File structure /*{{{*/
562{
567
568 map_stringitem_t Component;
569 map_stringitem_t Architecture;
570
580 map_filesize_t Size;
582 time_t mtime;
583
585 map_flags_t Flags;
586
587 // Linked list
591 map_fileid_t ID;
592
595};
596 /*}}}*/
597// VerFile structure /*{{{*/
611 /*}}}*/
612// DescFile structure /*{{{*/
623 /*}}}*/
624// SourceVersion structure /*{{{*/
631{
633 map_id_t ID;
638 map_pointer<Version> VersionList [[gnu::unavailable("not yet available")]];
639 map_pointer<SourceVersion> NextSourceVersion [[gnu::unavailable("not yet available")]];
640
643};
644 /*}}}*/
645// Version structure /*{{{*/
721
722#ifdef APT_COMPILING_APT
724struct pkgCache::Version::Extra
725{
726 uint8_t PhasedUpdatePercentage;
727};
728#endif
729 /*}}}*/
730// Description structure /*{{{*/
755 /*}}}*/
756// Dependency structure /*{{{*/
795 /*}}}*/
796// Provides structure /*{{{*/
822 /*}}}*/
823
824inline char const * pkgCache::NativeArch()
825 { return StrP + HeaderP->Architecture; }
826
827#include <apt-pkg/cacheiterators.h>
828
829 inline pkgCache::GrpIterator pkgCache::GrpBegin()
830 {
831 return GrpIterator(*this);
832 }
833 inline pkgCache::GrpIterator pkgCache::GrpEnd()
834 {
835 return GrpIterator(*this, GrpP);}
836inline pkgCache::PkgIterator pkgCache::PkgBegin()
837 {return PkgIterator(*this);}
838inline pkgCache::PkgIterator pkgCache::PkgEnd()
839 {return PkgIterator(*this,PkgP);}
840inline pkgCache::PkgFileIterator pkgCache::FileBegin()
841 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);}
842inline pkgCache::PkgFileIterator pkgCache::FileEnd()
843 {return PkgFileIterator(*this,PkgFileP);}
844inline pkgCache::RlsFileIterator pkgCache::RlsFileBegin()
845 {return RlsFileIterator(*this,RlsFileP + HeaderP->RlsFileList);}
846inline pkgCache::RlsFileIterator pkgCache::RlsFileEnd()
847 {return RlsFileIterator(*this,RlsFileP);}
848
849
850// Oh I wish for Real Name Space Support
852{
853 public:
854 typedef pkgCache::GrpIterator GrpIterator;
855 typedef pkgCache::PkgIterator PkgIterator;
856 typedef pkgCache::VerIterator VerIterator;
857 typedef pkgCache::SrcVerIterator SrcVerIterator;
858 typedef pkgCache::DescIterator DescIterator;
859 typedef pkgCache::DepIterator DepIterator;
860 typedef pkgCache::PrvIterator PrvIterator;
861 typedef pkgCache::RlsFileIterator RlsFileIterator;
862 typedef pkgCache::PkgFileIterator PkgFileIterator;
863 typedef pkgCache::VerFileIterator VerFileIterator;
867 typedef pkgCache::Header Header;
868 typedef pkgCache::Dep Dep;
869 typedef pkgCache::Flag Flag;
870};
871 /*}}}*/
872#undef __PKGLIB_IN_PKGCACHE_H
873#endif
Definition mmap.h:45
Definition pkgcache.h:98
Definition pkgcache.h:145
Definition pkgcache.h:852
Definition cacheiterators.h:47
Definition version.h:27
Definition mmap.h:87
Definition pkgcache.h:166
DepCompareOp
available compare operators
Definition pkgcache.h:174
@ ArchSpecific
Definition pkgcache.h:178
@ MultiArchImplicit
Definition pkgcache.h:177
information for a single dependency record
Definition pkgcache.h:764
map_flags_t CompareOp
comparison operator specified on the depends line
Definition pkgcache.h:778
map_stringitem_t Version
string of the version the dependency is applied against
Definition pkgcache.h:766
map_pointer< pkgCache::Package > Package
index of the package this depends applies to
Definition pkgcache.h:771
map_number_t Type
Dependency type - Depends, Recommends, Conflicts, etc.
Definition pkgcache.h:774
Definition pkgcache.h:783
map_pointer< Dependency > NextRevDepends
next reverse dependency of this package
Definition pkgcache.h:788
map_pointer< Dependency > NextDepends
next dependency of this version
Definition pkgcache.h:790
map_pointer< Version > ParentVer
version of the package which has the depends
Definition pkgcache.h:786
map_id_t ID
unique sequel ID
Definition pkgcache.h:793
associates a description with a Translation file
Definition pkgcache.h:615
map_pointer< DescFile > NextFile
next step in the linked list
Definition pkgcache.h:619
map_filesize_t Offset
position in the file
Definition pkgcache.h:621
map_pointer< PackageFile > File
index of the file that this description was found in
Definition pkgcache.h:617
datamember of a linked list of available description for a version
Definition pkgcache.h:733
map_pointer< Description > NextDesc
next translation for this description
Definition pkgcache.h:748
map_pointer< Package > ParentPkg
the text is a description of this package
Definition pkgcache.h:750
map_stringitem_t md5sum
MD5sum of the original description.
Definition pkgcache.h:743
map_id_t ID
unique sequel ID
Definition pkgcache.h:753
map_pointer< DescFile > FileList
Definition pkgcache.h:746
map_stringitem_t language_code
Language code of this description (translation)
Definition pkgcache.h:738
Definition pkgcache.h:196
ProvidesFlags
Definition pkgcache.h:207
ReleaseFileFlags
Definition pkgcache.h:203
PkgFFlags
Definition pkgcache.h:198
groups architecture depending packages together
Definition pkgcache.h:422
map_stringitem_t Name
Name of the group.
Definition pkgcache.h:424
map_pointer< Group > Next
Link to the next Group.
Definition pkgcache.h:433
map_pointer< Version > VersionsInSource
List of binary produces by source package with this name.
Definition pkgcache.h:438
map_pointer< Package > FirstPackage
Link to the first package which belongs to the group.
Definition pkgcache.h:428
map_pointer< Package > LastPackage
Link to the last package which belongs to the group.
Definition pkgcache.h:430
map_pointer< void > d
Private pointer.
Definition pkgcache.h:444
map_id_t ID
unique sequel ID
Definition pkgcache.h:435
map_pointer< SourceVersion > SourceVersionList
SourceVersionList.
Definition pkgcache.h:441
Definition pkgcache.h:297
uint32_t HashTableSize
hash tables providing rapid group/package name lookup
Definition pkgcache.h:392
map_number_t MajorVersion
Definition pkgcache.h:305
uint32_t Signature
Signature information.
Definition pkgcache.h:303
map_filesize_small_t CacheFileSize
Hash of the file (TODO: Rename)
Definition pkgcache.h:404
uint16_t HeaderSz
Size of structure values.
Definition pkgcache.h:321
map_stringitem_t VerSysName
String representing the version system used.
Definition pkgcache.h:362
map_filesize_t MaxVerFileSize
The maximum size of a raw entry from the original Package file.
Definition pkgcache.h:368
map_filesize_t MaxDescFileSize
The maximum size of a raw entry from the original Translation file.
Definition pkgcache.h:370
map_pointer< ReleaseFile > RlsFileList
index of the first ReleaseFile structure
Definition pkgcache.h:359
DynamicMMap::Pool Pools[2 *13]
The Pool structures manage the allocation pools that the generator uses.
Definition pkgcache.h:380
map_stringitem_t Architectures
all architectures the cache was built against
Definition pkgcache.h:366
map_stringitem_t Architecture
native architecture the cache was built against
Definition pkgcache.h:364
map_id_t GroupCount
Structure counts.
Definition pkgcache.h:340
map_pointer< PackageFile > FileList
index of the first PackageFile structure
Definition pkgcache.h:357
bool Dirty
indicates if the cache should be erased
Definition pkgcache.h:312
stores information about the files used to generate the cache
Definition pkgcache.h:562
map_pointer< PackageFile > NextFile
Link to the next PackageFile in the Cache.
Definition pkgcache.h:589
map_fileid_t ID
unique sequel ID
Definition pkgcache.h:591
time_t mtime
Modification time for the file.
Definition pkgcache.h:582
map_stringitem_t FileName
physical disk file that this PackageFile represents
Definition pkgcache.h:564
map_flags_t Flags
Definition pkgcache.h:585
map_stringitem_t IndexType
indicates what sort of index file this is
Definition pkgcache.h:574
map_filesize_t Size
Size of the file.
Definition pkgcache.h:580
map_pointer< void > d
Private pointer.
Definition pkgcache.h:594
map_pointer< ReleaseFile > Release
the release information
Definition pkgcache.h:566
contains information for a single unique package
Definition pkgcache.h:460
map_pointer< Dependency > RevDepends
List of all dependencies on this package.
Definition pkgcache.h:482
map_number_t CurrentState
indicates if the package is installed
Definition pkgcache.h:496
map_stringitem_t Arch
Architecture of the package.
Definition pkgcache.h:462
map_pointer< Version > VersionList
Base of a singly linked list of versions.
Definition pkgcache.h:472
map_number_t InstState
installation state of the package
Definition pkgcache.h:494
map_pointer< pkgCache::Group > Group
index of the group this package belongs to
Definition pkgcache.h:476
map_pointer< Version > CurrentVer
index to the installed version
Definition pkgcache.h:474
map_flags_t Flags
some useful indicators of the package's state
Definition pkgcache.h:506
map_pointer< Package > NextPackage
Link to the next package in the same bucket.
Definition pkgcache.h:480
map_number_t SelectedState
state that the user wishes the package to be in
Definition pkgcache.h:488
map_pointer< void > d
Private pointer.
Definition pkgcache.h:509
map_pointer< Provides > ProvidesList
List of all "packages" this package provide.
Definition pkgcache.h:484
map_id_t ID
unique sequel ID
Definition pkgcache.h:504
handles virtual packages
Definition pkgcache.h:806
map_pointer< Provides > NextPkgProv
next provides (based of version)
Definition pkgcache.h:820
map_pointer< pkgCache::Version > Version
index of the version this provide line applies to
Definition pkgcache.h:810
map_pointer< Package > ParentPkg
index of the package providing this
Definition pkgcache.h:808
map_pointer< Provides > NextProvides
next provides (based of package)
Definition pkgcache.h:818
map_stringitem_t ProvideVersion
version in the provides line (if any)
Definition pkgcache.h:815
stores information about the release files used to generate the cache
Definition pkgcache.h:518
map_stringitem_t Archive
the release information
Definition pkgcache.h:525
map_fileid_t ID
unique sequel ID
Definition pkgcache.h:549
map_stringitem_t Site
The site the index file was fetched from.
Definition pkgcache.h:531
map_pointer< ReleaseFile > NextFile
Link to the next ReleaseFile in the Cache.
Definition pkgcache.h:547
time_t mtime
Modification time for the file.
Definition pkgcache.h:540
map_stringitem_t FileName
physical disk file that this ReleaseFile represents
Definition pkgcache.h:520
map_flags_t Flags
Definition pkgcache.h:543
map_filesize_t Size
Size of the file.
Definition pkgcache.h:538
map_pointer< void > d
Private pointer.
Definition pkgcache.h:552
information for a single version of a source package
Definition pkgcache.h:631
map_stringitem_t VerStr
complete version string
Definition pkgcache.h:637
map_pointer< pkgCache::Group > Group
Group the source package belongs too.
Definition pkgcache.h:635
map_pointer< void > d
Private pointer.
Definition pkgcache.h:642
map_id_t ID
unique sequel ID
Definition pkgcache.h:633
Definition pkgcache.h:183
VerPriority
priority of a package version
Definition pkgcache.h:187
associates a version with a PackageFile
Definition pkgcache.h:603
map_pointer< VerFile > NextFile
next step in the linked list
Definition pkgcache.h:607
map_filesize_t Offset
position in the package file
Definition pkgcache.h:609
map_pointer< PackageFile > File
index of the package file that this version was found in
Definition pkgcache.h:605
information for a single version of a package
Definition pkgcache.h:652
map_number_t MultiArch
stores the MultiArch capabilities of this version
Definition pkgcache.h:678
map_pointer< Version > NextInSourceVersion
next version in the source package (might be different binary)
Definition pkgcache.h:663
map_stringitem_t VerStr
complete version string
Definition pkgcache.h:656
map_number_t Priority
parsed priority value
Definition pkgcache.h:714
map_pointer< Version > NextVer
next (lower or equal) version in the linked list
Definition pkgcache.h:688
map_stringitem_t Section
section this version is filled in
Definition pkgcache.h:658
uint32_t Hash
characteristic value representing this version
Definition pkgcache.h:710
map_filesize_t InstalledSize
uncompressed size for this version
Definition pkgcache.h:705
VerMultiArch
Multi-Arch capabilities of a package version.
Definition pkgcache.h:666
@ Same
Definition pkgcache.h:669
@ Foreign
Definition pkgcache.h:668
@ Allowed
Definition pkgcache.h:670
@ All
Definition pkgcache.h:667
@ No
Definition pkgcache.h:666
map_filesize_t Size
archive size for this version
Definition pkgcache.h:703
map_pointer< Package > ParentPkg
links to the owning package
Definition pkgcache.h:696
map_pointer< Version > NextInSource
next version in the source package (might be different binary)
Definition pkgcache.h:716
map_pointer< Dependency > DependsList
base of the dependency list
Definition pkgcache.h:692
map_pointer< Provides > ProvidesList
list of pkgCache::Provides
Definition pkgcache.h:698
map_id_t ID
unique sequel ID
Definition pkgcache.h:712
map_pointer< Extra > d
Private pointer.
Definition pkgcache.h:719
map_pointer< VerFile > FileList
references all the PackageFile's that this version came from
Definition pkgcache.h:686
map_pointer< Description > DescriptionList
next description in the linked list
Definition pkgcache.h:690
map_pointer< pkgCache::SourceVersion > SourceVersion
the source version object
Definition pkgcache.h:661