2 * dpkg - main program for package management
3 * filesdb.h - management of database of files installed on system
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
25 #include <dpkg/file.h>
28 * Data structure here is as follows:
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’.
34 * The struct filenamenodes are in a hash table, indexed by name.
35 * (This hash table is not visible to callers.)
37 * Each filenamenode has a (possibly empty) list of ‘struct filepackage’,
38 * giving a list of the packages listing that filename.
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).
50 * Flags to findnamenode().
53 /** Do not need to copy filename. */
54 fnn_nocopy = DPKG_BIT(0),
55 /** findnamenode may return NULL. */
56 fnn_nonew = DPKG_BIT(1),
59 enum 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),
81 struct filenamenode *next;
83 struct pkg_list *packages;
84 struct diversion *divert;
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.
90 * This functionality used to be in the suidmanager package. */
91 struct file_stat *statoverride;
94 * Fields from here on are used by archives.c &c, and cleared by
98 /** Set to zero when a new node is created. */
99 enum filenamenode_flags flags;
101 /** Valid iff this namenode is in the newconffiles list. */
104 /** Valid iff the file was unpacked and hashed on this run. */
107 struct stat *filestat;
108 struct trigfileint *trig_interested;
112 struct fileinlist *next;
113 struct filenamenode *namenode;
117 * Queue of filenamenode entries.
119 struct filenamenode_queue {
120 struct fileinlist *head, **tail;
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.
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.
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
141 struct filenamenode *useinstead;
142 struct filenamenode *camefrom;
143 struct pkgset *pkgset;
145 /** The ‘contested’ halves are in this list for easy cleanup. */
146 struct diversion *next;
149 struct filepackages_iterator;
150 struct filepackages_iterator *filepackages_iter_new(struct filenamenode *fnn);
151 struct pkginfo *filepackages_iter_next(struct filepackages_iterator *iter);
152 void filepackages_iter_free(struct filepackages_iterator *iter);
154 void filesdbinit(void);
155 void files_db_reset(void);
158 struct fileiterator *files_db_iter_new(void);
159 struct filenamenode *files_db_iter_next(struct fileiterator *iter);
160 void files_db_iter_free(struct fileiterator *iter);
162 void ensure_package_clientdata(struct pkginfo *pkg);
164 void ensure_diversions(void);
166 enum statdb_parse_flags {
167 STATDB_PARSE_NORMAL = 0,
168 STATDB_PARSE_LAX = 1,
171 uid_t statdb_parse_uid(const char *str);
172 gid_t statdb_parse_gid(const char *str);
173 mode_t statdb_parse_mode(const char *str);
174 void ensure_statoverrides(enum statdb_parse_flags flags);
176 #define LISTFILE "list"
177 #define HASHFILE "md5sums"
179 void ensure_packagefiles_available(struct pkginfo *pkg);
180 void ensure_allinstfiles_available(void);
181 void ensure_allinstfiles_available_quiet(void);
182 void note_must_reread_files_inpackage(struct pkginfo *pkg);
183 struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
184 void parse_filehash(struct pkginfo *pkg, struct pkgbin *pkgbin);
185 void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
186 struct fileinlist *list, enum filenamenode_flags mask);
187 void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
188 struct fileinlist *list, enum filenamenode_flags mask);
190 struct reversefilelistiter { struct fileinlist *todo; };
192 void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
193 struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
194 void reversefilelist_abort(struct reversefilelistiter *iterptr);
196 #endif /* FILESDB_H */