1 /* fsync.c - Synchronize a file's in-core state with storage device. 2 * 3 * Copyright 2015 Ranjan Kumar <[email protected]> 4 * 5 * No Standard. 6 7 USE_FSYNC(NEWTOY(fsync, "<1d", TOYFLAG_BIN)) 8 9 config FSYNC 10 bool "fsync" 11 default y 12 help 13 usage: fsync [-d] [FILE...] 14 15 Flush disk cache for FILE(s), writing cached data to storage device. 16 17 -d Skip directory info (sync file contents only). 18 */ 19 20 #define FOR_fsync 21 #include "toys.h" 22 do_fsync(int fd,char * name)23static void do_fsync(int fd, char *name) 24 { 25 if (FLAG(d) ? fdatasync(fd) : fsync(fd)) perror_msg("can't sync '%s'", name); 26 } 27 fsync_main(void)28void fsync_main(void) 29 { 30 loopfiles_rw(toys.optargs, O_RDONLY|O_NOATIME|O_NOCTTY|O_CLOEXEC|WARN_ONLY, 31 0, do_fsync); 32 } 33