Improve code formatting and convert `unsigned int` to `unsigned`.
[metastore.git] / src / metaentry.h
blobdedf5d6055391b9ffa189b8491af9a6943c9da3a
1 /*
2 * Various functions to work with meta entries.
4 * Copyright (C) 2007 David Härdeman <david@hardeman.nu>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; only version 2 of the License is applicable.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef METAENTRY_H
21 #define METAENTRY_H
23 #include <stdbool.h>
25 #include "settings.h"
27 /* Data structure to hold all metadata for a file/dir */
28 struct metaentry {
29 struct metaentry *next; /* For the metahash chains */
30 struct metaentry *list; /* For creating additional lists of entries */
32 char *path;
33 unsigned pathlen;
35 char *owner;
36 char *group;
37 mode_t mode;
38 time_t mtime;
39 long mtimensec;
41 unsigned xattrs;
42 char **xattr_names;
43 ssize_t *xattr_lvalues;
44 char **xattr_values;
47 #define HASH_INDEXES 1024
49 /* Data structure to hold a number of metadata entries */
50 struct metahash {
51 struct metaentry *bucket[HASH_INDEXES];
52 unsigned count;
55 /* Create a metaentry for the file/dir/etc at path */
56 struct metaentry *mentry_create(const char *path);
58 /* Recurses opath and adds metadata entries to the metaentry list */
59 void mentries_recurse_path(const char *opath, struct metahash **mhash,
60 msettings *st);
62 /* Stores a metaentry list to a file */
63 void mentries_tofile(const struct metahash *mhash, const char *path);
65 /* Creates a metaentry list from a file */
66 void mentries_fromfile(struct metahash **mhash, const char *path);
68 /* Searches haystack for an xattr matching xattr number n in needle */
69 int mentry_find_xattr(struct metaentry *haystack,
70 struct metaentry *needle,
71 unsigned n);
73 #define DIFF_NONE 0x00
74 #define DIFF_OWNER 0x01
75 #define DIFF_GROUP 0x02
76 #define DIFF_MODE 0x04
77 #define DIFF_TYPE 0x08
78 #define DIFF_MTIME 0x10
79 #define DIFF_XATTR 0x20
80 #define DIFF_ADDED 0x40
81 #define DIFF_DELE 0x80
83 /* Compares two metaentries and returns an int with a bitmask of differences */
84 int mentry_compare(struct metaentry *left,
85 struct metaentry *right,
86 msettings *st);
88 /* Compares lists of real and stored metadata and calls pfunc for each */
89 void mentries_compare(struct metahash *mhashreal,
90 struct metahash *mhashstored,
91 void (*pfunc)(struct metaentry *real,
92 struct metaentry *stored,
93 int cmp),
94 msettings *st);
96 void mentries_dump(struct metahash *mhash);
98 #endif /* METAENTRY_H */