fsync.c 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* 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 source tree.
  8. */
  9. #include "libbb.h"
  10. #ifndef O_NOATIME
  11. # define O_NOATIME 0
  12. #endif
  13. /* This is a NOFORK applet. Be very careful! */
  14. int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  15. int fsync_main(int argc UNUSED_PARAM, char **argv)
  16. {
  17. int status;
  18. int opts;
  19. opts = getopt32(argv, "d"); /* fdatasync */
  20. argv += optind;
  21. if (!*argv) {
  22. bb_show_usage();
  23. }
  24. status = EXIT_SUCCESS;
  25. do {
  26. int fd = open_or_warn(*argv, O_NOATIME | O_NOCTTY | O_RDONLY);
  27. if (fd == -1) {
  28. status = EXIT_FAILURE;
  29. continue;
  30. }
  31. if ((opts ? fdatasync(fd) : fsync(fd))) {
  32. //status = EXIT_FAILURE; - do we want this?
  33. bb_simple_perror_msg(*argv);
  34. }
  35. close(fd);
  36. } while (*++argv);
  37. return status;
  38. }