Dpkg::Vendor::Debian: Add support for new hardening branch feature
[dpkg.git] / lib / dpkg / fsys.h
blob2f52250bb4c907e77093048fb92d74a0d0efedfc
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * fsys.h - filesystem nodes hash table
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/>.
22 #ifndef LIBDPKG_FSYS_H
23 #define LIBDPKG_FSYS_H
25 #include <stdio.h>
27 #include <dpkg/file.h>
29 DPKG_BEGIN_DECLS
32 * Data structure here is as follows:
34 * For each package we have a ‘struct fsys_namenode_list *’, the head of a list of
35 * files in that package. They are in ‘forwards’ order. Each entry has a
36 * pointer to the ‘struct fsys_namenode’.
38 * The struct fsys_namenodes are in a hash table, indexed by name.
39 * (This hash table is not visible to callers.)
41 * Each fsys_namenode has a (possibly empty) list of ‘struct filepackage’,
42 * giving a list of the packages listing that filename.
44 * When we read files contained info about a particular package we set the
45 * ‘files’ member of the clientdata struct to the appropriate thing. When
46 * not yet set the files pointer is made to point to ‘fileslist_uninited’
47 * (this is available only internally, within filesdb.c - the published
48 * interface is ensure_*_available).
51 struct pkginfo;
53 /**
54 * Flags to fsys_hash_find_node().
56 enum DPKG_ATTR_ENUM_FLAGS fsys_hash_find_flags {
57 /** No flags. */
58 FHFF_NONE = 0,
59 /** Do not need to copy filename. */
60 FHFF_NOCOPY = DPKG_BIT(0),
61 /** Do not insert the item if it is not found, and return NULL. */
62 FHFF_NONEW = DPKG_BIT(1),
65 enum DPKG_ATTR_ENUM_FLAGS fsys_namenode_flags {
66 /** No flags. */
67 FNNF_NONE = 0,
68 /** In the newconffiles list. */
69 FNNF_NEW_CONFF = DPKG_BIT(0),
70 /** In the new filesystem archive. */
71 FNNF_NEW_INARCHIVE = DPKG_BIT(1),
72 /** In the old package's conffiles list. */
73 FNNF_OLD_CONFF = DPKG_BIT(2),
74 /** Obsolete conffile. */
75 FNNF_OBS_CONFF = DPKG_BIT(3),
76 /** Must remove from other packages' lists. */
77 FNNF_ELIDE_OTHER_LISTS = DPKG_BIT(4),
78 /** >= 1 instance is a dir, cannot rename over. */
79 FNNF_NO_ATOMIC_OVERWRITE = DPKG_BIT(5),
80 /** New file has been placed on the disk. */
81 FNNF_PLACED_ON_DISK = DPKG_BIT(6),
82 FNNF_DEFERRED_FSYNC = DPKG_BIT(7),
83 FNNF_DEFERRED_RENAME = DPKG_BIT(8),
84 /** Path being filtered. */
85 FNNF_FILTERED = DPKG_BIT(9),
86 /** Conffile removal requested by upgrade. */
87 FNNF_RM_CONFF_ON_UPGRADE = DPKG_BIT(10),
90 /**
91 * Stores information to uniquely identify an on-disk file.
93 struct file_ondisk_id {
94 dev_t id_dev;
95 ino_t id_ino;
98 struct fsys_namenode {
99 struct fsys_namenode *next;
100 const char *name;
101 struct pkg_list *packages;
102 struct fsys_diversion *divert;
104 /** We allow the administrator to override the owner, group and mode
105 * of a file. If such an override is present we use that instead of
106 * the stat information stored in the archive.
108 * This functionality used to be in the suidmanager package. */
109 struct file_stat *statoverride;
111 struct trigfileint *trig_interested;
114 * Fields from here on are used by archives.c &c, and cleared by
115 * fsys_hash_init().
118 /** Set to zero when a new node is created. */
119 enum fsys_namenode_flags flags;
121 /** Valid iff this namenode is in the newconffiles list. */
122 const char *oldhash;
124 /** Valid iff the file was unpacked and hashed on this run. */
125 const char *newhash;
127 struct file_ondisk_id *file_ondisk_id;
130 struct fsys_namenode_list {
131 struct fsys_namenode_list *next;
132 struct fsys_namenode *namenode;
136 * Queue of fsys_namenode entries.
138 struct fsys_namenode_queue {
139 struct fsys_namenode_list *head, **tail;
143 * When we deal with an ‘overridden’ file, every package except the
144 * overriding one is considered to contain the other file instead. Both
145 * files have entries in the filesdb database, and they refer to each other
146 * via these diversion structures.
148 * The contested filename's fsys_namenode has a diversion entry with
149 * useinstead set to point to the redirected filename's fsys_namenode; the
150 * redirected fsys_namenode has camefrom set to the contested fsys_namenode.
151 * Both sides' diversion entries will have pkg set to the package (if any)
152 * which is allowed to use the contended filename.
154 * Packages that contain either version of the file will all refer to the
155 * contested fsys_namenode in their per-file package lists (both in core and
156 * on disk). References are redirected to the other fsys_namenode's filename
157 * where appropriate.
159 struct fsys_diversion {
160 struct fsys_namenode *useinstead;
161 struct fsys_namenode *camefrom;
162 struct pkgset *pkgset;
164 /** The ‘contested’ halves are in this list for easy cleanup. */
165 struct fsys_diversion *next;
168 struct fsys_node_pkgs_iter;
169 struct fsys_node_pkgs_iter *
170 fsys_node_pkgs_iter_new(struct fsys_namenode *fnn);
171 struct pkginfo *
172 fsys_node_pkgs_iter_next(struct fsys_node_pkgs_iter *iter);
173 void
174 fsys_node_pkgs_iter_free(struct fsys_node_pkgs_iter *iter);
176 void
177 fsys_hash_init(void);
178 void
179 fsys_hash_reset(void);
180 void
181 fsys_hash_report(FILE *file);
183 fsys_hash_entries(void);
185 struct fsys_hash_iter;
186 struct fsys_hash_iter *
187 fsys_hash_iter_new(void);
188 struct fsys_namenode *
189 fsys_hash_iter_next(struct fsys_hash_iter *iter);
190 void
191 fsys_hash_iter_free(struct fsys_hash_iter *iter);
193 struct fsys_namenode *
194 fsys_hash_find_node(const char *filename, enum fsys_hash_find_flags flags);
196 struct fsys_hash_rev_iter {
197 struct fsys_namenode_list *todo;
200 void
201 fsys_hash_rev_iter_init(struct fsys_hash_rev_iter *iter,
202 struct fsys_namenode_list *files);
203 struct fsys_namenode *
204 fsys_hash_rev_iter_next(struct fsys_hash_rev_iter *iter);
205 void
206 fsys_hash_rev_iter_abort(struct fsys_hash_rev_iter *iter);
208 const char *dpkg_fsys_set_dir(const char *dir);
209 const char *dpkg_fsys_get_dir(void);
210 char *dpkg_fsys_get_path(const char *pathpart);
212 DPKG_END_DECLS
214 #endif /* LIBDPKG_FSYS_H */