aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-08-08 01:39:49 +0000
committerRob Landley <rob@landley.net>2006-08-08 01:39:49 +0000
commite3781b731215d826585fe37720eebe147705f340 (patch)
treeb146c666feca3c4908bc5bb90842a2c0d707385b
parent47b16a6fe98e1b18f269a2bd34471231553ebb94 (diff)
downloadbusybox-w32-e3781b731215d826585fe37720eebe147705f340.tar.gz
busybox-w32-e3781b731215d826585fe37720eebe147705f340.tar.bz2
busybox-w32-e3781b731215d826585fe37720eebe147705f340.zip
Add shared subtree support, suggested by Vladimir Dronnikov. Also break out a
few new (unfinished) config options, which I intend to make hidden (but enabled) when CONFIG_NITPICK is disabled. Getting the .config infrastructure to do that is non-obvious, it seems...
-rw-r--r--include/libbb.h2
-rw-r--r--include/platform.h29
-rw-r--r--libbb/mtab_file.c7
-rw-r--r--util-linux/Config.in19
-rw-r--r--util-linux/mount.c107
5 files changed, 107 insertions, 57 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 745f8372b..963a0290c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -407,7 +407,7 @@ extern const char * const bb_default_login_shell;
407#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) 407#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
408 408
409 409
410extern const char bb_path_mtab_file[]; 410extern char bb_path_mtab_file[];
411 411
412extern int bb_default_error_retval; 412extern int bb_default_error_retval;
413 413
diff --git a/include/platform.h b/include/platform.h
index 8890d4ffd..ca6f3634f 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -228,6 +228,35 @@ typedef unsigned long long int uintmax_t;
228 228
229#if defined(__linux__) 229#if defined(__linux__)
230#include <sys/mount.h> 230#include <sys/mount.h>
231// Make sure we have all the new mount flags we actually try to use.
232#ifndef MS_BIND
233#define MS_BIND (1<<12)
234#endif
235#ifndef MS_MOVE
236#define MS_MOVE (1<<13)
237#endif
238#ifndef MS_RECURSIVE
239#define MS_RECURSIVE (1<<14)
240#endif
241#ifndef MS_SILENT
242#define MS_SILENT (1<<15)
243#endif
244
245// The shared subtree stuff, which went in around 2.6.15
246#ifndef MS_UNBINDABLE
247#define MS_UNBINDABLE (1<<17)
248#endif
249#ifndef MS_PRIVATE
250#define MS_PRIVATE (1<<18)
251#endif
252#ifndef MS_SLAVE
253#define MS_SLAVE (1<<19)
254#endif
255#ifndef MS_SHARED
256#define MS_SHARED (1<<20)
257#endif
258
259
231#if !defined(BLKSSZGET) 260#if !defined(BLKSSZGET)
232#define BLKSSZGET _IO(0x12, 104) 261#define BLKSSZGET _IO(0x12, 104)
233#endif 262#endif
diff --git a/libbb/mtab_file.c b/libbb/mtab_file.c
index 3821a6806..92bd2394f 100644
--- a/libbb/mtab_file.c
+++ b/libbb/mtab_file.c
@@ -13,8 +13,5 @@
13 13
14/* Busybox mount uses either /proc/mounts or /etc/mtab to 14/* Busybox mount uses either /proc/mounts or /etc/mtab to
15 * get the list of currently mounted filesystems */ 15 * get the list of currently mounted filesystems */
16#if defined(CONFIG_FEATURE_MTAB_SUPPORT) 16char bb_path_mtab_file[] = USE_FEATURE_MTAB_SUPPORT("/etc/mtab")
17const char bb_path_mtab_file[] = "/etc/mtab"; 17 SKIP_FEATURE_MTAB_SUPPORT("/proc/mounts");
18#else
19const char bb_path_mtab_file[] = "/proc/mounts";
20#endif
diff --git a/util-linux/Config.in b/util-linux/Config.in
index 65d670824..2222e5c38 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -370,7 +370,24 @@ config CONFIG_FEATURE_MOUNT_NFS
370 default n 370 default n
371 depends on CONFIG_MOUNT 371 depends on CONFIG_MOUNT
372 help 372 help
373 Enable mounting of NFS file systems. 373 Enable mounting of NFS file systems.
374
375config CONFIG_FEATURE_MOUNT_FLAGS
376 depends on CONFIG_MOUNT
377 bool "Support lots of -o flags in mount."
378 default y
379 help
380 Without this, mount only supports ro/rw/remount. With this, it
381 supports nosuid, suid, dev, nodev, exec, noexec, sync, async, atime,
382 noatime, diratime, nodiratime, loud, bind, move, shared, slave,
383 private, unbindable, rshared, rslave, rprivate, and runbindable.
384
385config CONFIG_FEATURE_MOUNT_FSTAB
386 depends on CONFIG_MOUNT
387 bool "Support /etc/fstab and -a"
388 default y
389 help
390 Support mount all and looking for files in /etc/fstab.
374 391
375config CONFIG_PIVOT_ROOT 392config CONFIG_PIVOT_ROOT
376 bool "pivot_root" 393 bool "pivot_root"
diff --git a/util-linux/mount.c b/util-linux/mount.c
index d5d3eae17..5d5f487c2 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -25,17 +25,6 @@
25#include "busybox.h" 25#include "busybox.h"
26#include <mntent.h> 26#include <mntent.h>
27 27
28// These two aren't always defined in old headers
29#ifndef MS_BIND
30#define MS_BIND 4096
31#endif
32#ifndef MS_MOVE
33#define MS_MOVE 8192
34#endif
35#ifndef MS_SILENT
36#define MS_SILENT 32768
37#endif
38
39// Not real flags, but we want to be able to check for this. 28// Not real flags, but we want to be able to check for this.
40#define MOUNT_NOAUTO (1<<29) 29#define MOUNT_NOAUTO (1<<29)
41#define MOUNT_SWAP (1<<30) 30#define MOUNT_SWAP (1<<30)
@@ -43,40 +32,59 @@
43 * flags */ 32 * flags */
44 33
45struct { 34struct {
46 const char *name; 35 char *name;
47 long flags; 36 long flags;
48} static const mount_options[] = { 37} static mount_options[] = {
49 // NOP flags. 38 // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs.
50 39
51 {"loop", 0}, 40 USE_FEATURE_MOUNT_LOOP(
52 {"defaults", 0}, 41 {"loop", 0},
53 {"quiet", 0}, 42 )
54 43
55 // vfs flags 44 USE_FEATURE_MOUNT_FSTAB(
56 45 {"defaults", 0},
57 {"ro", MS_RDONLY}, 46 {"quiet", 0},
58 {"rw", ~MS_RDONLY}, 47 {"noauto",MOUNT_NOAUTO},
59 {"nosuid", MS_NOSUID}, 48 {"swap",MOUNT_SWAP},
60 {"suid", ~MS_NOSUID}, 49 )
61 {"dev", ~MS_NODEV}, 50
62 {"nodev", MS_NODEV}, 51 USE_FEATURE_MOUNT_FLAGS(
63 {"exec", ~MS_NOEXEC}, 52 // vfs flags
64 {"noexec", MS_NOEXEC}, 53 {"nosuid", MS_NOSUID},
65 {"sync", MS_SYNCHRONOUS}, 54 {"suid", ~MS_NOSUID},
66 {"async", ~MS_SYNCHRONOUS}, 55 {"dev", ~MS_NODEV},
67 {"atime", ~MS_NOATIME}, 56 {"nodev", MS_NODEV},
68 {"noatime", MS_NOATIME}, 57 {"exec", ~MS_NOEXEC},
69 {"diratime", ~MS_NODIRATIME}, 58 {"noexec", MS_NOEXEC},
70 {"nodiratime", MS_NODIRATIME}, 59 {"sync", MS_SYNCHRONOUS},
71 {"loud", ~MS_SILENT}, 60 {"async", ~MS_SYNCHRONOUS},
72 61 {"atime", ~MS_NOATIME},
73 // action flags 62 {"noatime", MS_NOATIME},
74 63 {"diratime", ~MS_NODIRATIME},
75 {"remount", MS_REMOUNT}, 64 {"nodiratime", MS_NODIRATIME},
76 {"bind", MS_BIND}, 65 {"loud", ~MS_SILENT},
77 {"move", MS_MOVE}, 66
78 {"noauto",MOUNT_NOAUTO}, 67 // action flags
79 {"swap",MOUNT_SWAP} 68
69 {"bind", MS_BIND},
70 {"move", MS_MOVE},
71 {"shared", MS_SHARED},
72 {"slave", MS_SLAVE},
73 {"private", MS_PRIVATE},
74 {"unbindable", MS_UNBINDABLE},
75 {"rshared", MS_SHARED|MS_RECURSIVE},
76 {"rslave", MS_SLAVE|MS_RECURSIVE},
77 {"rprivate", MS_SLAVE|MS_RECURSIVE},
78 {"runbindable", MS_UNBINDABLE|MS_RECURSIVE},
79 )
80
81 // Always understood.
82
83 {"ro", MS_RDONLY}, // vfs flag
84 {"rw", ~MS_RDONLY}, // vfs flag
85 {"remount", MS_REMOUNT}, // action flag
86
87
80}; 88};
81 89
82/* Append mount options to string */ 90/* Append mount options to string */
@@ -225,9 +233,8 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
225 233
226 for(i=0; mount_options[i].flags != MS_REMOUNT; i++) 234 for(i=0; mount_options[i].flags != MS_REMOUNT; i++)
227 if (mount_options[i].flags > 0) 235 if (mount_options[i].flags > 0)
228 append_mount_options(&(mp->mnt_opts), 236// Shut up about the darn const. It's not important. I don't care. (char *)
229// Shut up about the darn const. It's not important. I don't care. 237 append_mount_options(&(mp->mnt_opts), mount_options[i].name);
230 (char *)mount_options[i].name);
231 238
232 // Remove trailing / (if any) from directory we mounted on 239 // Remove trailing / (if any) from directory we mounted on
233 240
@@ -285,8 +292,8 @@ static int singlemount(struct mntent *mp, int ignore_busy)
285 // Look at the file. (Not found isn't a failure for remount, or for 292 // Look at the file. (Not found isn't a failure for remount, or for
286 // a synthetic filesystem like proc or sysfs.) 293 // a synthetic filesystem like proc or sysfs.)
287 294
288 if (stat(mp->mnt_fsname, &st)); 295 if (!lstat(mp->mnt_fsname, &st) && !(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE | MS_SHARED | MS_PRIVATE || MS_SLAVE | MS_UNBINDABLE)))
289 else if (!(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) { 296 {
290 // Do we need to allocate a loopback device for it? 297 // Do we need to allocate a loopback device for it?
291 298
292 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { 299 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
@@ -456,7 +463,7 @@ int mount_main(int argc, char **argv)
456 // Open either fstab or mtab 463 // Open either fstab or mtab
457 464
458 if (parse_mount_options(cmdopts,0) & MS_REMOUNT) 465 if (parse_mount_options(cmdopts,0) & MS_REMOUNT)
459 fstabname = (char *)bb_path_mtab_file; // Again with the evil const. 466 fstabname = bb_path_mtab_file; // Again with the evil const (char *).
460 else fstabname="/etc/fstab"; 467 else fstabname="/etc/fstab";
461 468
462 if (!(fstab=setmntent(fstabname,"r"))) 469 if (!(fstab=setmntent(fstabname,"r")))