filesdb.h 5.5 KB

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