apt: apt-pkg/pkgcache.h File Reference

apt 3.0.1 commandline package manager

Classes | Macros | Typedefs | Functions
pkgcache.h File Reference

pkgCache - Structure definitions for the cache file More...

`#include <apt-pkg/macros.h>`
`#include <apt-pkg/mmap.h>`
`#include <cstddef>`
`#include <cstdint>`
`#include <ctime>`
`#include <string>`
`#include <string_view>`
`#include <apt-pkg/cacheiterators.h>`

Go to the source code of this file.

## Classes
class | map_pointer< T >
class | pkgCache
struct | pkgCache::Dep
struct | pkgCache::State
struct | pkgCache::Flag
struct | pkgCache::Header
struct | pkgCache::Group
| groups architecture depending packages together More...
struct | pkgCache::Package
| contains information for a single unique package More...
struct | pkgCache::ReleaseFile
| stores information about the release files used to generate the cache More...
struct | pkgCache::PackageFile
| stores information about the files used to generate the cache More...
struct | pkgCache::VerFile
| associates a version with a PackageFile More...
struct | pkgCache::DescFile
| associates a description with a Translation file More...
struct | pkgCache::SourceVersion
| information for a single version of a source package More...
struct | pkgCache::Version
| information for a single version of a package More...
struct | pkgCache::Description
| datamember of a linked list of available description for a version More...
struct | pkgCache::DependencyData
| information for a single dependency record More...
struct | pkgCache::Dependency
struct | pkgCache::Provides
| handles virtual packages More...
class | pkgCache::Namespace

## Typedefs
typedef uint64_t | map_filesize_t
typedef uint32_t | map_filesize_small_t
typedef uint32_t | map_id_t
typedef uint16_t | map_fileid_t
typedef map_pointer< char > | map_stringitem_t
typedef uint8_t | map_flags_t
typedef uint8_t | map_number_t

## Functions
template<typename T>
T * | operator+ (T *p, map_pointer< T > m)
template<typename T>
bool | operator== (map_pointer< T > u, map_pointer< T > m)
template<typename T>
bool | operator!= (map_pointer< T > u, map_pointer< T > m)
template<typename T>
bool | operator< (map_pointer< T > u, map_pointer< T > m)
template<typename T>
bool | operator> (map_pointer< T > u, map_pointer< T > m)
template<typename T>
uint32_t | operator- (map_pointer< T > u, map_pointer< T > m)
template<typename T>
bool | operator== (map_pointer< T > m, std::nullptr_t)
template<typename T>
bool | operator!= (map_pointer< T > m, std::nullptr_t)

## Detailed Description

pkgCache - Structure definitions for the cache file

The goal of the cache file is two fold: Firstly to speed loading and processing of the package file array and secondly to reduce memory consumption of the package file array.

The implementation is aimed at an environment with many primary package files, for instance someone that has a Package file for their CD-ROM, a Package file for the latest version of the distribution on the CD-ROM and a package file for the development version. Always present is the information contained in the status file which might be considered a separate package file.

Please understand, this is designed as a Cache file it is not meant to be used on any system other than the one it was created for. It is not meant to be authoritative either, i.e. if a system crash or software failure occurs it must be perfectly acceptable for the cache file to be in an inconsistent state. Furthermore at any time the cache file may be erased without losing any information.

Also the structures and storage layout is optimized for use by the APT and may not be suitable for all purposes. However it should be possible to extend it with associate cache files that contain other information.

To keep memory use down the cache file only contains often used fields and fields that are inexpensive to store, the Package file has a full list of fields. Also the client may assume that all items are perfectly valid and need not perform checks against their correctness. Removal of information from the cache is possible, but blanks will be left in the file, and unused strings will also be present. The recommended implementation is to simply rebuild the cache each time any of the data files change. It is possible to add a new package file to the cache without any negative side effects.

Note on Pointer access Clients should always use the CacheIterators classes for access to the cache and the data in it. They also provide a simple STL-like method for traversing the links of the datastructure.

Every item in every structure is stored as the index to that structure. What this means is that once the files is mmaped every data access has to go through a fix up stage to get a real memory pointer. This is done by taking the index, multiplying it by the type size and then adding it to the start address of the memory block. This sounds complex, but in C it is a single array dereference. Because all items are aligned to their size and indexes are stored as multiples of the size of the structure the format is immediately portable to all possible architectures - BUT the generated files are -NOT-.

This scheme allows code like this to be written:

void *Map = mmap(...); Package *PkgList = (Package *)Map; Header *Head = (Header *)Map; char *Strings = (char *)Map; cout << (Strings + PkgList[Head->HashTable[0]]->Name) << endl;

Notice the lack of casting or multiplication. The net result is to return the name of the first package in the first hash bucket, without error checks.

The generator uses allocation pools to group similarly sized structures in large blocks to eliminate any alignment overhead. The generator also assures that no structures overlap and all indexes are unique. Although at first glance it may seem like there is the potential for two structures to exist at the same point the generator never allows this to happen. (See the discussion of free space pools)

See pkgcachegen.h for more information about generating cache structures.