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-03-14 02:40:51 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2000-03-04 22:23:27 +00:00
|
|
|
*/
|
|
|
|
|
2000-09-25 21:45:58 +00:00
|
|
|
#include "busybox.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)
|
|
|
|
|
2006-03-14 20:06:44 +00:00
|
|
|
int freeramdisk_main(int argc, char **argv)
|
2000-03-04 22:23:27 +00:00
|
|
|
{
|
2003-03-07 18:09:06 +00:00
|
|
|
int result;
|
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.
|
2006-03-18 15:59:29 +00:00
|
|
|
result = ioctl(fd, (ENABLE_FREERAMDISK && bb_applet_name[1]=='r')
|
2006-03-18 23:02:45 +00:00
|
|
|
|| !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH);
|
2005-09-08 03:11:58 +00:00
|
|
|
|
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) close(fd);
|
|
|
|
|
2006-03-14 02:40:51 +00:00
|
|
|
if (result) bb_perror_msg_and_die("%s", argv[1]);
|
2000-12-01 02:55:13 +00:00
|
|
|
return EXIT_SUCCESS;
|
2000-03-04 22:23:27 +00:00
|
|
|
}
|