Fix UB: Make read_int() follow SEI CERT INT13-C and INT34-C.
[metastore.git] / src / metaentry.h
blobd5f209d2ad1fa987eed072003e32aa27abf7d470
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Various functions to work with meta entries.
5 * Copyright (C) 2007-2008 David Härdeman <david@hardeman.nu>
6 * Copyright (C) 2012-2016 Przemyslaw Pawelczyk <przemoc@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; only version 2 of the License is applicable.
12 * This program 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.
15 * See the GNU General Public License for more details.
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/>.
21 #ifndef METAENTRY_H
22 #define METAENTRY_H
24 #include <stdbool.h>
26 #include "settings.h"
28 /* Data structure to hold all metadata for a file/dir */
29 struct metaentry {
30 struct metaentry *next; /* For the metahash chains */
31 struct metaentry *list; /* For creating additional lists of entries */
33 char *path;
34 unsigned pathlen;
36 char *owner;
37 char *group;
38 mode_t mode;
39 time_t mtime;
40 long mtimensec;
42 unsigned xattrs;
43 char **xattr_names;
44 ssize_t *xattr_lvalues;
45 char **xattr_values;
48 #define HASH_INDEXES 1024
50 /* Data structure to hold a number of metadata entries */
51 struct metahash {
52 struct metaentry *bucket[HASH_INDEXES];
53 unsigned count;
56 /* Create a metaentry for the file/dir/etc at path */
57 struct metaentry *mentry_create(const char *path);
59 /* Recurses opath and adds metadata entries to the metaentry list */
60 void mentries_recurse_path(const char *opath, struct metahash **mhash,
61 msettings *st);
63 /* Stores a metaentry list to a file */
64 void mentries_tofile(const struct metahash *mhash, const char *path);
66 /* Creates a metaentry list from a file */
67 void mentries_fromfile(struct metahash **mhash, const char *path);
69 /* Searches haystack for an xattr matching xattr number n in needle */
70 int mentry_find_xattr(struct metaentry *haystack,
71 struct metaentry *needle,
72 unsigned n);
74 #define DIFF_NONE 0x00
75 #define DIFF_OWNER 0x01
76 #define DIFF_GROUP 0x02
77 #define DIFF_MODE 0x04
78 #define DIFF_TYPE 0x08
79 #define DIFF_MTIME 0x10
80 #define DIFF_XATTR 0x20
81 #define DIFF_ADDED 0x40
82 #define DIFF_DELE 0x80
84 /* Compares two metaentries and returns an int with a bitmask of differences */
85 int mentry_compare(struct metaentry *left,
86 struct metaentry *right,
87 msettings *st);
89 /* Compares lists of real and stored metadata and calls pfunc for each */
90 void mentries_compare(struct metahash *mhashreal,
91 struct metahash *mhashstored,
92 void (*pfunc)(struct metaentry *real,
93 struct metaentry *stored,
94 int cmp),
95 msettings *st);
97 void mentries_dump(struct metahash *mhash);
99 #endif /* METAENTRY_H */