filesdb.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #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. enum filenamenode_flags {
  54. /** In the newconffiles list. */
  55. fnnf_new_conff = DPKG_BIT(0),
  56. /** In the new filesystem archive. */
  57. fnnf_new_inarchive = DPKG_BIT(1),
  58. /** In the old package's conffiles list. */
  59. fnnf_old_conff = DPKG_BIT(2),
  60. /** Obsolete conffile. */
  61. fnnf_obs_conff = DPKG_BIT(3),
  62. /** Must remove from other packages' lists. */
  63. fnnf_elide_other_lists = DPKG_BIT(4),
  64. /** >= 1 instance is a dir, cannot rename over. */
  65. fnnf_no_atomic_overwrite = DPKG_BIT(5),
  66. /** New file has been placed on the disk. */
  67. fnnf_placed_on_disk = DPKG_BIT(6),
  68. fnnf_deferred_fsync = DPKG_BIT(7),
  69. fnnf_deferred_rename = DPKG_BIT(8),
  70. /** Path being filtered. */
  71. fnnf_filtered = DPKG_BIT(9),
  72. };
  73. struct filenamenode {
  74. struct filenamenode *next;
  75. const char *name;
  76. struct pkg_list *packages;
  77. struct diversion *divert;
  78. /** We allow the administrator to override the owner, group and mode of
  79. * a file. If such an override is present we use that instead of the
  80. * stat information stored in the archive.
  81. *
  82. * This functionality used to be in the suidmanager package. */
  83. struct file_stat *statoverride;
  84. /*
  85. * Fields from here on are used by archives.c &c, and cleared by
  86. * filesdbinit.
  87. */
  88. /** Set to zero when a new node is created. */
  89. enum filenamenode_flags flags;
  90. /** Valid iff this namenode is in the newconffiles list. */
  91. const char *oldhash;
  92. /** Valid iff the file was unpacked and hashed on this run. */
  93. const char *newhash;
  94. struct stat *filestat;
  95. struct trigfileint *trig_interested;
  96. };
  97. struct fileinlist {
  98. struct fileinlist *next;
  99. struct filenamenode *namenode;
  100. };
  101. /**
  102. * Queue of filenamenode entries.
  103. */
  104. struct filenamenode_queue {
  105. struct fileinlist *head, **tail;
  106. };
  107. /**
  108. * When we deal with an ‘overridden’ file, every package except the
  109. * overriding one is considered to contain the other file instead. Both
  110. * files have entries in the filesdb database, and they refer to each other
  111. * via these diversion structures.
  112. *
  113. * The contested filename's filenamenode has an diversion entry with
  114. * useinstead set to point to the redirected filename's filenamenode; the
  115. * redirected filenamenode has camefrom set to the contested filenamenode.
  116. * Both sides' diversion entries will have pkg set to the package (if any)
  117. * which is allowed to use the contended filename.
  118. *
  119. * Packages that contain either version of the file will all refer to the
  120. * contested filenamenode in their per-file package lists (both in core and
  121. * on disk). References are redirected to the other filenamenode's filename
  122. * where appropriate.
  123. */
  124. struct diversion {
  125. struct filenamenode *useinstead;
  126. struct filenamenode *camefrom;
  127. struct pkgset *pkgset;
  128. /** The ‘contested’ halves are in this list for easy cleanup. */
  129. struct diversion *next;
  130. };
  131. struct filepackages_iterator;
  132. struct filepackages_iterator *filepackages_iter_new(struct filenamenode *fnn);
  133. struct pkginfo *filepackages_iter_next(struct filepackages_iterator *iter);
  134. void filepackages_iter_free(struct filepackages_iterator *iter);
  135. void filesdbinit(void);
  136. void files_db_reset(void);
  137. struct fileiterator;
  138. struct fileiterator *files_db_iter_new(void);
  139. struct filenamenode *files_db_iter_next(struct fileiterator *iter);
  140. void files_db_iter_free(struct fileiterator *iter);
  141. void ensure_package_clientdata(struct pkginfo *pkg);
  142. void ensure_diversions(void);
  143. enum statdb_parse_flags {
  144. STATDB_PARSE_NORMAL = 0,
  145. STATDB_PARSE_LAX = 1,
  146. };
  147. uid_t statdb_parse_uid(const char *str);
  148. gid_t statdb_parse_gid(const char *str);
  149. mode_t statdb_parse_mode(const char *str);
  150. void ensure_statoverrides(enum statdb_parse_flags flags);
  151. #define LISTFILE "list"
  152. #define HASHFILE "md5sums"
  153. void ensure_packagefiles_available(struct pkginfo *pkg);
  154. void ensure_allinstfiles_available(void);
  155. void ensure_allinstfiles_available_quiet(void);
  156. void note_must_reread_files_inpackage(struct pkginfo *pkg);
  157. struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
  158. void parse_filehash(struct pkginfo *pkg, struct pkgbin *pkgbin);
  159. void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  160. struct fileinlist *list, enum filenamenode_flags mask);
  161. void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  162. struct fileinlist *list, enum filenamenode_flags mask);
  163. struct reversefilelistiter { struct fileinlist *todo; };
  164. void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
  165. struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
  166. void reversefilelist_abort(struct reversefilelistiter *iterptr);
  167. #endif /* FILESDB_H */