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 | * |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame^] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 14 | #include <sys/types.h> |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 15 | #include <fcntl.h> |
| 16 | #include <sys/ioctl.h> |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
Eric Andersen | 45638df | 2003-09-15 08:12:53 +0000 | [diff] [blame] | 18 | #include <unistd.h> |
Eric Andersen | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 19 | #include "busybox.h" |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 20 | |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame^] | 21 | extern int freeramdisk_main(int argc, char **argv) |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 22 | { |
Eric Andersen | 77831c1 | 2003-03-07 18:09:06 +0000 | [diff] [blame] | 23 | int result; |
Glenn L McGrath | 8c6887c | 2003-05-08 13:09:28 +0000 | [diff] [blame] | 24 | int fd; |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 25 | |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame^] | 26 | if (argc != 2) bb_show_usage(); |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 27 | |
Glenn L McGrath | 8c6887c | 2003-05-08 13:09:28 +0000 | [diff] [blame] | 28 | fd = bb_xopen(argv[1], O_RDWR); |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 29 | |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame^] | 30 | // Act like freeramdisk, fdflush, or both depending on configuration. |
| 31 | result = ioctl(fd, (bb_applet_name[1]=='r' && ENABLE_FREERAMDISK) |
| 32 | || !ENABLE_FDFLUSH ? _IO(0x12,97) : _IO(2,0x4b)); |
Rob Landley | 658d2cf | 2005-09-08 03:11:58 +0000 | [diff] [blame] | 33 | |
| 34 | if (ENABLE_FEATURE_CLEAN_UP) close(fd); |
| 35 | |
Rob Landley | 0b22c1c | 2006-03-14 02:40:51 +0000 | [diff] [blame^] | 36 | if (result) bb_perror_msg_and_die("%s", argv[1]); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 37 | return EXIT_SUCCESS; |
Erik Andersen | 6437170 | 2000-03-04 22:23:27 +0000 | [diff] [blame] | 38 | } |