freeramdisk.c 908 B

12345678910111213141516171819202122232425262728293031
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * freeramdisk and fdflush implementations for busybox
  4. *
  5. * Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
  6. * Adjusted a bit by Erik Andersen <andersen@codepoet.org>
  7. * Unified with fdflush by Tito Ragusa <farmatito@tiscali.it>
  8. *
  9. * Licensed under GPLv2, see file LICENSE in this tarball for details.
  10. */
  11. #include <sys/mount.h>
  12. #include "libbb.h"
  13. /* From <linux/fd.h> */
  14. #define FDFLUSH _IO(2,0x4b)
  15. int freeramdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  16. int freeramdisk_main(int argc UNUSED_PARAM, char **argv)
  17. {
  18. int fd;
  19. fd = xopen(single_argv(argv), O_RDWR);
  20. // Act like freeramdisk, fdflush, or both depending on configuration.
  21. ioctl_or_perror_and_die(fd, (ENABLE_FREERAMDISK && applet_name[1] == 'r')
  22. || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH, NULL, "%s", argv[1]);
  23. if (ENABLE_FEATURE_CLEAN_UP) close(fd);
  24. return EXIT_SUCCESS;
  25. }