blob: bf673df16db3292a3c0540e8d3c212342a312c47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/* fsync.c - Synchronize a file's in-core state with storage device.
*
* Copyright 2015 Ranjan Kumar <ranjankumar.bth@gmail.comi>
*
* No Standard.
USE_FSYNC(NEWTOY(fsync, "<1d", TOYFLAG_BIN))
config FSYNC
bool "fsync"
default n
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);
}
|