aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-16 23:28:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-16 23:28:42 +0000
commitb1d8e7db0fced98ba2cd049019f8820fd91a0482 (patch)
treef57502cb47f3036e742e34609a3f485197b3fd73
parent25591c322c9305bd54d3ab80cfaf01ef87640d77 (diff)
downloadbusybox-w32-b1d8e7db0fced98ba2cd049019f8820fd91a0482.tar.gz
busybox-w32-b1d8e7db0fced98ba2cd049019f8820fd91a0482.tar.bz2
busybox-w32-b1d8e7db0fced98ba2cd049019f8820fd91a0482.zip
mount: make -f work even without mtab support
(Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn at axis.com>)
-rw-r--r--include/usage.h4
-rw-r--r--scripts/defconfig1
-rw-r--r--util-linux/Config.in8
-rw-r--r--util-linux/mount.c54
4 files changed, 46 insertions, 21 deletions
diff --git a/include/usage.h b/include/usage.h
index 59e57f3a0..04ef1822e 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2449,8 +2449,10 @@ USE_FEATURE_BRCTL_FANCY("\n" \
2449 "Mount a filesystem. Filesystem autodetection requires /proc be mounted." \ 2449 "Mount a filesystem. Filesystem autodetection requires /proc be mounted." \
2450 "\n\nOptions:\n" \ 2450 "\n\nOptions:\n" \
2451 " -a Mount all filesystems in fstab\n" \ 2451 " -a Mount all filesystems in fstab\n" \
2452 USE_FEATURE_MOUNT_FAKE( \
2453 " -f "USE_FEATURE_MTAB_SUPPORT("Update /etc/mtab, but ")"don't mount\n" \
2454 ) \
2452 USE_FEATURE_MTAB_SUPPORT( \ 2455 USE_FEATURE_MTAB_SUPPORT( \
2453 " -f Update /etc/mtab, but don't mount\n" \
2454 " -n Don't update /etc/mtab\n" \ 2456 " -n Don't update /etc/mtab\n" \
2455 ) \ 2457 ) \
2456 " -r Read-only mount\n" \ 2458 " -r Read-only mount\n" \
diff --git a/scripts/defconfig b/scripts/defconfig
index 31a172c56..87bc6bd7e 100644
--- a/scripts/defconfig
+++ b/scripts/defconfig
@@ -478,6 +478,7 @@ CONFIG_MOUNT=y
478# CONFIG_FEATURE_MOUNT_HELPERS is not set 478# CONFIG_FEATURE_MOUNT_HELPERS is not set
479CONFIG_FEATURE_MOUNT_NFS=y 479CONFIG_FEATURE_MOUNT_NFS=y
480CONFIG_FEATURE_MOUNT_CIFS=y 480CONFIG_FEATURE_MOUNT_CIFS=y
481CONFIG_FEATURE_MOUNT_FAKE=y
481CONFIG_FEATURE_MOUNT_FLAGS=y 482CONFIG_FEATURE_MOUNT_FLAGS=y
482CONFIG_FEATURE_MOUNT_FSTAB=y 483CONFIG_FEATURE_MOUNT_FSTAB=y
483CONFIG_PIVOT_ROOT=y 484CONFIG_PIVOT_ROOT=y
diff --git a/util-linux/Config.in b/util-linux/Config.in
index d1688e8c9..5a47318fe 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -386,6 +386,13 @@ config MOUNT
386 NFS filesystems. Most people using BusyBox will also want to enable 386 NFS filesystems. Most people using BusyBox will also want to enable
387 the 'mount' utility. 387 the 'mount' utility.
388 388
389config FEATURE_MOUNT_FAKE
390 bool "mount -f option"
391 default n
392 depends on MOUNT
393 help
394 Enable support for faking a file system mount.
395
389config FEATURE_MOUNT_HELPERS 396config FEATURE_MOUNT_HELPERS
390 bool "Support mount helpers" 397 bool "Support mount helpers"
391 default n 398 default n
@@ -542,6 +549,7 @@ config FEATURE_MTAB_SUPPORT
542 bool "Support for the old /etc/mtab file" 549 bool "Support for the old /etc/mtab file"
543 default n 550 default n
544 depends on MOUNT || UMOUNT 551 depends on MOUNT || UMOUNT
552 select FEATURE_MOUNT_FAKE
545 help 553 help
546 Historically, Unix systems kept track of the currently mounted 554 Historically, Unix systems kept track of the currently mounted
547 partitions in the file "/etc/mtab". These days, the kernel exports 555 partitions in the file "/etc/mtab". These days, the kernel exports
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 5e6c3ba72..dd753235e 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -54,6 +54,35 @@ enum {
54 MOUNT_NOAUTO = (1<<29), 54 MOUNT_NOAUTO = (1<<29),
55 MOUNT_SWAP = (1<<30), 55 MOUNT_SWAP = (1<<30),
56}; 56};
57
58
59#define OPTION_STR "o:t:rwanfvsi"
60enum {
61 OPT_o = (1 << 0),
62 OPT_t = (1 << 1),
63 OPT_r = (1 << 2),
64 OPT_w = (1 << 3),
65 OPT_a = (1 << 4),
66 OPT_n = (1 << 5),
67 OPT_f = (1 << 6),
68 OPT_v = (1 << 7),
69 OPT_s = (1 << 8),
70 OPT_i = (1 << 9),
71};
72
73#if ENABLE_FEATURE_MTAB_SUPPORT
74#define useMtab (!(option_mask32 & OPT_n))
75#else
76#define useMtab 0
77#endif
78
79#if ENABLE_FEATURE_MOUNT_FAKE
80#define fakeIt (option_mask32 & OPT_f)
81#else
82#define fakeIt 0
83#endif
84
85
57// TODO: more "user" flag compatibility. 86// TODO: more "user" flag compatibility.
58// "user" option (from mount manpage): 87// "user" option (from mount manpage):
59// Only the user that mounted a filesystem can unmount it again. 88// Only the user that mounted a filesystem can unmount it again.
@@ -288,14 +317,6 @@ static void delete_block_backed_filesystems(void)
288void delete_block_backed_filesystems(void); 317void delete_block_backed_filesystems(void);
289#endif 318#endif
290 319
291#if ENABLE_FEATURE_MTAB_SUPPORT
292static int useMtab = 1;
293static int fakeIt;
294#else
295#define useMtab 0
296#define fakeIt 0
297#endif
298
299// Perform actual mount of specific filesystem at specific location. 320// Perform actual mount of specific filesystem at specific location.
300// NB: mp->xxx fields may be trashed on exit 321// NB: mp->xxx fields may be trashed on exit
301static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) 322static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
@@ -346,7 +367,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
346 /* If the mount was successful, and we're maintaining an old-style 367 /* If the mount was successful, and we're maintaining an old-style
347 * mtab file by hand, add the new entry to it now. */ 368 * mtab file by hand, add the new entry to it now. */
348 mtab: 369 mtab:
349 if (ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc && !(vfsflags & MS_REMOUNT)) { 370 if (useMtab && !rc && !(vfsflags & MS_REMOUNT)) {
350 char *fsname; 371 char *fsname;
351 FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); 372 FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
352 const char *option_str = mount_option_str; 373 const char *option_str = mount_option_str;
@@ -1657,17 +1678,10 @@ int mount_main(int argc, char **argv)
1657 1678
1658 // Parse remaining options 1679 // Parse remaining options
1659 1680
1660 opt = getopt32(argv, "o:t:rwanfvsi", &opt_o, &fstype); 1681 opt = getopt32(argv, OPTION_STR, &opt_o, &fstype);
1661 if (opt & 0x1) append_mount_options(&cmdopts, opt_o); // -o 1682 if (opt & OPT_o) append_mount_options(&cmdopts, opt_o); // -o
1662 //if (opt & 0x2) // -t 1683 if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r
1663 if (opt & 0x4) append_mount_options(&cmdopts, "ro"); // -r 1684 if (opt & OPT_w) append_mount_options(&cmdopts, "rw"); // -w
1664 if (opt & 0x8) append_mount_options(&cmdopts, "rw"); // -w
1665 //if (opt & 0x10) // -a
1666 if (opt & 0x20) USE_FEATURE_MTAB_SUPPORT(useMtab = 0); // -n
1667 if (opt & 0x40) USE_FEATURE_MTAB_SUPPORT(fakeIt = 1); // -f
1668 //if (opt & 0x80) // -v: verbose (ignore)
1669 //if (opt & 0x100) // -s: sloppy (ignore)
1670 //if (opt & 0x200) // -i: don't call mount.<fstype> (ignore)
1671 argv += optind; 1685 argv += optind;
1672 argc -= optind; 1686 argc -= optind;
1673 1687