From d073e1c0aa17f36fe28338a0787e6b07cc463a1d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 24 Jul 2015 19:58:59 -0500 Subject: Promote fsync. --- toys/other/fsync.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 toys/other/fsync.c (limited to 'toys/other') diff --git a/toys/other/fsync.c b/toys/other/fsync.c new file mode 100644 index 00000000..e6f6c8d9 --- /dev/null +++ b/toys/other/fsync.c @@ -0,0 +1,33 @@ +/* fsync.c - Synchronize a file's in-core state with storage device. + * + * Copyright 2015 Ranjan Kumar + * + * No Standard. + +USE_FSYNC(NEWTOY(fsync, "<1d", TOYFLAG_BIN)) + +config FSYNC + bool "fsync" + default y + help + usage: fsync [-d] [FILE...] + + Synchronize a file's in-core state with storage device. + + -d Avoid syncing metadata. +*/ + +#define FOR_fsync +#include "toys.h" + +static void do_fsync(int fd, char *name) +{ + if (((toys.optflags & FLAG_d) ? fdatasync(fd) : fsync(fd))) + perror_msg("can't sync '%s'", name); +} + +void fsync_main(void) +{ + loopfiles_rw(toys.optargs, O_RDONLY|O_NOATIME|O_NOCTTY|O_CLOEXEC, + 0, 0, do_fsync); +} -- cgit v1.2.3