dpkg (1.18.25) stretch; urgency=medium
[dpkg] / src / filesdb.h
CommitLineData
1479465f
GJ
1/*
2 * dpkg - main program for package management
3 * filesdb.h - management of database of files installed on system
4 *
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
7 *
8 * This is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef FILESDB_H
23#define FILESDB_H
24
25#include <dpkg/file.h>
26
27/*
28 * Data structure here is as follows:
29 *
30 * For each package we have a ‘struct fileinlist *’, the head of a list of
31 * files in that package. They are in ‘forwards’ order. Each entry has a
32 * pointer to the ‘struct filenamenode’.
33 *
34 * The struct filenamenodes are in a hash table, indexed by name.
35 * (This hash table is not visible to callers.)
36 *
37 * Each filenamenode has a (possibly empty) list of ‘struct filepackage’,
38 * giving a list of the packages listing that filename.
39 *
40 * When we read files contained info about a particular package we set the
41 * ‘files’ member of the clientdata struct to the appropriate thing. When
42 * not yet set the files pointer is made to point to ‘fileslist_uninited’
43 * (this is available only internally, within filesdb.c - the published
44 * interface is ensure_*_available).
45 */
46
47struct pkginfo;
48
49/**
50 * Flags to findnamenode().
51 */
52enum fnnflags {
53 /** Do not need to copy filename. */
54 fnn_nocopy = DPKG_BIT(0),
55 /** findnamenode may return NULL. */
56 fnn_nonew = DPKG_BIT(1),
57};
58
59enum filenamenode_flags {
60 /** In the newconffiles list. */
61 fnnf_new_conff = DPKG_BIT(0),
62 /** In the new filesystem archive. */
63 fnnf_new_inarchive = DPKG_BIT(1),
64 /** In the old package's conffiles list. */
65 fnnf_old_conff = DPKG_BIT(2),
66 /** Obsolete conffile. */
67 fnnf_obs_conff = DPKG_BIT(3),
68 /** Must remove from other packages' lists. */
69 fnnf_elide_other_lists = DPKG_BIT(4),
70 /** >= 1 instance is a dir, cannot rename over. */
71 fnnf_no_atomic_overwrite = DPKG_BIT(5),
72 /** New file has been placed on the disk. */
73 fnnf_placed_on_disk = DPKG_BIT(6),
74 fnnf_deferred_fsync = DPKG_BIT(7),
75 fnnf_deferred_rename = DPKG_BIT(8),
76 /** Path being filtered. */
77 fnnf_filtered = DPKG_BIT(9),
78};
79
80struct filenamenode {
81 struct filenamenode *next;
82 const char *name;
83 struct pkg_list *packages;
84 struct diversion *divert;
85
86 /** We allow the administrator to override the owner, group and mode of
87 * a file. If such an override is present we use that instead of the
88 * stat information stored in the archive.
89 *
90 * This functionality used to be in the suidmanager package. */
91 struct file_stat *statoverride;
92
93 /*
94 * Fields from here on are used by archives.c &c, and cleared by
95 * filesdbinit.
96 */
97
98 /** Set to zero when a new node is created. */
99 enum filenamenode_flags flags;
100
101 /** Valid iff this namenode is in the newconffiles list. */
102 const char *oldhash;
103
104 /** Valid iff the file was unpacked and hashed on this run. */
105 const char *newhash;
106
107 struct stat *filestat;
108 struct trigfileint *trig_interested;
109};
110
111struct fileinlist {
112 struct fileinlist *next;
113 struct filenamenode *namenode;
114};
115
116/**
117 * Queue of filenamenode entries.
118 */
119struct filenamenode_queue {
120 struct fileinlist *head, **tail;
121};
122
123/**
124 * When we deal with an ‘overridden’ file, every package except the
125 * overriding one is considered to contain the other file instead. Both
126 * files have entries in the filesdb database, and they refer to each other
127 * via these diversion structures.
128 *
129 * The contested filename's filenamenode has an diversion entry with
130 * useinstead set to point to the redirected filename's filenamenode; the
131 * redirected filenamenode has camefrom set to the contested filenamenode.
132 * Both sides' diversion entries will have pkg set to the package (if any)
133 * which is allowed to use the contended filename.
134 *
135 * Packages that contain either version of the file will all refer to the
136 * contested filenamenode in their per-file package lists (both in core and
137 * on disk). References are redirected to the other filenamenode's filename
138 * where appropriate.
139 */
140struct diversion {
141 struct filenamenode *useinstead;
142 struct filenamenode *camefrom;
143 struct pkgset *pkgset;
144
145 /** The ‘contested’ halves are in this list for easy cleanup. */
146 struct diversion *next;
147};
148
149struct filepackages_iterator;
150struct filepackages_iterator *filepackages_iter_new(struct filenamenode *fnn);
151struct pkginfo *filepackages_iter_next(struct filepackages_iterator *iter);
152void filepackages_iter_free(struct filepackages_iterator *iter);
153
154void filesdbinit(void);
155void files_db_reset(void);
156
157struct fileiterator;
158struct fileiterator *files_db_iter_new(void);
159struct filenamenode *files_db_iter_next(struct fileiterator *iter);
160void files_db_iter_free(struct fileiterator *iter);
161
162void ensure_package_clientdata(struct pkginfo *pkg);
163
164void ensure_diversions(void);
165
166enum statdb_parse_flags {
167 STATDB_PARSE_NORMAL = 0,
168 STATDB_PARSE_LAX = 1,
169};
170
171uid_t statdb_parse_uid(const char *str);
172gid_t statdb_parse_gid(const char *str);
173mode_t statdb_parse_mode(const char *str);
174void ensure_statoverrides(enum statdb_parse_flags flags);
175
176#define LISTFILE "list"
177#define HASHFILE "md5sums"
178
179void ensure_packagefiles_available(struct pkginfo *pkg);
180void ensure_allinstfiles_available(void);
181void ensure_allinstfiles_available_quiet(void);
182void note_must_reread_files_inpackage(struct pkginfo *pkg);
183struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
184void parse_filehash(struct pkginfo *pkg, struct pkgbin *pkgbin);
185void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
186 struct fileinlist *list, enum filenamenode_flags mask);
187void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
188 struct fileinlist *list, enum filenamenode_flags mask);
189
190struct reversefilelistiter { struct fileinlist *todo; };
191
192void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
193struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
194void reversefilelist_abort(struct reversefilelistiter *iterptr);
195
196#endif /* FILESDB_H */