This is the first item in the file.
struct Header
{
// Signature information
unsigned long Signature;
short MajorVersion;
short MinorVersion;
bool Dirty;
// Size of structure values
unsigned short HeaderSz;
unsigned short PackageSz;
unsigned short PackageFileSz;
unsigned short VersionSz;
unsigned short DependencySz;
unsigned short ProvidesSz;
unsigned short VerFileSz;
// Structure counts
unsigned long PackageCount;
unsigned long VersionCount;
unsigned long DependsCount;
unsigned long PackageFileCount;
unsigned long MaxVerFileSize;
// Offsets
unsigned long FileList; // PackageFile
unsigned long StringList; // StringItem
// Allocation pools
struct
{
unsigned long ItemSize;
unsigned long Start;
unsigned long Count;
} Pools[7];
// Package name lookup
unsigned long HashTable[512]; // Package
};
unsigned long Hash(string Str)
{
unsigned long Hash = 0;
for (const char *I = Str.begin(); I != Str.end(); I++)
Hash += *I * ((Str.end() - I + 1));
return Hash % _count(Head.HashTable);
}
By iterating over each entry in the hash table it is possible to iterate over
the entire list of packages. Hash Collisions are handled with a singely linked
list of packages based at the hash item. The linked list contains only
packages that macth the hashing function.
This contians information for a single unique package. There can be any number of versions of a given package. Package exists in a singly linked list of package records starting at the hash index of the name in the Header->HashTable.
struct Pacakge
{
// Pointers
unsigned long Name; // Stringtable
unsigned long VersionList; // Version
unsigned long TargetVer; // Version
unsigned long CurrentVer; // Version
unsigned long TargetDist; // StringTable (StringItem)
unsigned long Section; // StringTable (StringItem)
// Linked lists
unsigned long NextPackage; // Package
unsigned long RevDepends; // Dependency
unsigned long ProvidesList; // Provides
// Install/Remove/Purge etc
unsigned char SelectedState; // What
unsigned char InstState; // Flags
unsigned char CurrentState; // State
// Unique ID for this pkg
unsigned short ID;
unsigned long Flags;
};
This contians information for a single package file. Package files are referenced by Version structures. This is a singly linked list based from Header.FileList
struct PackageFile
{
// Names
unsigned long FileName; // Stringtable
unsigned long Archive; // Stringtable
unsigned long Component; // Stringtable
unsigned long Version; // Stringtable
unsigned long Origin; // Stringtable
unsigned long Label; // Stringtable
unsigned long Architecture; // Stringtable
unsigned long Size;
// Linked list
unsigned long NextFile; // PackageFile
unsigned short ID;
unsigned long Flags;
time_t mtime; // Modification time
};
This contians the information for a single version of a package. This is a singley linked list based from Package.Versionlist.
The version list is always sorted from highest version to lowest version by the generator. Also there may not be any duplicate entries in the list (same VerStr).
struct Version
{
unsigned long VerStr; // Stringtable
unsigned long Section; // StringTable (StringItem)
unsigned long Arch; // StringTable
// Lists
unsigned long FileList; // VerFile
unsigned long NextVer; // Version
unsigned long DependsList; // Dependency
unsigned long ParentPkg; // Package
unsigned long ProvidesList; // Provides
unsigned long Size;
unsigned long InstalledSize;
unsigned long Hash;
unsigned short ID;
unsigned char Priority;
};
Dependency contains the information for a single dependency record. The records are split up like this to ease processing by the client. The base of list linked list is Version.DependsList. All forms of dependencies are recorded here including Conflicts, Suggests and Recommends.
Multiple depends on the same package must be grouped together in the Dependency lists. Clients should assume this is always true.
struct Dependency
{
unsigned long Version; // Stringtable
unsigned long Package; // Package
unsigned long NextDepends; // Dependency
unsigned long NextRevDepends; // Reverse dependency linking
unsigned long ParentVer; // Upwards parent version link
// Specific types of depends
unsigned char Type;
unsigned char CompareOp;
unsigned short ID;
};
Provides handles virtual packages. When a Provides: line is encountered a new provides record is added associating the package with a virtual package name. The provides structures are linked off the package structures. This simplifies the analysis of dependencies and other aspects A provides refers to a specific version of a specific package, not all versions need to provide that provides.
There is a linked list of provided package names started from each version that provides packages. This is the forwards provides mechanism.
struct Provides
{
unsigned long ParentPkg; // Package
unsigned long Version; // Version
unsigned long ProvideVersion; // Stringtable
unsigned long NextProvides; // Provides
unsigned long NextPkgProv; // Provides
};
VerFile associates a version with a PackageFile, this allows a full description of all Versions in all files (and hence all sources) under consideration.
struct pkgCache::VerFile
{
unsigned long File; // PackageFile
unsigned long NextFile; // PkgVerFile
unsigned long Offset;
unsigned short Size;
}
StringItem is used for generating single instances of strings. Some things like Section Name are are usefull to have as unique tags. It is part of a linked list based at Header::StringList.
struct StringItem
{
unsigned long String; // Stringtable
unsigned long NextItem; // StringItem
};
All strings are simply inlined any place in the file that is natural for the writer. The client should make no assumptions about the positioning of strings. All stringtable values point to a byte offset from the start of the file that a null terminated string will begin.
Several structures use variables to indicate things. Here is a list of all of them.
#define pkgDEP_Depends 1 #define pkgDEP_PreDepends 2 #define pkgDEP_Suggests 3 #define pkgDEP_Recommends 4 #define pkgDEP_Conflicts 5 #define pkgDEP_Replaces 6
#define pkgOP_OR 0x10 #define pkgOP_LESSEQ 0x1 #define pkgOP_GREATEREQ 0x2 #define pkgOP_LESS 0x3 #define pkgOP_GREATER 0x4 #define pkgOP_EQUALS 0x5The lower 4 bits are used to indicate what operator is being specified and the upper 4 bits are flags. pkgOP_OR indicates that the next package is or'd with the current package.
#define pkgSTATE_Unkown 0 #define pkgSTATE_Install 1 #define pkgSTATE_Hold 2 #define pkgSTATE_DeInstall 3 #define pkgSTATE_Purge 4
#define pkgSTATE_Ok 0 #define pkgSTATE_ReInstReq 1 #define pkgSTATE_Hold 2 #define pkgSTATE_HoldReInstReq 3
#define pkgSTATE_NotInstalled 0 #define pkgSTATE_UnPacked 1 #define pkgSTATE_HalfConfigured 2 #define pkgSTATE_UnInstalled 3 #define pkgSTATE_HalfInstalled 4 #define pkgSTATE_ConfigFiles 5 #define pkgSTATE_Installed 6
#define pkgFLAG_Auto (1 << 0) #define pkgFLAG_New (1 << 1) #define pkgFLAG_Obsolete (1 << 2) #define pkgFLAG_Essential (1 << 3) #define pkgFLAG_ImmediateConf (1 << 4)
Zero is used for unparsable or absent Priority fields.
#define pkgPRIO_Important 1 #define pkgPRIO_Required 2 #define pkgPRIO_Standard 3 #define pkgPRIO_Optional 4 #define pkgPRIO_Extra 5
#define pkgFLAG_NotSource (1 << 0) #define pkgFLAG_NotAutomatic (1 << 1)