Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/write-or-die.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / write-or-die.h` 81 lines ยท 2592 bytes Raw Blame History 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 void writev_or_die(int fd, struct iovec *iov, int iovlen); 11 12 /* 13 * These values are used to help identify parts of a repository to fsync. 14 * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the 15 * repository and so shouldn't be fsynced. 16 */ 17 enum fsync_component { 18 FSYNC_COMPONENT_NONE, 19 FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0, 20 FSYNC_COMPONENT_PACK = 1 << 1, 21 FSYNC_COMPONENT_PACK_METADATA = 1 << 2, 22 FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3, 23 FSYNC_COMPONENT_INDEX = 1 << 4, 24 FSYNC_COMPONENT_REFERENCE = 1 << 5, 25 FSYNC_COMPONENT_OBJECT_MAP = 1 << 6, 26 }; 27 28 #define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \ 29 FSYNC_COMPONENT_PACK) 30 31 #define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \ 32 FSYNC_COMPONENT_COMMIT_GRAPH) 33 34 #define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \ 35 FSYNC_COMPONENTS_DERIVED_METADATA) & \ 36 ~FSYNC_COMPONENT_LOOSE_OBJECT) 37 38 #define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \ 39 FSYNC_COMPONENT_REFERENCE) 40 41 #define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \ 42 FSYNC_COMPONENT_INDEX) 43 44 #define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \ 45 FSYNC_COMPONENT_PACK | \ 46 FSYNC_COMPONENT_PACK_METADATA | \ 47 FSYNC_COMPONENT_COMMIT_GRAPH | \ 48 FSYNC_COMPONENT_INDEX | \ 49 FSYNC_COMPONENT_REFERENCE | \ 50 FSYNC_COMPONENT_OBJECT_MAP) 51 52 #ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT 53 #define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT 54 #endif 55 56 /* IO helper functions */ 57 void fsync_or_die(int fd, const char *); 58 int fsync_component(enum fsync_component component, int fd); 59 void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); 60 61 /* 62 * A bitmask indicating which components of the repo should be fsynced. 63 */ 64 extern enum fsync_component fsync_components; 65 extern int fsync_object_files; 66 extern int use_fsync; 67 68 enum fsync_method { 69 FSYNC_METHOD_FSYNC, 70 FSYNC_METHOD_WRITEOUT_ONLY, 71 FSYNC_METHOD_BATCH, 72 }; 73 74 extern enum fsync_method fsync_method; 75 76 static inline int batch_fsync_enabled(enum fsync_component component) 77 { 78 return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); 79 } 80 81 #endif /* WRITE_OR_DIE_H */