freeramdisk.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 source tree.
  10. */
  11. //usage:#define freeramdisk_trivial_usage
  12. //usage: "DEVICE"
  13. //usage:#define freeramdisk_full_usage "\n\n"
  14. //usage: "Free all memory used by the specified ramdisk"
  15. //usage:
  16. //usage:#define freeramdisk_example_usage
  17. //usage: "$ freeramdisk /dev/ram2\n"
  18. //usage:
  19. //usage:#define fdflush_trivial_usage
  20. //usage: "DEVICE"
  21. //usage:#define fdflush_full_usage "\n\n"
  22. //usage: "Force floppy disk drive to detect disk change"
  23. #include <sys/mount.h>
  24. #include "libbb.h"
  25. /* From <linux/fd.h> */
  26. #define FDFLUSH _IO(2,0x4b)
  27. int freeramdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  28. int freeramdisk_main(int argc UNUSED_PARAM, char **argv)
  29. {
  30. int fd;
  31. fd = xopen(single_argv(argv), O_RDWR);
  32. // Act like freeramdisk, fdflush, or both depending on configuration.
  33. ioctl_or_perror_and_die(fd, (ENABLE_FREERAMDISK && applet_name[1] == 'r')
  34. || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH, NULL, "%s", argv[1]);
  35. if (ENABLE_FEATURE_CLEAN_UP) close(fd);
  36. return EXIT_SUCCESS;
  37. }