filesdb.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef FILESDB_H
  21. #define FILESDB_H
  22. /*
  23. * Data structure here is as follows:
  24. *
  25. * For each package we have a `struct fileinlist *', the head of
  26. * a list of files in that package. They are in `forwards' order.
  27. * Each entry has a pointer to the `struct filenamenode'.
  28. *
  29. * The struct filenamenodes are in a hash table, indexed by name.
  30. * (This hash table is not visible to callers.)
  31. *
  32. * Each filenamenode has a (possibly empty) list of `struct
  33. * filepackage', giving a list of the packages listing that
  34. * filename.
  35. *
  36. * When we read files contained info about a particular package
  37. * we set the `files' member of the clientdata struct to the
  38. * appropriate thing. When not yet set the files pointer is
  39. * made to point to `fileslist_uninited' (this is available only
  40. * internally, withing filesdb.c - the published interface is
  41. * ensure_*_available).
  42. */
  43. struct pkginfo;
  44. /* flags to findnamenode() */
  45. enum fnnflags {
  46. fnn_nocopy= 000001, /* do not need to copy filename */
  47. fnn_nonew = 000002, /* findnamenode may return NULL */
  48. };
  49. struct filenamenode {
  50. struct filenamenode *next;
  51. const char *name;
  52. struct filepackages *packages;
  53. struct diversion *divert;
  54. struct filestatoverride *statoverride;
  55. /* Fields from here on are used by archives.c &c, and cleared by
  56. * filesdbinit.
  57. */
  58. enum {
  59. fnnf_new_conff= 000001, /* in the newconffiles list */
  60. fnnf_new_inarchive= 000002, /* in the new filesystem archive */
  61. fnnf_old_conff= 000004, /* in the old package's conffiles list */
  62. fnnf_obs_conff= 000100, /* obsolete conffile */
  63. fnnf_elide_other_lists= 000010, /* must remove from other packages' lists */
  64. fnnf_no_atomic_overwrite= 000020, /* >=1 instance is a dir, cannot rename over */
  65. fnnf_placed_on_disk= 000040, /* new file has been placed on the disk */
  66. fnnf_deferred_fsync = 000200,
  67. fnnf_deferred_rename = 000400,
  68. fnnf_filtered = 001000, /* path being filtered */
  69. } flags; /* Set to zero when a new node is created. */
  70. const char *oldhash; /* valid iff this namenode is in the newconffiles list */
  71. struct stat *filestat;
  72. struct trigfileint *trig_interested;
  73. };
  74. struct fileinlist {
  75. struct fileinlist *next;
  76. struct filenamenode *namenode;
  77. };
  78. struct filestatoverride {
  79. /* We allow the administrator to override the owner, group and mode of
  80. * a file. If such an override is present we use that instead of the
  81. * stat information stored in the archive.
  82. *
  83. * This functionality used to be in the suidmanager package.
  84. */
  85. uid_t uid;
  86. gid_t gid;
  87. mode_t mode;
  88. };
  89. struct diversion {
  90. /* When we deal with an `overridden' file, every package except
  91. * the overriding one is considered to contain the other file
  92. * instead. Both files have entries in the filesdb database, and
  93. * they refer to each other via these diversion structures.
  94. *
  95. * The contested filename's filenamenode has an diversion entry
  96. * with useinstead set to point to the redirected filename's
  97. * filenamenode; the redirected filenamenode has camefrom set to the
  98. * contested filenamenode. Both sides' diversion entries will
  99. * have pkg set to the package (if any) which is allowed to use the
  100. * contended filename.
  101. *
  102. * Packages that contain either version of the file will all
  103. * refer to the contested filenamenode in their per-file package lists
  104. * (both in core and on disk). References are redirected to the other
  105. * filenamenode's filename where appropriate.
  106. */
  107. struct filenamenode *useinstead;
  108. struct filenamenode *camefrom;
  109. struct pkginfo *pkg;
  110. struct diversion *next;
  111. /* The `contested' halves are in this list for easy cleanup. */
  112. };
  113. struct filepackages_iterator;
  114. struct filepackages_iterator *filepackages_iter_new(struct filenamenode *fnn);
  115. struct pkginfo *filepackages_iter_next(struct filepackages_iterator *i);
  116. void filepackages_iter_free(struct filepackages_iterator *i);
  117. void filesdbinit(void);
  118. struct fileiterator;
  119. struct fileiterator *iterfilestart(void);
  120. struct filenamenode *iterfilenext(struct fileiterator *i);
  121. void iterfileend(struct fileiterator *i);
  122. void ensure_package_clientdata(struct pkginfo *pkg);
  123. void ensure_diversions(void);
  124. uid_t statdb_parse_uid(const char *str);
  125. gid_t statdb_parse_gid(const char *str);
  126. mode_t statdb_parse_mode(const char *str);
  127. void ensure_statoverrides(void);
  128. #define LISTFILE "list"
  129. void ensure_packagefiles_available(struct pkginfo *pkg);
  130. void ensure_allinstfiles_available(void);
  131. void ensure_allinstfiles_available_quiet(void);
  132. void note_must_reread_files_inpackage(struct pkginfo *pkg);
  133. struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
  134. void write_filelist_except(struct pkginfo *pkg, struct fileinlist *list,
  135. bool leaveout);
  136. struct reversefilelistiter { struct fileinlist *todo; };
  137. void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
  138. struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
  139. void reversefilelist_abort(struct reversefilelistiter *iterptr);
  140. #endif /* FILESDB_H */