"Fossies" - the Fresh Open Source Software Archive

Member "dpkg-1.19.7/lib/dpkg/fsys.h" (19 Apr 2019, 6215 Bytes) of package /linux/misc/dpkg_1.19.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fsys.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.19.4_vs_1.19.5.

    1 /*
    2  * libdpkg - Debian packaging suite library routines
    3  * fsys.h - filesystem nodes hash table
    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 
   22 #ifndef LIBDPKG_FSYS_H
   23 #define LIBDPKG_FSYS_H
   24 
   25 #include <stdio.h>
   26 
   27 #include <dpkg/file.h>
   28 
   29 /*
   30  * Data structure here is as follows:
   31  *
   32  * For each package we have a ‘struct fsys_namenode_list *’, the head of a list of
   33  * files in that package. They are in ‘forwards’ order. Each entry has a
   34  * pointer to the ‘struct fsys_namenode’.
   35  *
   36  * The struct fsys_namenodes are in a hash table, indexed by name.
   37  * (This hash table is not visible to callers.)
   38  *
   39  * Each fsys_namenode has a (possibly empty) list of ‘struct filepackage’,
   40  * giving a list of the packages listing that filename.
   41  *
   42  * When we read files contained info about a particular package we set the
   43  * ‘files’ member of the clientdata struct to the appropriate thing. When
   44  * not yet set the files pointer is made to point to ‘fileslist_uninited’
   45  * (this is available only internally, within filesdb.c - the published
   46  * interface is ensure_*_available).
   47  */
   48 
   49 struct pkginfo;
   50 
   51 /**
   52  * Flags to fsys_hash_find_node().
   53  */
   54 enum fsys_hash_find_flags {
   55     /** Do not need to copy filename. */
   56     FHFF_NOCOPY         = DPKG_BIT(0),
   57     /** The find function might return NULL. */
   58     FHFF_NONE           = DPKG_BIT(1),
   59 };
   60 
   61 enum fsys_namenode_flags {
   62     /** In the newconffiles list. */
   63     FNNF_NEW_CONFF          = DPKG_BIT(0),
   64     /** In the new filesystem archive. */
   65     FNNF_NEW_INARCHIVE      = DPKG_BIT(1),
   66     /** In the old package's conffiles list. */
   67     FNNF_OLD_CONFF          = DPKG_BIT(2),
   68     /** Obsolete conffile. */
   69     FNNF_OBS_CONFF          = DPKG_BIT(3),
   70     /** Must remove from other packages' lists. */
   71     FNNF_ELIDE_OTHER_LISTS      = DPKG_BIT(4),
   72     /** >= 1 instance is a dir, cannot rename over. */
   73     FNNF_NO_ATOMIC_OVERWRITE    = DPKG_BIT(5),
   74     /** New file has been placed on the disk. */
   75     FNNF_PLACED_ON_DISK     = DPKG_BIT(6),
   76     FNNF_DEFERRED_FSYNC     = DPKG_BIT(7),
   77     FNNF_DEFERRED_RENAME        = DPKG_BIT(8),
   78     /** Path being filtered. */
   79     FNNF_FILTERED           = DPKG_BIT(9),
   80 };
   81 
   82 /**
   83  * Stores information to uniquely identify an on-disk file.
   84  */
   85 struct file_ondisk_id {
   86     dev_t id_dev;
   87     ino_t id_ino;
   88 };
   89 
   90 struct fsys_namenode {
   91     struct fsys_namenode *next;
   92     const char *name;
   93     struct pkg_list *packages;
   94     struct fsys_diversion *divert;
   95 
   96     /** We allow the administrator to override the owner, group and mode
   97      * of a file. If such an override is present we use that instead of
   98      * the stat information stored in the archive.
   99      *
  100      * This functionality used to be in the suidmanager package. */
  101     struct file_stat *statoverride;
  102 
  103     struct trigfileint *trig_interested;
  104 
  105     /*
  106      * Fields from here on are used by archives.c &c, and cleared by
  107      * fsys_hash_init().
  108      */
  109 
  110     /** Set to zero when a new node is created. */
  111     enum fsys_namenode_flags flags;
  112 
  113     /** Valid iff this namenode is in the newconffiles list. */
  114     const char *oldhash;
  115 
  116     /** Valid iff the file was unpacked and hashed on this run. */
  117     const char *newhash;
  118 
  119     struct file_ondisk_id *file_ondisk_id;
  120 };
  121 
  122 struct fsys_namenode_list {
  123     struct fsys_namenode_list *next;
  124     struct fsys_namenode *namenode;
  125 };
  126 
  127 /**
  128  * Queue of fsys_namenode entries.
  129  */
  130 struct fsys_namenode_queue {
  131     struct fsys_namenode_list *head, **tail;
  132 };
  133 
  134 /**
  135  * When we deal with an ‘overridden’ file, every package except the
  136  * overriding one is considered to contain the other file instead. Both
  137  * files have entries in the filesdb database, and they refer to each other
  138  * via these diversion structures.
  139  *
  140  * The contested filename's fsys_namenode has an diversion entry with
  141  * useinstead set to point to the redirected filename's fsys_namenode; the
  142  * redirected fsys_namenode has camefrom set to the contested fsys_namenode.
  143  * Both sides' diversion entries will have pkg set to the package (if any)
  144  * which is allowed to use the contended filename.
  145  *
  146  * Packages that contain either version of the file will all refer to the
  147  * contested fsys_namenode in their per-file package lists (both in core and
  148  * on disk). References are redirected to the other fsys_namenode's filename
  149  * where appropriate.
  150  */
  151 struct fsys_diversion {
  152     struct fsys_namenode *useinstead;
  153     struct fsys_namenode *camefrom;
  154     struct pkgset *pkgset;
  155 
  156     /** The ‘contested’ halves are in this list for easy cleanup. */
  157     struct fsys_diversion *next;
  158 };
  159 
  160 struct fsys_node_pkgs_iter;
  161 struct fsys_node_pkgs_iter *
  162 fsys_node_pkgs_iter_new(struct fsys_namenode *fnn);
  163 struct pkginfo *
  164 fsys_node_pkgs_iter_next(struct fsys_node_pkgs_iter *iter);
  165 void
  166 fsys_node_pkgs_iter_free(struct fsys_node_pkgs_iter *iter);
  167 
  168 void
  169 fsys_hash_init(void);
  170 void
  171 fsys_hash_reset(void);
  172 void
  173 fsys_hash_report(FILE *file);
  174 int
  175 fsys_hash_entries(void);
  176 
  177 struct fsys_hash_iter;
  178 struct fsys_hash_iter *
  179 fsys_hash_iter_new(void);
  180 struct fsys_namenode *
  181 fsys_hash_iter_next(struct fsys_hash_iter *iter);
  182 void
  183 fsys_hash_iter_free(struct fsys_hash_iter *iter);
  184 
  185 struct fsys_namenode *
  186 fsys_hash_find_node(const char *filename, enum fsys_hash_find_flags flags);
  187 
  188 struct fsys_hash_rev_iter {
  189     struct fsys_namenode_list *todo;
  190 };
  191 
  192 void
  193 fsys_hash_rev_iter_init(struct fsys_hash_rev_iter *iter,
  194                         struct fsys_namenode_list *files);
  195 struct fsys_namenode *
  196 fsys_hash_rev_iter_next(struct fsys_hash_rev_iter *iter);
  197 void
  198 fsys_hash_rev_iter_abort(struct fsys_hash_rev_iter *iter);
  199 
  200 const char *dpkg_fsys_set_dir(const char *dir);
  201 const char *dpkg_fsys_get_dir(void);
  202 char *dpkg_fsys_get_path(const char *pathpart);
  203 
  204 #endif /* LIBDPKG_FSYS_H */