aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2010-11-01 00:43:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-11-01 00:43:34 +0100
commit2658888c78b572f349f326dce499930fa4418b4e (patch)
treef7a8733c225fb0eb1f2c8b6e2b274b8c1c80f541
parent66be9197a5111d0293732f4823d1711ccab51675 (diff)
downloadbusybox-w32-2658888c78b572f349f326dce499930fa4418b4e.tar.gz
busybox-w32-2658888c78b572f349f326dce499930fa4418b4e.tar.bz2
busybox-w32-2658888c78b572f349f326dce499930fa4418b4e.zip
umount: cleanup and code shrink
Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/umount.c47
1 files changed, 7 insertions, 40 deletions
diff --git a/util-linux/umount.c b/util-linux/umount.c
index 78c603856..5597d9eba 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -9,39 +9,10 @@
9 */ 9 */
10#include <mntent.h> 10#include <mntent.h>
11#include <sys/mount.h> 11#include <sys/mount.h>
12/* Make sure we have all the new mount flags we actually try to use. */
13#ifndef MS_BIND
14# define MS_BIND (1 << 12)
15#endif
16#ifndef MS_MOVE
17# define MS_MOVE (1 << 13)
18#endif
19#ifndef MS_RECURSIVE
20# define MS_RECURSIVE (1 << 14)
21#endif
22#ifndef MS_SILENT
23# define MS_SILENT (1 << 15)
24#endif
25/* The shared subtree stuff, which went in around 2.6.15. */
26#ifndef MS_UNBINDABLE
27# define MS_UNBINDABLE (1 << 17)
28#endif
29#ifndef MS_PRIVATE
30# define MS_PRIVATE (1 << 18)
31#endif
32#ifndef MS_SLAVE
33# define MS_SLAVE (1 << 19)
34#endif
35#ifndef MS_SHARED
36# define MS_SHARED (1 << 20)
37#endif
38#ifndef MS_RELATIME
39# define MS_RELATIME (1 << 21)
40#endif
41#include "libbb.h" 12#include "libbb.h"
42 13
43
44#if defined(__dietlibc__) 14#if defined(__dietlibc__)
15// TODO: This does not belong here.
45/* 16.12.2006, Sampo Kellomaki (sampo@iki.fi) 16/* 16.12.2006, Sampo Kellomaki (sampo@iki.fi)
46 * dietlibc-0.30 does not have implementation of getmntent_r() */ 17 * dietlibc-0.30 does not have implementation of getmntent_r() */
47static struct mntent *getmntent_r(FILE* stream, struct mntent* result, 18static struct mntent *getmntent_r(FILE* stream, struct mntent* result,
@@ -54,23 +25,17 @@ static struct mntent *getmntent_r(FILE* stream, struct mntent* result,
54 25
55/* ignored: -v -d -t -i */ 26/* ignored: -v -d -t -i */
56#define OPTION_STRING "fldnra" "vdt:i" 27#define OPTION_STRING "fldnra" "vdt:i"
57#define OPT_FORCE (1 << 0) 28#define OPT_FORCE (1 << 0) // Same as MNT_FORCE
58#define OPT_LAZY (1 << 1) 29#define OPT_LAZY (1 << 1) // Same as MNT_DETACH
59#define OPT_FREELOOP (1 << 2) 30#define OPT_FREELOOP (1 << 2)
60#define OPT_NO_MTAB (1 << 3) 31#define OPT_NO_MTAB (1 << 3)
61#define OPT_REMOUNT (1 << 4) 32#define OPT_REMOUNT (1 << 4)
62#define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 5) : 0) 33#define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 5) : 0)
63 34
64// These constants from linux/fs.h must match OPT_FORCE and OPT_LAZY,
65// otherwise "doForce" trick below won't work!
66//#define MNT_FORCE 0x00000001 /* Attempt to forcibly umount */
67//#define MNT_DETACH 0x00000002 /* Just detach from the tree */
68
69int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 35int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
70int umount_main(int argc UNUSED_PARAM, char **argv) 36int umount_main(int argc UNUSED_PARAM, char **argv)
71{ 37{
72 int doForce; 38 int doForce;
73 char *const buf = xmalloc(4096); /* reducing stack usage */
74 struct mntent me; 39 struct mntent me;
75 FILE *fp; 40 FILE *fp;
76 char *fstype = NULL; 41 char *fstype = NULL;
@@ -85,6 +50,9 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
85 opt = getopt32(argv, OPTION_STRING, &fstype); 50 opt = getopt32(argv, OPTION_STRING, &fstype);
86 //argc -= optind; 51 //argc -= optind;
87 argv += optind; 52 argv += optind;
53
54 // MNT_FORCE and MNT_DETACH (from linux/fs.h) must match
55 // OPT_FORCE and OPT_LAZY, otherwise this trick won't work:
88 doForce = MAX((opt & OPT_FORCE), (opt & OPT_LAZY)); 56 doForce = MAX((opt & OPT_FORCE), (opt & OPT_LAZY));
89 57
90 /* Get a list of mount points from mtab. We read them all in now mostly 58 /* Get a list of mount points from mtab. We read them all in now mostly
@@ -101,7 +69,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
101 if (opt & OPT_ALL) 69 if (opt & OPT_ALL)
102 bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); 70 bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file);
103 } else { 71 } else {
104 while (getmntent_r(fp, &me, buf, 4096)) { 72 while (getmntent_r(fp, &me, bb_common_bufsiz1, sizeof(bb_common_bufsiz1))) {
105 /* Match fstype if passed */ 73 /* Match fstype if passed */
106 if (!match_fstype(&me, fstype)) 74 if (!match_fstype(&me, fstype))
107 continue; 75 continue;
@@ -203,7 +171,6 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
203 free(mtl); 171 free(mtl);
204 mtl = m; 172 mtl = m;
205 } 173 }
206 free(buf);
207 } 174 }
208 175
209 return status; 176 return status;