Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame] | 3 | * freeramdisk and fdflush implementations for busybox |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it> |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 6 | * Adjusted a bit by Erik Andersen <andersen@codepoet.org> |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame] | 7 | * Unified with fdflush by Tito Ragusa <farmatito@tiscali.it> |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 8 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 9 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 10 | */ |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 11 | |
| 12 | //usage:#define freeramdisk_trivial_usage |
| 13 | //usage: "DEVICE" |
| 14 | //usage:#define freeramdisk_full_usage "\n\n" |
| 15 | //usage: "Free all memory used by the specified ramdisk" |
| 16 | //usage: |
| 17 | //usage:#define freeramdisk_example_usage |
| 18 | //usage: "$ freeramdisk /dev/ram2\n" |
| 19 | //usage: |
| 20 | //usage:#define fdflush_trivial_usage |
| 21 | //usage: "DEVICE" |
| 22 | //usage:#define fdflush_full_usage "\n\n" |
| 23 | //usage: "Force floppy disk drive to detect disk change" |
| 24 | |
Denys Vlasenko | da49f58 | 2009-07-08 02:58:38 +0200 | [diff] [blame] | 25 | #include <sys/mount.h> |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 26 | #include "libbb.h" |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 27 | |
Bernhard Reutner-Fischer | 2523da2 | 2006-03-18 23:02:45 +0000 | [diff] [blame] | 28 | /* From <linux/fd.h> */ |
| 29 | #define FDFLUSH _IO(2,0x4b) |
| 30 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 31 | int freeramdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 32 | int freeramdisk_main(int argc UNUSED_PARAM, char **argv) |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 33 | { |
Glenn L McGrath | 8c6887c | 2003-05-08 13:09:28 +0000 | [diff] [blame] | 34 | int fd; |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 35 | |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 36 | fd = xopen(single_argv(argv), O_RDWR); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 37 | |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame] | 38 | // Act like freeramdisk, fdflush, or both depending on configuration. |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 39 | ioctl_or_perror_and_die(fd, (ENABLE_FREERAMDISK && applet_name[1] == 'r') |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 40 | || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH, NULL, "%s", argv[1]); |
Rob Landley | 658d2cf | 2005-09-08 03:11:58 +0000 | [diff] [blame] | 41 | |
| 42 | if (ENABLE_FEATURE_CLEAN_UP) close(fd); |
| 43 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 44 | return EXIT_SUCCESS; |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 45 | } |