1 <!doctype debiandoc system>
3 <title>dpkg technical manual</title>
5 <author>Tom Lees <email>tom@lpsg.demon.co.uk</email></author>
6 <version>$Id: dpkg-tech.sgml,v 1.1 1998/07/02 02:58:12 jgg Exp $</version>
9 This document describes the minimum necessary workings for the APT dselect
10 replacement. It gives an overall specification of what its external interface
11 must look like for compatibility, and also gives details of some internal
16 Copyright © Tom Lees, 1997.
18 APT and this document are free software; you can redistribute them and/or
19 modify them under the terms of the GNU General Public License as published
20 by the Free Software Foundation; either version 2 of the License, or (at your
21 option) any later version.
24 For more details, on Debian GNU/Linux systems, see the file
25 /usr/doc/copyright/GPL for the full license.
30 <chapt>Quick summary of dpkg's external interface
31 <sect id="control">Control files
34 The basic dpkg package control file supports the following major features:-
37 <item>5 types of dependencies:-
39 <item>Pre-Depends, which must be satisfied before a package may be
41 <item>Depends, which must be satisfied before a package may be
43 <item>Recommends, to specify a package which if not installed may
44 severely limit the usefulness of the package
45 <item>Suggests, to specify a package which may increase the
46 productivity of the package
47 <item>Conflicts, to specify a package which must NOT be installed
48 in order for the package to be configured
50 Each of these dependencies can specify a version and a depedency on that
51 version, for example "<= 0.5-1", "== 2.7.2-1", etc. The comparators available
54 <item>"<<" - less than
55 <item>"<=" - less than or equal to
56 <item>">>" - greater than
57 <item>">=" - greater than or equal to
60 <item>The concept of "virtual packages", which many other packages may provide,
61 using the Provides mechanism. An example of this is the "httpd" virtual package,
62 which all web servers should provide. Virtual package names may be used in
63 dependency headers. However, current policy is that virtual packages do not
64 support version numbers, so dependencies on virtual packages with versions
66 <item>Several other control fields, such as Package, Version, Description,
67 Section, Priority, etc., which are mainly for classification purposes. The
68 package name must consist entirely of lowercase characters, plus the characters
69 '+', '-', and '.'. Fields can extend across multiple lines - on the second
70 and subsequent lines, there is a space at the beginning instead of a field
71 name and a ':'. Empty lines must consist of the text " .", which will be
72 ignored, as will the initial space for other continuation lines. This feature
73 is usually only used in the Description field.
76 <sect>The dpkg status area
79 The "dpkg status area" is the term used to refer to the directory where dpkg
80 keeps its various status files (GNU would have you call it the dpkg shared
81 state directory). This is always, on Debian systems, /var/lib/dpkg. However,
82 the default directory name should not be hard-coded, but #define'd, so that
83 alteration is possible (it is available via configure in dpkg 1.4.0.9 and
84 above). Of course, in a library, code should be allowed to override the
85 default directory, but the default should be part of the library (so that
86 the user may change the dpkg admin dir simply by replacing the library).
89 Dpkg keeps a variety of files in its status area. These are discussed later
90 on in this document, but a quick summary of the files is here:-
93 <item>available - this file contains a concatenation of control information
94 from all the packages which dpkg knows about. This is updated using the dpkg
95 commands "--update-avail <file>", "--merge-avail <file>", and
97 <item>status - this file contains information on the following things for
100 <item>Whether it is installed, not installed, unpacked, removed,
101 failed configuration, or half-installed (deconfigured in
102 favour of another package).
103 <item>Whether it is selected as install, hold, remove, or purge.
104 <item>If it is "ok" (no installation problems), or "not-ok".
105 <item>It usually also contains the section and priority (so that
106 dselect may classify packages not in available)
107 <item>For packages which did not initially appear in the "available"
108 file when they were installed, the other control information
112 The exact format for the "Status:" field is:
114 Status: Want Flag Status
116 Where <var>Want</> may be one of <em>unknown</>, <em>install</>,
117 <em>hold</>, <em>deinstall</>, <em>purge</>. <var>Flag</>
118 may be one of <em>ok</>, <em>reinstreq</>, <em>hold</>,
119 <em>hold-reinstreq</>.
120 <var>Status</> may be one of <em>not-installed</>, <em>unpacked</>,
121 <em>half-configured</>, <em>installed</>, <em>half-installed</>
122 <em>config-files</>, <em>post-inst-failed</>, <em>removal-failed</>.
123 The states are as follows:-
126 <item>No files are installed from the package, it has no config files
127 left, it uninstalled cleanly if it ever was installed.
129 <item>The basic files have been unpacked (and are listed in
130 /var/lib/dpkg/info/[package].list. There are config files present,
131 but the postinst script has _NOT_ been run.
133 <item>The package was installed and unpacked, but the postinst script
136 <item>All files for the package are installed, and the configuration
139 <item>An attempt was made to remove the packagem but there was a failure
142 <item>The package was "removed", not "purged". The config files are left,
144 <tag>post-inst-failed
145 <item>Old name for half-configured. Do not use.
147 <item>Old name for half-installed. Do not use.
149 The two last items are only left in dpkg for compatibility - they are
150 understood by it, but never written out in this form.
153 Please see the dpkg source code, <tt>lib/parshelp.c</tt>,
154 <em>statusinfos</>, <em>eflaginfos</> and <em>wantinfos</> for more
157 <item>info - this directory contains files from the control archive of every
158 package currently installed. They are installed with a prefix of "<packagename>.".
159 In addition to this, it also contains a file called <package>.list for every
160 package, which contains a list of files. Note also that the control file is
161 not copied into here; it is instead found as part of status or available.
162 <item>methods - this directory is reserved for "method"-specific files - each
163 "method" has a subdirectory underneath this directory (or at least, it can
164 have). In addition, there is another subdirectory "mnt", where misc.
165 filesystems (floppies, CDROMs, etc.) are mounted.
166 <item>alternatives - directory used by the "update-alternatives" program. It
167 contains one file for each "alternatives" interface, which contains information
168 about all the needed symlinked files for each alternative.
169 <item>diversions - file used by the "dpkg-divert" program. Each diversion takes
170 three lines. The first is the package name (or ":" for user diversion), the
171 second the original filename, and the third the diverted filename.
172 <item>updates - directory used internally by dpkg. This is discussed later,
173 in the section <ref id="updates">.
174 <item>parts - temporary directory used by dpkg-split
177 <sect>The dpkg library files
180 These files are installed under /usr/lib/dpkg (usually), but
181 /usr/local/lib/dpkg is also a possibility (as Debian policy dictates). Under
182 this directory, there is a "methods" subdirectory. The methods subdirectory
183 in turn contains any number of subdirectories for each general method
184 processor (note that one set of method scripts can, and is, used for more than
185 one of the methods listed under dselect).
188 The following files may be found in each of these subdirectories:-
191 <item>names - One line per method, two-digit priority to appear on menu
192 at beginning, followed by a space, the name, and then another space and the
194 <item>desc.<name> - Contains the long description displayed by dselect
195 when the cursor is put over the <name> method.
196 <item>setup - Script or program which sets up the initial values to be used
197 by this method. Called with first argument as the status area directory
198 (/var/lib/dpkg), second argument as the name of the method (as in the directory
199 name), and the third argument as the option (as in the names file).
200 <item>install - Script/program called when the "install" option of dselect is
201 run with this method. Same arguments as for setup.
202 <item>update - Script/program called when the "update" option of dselect is
203 run. Same arguments as for setup/install.
206 <sect>The "dpkg" command-line utility
208 <sect1>"Documented" command-line interfaces
211 As yet unwritten. You can refer to the other manuals for now. See
212 <manref name="dpkg" section="8">.
214 <sect1>Environment variables which dpkg responds to
218 <item>DPKG_NO_TSTP - if set to a non-null value, this variable causes dpkg to
219 run a child shell process instead of sending itself a SIGTSTP, when the user
220 selects to background the dpkg process when it asks about conffiles.
221 <item>SHELL - used to determine which shell to run in the case when
223 <item>CC - used as the C compiler to call to determine the target architecture.
224 The default is "gcc".
225 <item>PATH - dpkg checks that it can find at least the following files in the
226 path when it wants to run package installation scripts, and gives an error if
227 it cannot find all of them:-
230 <item>start-stop-daemon
239 The dpkg utility itself is required for quite a number of packages, even if
240 they have been installed with a tool totally separate from dpkg. The reason for
241 this is that some packages, in their pre-installation scripts, check that your
242 version of dpkg supports certain features. This was broken from the start, and
243 it should have actually been a control file header "Dpkg-requires", or similar.
244 What happens is that the configuration scripts will abort or continue according
245 to the exit code of a call to dpkg, which will stop them from being wrongly
249 These special command-line options, which simply return as true or false are
250 all prefixed with "--assert-". Here is a list of them (without the prefix):-
253 <item>support-predepends - Returns success or failure according to whether
254 a version of dpkg which supports predepends properly (1.1.0 or above) is
255 installed, according to the database.
256 <item>working-epoch - Return success or failure according to whether a version
257 of dpkg which supports epochs in version properly (1.4.0.7 or above) is
258 installed, according to the database.
262 Both these options check the status database to see what version of the "dpkg"
263 package is installed, and check it against a known working version.
265 <sect1>--predep-package
268 This strange option is described as follows in the source code:
271 /* Print a single package which:
272 * (a) is the target of one or more relevant predependencies.
273 * (b) has itself no unsatisfied pre-dependencies.
274 * If such a package is present output is the Packages file entry,
275 * which can be massaged as appropriate.
277 * 0 = a package printed, OK
278 * 1 = no suitable package available
284 On further inspection of the source code, it appears that what is does is
288 <item>Looks at the packages in the database which are selected as "install",
290 <item>It then looks at the Pre-Depends information for each of these packages
291 from the available file. When it find a package for which any of the
292 pre-dependencies are not satisfied, it breaks from the loop through the packages.
293 <item>It then looks through the unsatisfied pre-dependencies, and looks for
294 packages which would satisfy this pre-dependency, stopping on the first it
295 finds. If it finds none, it bombs out with an error.
296 <item>It then continues this for every dependency of the initial package.
299 Eventually, it writes out the record of all the packages to satisfy the
300 pre-dependencies. This is used by the disk method to make sure that its
301 dependency ordering is correct. What happens is that all pre-depending
302 packages are first installed, then it runs dpkg -iGROEB on the directory,
303 which installs in the order package files are found. Since pre-dependencies
304 mean that a package may not even be unpacked unless they are satisfied, it is
305 necessary to do this (usually, since all the package files are unpacked in one
306 phase, the configured in another, this is not needed).
308 <chapt>dpkg-deb and .deb file internals
311 This chapter describes the internals to the "dpkg-deb" tool, which is used
312 by "dpkg" as a back-end. dpkg-deb has its own tar extraction functions, which
313 is the source of many problems, as it does not support long filenames, using
316 <sect>The .deb archive format
319 The main principal of the new-format Debian archive (I won't describe the old
320 format - for that have a look at deb-old.5), is that the archive really is
321 an archive - as used by "ar" and friends. However, dpkg-deb uses this format
322 internally, rather than calling "ar". Inside this archive, there are usually
323 the folowing members:-
332 The debian-binary member consists simply of the string "2.0", indicating the
333 format version. control.tar.gz contains the control files (and scripts), and
334 the data.tar.gz contains the actual files to populate the filesystem with.
335 Both tarfiles extract straight into the current directory. Information on the
336 tar formats can be found in the GNU tar info page. Since dpkg-deb calls
337 "tar -cf" to build packages, the Debian packages use the GNU extensions.
339 <sect>The dpkg-deb command-line
342 dpkg-deb documents itself thoroughly with its '--help' command-line option.
343 However, I am including a reference to these for completeness. dpkg-deb
344 supports the following options:-
347 <item>--build (-b) <dir> - builds a .deb archive, takes a directory which
348 contains all the files as an argument. Note that the directory
349 <dir>/DEBIAN will be packed separately into the control archive.
350 <item>--contents (-c) <debfile> - Lists the contents of ther "data.tar.gz"
352 <item>--control (-e) <debfile> - Extracts the control archive into a
353 directory called DEBIAN. Alternatively, with another argument, it will extract
354 it into a different directory.
355 <item>--info (-I) <debfile> - Prints the contents of the "control" file
356 in the control archive to stdout. Alternatively, giving it other arguments will
357 cause it to print the contents of those files instead.
358 <item>--field (-f) <debfile> <field> ... - Prints any number of
359 fields from the "control" file. Giving it extra arguments limits the fields it
360 prints to only those specified. With no command-line arguments other than a
361 filename, it is equivalent to -I and just the .deb filename.
362 <item>--extract (-x) <debfile> <dir> - Extracts the data archive
363 of a debian package under the directory <dir>.
364 <item>--vextract (-X) <debfile> <dir> - Same as --extract, except
365 it is equivalent of giving tar the '-v' option - it prints the filenames as
367 <item>--fsys-tarfile <debfile> - This option outputs a gunzip'd version
368 of data.tar.gz to stdout.
369 <item>--new - sets the archive format to be used to the new Debian format
370 <item>--old - sets the archive format to be used to the old Debian format
371 <item>--debug - Tells dpkg-deb to produce debugging output
372 <item>--nocheck - Tells dpkg-deb not to check the sanity of the control file
373 <item>--help (-h) - Gives a help message
374 <item>--version - Shows the version number
375 <item>--licence/--license (UK/US spellings) - Shows a brief outline of the GPL
378 <sect1>Internal checks used by dpkg-deb when building packages
381 Here is a list of the internal checks used by dpkg-deb when building packages.
382 It is in the order they are done.
385 <item>First, the output Debian archive argument, if it is given, is checked
386 using stat. If it is a directory, an internal flag is set. This check is only
387 made if the archive name is specified explicitly on the command-line. If the
388 argument was not given, the default is the directory name, with ".deb"
390 <item>Next, the control file is checked, unless the --nocheck flag was
391 specified on the command-line. dpkg-deb will bomb out if the second argument
392 to --build was a directory, and --nocheck was specified. Note that dpkg-deb
393 will not be able to determine the name of the package in this case. In the
394 control file, the following things are checked:-
396 <item>The package name is checked to see if it contains any invalid
397 characters (see <ref id="control"> for this).
398 <item>The priority field is checked to see if it uses standard values,
399 and user-defined values are warned against. However, note that this
400 check is now redundant, since the control file no longer contains
401 the priority - the changes file now does this.
402 <item>The control file fields are then checked against the standard
403 list of fields which appear in control files, and any "user-defined"
404 fields are reported as warnings.
405 <item>dpkg-deb then checks that the control file contains a valid
408 <item>After this, in the case where a directory was specified to build the
409 .deb file in, the filename is created as "directory/pkg_ver.deb" or
410 "directory/pkg_ver_arch.deb", depending on whether the control file contains
411 an architecture field.
412 <item>Next, dpkg-deb checks for the <dir>/DEBIAN directory. It complains
413 if it doesn't exist, or if it has permissions < 0755, or > 0775.
414 <item>It then checks that all the files in this subdir are either symlinks
415 or plain files, and have permissions between 0555 and 0775.
416 <item>The conffiles file is then checked to see if the filenames are too
417 long. Warnings are produced for each that is. After this, it checks that
418 the package provides initial copies of each of these conffiles, and that
419 they are all plain files.
422 <chapt>dpkg internals
425 This chapter describes the internals of dpkg itself. Although the low-level
426 formats are quite simple, what dpkg does in certain cases often does not
429 <sect id="updates">Updates
432 This describes the /var/lib/dpkg/updates directory. The function of this
433 directory is somewhat strange, and seems only to be used internally. A function
434 called cleanupdates is called whenever the database is scanned. This function
435 in turn uses <manref name="scandir" section="3">, to sort the files in this
436 directory. Files who names do not consist entirely of digits are discarded.
437 dpkg also causes a fatal error if any of the filenames are different lengths.
440 After having scanned the directory, dpkg in turn parses each file the same way
441 it parses the status file (they are sorted by the scandir to be in numerical
442 order). After having done this, it then writes the status information back
443 to the "status" file, and removes all the "updates" files.
446 These files are created internally by dpkg's "checkpoint" function, and are
447 cleaned up when dpkg exits cleanly.
450 Juding by the use of the updates directory I would call it a Journal. Inorder
451 to effeciently ensure the complete integrity of the status file dpkg will
452 "checkpoint" or journal all of it's activities in the updates directory. By
453 merging the contents of the updates directory (in order!!) against the
454 original status file it can get the precise current state of the system,
455 even in the event of a system failure while dpkg is running.
458 The other option would be to sync-rewrite the status file after each
459 operation, which would kill performance.
462 It is very important that any program that uses the status file abort if
463 the updates directory is not empty! The user should be informed to run dpkg
464 manually (what options though??) to correct the situation.
466 <sect>What happens when dpkg reads the database
469 First, the status file is read. This gives dpkg an initial idea of the packages
470 that are there. Next, the updates files are read in, overriding the status
471 file, and if necessary, the status file is re-written, and updates files are
472 removed. Finally, the available file is read. The available file is read
473 with flags which preclude dpkg from updating any status information from it,
474 though - installed version, etc., and is also told to record that the packages
475 it reads this time are available, not installed.
478 More information on updates is given above.
480 <sect>How dpkg compares version numbers
483 Version numbers consist of three parts: the epoch, the upstream version, and
484 the Debian revision. Dpkg compares these parts in that order. If the epochs
485 are different, it returns immediately, and so on.
488 However, the important part is how it compares the versions which are
489 essentially stored as just strings. These are compared in two distinct parts:
490 those consisting of numerical characters (which are evaluated, and then
491 compared), and those consisting of other characters. When comparing
492 non-numerical parts, they are compared as the character values (ASCII), but
493 non-alphabetical characters are considered "greater than" alphabetical ones.
494 Also note that longer strings (after excluding differences where numerical
495 values are equal) are considered "greater than" shorter ones.
498 Here are a few examples of how these rules apply:-