1 /* vi: set sw=4 ts=4: */
3 * freeramdisk and fdflush implementations for busybox
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>
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 #include <sys/types.h>
16 #include <sys/ioctl.h>
22 #define BLKFLSBUF _IO(0x12,97)
23 /* From <linux/fd.h> */
24 #define FDFLUSH _IO(2,0x4b)
26 int freeramdisk_main(int argc, char **argv)
31 if (argc != 2) bb_show_usage();
33 fd = bb_xopen(argv[1], O_RDWR);
35 // Act like freeramdisk, fdflush, or both depending on configuration.
36 result = ioctl(fd, (ENABLE_FREERAMDISK && bb_applet_name[1]=='r')
37 || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH);
39 if (ENABLE_FEATURE_CLEAN_UP) close(fd);
41 if (result) bb_perror_msg_and_die("%s", argv[1]);