]>
Commit | Line | Data |
---|---|---|
d48be35c EN |
1 | #ifndef WRITE_OR_DIE_H |
2 | #define WRITE_OR_DIE_H | |
3 | ||
4 | void maybe_flush_or_die(FILE *, const char *); | |
5 | __attribute__((format (printf, 2, 3))) | |
6 | void fprintf_or_die(FILE *, const char *fmt, ...); | |
7 | void fwrite_or_die(FILE *f, const void *buf, size_t count); | |
8 | void fflush_or_die(FILE *f); | |
9 | void write_or_die(int fd, const void *buf, size_t count); | |
10 | ||
11 | /* | |
12 | * These values are used to help identify parts of a repository to fsync. | |
13 | * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the | |
14 | * repository and so shouldn't be fsynced. | |
15 | */ | |
16 | enum fsync_component { | |
17 | FSYNC_COMPONENT_NONE, | |
18 | FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0, | |
19 | FSYNC_COMPONENT_PACK = 1 << 1, | |
20 | FSYNC_COMPONENT_PACK_METADATA = 1 << 2, | |
21 | FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3, | |
22 | FSYNC_COMPONENT_INDEX = 1 << 4, | |
23 | FSYNC_COMPONENT_REFERENCE = 1 << 5, | |
24 | }; | |
25 | ||
26 | #define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \ | |
27 | FSYNC_COMPONENT_PACK) | |
28 | ||
29 | #define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \ | |
30 | FSYNC_COMPONENT_COMMIT_GRAPH) | |
31 | ||
32 | #define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \ | |
33 | FSYNC_COMPONENTS_DERIVED_METADATA) & \ | |
34 | ~FSYNC_COMPONENT_LOOSE_OBJECT) | |
35 | ||
36 | #define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \ | |
37 | FSYNC_COMPONENT_REFERENCE) | |
38 | ||
39 | #define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \ | |
40 | FSYNC_COMPONENT_INDEX) | |
41 | ||
42 | #define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \ | |
43 | FSYNC_COMPONENT_PACK | \ | |
44 | FSYNC_COMPONENT_PACK_METADATA | \ | |
45 | FSYNC_COMPONENT_COMMIT_GRAPH | \ | |
46 | FSYNC_COMPONENT_INDEX | \ | |
47 | FSYNC_COMPONENT_REFERENCE) | |
48 | ||
49 | #ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT | |
50 | #define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT | |
51 | #endif | |
52 | ||
53 | /* IO helper functions */ | |
54 | void fsync_or_die(int fd, const char *); | |
55 | int fsync_component(enum fsync_component component, int fd); | |
56 | void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); | |
57 | ||
58 | /* | |
59 | * A bitmask indicating which components of the repo should be fsynced. | |
60 | */ | |
61 | extern enum fsync_component fsync_components; | |
62 | extern int fsync_object_files; | |
63 | extern int use_fsync; | |
64 | ||
65 | enum fsync_method { | |
66 | FSYNC_METHOD_FSYNC, | |
67 | FSYNC_METHOD_WRITEOUT_ONLY, | |
68 | FSYNC_METHOD_BATCH, | |
69 | }; | |
70 | ||
71 | extern enum fsync_method fsync_method; | |
72 | ||
73 | static inline int batch_fsync_enabled(enum fsync_component component) | |
74 | { | |
75 | return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); | |
76 | } | |
77 | ||
78 | #endif /* WRITE_OR_DIE_H */ |