blob: 53900f8d26d332507da84463a1422eeb5de2c093 [file] [log] [blame]
Denys Vlasenko14f6f0a2009-06-18 08:20:02 +02001/* vi: set sw=4 ts=4: */
2/*
3 * Mini fsync implementation for busybox
4 *
5 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9#include "libbb.h"
Denys Vlasenko10544a82010-02-09 00:26:10 +010010#ifndef O_NOATIME
11# define O_NOATIME 0
12#endif
Denys Vlasenko14f6f0a2009-06-18 08:20:02 +020013
14/* This is a NOFORK applet. Be very careful! */
15
16int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
17int fsync_main(int argc UNUSED_PARAM, char **argv)
18{
19 int status;
20 int opts;
21
22 opts = getopt32(argv, "d"); /* fdatasync */
23 argv += optind;
24 if (!*argv) {
25 bb_show_usage();
26 }
27
28 status = EXIT_SUCCESS;
29 do {
30 int fd = open3_or_warn(*argv, O_NOATIME | O_NOCTTY | O_RDONLY, 0);
31
32 if (fd == -1) {
33 status = EXIT_FAILURE;
34 continue;
35 }
36 if ((opts ? fdatasync(fd) : fsync(fd))) {
37 //status = EXIT_FAILURE; - do we want this?
38 bb_simple_perror_msg(*argv);
39 }
40 close(fd);
41 } while (*++argv);
42
43 return status;
44}