~paulo-trezentos/apt/0.7.20_pbo

« back to all changes in this revision

Viewing changes to build/docs/cache.html/ch1.html

  • Committer: Paulo Trezentos
  • Date: 2010-07-19 00:47:36 UTC
  • Revision ID: paulo.trezentos@caixamagica.pt-20100719004736-e7gupo9ec0kpfx0s
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
 
2
 
 
3
<html>
 
4
 
 
5
<head>
 
6
 
 
7
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
 
8
 
 
9
<title>APT Cache File Format - Introduction</title>
 
10
 
 
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">
 
40
 
 
41
</head>
 
42
 
 
43
<body>
 
44
 
 
45
<p><a name="ch1"></a></p>
 
46
<hr>
 
47
 
 
48
<p>
 
49
[ <a href="index.html">previous</a> ]
 
50
[ <a href="index.html#contents">Contents</a> ]
 
51
[ 1 ]
 
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> ]
 
56
</p>
 
57
 
 
58
<hr>
 
59
 
 
60
<h1>
 
61
APT Cache File Format
 
62
<br>Chapter 1 - Introduction
 
63
</h1>
 
64
 
 
65
<hr>
 
66
 
 
67
<h2><a name="s1.1"></a>1.1 Purpose</h2>
 
68
 
 
69
<p>
 
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.
 
74
</p>
 
75
 
 
76
<p>
 
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.
 
82
</p>
 
83
 
 
84
<p>
 
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
 
90
information.
 
91
</p>
 
92
 
 
93
<p>
 
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.
 
97
</p>
 
98
 
 
99
<p>
 
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.
 
108
</p>
 
109
 
 
110
<hr>
 
111
 
 
112
<h3><a name="s1.1.1"></a>1.1.1 Note on Pointer access</h3>
 
113
 
 
114
<p>
 
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-.
 
123
</p>
 
124
 
 
125
<p>
 
126
This scheme allows code like this to be written:
 
127
</p>
 
128
 
 
129
<pre>
 
130
       void *Map = mmap(...);
 
131
       Package *PkgList = (Package *)Map;
 
132
       Header *Head = (Header *)Map;
 
133
       char *Strings = (char *)Map;
 
134
       cout &lt;&lt; (Strings + PkgList[Head-&gt;HashTable[0]]-&gt;Name) &lt;&lt; endl;
 
135
</pre>
 
136
 
 
137
<p>
 
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.
 
140
</p>
 
141
 
 
142
<p>
 
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
 
148
of free space pools)
 
149
</p>
 
150
 
 
151
<hr>
 
152
 
 
153
<p>
 
154
[ <a href="index.html">previous</a> ]
 
155
[ <a href="index.html#contents">Contents</a> ]
 
156
[ 1 ]
 
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> ]
 
161
</p>
 
162
 
 
163
<hr>
 
164
 
 
165
<p>
 
166
APT Cache File Format
 
167
</p>
 
168
 
 
169
<address>
 
170
$Id: cache.sgml,v 1.11 2003/02/12 15:05:44 doogie Exp $<br>
 
171
<br>
 
172
Jason Gunthorpe <code><a href="mailto:jgg@debian.org">jgg@debian.org</a></code><br>
 
173
<br>
 
174
</address>
 
175
<hr>
 
176
 
 
177
</body>
 
178
 
 
179
</html>
 
180