blob: 7ad443086771e38400bdf7ab5fe8f3644d95b293 [file] [log] [blame]
Erik Andersen64371702000-03-04 22:23:27 +00001/* vi: set sw=4 ts=4: */
2/*
Rob Landley0b22c1c2006-03-14 02:40:51 +00003 * freeramdisk and fdflush implementations for busybox
Erik Andersen64371702000-03-04 22:23:27 +00004 *
5 * Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it>
Eric Andersencb81e642003-07-14 21:21:08 +00006 * Adjusted a bit by Erik Andersen <andersen@codepoet.org>
Rob Landley0b22c1c2006-03-14 02:40:51 +00007 * Unified with fdflush by Tito Ragusa <farmatito@tiscali.it>
Erik Andersen64371702000-03-04 22:23:27 +00008 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02009 * Licensed under GPLv2, see file LICENSE in this source tree.
Erik Andersen64371702000-03-04 22:23:27 +000010 */
Denys Vlasenkoda49f582009-07-08 02:58:38 +020011#include <sys/mount.h>
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000012#include "libbb.h"
Erik Andersen64371702000-03-04 22:23:27 +000013
Bernhard Reutner-Fischer2523da22006-03-18 23:02:45 +000014/* From <linux/fd.h> */
15#define FDFLUSH _IO(2,0x4b)
16
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000017int freeramdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010018int freeramdisk_main(int argc UNUSED_PARAM, char **argv)
Erik Andersen64371702000-03-04 22:23:27 +000019{
Glenn L McGrath8c6887c2003-05-08 13:09:28 +000020 int fd;
Erik Andersen64371702000-03-04 22:23:27 +000021
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010022 fd = xopen(single_argv(argv), O_RDWR);
Eric Andersenc7bda1c2004-03-15 08:29:22 +000023
Rob Landley0b22c1c2006-03-14 02:40:51 +000024 // Act like freeramdisk, fdflush, or both depending on configuration.
Denys Vlasenkoe992bae2009-11-28 15:18:53 +010025 ioctl_or_perror_and_die(fd, (ENABLE_FREERAMDISK && applet_name[1] == 'r')
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000026 || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH, NULL, "%s", argv[1]);
Rob Landley658d2cf2005-09-08 03:11:58 +000027
28 if (ENABLE_FEATURE_CLEAN_UP) close(fd);
29
Matt Kraai3e856ce2000-12-01 02:55:13 +000030 return EXIT_SUCCESS;
Erik Andersen64371702000-03-04 22:23:27 +000031}