blob: a1f2c56cf382f11e40ac58c2359001d4688fbbcd [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 *
Rob Landleye9a7a622006-09-22 02:52:41 +00009 * Licensed under GPLv2, see file LICENSE in this tarball for details.
Erik Andersen64371702000-03-04 22:23:27 +000010 */
11
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 Vlasenko06af2162007-02-03 17:28:39 +000017int freeramdisk_main(int argc, char **argv);
Rob Landleyd221d212006-03-14 20:06:44 +000018int freeramdisk_main(int argc, char **argv)
Erik Andersen64371702000-03-04 22:23:27 +000019{
Eric Andersen77831c12003-03-07 18:09:06 +000020 int result;
Glenn L McGrath8c6887c2003-05-08 13:09:28 +000021 int fd;
Erik Andersen64371702000-03-04 22:23:27 +000022
Rob Landley0b22c1c2006-03-14 02:40:51 +000023 if (argc != 2) bb_show_usage();
Erik Andersen64371702000-03-04 22:23:27 +000024
Rob Landleyd921b2e2006-08-03 15:41:12 +000025 fd = xopen(argv[1], O_RDWR);
Eric Andersenc7bda1c2004-03-15 08:29:22 +000026
Rob Landley0b22c1c2006-03-14 02:40:51 +000027 // Act like freeramdisk, fdflush, or both depending on configuration.
Denis Vlasenko8f8f2682006-10-03 21:00:43 +000028 result = ioctl(fd, (ENABLE_FREERAMDISK && applet_name[1]=='r')
Bernhard Reutner-Fischer2523da22006-03-18 23:02:45 +000029 || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH);
Rob Landley658d2cf2005-09-08 03:11:58 +000030
31 if (ENABLE_FEATURE_CLEAN_UP) close(fd);
32
Rob Landley0b22c1c2006-03-14 02:40:51 +000033 if (result) bb_perror_msg_and_die("%s", argv[1]);
Matt Kraai3e856ce2000-12-01 02:55:13 +000034 return EXIT_SUCCESS;
Erik Andersen64371702000-03-04 22:23:27 +000035}