1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
7
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
9
<title>APT Cache File Format - Introduction</title>
11
<link href="index.html" rel="start">
12
<link href="index.html" rel="prev">
13
<link href="ch2.html" rel="next">
14
<link href="index.html#contents" rel="contents">
15
<link href="index.html#copyright" rel="copyright">
16
<link href="ch1.html" rel="chapter" title="1 Introduction">
17
<link href="ch2.html" rel="chapter" title="2 Structures">
18
<link href="ch3.html" rel="chapter" title="3 Notes on the Generator">
19
<link href="ch4.html" rel="chapter" title="4 Future Directions">
20
<link href="ch1.html#s1.1" rel="section" title="1.1 Purpose">
21
<link href="ch2.html#s2.1" rel="section" title="2.1 Header">
22
<link href="ch2.html#s2.2" rel="section" title="2.2 Package">
23
<link href="ch2.html#s2.3" rel="section" title="2.3 PackageFile">
24
<link href="ch2.html#s2.4" rel="section" title="2.4 Version">
25
<link href="ch2.html#s2.5" rel="section" title="2.5 Dependency">
26
<link href="ch2.html#s2.6" rel="section" title="2.6 Provides">
27
<link href="ch2.html#s2.7" rel="section" title="2.7 VerFile">
28
<link href="ch2.html#s2.8" rel="section" title="2.8 StringItem">
29
<link href="ch2.html#s2.9" rel="section" title="2.9 StringTable">
30
<link href="ch2.html#s2.10" rel="section" title="2.10 Defines">
31
<link href="ch1.html#s1.1.1" rel="subsection" title="1.1.1 Note on Pointer access">
32
<link href="ch2.html#s2.10.1" rel="subsection" title="2.10.1 Definitions for Dependency::Type">
33
<link href="ch2.html#s2.10.2" rel="subsection" title="2.10.2 Definitions for Dependency::CompareOp">
34
<link href="ch2.html#s2.10.3" rel="subsection" title="2.10.3 Definitions for Package::SelectedState">
35
<link href="ch2.html#s2.10.4" rel="subsection" title="2.10.4 Definitions for Package::InstState">
36
<link href="ch2.html#s2.10.5" rel="subsection" title="2.10.5 Definitions for Package::CurrentState">
37
<link href="ch2.html#s2.10.6" rel="subsection" title="2.10.6 Definitions for Package::Flags">
38
<link href="ch2.html#s2.10.7" rel="subsection" title="2.10.7 Definitions for Version::Priority">
39
<link href="ch2.html#s2.10.8" rel="subsection" title="2.10.8 Definitions for PackageFile::Flags">
45
<p><a name="ch1"></a></p>
49
[ <a href="index.html">previous</a> ]
50
[ <a href="index.html#contents">Contents</a> ]
52
[ <a href="ch2.html">2</a> ]
53
[ <a href="ch3.html">3</a> ]
54
[ <a href="ch4.html">4</a> ]
55
[ <a href="ch2.html">next</a> ]
62
<br>Chapter 1 - Introduction
67
<h2><a name="s1.1"></a>1.1 Purpose</h2>
70
This document describes the implementation of an architecture dependent binary
71
cache file. The goal of this cache file is two fold, firstly to speed loading
72
and processing of the package file array and secondly to reduce memory
73
consumption of the package file array.
77
The implementation is aimed at an environment with many primary package files,
78
for instance someone that has a Package file for their CD-ROM, a Package file
79
for the latest version of the distribution on the CD-ROM and a package file for
80
the development version. Always present is the information contained in the
81
status file which might be considered a separate package file.
85
Please understand, this is designed as a -CACHE FILE- it is not meant to be
86
used on any system other than the one it was created for. It is not meant to
87
be authoritative either, i.e. if a system crash or software failure occurs it
88
must be perfectly acceptable for the cache file to be in an inconsistent state.
89
Furthermore at any time the cache file may be erased without losing any
94
Also the structures and storage layout is optimized for use by the APT GUI and
95
may not be suitable for all purposes. However it should be possible to extend
96
it with associate cache files that contain other information.
100
To keep memory use down the cache file only contains often used fields and
101
fields that are inexpensive to store, the Package file has a full list of
102
fields. Also the client may assume that all items are perfectly valid and need
103
not perform checks against their correctness. Removal of information from the
104
cache is possible, but blanks will be left in the file, and unused strings will
105
also be present. The recommended implementation is to simply rebuild the cache
106
each time any of the data files change. It is possible to add a new package
107
file to the cache without any negative side effects.
112
<h3><a name="s1.1.1"></a>1.1.1 Note on Pointer access</h3>
115
Every item in every structure is stored as the index to that structure. What
116
this means is that once the files is mmaped every data access has to go through
117
a fixup stage to get a real memory pointer. This is done by taking the index,
118
multiplying it by the type size and then adding it to the start address of the
119
memory block. This sounds complex, but in C it is a single array dereference.
120
Because all items are aligned to their size and indexes are stored as multiples
121
of the size of the structure the format is immediately portable to all possible
122
architectures - BUT the generated files are -NOT-.
126
This scheme allows code like this to be written:
130
void *Map = mmap(...);
131
Package *PkgList = (Package *)Map;
132
Header *Head = (Header *)Map;
133
char *Strings = (char *)Map;
134
cout << (Strings + PkgList[Head->HashTable[0]]->Name) << endl;
138
Notice the lack of casting or multiplication. The net result is to return the
139
name of the first package in the first hash bucket, without error checks.
143
The generator uses allocation pools to group similarly sized structures in
144
large blocks to eliminate any alignment overhead. The generator also assures
145
that no structures overlap and all indexes are unique. Although at first
146
glance it may seem like there is the potential for two structures to exist at
147
the same point the generator never allows this to happen. (See the discussion
154
[ <a href="index.html">previous</a> ]
155
[ <a href="index.html#contents">Contents</a> ]
157
[ <a href="ch2.html">2</a> ]
158
[ <a href="ch3.html">3</a> ]
159
[ <a href="ch4.html">4</a> ]
160
[ <a href="ch2.html">next</a> ]
166
APT Cache File Format
170
$Id: cache.sgml,v 1.11 2003/02/12 15:05:44 doogie Exp $<br>
172
Jason Gunthorpe <code><a href="mailto:jgg@debian.org">jgg@debian.org</a></code><br>