filesdb.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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-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. * When we deal with an ‘overridden’ file, every package except the
  103. * overriding one is considered to contain the other file instead. Both
  104. * files have entries in the filesdb database, and they refer to each other
  105. * via these diversion structures.
  106. *
  107. * The contested filename's filenamenode has an diversion entry with
  108. * useinstead set to point to the redirected filename's filenamenode; the
  109. * redirected filenamenode has camefrom set to the contested filenamenode.
  110. * Both sides' diversion entries will have pkg set to the package (if any)
  111. * which is allowed to use the contended filename.
  112. *
  113. * Packages that contain either version of the file will all refer to the
  114. * contested filenamenode in their per-file package lists (both in core and
  115. * on disk). References are redirected to the other filenamenode's filename
  116. * where appropriate.
  117. */
  118. struct diversion {
  119. struct filenamenode *useinstead;
  120. struct filenamenode *camefrom;
  121. struct pkgset *pkgset;
  122. /** The ‘contested’ halves are in this list for easy cleanup. */
  123. struct diversion *next;
  124. };
  125. struct filepackages_iterator;
  126. struct filepackages_iterator *filepackages_iter_new(struct filenamenode *fnn);
  127. struct pkginfo *filepackages_iter_next(struct filepackages_iterator *iter);
  128. void filepackages_iter_free(struct filepackages_iterator *iter);
  129. void filesdbinit(void);
  130. struct fileiterator;
  131. struct fileiterator *files_db_iter_new(void);
  132. struct filenamenode *files_db_iter_next(struct fileiterator *iter);
  133. void files_db_iter_free(struct fileiterator *iter);
  134. void ensure_package_clientdata(struct pkginfo *pkg);
  135. void ensure_diversions(void);
  136. enum statdb_parse_flags {
  137. STATDB_PARSE_NORMAL = 0,
  138. STATDB_PARSE_LAX = 1,
  139. };
  140. uid_t statdb_parse_uid(const char *str);
  141. gid_t statdb_parse_gid(const char *str);
  142. mode_t statdb_parse_mode(const char *str);
  143. void ensure_statoverrides(enum statdb_parse_flags flags);
  144. #define LISTFILE "list"
  145. #define HASHFILE "md5sums"
  146. void ensure_packagefiles_available(struct pkginfo *pkg);
  147. void ensure_allinstfiles_available(void);
  148. void ensure_allinstfiles_available_quiet(void);
  149. void note_must_reread_files_inpackage(struct pkginfo *pkg);
  150. struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
  151. void parse_filehash(struct pkginfo *pkg, struct pkgbin *pkgbin);
  152. void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  153. struct fileinlist *list, enum filenamenode_flags mask);
  154. void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  155. struct fileinlist *list, enum filenamenode_flags mask);
  156. struct reversefilelistiter { struct fileinlist *todo; };
  157. void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
  158. struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
  159. void reversefilelist_abort(struct reversefilelistiter *iterptr);
  160. #endif /* FILESDB_H */