1 /* vi: set sw=4 ts=4: */
3 * Mini fsync implementation for busybox
5 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //config: bool "fsync"
13 //config: fsync is used to flush file-related cached blocks to disk.
15 //applet:IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync))
17 //kbuild:lib-$(CONFIG_FSYNC) += fsync.o
19 //usage:#define fsync_trivial_usage
20 //usage: "[-d] FILE..."
21 //usage:#define fsync_full_usage "\n\n"
22 //usage: "Write files' buffered blocks to disk\n"
23 //usage: "\n -d Avoid syncing metadata"
30 /* This is a NOFORK applet. Be very careful! */
32 int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
33 int fsync_main(int argc UNUSED_PARAM, char **argv)
38 opts = getopt32(argv, "d"); /* fdatasync */
44 status = EXIT_SUCCESS;
46 int fd = open_or_warn(*argv, O_NOATIME | O_NOCTTY | O_RDONLY);
49 status = EXIT_FAILURE;
52 if ((opts ? fdatasync(fd) : fsync(fd))) {
53 //status = EXIT_FAILURE; - do we want this?
54 bb_simple_perror_msg(*argv);