filesdb.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <iwj10@cus.cam.ac.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. };
  49. struct filenamenode {
  50. struct filenamenode *next;
  51. char *name;
  52. struct filepackages *packages;
  53. struct diversion *divert;
  54. /* Fields from here on are used by archives.c &c, and cleared by
  55. * filesdbinit.
  56. */
  57. enum {
  58. fnnf_new_conff= 000001, /* in the newconffiles list */
  59. fnnf_new_inarchive= 000002, /* in the new filesystem archive */
  60. fnnf_old_conff= 000004, /* in the old package's conffiles list */
  61. fnnf_elide_other_lists= 000010, /* must remove from other packages' lists */
  62. fnnf_no_atomic_overwrite= 000020, /* >=1 instance is a dir, cannot rename over */
  63. } flags; /* Set to zero when a new node is created. */
  64. const char *oldhash; /* valid iff this namenode is in the newconffiles list */
  65. struct stat *filestat;
  66. };
  67. struct fileinlist {
  68. struct fileinlist *next;
  69. struct filenamenode *namenode;
  70. };
  71. struct diversion {
  72. /* When we deal with an `overridden' file, every package except
  73. * the overriding one is considered to contain the other file
  74. * instead. Both files have entries in the filesdb database, and
  75. * they refer to each other via these diversion structures.
  76. *
  77. * The contested filename's filenamenode has an diversion entry
  78. * with useinstead set to point to the redirected filename's
  79. * filenamenode; the redirected filenamenode has camefrom set to the
  80. * contested filenamenode. Both sides' diversion entries will
  81. * have pkg set to the package (if any) which is allowed to use the
  82. * contended filename.
  83. *
  84. * Packages that contain either version of the file will all
  85. * refer to the contested filenamenode in their per-file package lists
  86. * (both in core and on disk). References are redirected to the other
  87. * filenamenode's filename where appropriate.
  88. */
  89. struct filenamenode *useinstead;
  90. struct filenamenode *camefrom;
  91. struct pkginfo *pkg;
  92. struct diversion *next;
  93. /* The `contested' halves are in this list for easy cleanup. */
  94. };
  95. #define PERFILEPACKAGESLUMP 10
  96. struct filepackages {
  97. struct filepackages *more;
  98. struct pkginfo *pkgs[PERFILEPACKAGESLUMP];
  99. /* pkgs is a null-pointer-terminated list; anything after the first null
  100. * is garbage
  101. */
  102. };
  103. struct fileiterator;
  104. struct fileiterator *iterfilestart(void);
  105. struct filenamenode *iterfilenext(struct fileiterator *i);
  106. void iterfileend(struct fileiterator *i);
  107. void ensure_diversions(void);
  108. void ensure_packagefiles_available(struct pkginfo *pkg);
  109. void ensure_allinstfiles_available(void);
  110. void ensure_allinstfiles_available_quiet(void);
  111. void note_must_reread_files_inpackage(struct pkginfo *pkg);
  112. struct filenamenode *findnamenode(const char *filename, enum fnnflags flags);
  113. void write_filelist_except(struct pkginfo *pkg, struct fileinlist *list, int leaveout);
  114. struct reversefilelistiter { struct fileinlist *todo; };
  115. void reversefilelist_init(struct reversefilelistiter *iterptr, struct fileinlist *files);
  116. struct filenamenode *reversefilelist_next(struct reversefilelistiter *iterptr);
  117. void reversefilelist_abort(struct reversefilelistiter *iterptr);
  118. #endif /* FILESDB_H */