filesdb.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 <ian@chiark.greenend.org.uk>
  6. * Copyright © 2008-2012 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 <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef FILESDB_H
  22. #define FILESDB_H
  23. #include <dpkg/file.h>
  24. /*
  25. * Data structure here is as follows:
  26. *
  27. * For each package we have a ‘struct fileinlist *’, the head of a list of
  28. * files in that package. They are in ‘forwards’ order. Each entry has a
  29. * pointer to the ‘struct filenamenode’.
  30. *
  31. * The struct filenamenodes are in a hash table, indexed by name.
  32. * (This hash table is not visible to callers.)
  33. *
  34. * Each filenamenode has a (possibly empty) list of ‘struct filepackage’,
  35. * giving a list of the packages listing that filename.
  36. *
  37. * When we read files contained info about a particular package we set the
  38. * ‘files’ member of the clientdata struct to the appropriate thing. When
  39. * not yet set the files pointer is made to point to ‘fileslist_uninited’
  40. * (this is available only internally, within filesdb.c - the published
  41. * interface is ensure_*_available).
  42. */
  43. struct pkginfo;
  44. /**
  45. * Flags to findnamenode().
  46. */
  47. enum fnnflags {
  48. /** Do not need to copy filename. */
  49. fnn_nocopy = DPKG_BIT(0),
  50. /** findnamenode may return NULL. */
  51. fnn_nonew = DPKG_BIT(1),
  52. };
  53. struct filenamenode {
  54. struct filenamenode *next;
  55. const char *name;
  56. struct filepackages *packages;
  57. struct diversion *divert;
  58. /** We allow the administrator to override the owner, group and mode of
  59. * a file. If such an override is present we use that instead of the
  60. * stat information stored in the archive.
  61. *
  62. * This functionality used to be in the suidmanager package. */
  63. struct file_stat *statoverride;
  64. /*
  65. * Fields from here on are used by archives.c &c, and cleared by
  66. * filesdbinit.
  67. */
  68. /** Set to zero when a new node is created. */
  69. enum {
  70. /** In the newconffiles list. */
  71. fnnf_new_conff = DPKG_BIT(0),
  72. /** In the new filesystem archive. */
  73. fnnf_new_inarchive = DPKG_BIT(1),
  74. /** In the old package's conffiles list. */
  75. fnnf_old_conff = DPKG_BIT(2),
  76. /** Obsolete conffile. */
  77. fnnf_obs_conff = DPKG_BIT(3),
  78. /** Must remove from other packages' lists. */
  79. fnnf_elide_other_lists = DPKG_BIT(4),
  80. /** >= 1 instance is a dir, cannot rename over. */
  81. fnnf_no_atomic_overwrite = DPKG_BIT(5),
  82. /** New file has been placed on the disk. */
  83. fnnf_placed_on_disk = DPKG_BIT(6),
  84. fnnf_deferred_fsync = DPKG_BIT(7),
  85. fnnf_deferred_rename = DPKG_BIT(8),
  86. /** Path being filtered. */
  87. fnnf_filtered = DPKG_BIT(9),
  88. } flags;
  89. /** Valid iff this namenode is in the newconffiles list. */
  90. const char *oldhash;
  91. /** Valid iff the file was unpacked and hashed on this run. */
  92. const char *newhash;
  93. struct stat *filestat;
  94. struct trigfileint *trig_interested;
  95. };
  96. struct fileinlist {
  97. struct fileinlist *next;
  98. struct filenamenode *namenode;
  99. };
  100. /**
  101. * When we deal with an ‘overridden’ file, every package except the
  102. * overriding one is considered to contain the other file instead. Both
  103. * files have entries in the filesdb database, and they refer to each other
  104. * via these diversion structures.
  105. *
  106. * The contested filename's filenamenode has an diversion entry with
  107. * useinstead set to point to the redirected filename's filenamenode; the
  108. * redirected filenamenode has camefrom set to the contested filenamenode.
  109. * Both sides' diversion entries will have pkg set to the package (if any)
  110. * which is allowed to use the contended filename.
  111. *
  112. * Packages that contain either version of the file will all refer to the
  113. * contested filenamenode in their per-file package lists (both in core and
  114. * on disk). References are redirected to the other filenamenode's filename
  115. * where appropriate.
  116. */
  117. struct diversion {
  118. struct filenamenode *useinstead;
  119. struct filenamenode *camefrom;
  120. struct pkgset *pkgset;
  121. /** The ‘contested’ halves are in this list for easy cleanup. */
  122. struct diversion *next;
  123. };
  124. struct filepackages_iterator;
  125. struct filepackages_iterator *filepackages_iter_new(struct filenamenode *fnn);
  126. struct pkginfo *filepackages_iter_next(struct filepackages_iterator *iter);
  127. void filepackages_iter_free(struct filepackages_iterator *iter);
  128. void filesdbinit(void);
  129. struct fileiterator;
  130. struct fileiterator *files_db_iter_new(void);
  131. struct filenamenode *files_db_iter_next(struct fileiterator *iter);
  132. void files_db_iter_free(struct fileiterator *iter);
  133. void ensure_package_clientdata(struct pkginfo *pkg);
  134. void ensure_diversions(void);
  135. uid_t statdb_parse_uid(const char *str);
  136. gid_t statdb_parse_gid(const char *str);
  137. mode_t statdb_parse_mode(const char *str);
  138. void ensure_statoverrides(void);
  139. #define LISTFILE "list"
  140. #define HASHFILE "md5sums"
  141. void ensure_packagefiles_available(struct pkginfo *pkg);
  142. void ensure_allinstfiles_available(void);
  143. void ensure_allinstfiles_available_quiet(void);
  144. void note_must_reread_files_inpackage(struct pkginfo *pkg);
  145. struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
  146. void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  147. struct fileinlist *list, enum fnnflags mask);
  148. void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  149. struct fileinlist *list, enum fnnflags mask);
  150. struct reversefilelistiter { struct fileinlist *todo; };
  151. void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
  152. struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
  153. void reversefilelist_abort(struct reversefilelistiter *iterptr);
  154. #endif /* FILESDB_H */