diff options
author | Rob Landley <rob@landley.net> | 2006-03-14 02:40:51 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-03-14 02:40:51 +0000 |
commit | 0b22c1c962ff57e68035413d7790dd2b137a2aeb (patch) | |
tree | 19fea5141691cfadfdb2394d6d4c948609153488 /util-linux/freeramdisk.c | |
parent | 2f135fc6bf5184bf782ec6cdd39c49a708670163 (diff) | |
download | busybox-w32-0b22c1c962ff57e68035413d7790dd2b137a2aeb.tar.gz busybox-w32-0b22c1c962ff57e68035413d7790dd2b137a2aeb.tar.bz2 busybox-w32-0b22c1c962ff57e68035413d7790dd2b137a2aeb.zip |
Tito unified fdflush and freeramdisk. I tweaked the result a bit.
Diffstat (limited to 'util-linux/freeramdisk.c')
-rw-r--r-- | util-linux/freeramdisk.c | 49 |
1 files changed, 9 insertions, 40 deletions
diff --git a/util-linux/freeramdisk.c b/util-linux/freeramdisk.c index cfea35bea..b5449750a 100644 --- a/util-linux/freeramdisk.c +++ b/util-linux/freeramdisk.c | |||
@@ -1,24 +1,12 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * freeramdisk implementation for busybox | 3 | * freeramdisk and fdflush implementations for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it> | 5 | * Copyright (C) 2000 and written by Emanuele Caratti <wiz@iol.it> |
6 | * Adjusted a bit by Erik Andersen <andersen@codepoet.org> | 6 | * Adjusted a bit by Erik Andersen <andersen@codepoet.org> |
7 | * Unified with fdflush by Tito Ragusa <farmatito@tiscali.it> | ||
7 | * | 8 | * |
8 | * This program is free software; you can redistribute it and/or modify | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | 10 | */ |
23 | 11 | ||
24 | #include <stdio.h> | 12 | #include <stdio.h> |
@@ -30,40 +18,21 @@ | |||
30 | #include <unistd.h> | 18 | #include <unistd.h> |
31 | #include "busybox.h" | 19 | #include "busybox.h" |
32 | 20 | ||
33 | 21 | extern int freeramdisk_main(int argc, char **argv) | |
34 | /* From linux/fs.h */ | ||
35 | #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ | ||
36 | |||
37 | extern int | ||
38 | freeramdisk_main(int argc, char **argv) | ||
39 | { | 22 | { |
40 | int result; | 23 | int result; |
41 | int fd; | 24 | int fd; |
42 | 25 | ||
43 | if (argc != 2) { | 26 | if (argc != 2) bb_show_usage(); |
44 | bb_show_usage(); | ||
45 | } | ||
46 | 27 | ||
47 | fd = bb_xopen(argv[1], O_RDWR); | 28 | fd = bb_xopen(argv[1], O_RDWR); |
48 | 29 | ||
49 | result = ioctl(fd, BLKFLSBUF); | 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)); | ||
50 | 33 | ||
51 | if (ENABLE_FEATURE_CLEAN_UP) close(fd); | 34 | if (ENABLE_FEATURE_CLEAN_UP) close(fd); |
52 | 35 | ||
53 | if (result < 0) { | 36 | if (result) bb_perror_msg_and_die("%s", argv[1]); |
54 | bb_perror_msg_and_die("failed ioctl on %s", argv[1]); | ||
55 | } | ||
56 | |||
57 | /* Don't bother closing. Exit does | ||
58 | * that, so we can save a few bytes */ | ||
59 | return EXIT_SUCCESS; | 37 | return EXIT_SUCCESS; |
60 | } | 38 | } |
61 | |||
62 | /* | ||
63 | Local Variables: | ||
64 | c-file-style: "linux" | ||
65 | c-basic-offset: 4 | ||
66 | tab-width: 4 | ||
67 | End: | ||
68 | */ | ||
69 | |||