diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-21 12:08:56 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-21 12:08:56 +0200 |
| commit | 9ee426649006c4a0db7b4784f2ebb96865d4c705 (patch) | |
| tree | 4dc66f24a808133bf6e3c204b2600b19fd2e020d /util-linux | |
| parent | 1d7ad7a022bf894e89904832a0c84f14c8ca2d31 (diff) | |
| download | busybox-w32-9ee426649006c4a0db7b4784f2ebb96865d4c705.tar.gz busybox-w32-9ee426649006c4a0db7b4784f2ebb96865d4c705.tar.bz2 busybox-w32-9ee426649006c4a0db7b4784f2ebb96865d4c705.zip | |
mount: set up RO loop device if mount -o ro. Closes 4784
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/mount.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index f1da30fac..220a4e67c 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
| @@ -450,9 +450,9 @@ static void append_mount_options(char **oldopts, const char *newopts) | |||
| 450 | 450 | ||
| 451 | // Use the mount_options list to parse options into flags. | 451 | // Use the mount_options list to parse options into flags. |
| 452 | // Also update list of unrecognized options if unrecognized != NULL | 452 | // Also update list of unrecognized options if unrecognized != NULL |
| 453 | static long parse_mount_options(char *options, char **unrecognized) | 453 | static unsigned long parse_mount_options(char *options, char **unrecognized) |
| 454 | { | 454 | { |
| 455 | long flags = MS_SILENT; | 455 | unsigned long flags = MS_SILENT; |
| 456 | 456 | ||
| 457 | // Loop through options | 457 | // Loop through options |
| 458 | for (;;) { | 458 | for (;;) { |
| @@ -466,7 +466,7 @@ static long parse_mount_options(char *options, char **unrecognized) | |||
| 466 | // Find this option in mount_options | 466 | // Find this option in mount_options |
| 467 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { | 467 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { |
| 468 | if (strcasecmp(option_str, options) == 0) { | 468 | if (strcasecmp(option_str, options) == 0) { |
| 469 | long fl = mount_options[i]; | 469 | unsigned long fl = mount_options[i]; |
| 470 | if (fl < 0) | 470 | if (fl < 0) |
| 471 | flags &= fl; | 471 | flags &= fl; |
| 472 | else | 472 | else |
| @@ -548,7 +548,7 @@ void delete_block_backed_filesystems(void); | |||
| 548 | 548 | ||
| 549 | // Perform actual mount of specific filesystem at specific location. | 549 | // Perform actual mount of specific filesystem at specific location. |
| 550 | // NB: mp->xxx fields may be trashed on exit | 550 | // NB: mp->xxx fields may be trashed on exit |
| 551 | static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) | 551 | static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filteropts) |
| 552 | { | 552 | { |
| 553 | int rc = 0; | 553 | int rc = 0; |
| 554 | 554 | ||
| @@ -1080,7 +1080,7 @@ static void error_msg_rpc(const char *msg) | |||
| 1080 | } | 1080 | } |
| 1081 | 1081 | ||
| 1082 | /* NB: mp->xxx fields may be trashed on exit */ | 1082 | /* NB: mp->xxx fields may be trashed on exit */ |
| 1083 | static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) | 1083 | static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts) |
| 1084 | { | 1084 | { |
| 1085 | CLIENT *mclient; | 1085 | CLIENT *mclient; |
| 1086 | char *hostname; | 1086 | char *hostname; |
| @@ -1711,7 +1711,7 @@ static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) | |||
| 1711 | * For older kernels, you must build busybox with ENABLE_FEATURE_MOUNT_NFS. | 1711 | * For older kernels, you must build busybox with ENABLE_FEATURE_MOUNT_NFS. |
| 1712 | * (However, note that then you lose any chances that NFS over IPv6 would work). | 1712 | * (However, note that then you lose any chances that NFS over IPv6 would work). |
| 1713 | */ | 1713 | */ |
| 1714 | static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) | 1714 | static int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts) |
| 1715 | { | 1715 | { |
| 1716 | len_and_sockaddr *lsa; | 1716 | len_and_sockaddr *lsa; |
| 1717 | char *opts; | 1717 | char *opts; |
| @@ -1753,7 +1753,7 @@ static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts) | |||
| 1753 | static int singlemount(struct mntent *mp, int ignore_busy) | 1753 | static int singlemount(struct mntent *mp, int ignore_busy) |
| 1754 | { | 1754 | { |
| 1755 | int rc = -1; | 1755 | int rc = -1; |
| 1756 | long vfsflags; | 1756 | unsigned long vfsflags; |
| 1757 | char *loopFile = NULL, *filteropts = NULL; | 1757 | char *loopFile = NULL, *filteropts = NULL; |
| 1758 | llist_t *fl = NULL; | 1758 | llist_t *fl = NULL; |
| 1759 | struct stat st; | 1759 | struct stat st; |
| @@ -1854,7 +1854,7 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
| 1854 | if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { | 1854 | if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { |
| 1855 | loopFile = bb_simplify_path(mp->mnt_fsname); | 1855 | loopFile = bb_simplify_path(mp->mnt_fsname); |
| 1856 | mp->mnt_fsname = NULL; // will receive malloced loop dev name | 1856 | mp->mnt_fsname = NULL; // will receive malloced loop dev name |
| 1857 | if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ 0) < 0) { | 1857 | if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ (vfsflags & MS_RDONLY)) < 0) { |
| 1858 | if (errno == EPERM || errno == EACCES) | 1858 | if (errno == EPERM || errno == EACCES) |
| 1859 | bb_error_msg(bb_msg_perm_denied_are_you_root); | 1859 | bb_error_msg(bb_msg_perm_denied_are_you_root); |
| 1860 | else | 1860 | else |
| @@ -1992,6 +1992,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
| 1992 | FILE *fstab; | 1992 | FILE *fstab; |
| 1993 | int i, j; | 1993 | int i, j; |
| 1994 | int rc = EXIT_SUCCESS; | 1994 | int rc = EXIT_SUCCESS; |
| 1995 | unsigned long cmdopt_flags; | ||
| 1995 | unsigned opt; | 1996 | unsigned opt; |
| 1996 | struct mntent mtpair[2], *mtcur = mtpair; | 1997 | struct mntent mtpair[2], *mtcur = mtpair; |
| 1997 | IF_NOT_DESKTOP(const int nonroot = 0;) | 1998 | IF_NOT_DESKTOP(const int nonroot = 0;) |
| @@ -2066,16 +2067,16 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
| 2066 | // Past this point, we are handling either "mount -a [opts]" | 2067 | // Past this point, we are handling either "mount -a [opts]" |
| 2067 | // or "mount [opts] single_param" | 2068 | // or "mount [opts] single_param" |
| 2068 | 2069 | ||
| 2069 | i = parse_mount_options(cmdopts, NULL); // FIXME: should be "long", not "int" | 2070 | cmdopt_flags = parse_mount_options(cmdopts, NULL); |
| 2070 | if (nonroot && (i & ~MS_SILENT)) // Non-root users cannot specify flags | 2071 | if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags |
| 2071 | bb_error_msg_and_die(bb_msg_you_must_be_root); | 2072 | bb_error_msg_and_die(bb_msg_you_must_be_root); |
| 2072 | 2073 | ||
| 2073 | // If we have a shared subtree flag, don't worry about fstab or mtab. | 2074 | // If we have a shared subtree flag, don't worry about fstab or mtab. |
| 2074 | if (ENABLE_FEATURE_MOUNT_FLAGS | 2075 | if (ENABLE_FEATURE_MOUNT_FLAGS |
| 2075 | && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) | 2076 | && (cmdopt_flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) |
| 2076 | ) { | 2077 | ) { |
| 2077 | // verbose_mount(source, target, type, flags, data) | 2078 | // verbose_mount(source, target, type, flags, data) |
| 2078 | rc = verbose_mount("", argv[0], "", i, ""); | 2079 | rc = verbose_mount("", argv[0], "", cmdopt_flags, ""); |
| 2079 | if (rc) | 2080 | if (rc) |
| 2080 | bb_simple_perror_msg_and_die(argv[0]); | 2081 | bb_simple_perror_msg_and_die(argv[0]); |
| 2081 | return rc; | 2082 | return rc; |
| @@ -2083,7 +2084,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
| 2083 | 2084 | ||
| 2084 | // Open either fstab or mtab | 2085 | // Open either fstab or mtab |
| 2085 | fstabname = "/etc/fstab"; | 2086 | fstabname = "/etc/fstab"; |
| 2086 | if (i & MS_REMOUNT) { | 2087 | if (cmdopt_flags & MS_REMOUNT) { |
| 2087 | // WARNING. I am not sure this matches util-linux's | 2088 | // WARNING. I am not sure this matches util-linux's |
| 2088 | // behavior. It's possible util-linux does not | 2089 | // behavior. It's possible util-linux does not |
| 2089 | // take -o opts from mtab (takes only mount source). | 2090 | // take -o opts from mtab (takes only mount source). |
| @@ -2182,7 +2183,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
| 2182 | // End of fstab/mtab is reached. | 2183 | // End of fstab/mtab is reached. |
| 2183 | // Were we looking for something specific? | 2184 | // Were we looking for something specific? |
| 2184 | if (argv[0]) { // yes | 2185 | if (argv[0]) { // yes |
| 2185 | long l; | 2186 | unsigned long l; |
| 2186 | 2187 | ||
| 2187 | // If we didn't find anything, complain | 2188 | // If we didn't find anything, complain |
| 2188 | if (!mtcur->mnt_fsname) | 2189 | if (!mtcur->mnt_fsname) |
