2 * libdpkg - Debian packaging suite library routines
3 * dpkg-db.h - declarations for in-core package database management
5 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
6 * Copyright © 2000,2001 Wichert Akkerman
7 * Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
9 * This is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef LIBDPKG_DPKG_DB_H
24 #define LIBDPKG_DPKG_DB_H
26 #include <sys/types.h>
31 #include <dpkg/macros.h>
32 #include <dpkg/varbuf.h>
33 #include <dpkg/version.h>
34 #include <dpkg/arch.h>
39 * @defgroup dpkg-db In-core package database management
40 * @ingroup dpkg-public
58 struct dependency *next;
59 struct deppossi *list;
64 struct dependency *up;
66 struct deppossi *next, *rev_next, *rev_prev;
67 const struct dpkg_arch *arch;
68 struct dpkg_version version;
69 enum dpkg_relation verrel;
70 bool arch_is_implicit;
74 struct arbitraryfield {
75 struct arbitraryfield *next;
81 struct conffile *next;
88 struct filedetails *next;
90 const char *msdosname;
96 * Node describing a binary package file.
98 * This structure holds information contained on each binary package.
101 struct dependency *depends;
102 /** The ‘essential’ flag, true = yes, false = no (absent). */
110 const struct dpkg_arch *arch;
111 /** The following is the "pkgname:archqual" cached string, if this was a
112 * C++ class this member would be mutable. */
113 const char *pkgname_archqual;
114 const char *description;
115 const char *maintainer;
117 const char *installedsize;
120 struct dpkg_version version;
121 struct conffile *conffiles;
122 struct arbitraryfield *arbs;
126 * Node indicates that parent's Triggers-Pending mentions name.
128 * Note: These nodes do double duty: after they're removed from a package's
129 * trigpend list, references may be preserved by the trigger cycle checker
133 struct trigpend *next;
138 * Node indicates that aw's Triggers-Awaited mentions pend.
141 struct pkginfo *aw, *pend;
142 struct trigaw *samepend_next;
144 struct trigaw *next, *prev;
148 /* Note: dselect and dpkg have different versions of this. */
149 struct perpackagestate;
152 * Node describing an architecture package instance.
154 * This structure holds state information.
158 struct pkginfo *arch_next;
161 want_unknown, want_install, want_hold, want_deinstall, want_purge,
162 /** Not allowed except as special sentinel value in some places. */
165 /** The error flag bitmask. */
176 stat_triggersawaited,
177 stat_triggerspending,
186 pri_other, pri_unknown, pri_unset=-1
188 const char *otherpriority;
190 struct dpkg_version configversion;
191 struct filedetails *files;
192 struct pkgbin installed;
193 struct pkgbin available;
194 struct perpackagestate *clientdata;
198 struct trigaw *head, *tail;
201 /* ->pend == this, non-NULL for us when Triggers-Pending. */
202 struct trigaw *othertrigaw_head;
203 struct trigpend *trigpend_head;
207 * Node describing a package set sharing the same package name.
214 struct deppossi *available;
215 struct deppossi *installed;
217 int installed_instances;
220 /*** from dbdir.c ***/
222 const char *dpkg_db_set_dir(const char *dir);
223 const char *dpkg_db_get_dir(void);
224 char *dpkg_db_get_path(const char *pathpart);
226 #include <dpkg/atomic-file.h>
228 /*** from dbmodify.c ***/
231 /* Those marked with \*s*\ are possible returns from modstatdb_init. */
232 msdbrw_readonly/*s*/, msdbrw_needsuperuserlockonly/*s*/,
234 msdbrw_write/*s*/, msdbrw_needsuperuser,
236 /* Now some optional flags (starting at bit 8): */
237 msdbrw_available_readonly = DPKG_BIT(8),
238 msdbrw_available_write = DPKG_BIT(9),
239 msdbrw_available_mask = 0xff00,
242 void modstatdb_init(void);
243 void modstatdb_done(void);
244 bool modstatdb_is_locked(void);
245 bool modstatdb_can_lock(void);
246 void modstatdb_lock(void);
247 void modstatdb_unlock(void);
248 enum modstatdb_rw modstatdb_open(enum modstatdb_rw reqrwflags);
249 enum modstatdb_rw modstatdb_get_status(void);
250 void modstatdb_note(struct pkginfo *pkg);
251 void modstatdb_note_ifwrite(struct pkginfo *pkg);
252 void modstatdb_checkpoint(void);
253 void modstatdb_shutdown(void);
255 /*** from database.c ***/
257 void pkgset_blank(struct pkgset *set);
258 int pkgset_installed_instances(struct pkgset *set);
260 void pkg_blank(struct pkginfo *pp);
261 void pkgbin_blank(struct pkgbin *pkgbin);
262 bool pkg_is_informative(struct pkginfo *pkg, struct pkgbin *info);
264 struct pkgset *pkg_db_find_set(const char *name);
265 struct pkginfo *pkg_db_get_singleton(struct pkgset *set);
266 struct pkginfo *pkg_db_find_singleton(const char *name);
267 struct pkginfo *pkg_db_get_pkg(struct pkgset *set, const struct dpkg_arch *arch);
268 struct pkginfo *pkg_db_find_pkg(const char *name, const struct dpkg_arch *arch);
269 int pkg_db_count_set(void);
270 int pkg_db_count_pkg(void);
271 void pkg_db_reset(void);
273 struct pkgiterator *pkg_db_iter_new(void);
274 struct pkgset *pkg_db_iter_next_set(struct pkgiterator *iter);
275 struct pkginfo *pkg_db_iter_next_pkg(struct pkgiterator *iter);
276 void pkg_db_iter_free(struct pkgiterator *iter);
278 void pkg_db_report(FILE *);
280 /*** from parse.c ***/
283 /** Parse the control file from a binary .deb package. */
284 pdb_deb_control = DPKG_BIT(0),
285 /** Store in ‘available’ in-core structures, not ‘status’. */
286 pdb_recordavailable = DPKG_BIT(1),
287 /** Throw up an error if ‘Status’ encountered. */
288 pdb_rejectstatus = DPKG_BIT(2),
289 /** Ignore priority/section info if we already have any. */
290 pdb_weakclassification = DPKG_BIT(3),
291 /** Ignore files info if we already have them. */
292 pdb_ignorefiles = DPKG_BIT(4),
293 /** Ignore packages with older versions already read. */
294 pdb_ignoreolder = DPKG_BIT(5),
295 /** Perform laxer version parsing. */
296 pdb_lax_version_parser = DPKG_BIT(6),
297 /** Perform laxer parsing, used to transition to stricter parsing. */
298 pdb_lax_parser = pdb_lax_version_parser,
300 /* Standard operations. */
302 pdb_parse_status = pdb_lax_parser | pdb_weakclassification,
303 pdb_parse_update = pdb_parse_status | pdb_deb_control,
304 pdb_parse_available = pdb_recordavailable | pdb_rejectstatus |
306 pdb_parse_binary = pdb_recordavailable | pdb_rejectstatus |
310 const char *pkg_name_is_illegal(const char *p);
311 int parsedb(const char *filename, enum parsedbflags, struct pkginfo **donep);
312 void copy_dependency_links(struct pkginfo *pkg,
313 struct dependency **updateme,
314 struct dependency *newdepends,
317 /*** from parsehelp.c ***/
319 #include <dpkg/namevalue.h>
321 extern const struct namevalue booleaninfos[];
322 extern const struct namevalue multiarchinfos[];
323 extern const struct namevalue priorityinfos[];
324 extern const struct namevalue statusinfos[];
325 extern const struct namevalue eflaginfos[];
326 extern const struct namevalue wantinfos[];
328 #include <dpkg/error.h>
330 enum versiondisplayepochwhen { vdew_never, vdew_nonambig, vdew_always };
331 void varbufversion(struct varbuf *, const struct dpkg_version *,
332 enum versiondisplayepochwhen);
333 int parseversion(struct dpkg_version *version, const char *,
334 struct dpkg_error *err);
335 const char *versiondescribe(const struct dpkg_version *,
336 enum versiondisplayepochwhen);
338 enum pkg_name_arch_when {
339 /** Never display arch. */
341 /** Display arch only when it's non-ambiguous. */
343 /** Display arch only when it's a foreign one. */
345 /** Always display arch. */
349 void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg,
350 const struct pkgbin *pkgbin,
351 enum pkg_name_arch_when pnaw);
352 const char *pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin,
353 enum pkg_name_arch_when pnaw);
354 const char *pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw);
356 /*** from dump.c ***/
358 void writerecord(FILE*, const char*,
359 const struct pkginfo *, const struct pkgbin *);
362 /** Dump ‘available’ in-core structures, not ‘status’. */
363 wdb_dump_available = DPKG_BIT(0),
364 /** Must sync the written file. */
365 wdb_must_sync = DPKG_BIT(1),
368 void writedb(const char *filename, enum writedb_flags flags);
370 /* Note: The varbufs must have been initialized and will not be
372 void varbufrecord(struct varbuf *, const struct pkginfo *,
373 const struct pkgbin *);
374 void varbufdependency(struct varbuf *vb, struct dependency *dep);
376 /*** from depcon.c ***/
378 bool versionsatisfied(struct pkgbin *it, struct deppossi *against);
379 bool deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *arch,
380 struct deppossi *against);
381 bool archsatisfied(struct pkgbin *it, struct deppossi *against);
383 /*** from nfmalloc.c ***/
384 void *nfmalloc(size_t);
385 char *nfstrsave(const char*);
386 char *nfstrnsave(const char*, size_t);
387 void nffreeall(void);
393 #endif /* LIBDPKG_DPKG_DB_H */