2000-03-04 22:23:27 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2006-03-14 02:40:51 +00:00
|
|
|
* freeramdisk and fdflush implementations for busybox
|
2000-03-04 22:23:27 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
|
2003-07-14 21:21:08 +00:00
|
|
|
* Adjusted a bit by Erik Andersen <andersen@codepoet.org>
|
2006-03-14 02:40:51 +00:00
|
|
|
* Unified with fdflush by Tito Ragusa <farmatito@tiscali.it>
|
2000-03-04 22:23:27 +00:00
|
|
|
*
|
2006-09-22 02:52:41 +00:00
|
|
|
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
2000-03-04 22:23:27 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2000-03-04 22:23:27 +00:00
|
|
|
|
2006-03-18 23:02:45 +00:00
|
|
|
/* From <linux/fd.h> */
|
|
|
|
#define FDFLUSH _IO(2,0x4b)
|
|
|
|
|
2007-02-03 17:28:39 +00:00
|
|
|
int freeramdisk_main(int argc, char **argv);
|
2006-03-14 20:06:44 +00:00
|
|
|
int freeramdisk_main(int argc, char **argv)
|
2000-03-04 22:23:27 +00:00
|
|
|
{
|
2003-05-08 13:09:28 +00:00
|
|
|
int fd;
|
2000-03-04 22:23:27 +00:00
|
|
|
|
2006-03-14 02:40:51 +00:00
|
|
|
if (argc != 2) bb_show_usage();
|
2000-03-04 22:23:27 +00:00
|
|
|
|
2006-08-03 15:41:12 +00:00
|
|
|
fd = xopen(argv[1], O_RDWR);
|
2004-03-15 08:29:22 +00:00
|
|
|
|
2006-03-14 02:40:51 +00:00
|
|
|
// Act like freeramdisk, fdflush, or both depending on configuration.
|
2007-07-14 22:07:14 +00:00
|
|
|
ioctl_or_perror_and_die(fd, (ENABLE_FREERAMDISK && applet_name[1]=='r')
|
|
|
|
|| !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH, NULL, "%s", argv[1]);
|
2005-09-08 03:11:58 +00:00
|
|
|
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) close(fd);
|
|
|
|
|
2000-12-01 02:55:13 +00:00
|
|
|
return EXIT_SUCCESS;
|
2000-03-04 22:23:27 +00:00
|
|
|
}
|