10f66f451Sopenharmony_ci/* fsync.c - Synchronize a file's in-core state with storage device.
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2015 Ranjan Kumar <ranjankumar.bth@gmail.comi>
40f66f451Sopenharmony_ci *
50f66f451Sopenharmony_ci * No Standard.
60f66f451Sopenharmony_ci
70f66f451Sopenharmony_ciUSE_FSYNC(NEWTOY(fsync, "<1d", TOYFLAG_BIN))
80f66f451Sopenharmony_ci
90f66f451Sopenharmony_ciconfig FSYNC
100f66f451Sopenharmony_ci  bool "fsync"
110f66f451Sopenharmony_ci  default y
120f66f451Sopenharmony_ci  help
130f66f451Sopenharmony_ci    usage: fsync [-d] [FILE...]
140f66f451Sopenharmony_ci
150f66f451Sopenharmony_ci    Synchronize a file's in-core state with storage device.
160f66f451Sopenharmony_ci
170f66f451Sopenharmony_ci    -d	Avoid syncing metadata
180f66f451Sopenharmony_ci*/
190f66f451Sopenharmony_ci
200f66f451Sopenharmony_ci#define FOR_fsync
210f66f451Sopenharmony_ci#include "toys.h"
220f66f451Sopenharmony_ci
230f66f451Sopenharmony_cistatic void do_fsync(int fd, char *name)
240f66f451Sopenharmony_ci{
250f66f451Sopenharmony_ci  if (((toys.optflags & FLAG_d) ? fdatasync(fd) : fsync(fd)))
260f66f451Sopenharmony_ci    perror_msg("can't sync '%s'", name);
270f66f451Sopenharmony_ci}
280f66f451Sopenharmony_ci
290f66f451Sopenharmony_civoid fsync_main(void)
300f66f451Sopenharmony_ci{
310f66f451Sopenharmony_ci  loopfiles_rw(toys.optargs, O_RDONLY|O_NOATIME|O_NOCTTY|O_CLOEXEC|WARN_ONLY,
320f66f451Sopenharmony_ci      0, do_fsync);
330f66f451Sopenharmony_ci}
34