]>
Commit | Line | Data |
---|---|---|
ac48adf4 EN |
1 | #ifndef STATINFO_H |
2 | #define STATINFO_H | |
3 | ||
90cbae9c EN |
4 | struct index_state; |
5 | ||
ac48adf4 EN |
6 | /* |
7 | * The "cache_time" is just the low 32 bits of the | |
8 | * time. It doesn't matter if it overflows - we only | |
9 | * check it for equality in the 32 bits we save. | |
10 | */ | |
11 | struct cache_time { | |
12 | uint32_t sec; | |
13 | uint32_t nsec; | |
14 | }; | |
15 | ||
16 | struct stat_data { | |
17 | struct cache_time sd_ctime; | |
18 | struct cache_time sd_mtime; | |
19 | unsigned int sd_dev; | |
20 | unsigned int sd_ino; | |
21 | unsigned int sd_uid; | |
22 | unsigned int sd_gid; | |
23 | unsigned int sd_size; | |
24 | }; | |
25 | ||
90cbae9c EN |
26 | /* |
27 | * A struct to encapsulate the concept of whether a file has changed | |
28 | * since we last checked it. This uses criteria similar to those used | |
29 | * for the index. | |
30 | */ | |
31 | struct stat_validity { | |
32 | struct stat_data *sd; | |
33 | }; | |
34 | ||
35 | #define MTIME_CHANGED 0x0001 | |
36 | #define CTIME_CHANGED 0x0002 | |
37 | #define OWNER_CHANGED 0x0004 | |
38 | #define MODE_CHANGED 0x0008 | |
39 | #define INODE_CHANGED 0x0010 | |
40 | #define DATA_CHANGED 0x0020 | |
41 | #define TYPE_CHANGED 0x0040 | |
42 | ||
43 | /* | |
44 | * Record to sd the data from st that we use to check whether a file | |
45 | * might have changed. | |
46 | */ | |
47 | void fill_stat_data(struct stat_data *sd, struct stat *st); | |
48 | ||
49 | /* | |
50 | * Return 0 if st is consistent with a file not having been changed | |
51 | * since sd was filled. If there are differences, return a | |
52 | * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED, | |
53 | * INODE_CHANGED, and DATA_CHANGED. | |
54 | */ | |
55 | int match_stat_data(const struct stat_data *sd, struct stat *st); | |
56 | ||
57 | void stat_validity_clear(struct stat_validity *sv); | |
58 | ||
59 | /* | |
60 | * Returns 1 if the path is a regular file (or a symlink to a regular | |
61 | * file) and matches the saved stat_validity, 0 otherwise. A missing | |
62 | * or inaccessible file is considered a match if the struct was just | |
63 | * initialized, or if the previous update found an inaccessible file. | |
64 | */ | |
65 | int stat_validity_check(struct stat_validity *sv, const char *path); | |
66 | ||
67 | /* | |
68 | * Update the stat_validity from a file opened at descriptor fd. If | |
69 | * the file is missing, inaccessible, or not a regular file, then | |
70 | * future calls to stat_validity_check will match iff one of those | |
71 | * conditions continues to be true. | |
72 | */ | |
73 | void stat_validity_update(struct stat_validity *sv, int fd); | |
74 | ||
03bf92b9 AS |
75 | #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) |
76 | #define DTYPE(de) ((de)->d_type) | |
77 | #else | |
78 | #undef DT_UNKNOWN | |
79 | #undef DT_DIR | |
80 | #undef DT_REG | |
81 | #undef DT_LNK | |
82 | #define DT_UNKNOWN 0 | |
83 | #define DT_DIR 1 | |
84 | #define DT_REG 2 | |
85 | #define DT_LNK 3 | |
86 | #define DTYPE(de) DT_UNKNOWN | |
87 | #endif | |
88 | ||
ac48adf4 | 89 | #endif |