diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-18 12:07:49 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-18 12:07:49 +0000 |
commit | f732e96757090253fe4ed481674779864df95cfa (patch) | |
tree | 5c487ed65e3638622f400b26c68d8824e93490e4 | |
parent | c9ca0a32745a43eaa6cb6b7b460718de8ccb84f2 (diff) | |
download | busybox-w32-f732e96757090253fe4ed481674779864df95cfa.tar.gz busybox-w32-f732e96757090253fe4ed481674779864df95cfa.tar.bz2 busybox-w32-f732e96757090253fe4ed481674779864df95cfa.zip |
mount: optional support for -vv verbosity
mount: do "struct globals" trick
With -vv on:
function old new delta
verbose_mount - 83 +83
mount_main 970 988 +18
mount_it_now 219 229 +10
singlemount 4564 4570 +6
mount_option_str 227 233 +6
nfs_mount_version 1 - -1
fslist 4 - -4
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 4/0 up/down: 123/-5) Total: 118 bytes
-rw-r--r-- | util-linux/Config.in | 9 | ||||
-rw-r--r-- | util-linux/mount.c | 60 |
2 files changed, 57 insertions, 12 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in index 5a47318fe..3b0f778cb 100644 --- a/util-linux/Config.in +++ b/util-linux/Config.in | |||
@@ -393,6 +393,15 @@ config FEATURE_MOUNT_FAKE | |||
393 | help | 393 | help |
394 | Enable support for faking a file system mount. | 394 | Enable support for faking a file system mount. |
395 | 395 | ||
396 | config FEATURE_MOUNT_VERBOSE | ||
397 | bool "mount -v option" | ||
398 | default n | ||
399 | depends on MOUNT | ||
400 | help | ||
401 | Enable multi-level -v[vv...] verbose messages. Useful if you | ||
402 | debug mount problems and want to see what is exactly passed | ||
403 | to the kernel. | ||
404 | |||
396 | config FEATURE_MOUNT_HELPERS | 405 | config FEATURE_MOUNT_HELPERS |
397 | bool "Support mount helpers" | 406 | bool "Support mount helpers" |
398 | default n | 407 | default n |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 054db57b3..cd8fef9ee 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -50,8 +50,6 @@ static struct mntent *getmntent_r(FILE* stream, struct mntent* result, char* buf | |||
50 | } | 50 | } |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #define getmntent_buf bb_common_bufsiz1 | ||
54 | |||
55 | 53 | ||
56 | // Not real flags, but we want to be able to check for this. | 54 | // Not real flags, but we want to be able to check for this. |
57 | enum { | 55 | enum { |
@@ -204,6 +202,44 @@ static const char mount_option_str[] = | |||
204 | "remount" "\0" // action flag | 202 | "remount" "\0" // action flag |
205 | ; | 203 | ; |
206 | 204 | ||
205 | |||
206 | struct globals { | ||
207 | #if ENABLE_FEATURE_MOUNT_NFS | ||
208 | smalluint nfs_mount_version; | ||
209 | #endif | ||
210 | #if ENABLE_FEATURE_MOUNT_VERBOSE | ||
211 | unsigned verbose; | ||
212 | #endif | ||
213 | llist_t *fslist; | ||
214 | char getmntent_buf[sizeof(bb_common_bufsiz1) - 8*3]; | ||
215 | |||
216 | }; | ||
217 | #define G (*(struct globals*)&bb_common_bufsiz1) | ||
218 | #define nfs_mount_version (G.nfs_mount_version) | ||
219 | #define verbose (G.verbose ) | ||
220 | #define fslist (G.fslist ) | ||
221 | #define getmntent_buf (G.getmntent_buf ) | ||
222 | |||
223 | |||
224 | #if ENABLE_FEATURE_MOUNT_VERBOSE | ||
225 | static int verbose_mount(const char *source, const char *target, | ||
226 | const char *filesystemtype, | ||
227 | unsigned long mountflags, const void *data) | ||
228 | { | ||
229 | int rc; | ||
230 | |||
231 | errno = 0; | ||
232 | rc = mount(source, target, filesystemtype, mountflags, data); | ||
233 | if (verbose >= 2) | ||
234 | bb_perror_msg("mount('%s','%s','%s',0x%08lx,'%s'):%d", | ||
235 | source, target, filesystemtype, | ||
236 | mountflags, (char*)data, rc); | ||
237 | return rc; | ||
238 | } | ||
239 | #else | ||
240 | #define verbose_mount(...) mount(__VA_ARGS__) | ||
241 | #endif | ||
242 | |||
207 | /* Append mount options to string */ | 243 | /* Append mount options to string */ |
208 | static void append_mount_options(char **oldopts, const char *newopts) | 244 | static void append_mount_options(char **oldopts, const char *newopts) |
209 | { | 245 | { |
@@ -313,8 +349,6 @@ static llist_t *get_block_backed_filesystems(void) | |||
313 | return list; | 349 | return list; |
314 | } | 350 | } |
315 | 351 | ||
316 | static llist_t *fslist; | ||
317 | |||
318 | #if ENABLE_FEATURE_CLEAN_UP | 352 | #if ENABLE_FEATURE_CLEAN_UP |
319 | static void delete_block_backed_filesystems(void) | 353 | static void delete_block_backed_filesystems(void) |
320 | { | 354 | { |
@@ -333,9 +367,9 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) | |||
333 | if (fakeIt) goto mtab; | 367 | if (fakeIt) goto mtab; |
334 | 368 | ||
335 | // Mount, with fallback to read-only if necessary. | 369 | // Mount, with fallback to read-only if necessary. |
336 | |||
337 | for (;;) { | 370 | for (;;) { |
338 | rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, | 371 | errno = 0; |
372 | rc = verbose_mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, | ||
339 | vfsflags, filteropts); | 373 | vfsflags, filteropts); |
340 | 374 | ||
341 | // If mount failed, try | 375 | // If mount failed, try |
@@ -738,8 +772,6 @@ static bool_t xdr_mountres3(XDR *xdrs, mountres3 *objp) | |||
738 | 772 | ||
739 | #define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2) | 773 | #define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2) |
740 | 774 | ||
741 | static smalluint nfs_mount_version; | ||
742 | |||
743 | /* | 775 | /* |
744 | * Unfortunately, the kernel prints annoying console messages | 776 | * Unfortunately, the kernel prints annoying console messages |
745 | * in case of an unexpected nfs mount version (instead of | 777 | * in case of an unexpected nfs mount version (instead of |
@@ -1674,8 +1706,8 @@ int mount_main(int argc, char **argv) | |||
1674 | 1706 | ||
1675 | sanitize_env_if_suid(); | 1707 | sanitize_env_if_suid(); |
1676 | 1708 | ||
1677 | /* parse long options, like --bind and --move. Note that -o option | 1709 | // Parse long options, like --bind and --move. Note that -o option |
1678 | * and --option are synonymous. Yes, this means --remount,rw works. */ | 1710 | // and --option are synonymous. Yes, this means --remount,rw works. |
1679 | 1711 | ||
1680 | for (i = j = 0; i < argc; i++) { | 1712 | for (i = j = 0; i < argc; i++) { |
1681 | if (argv[i][0] == '-' && argv[i][1] == '-') { | 1713 | if (argv[i][0] == '-' && argv[i][1] == '-') { |
@@ -1687,7 +1719,11 @@ int mount_main(int argc, char **argv) | |||
1687 | 1719 | ||
1688 | // Parse remaining options | 1720 | // Parse remaining options |
1689 | 1721 | ||
1690 | opt = getopt32(argv, OPTION_STR, &opt_o, &fstype); | 1722 | #if ENABLE_FEATURE_MOUNT_VERBOSE |
1723 | opt_complementary = "vv"; // -v is a counter | ||
1724 | #endif | ||
1725 | opt = getopt32(argv, OPTION_STR, &opt_o, &fstype | ||
1726 | USE_FEATURE_MOUNT_VERBOSE(, &verbose)); | ||
1691 | if (opt & OPT_o) append_mount_options(&cmdopts, opt_o); // -o | 1727 | if (opt & OPT_o) append_mount_options(&cmdopts, opt_o); // -o |
1692 | if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r | 1728 | if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r |
1693 | if (opt & OPT_w) append_mount_options(&cmdopts, "rw"); // -w | 1729 | if (opt & OPT_w) append_mount_options(&cmdopts, "rw"); // -w |
@@ -1747,7 +1783,7 @@ int mount_main(int argc, char **argv) | |||
1747 | if (ENABLE_FEATURE_MOUNT_FLAGS | 1783 | if (ENABLE_FEATURE_MOUNT_FLAGS |
1748 | && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) | 1784 | && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) |
1749 | ) { | 1785 | ) { |
1750 | rc = mount("", argv[0], "", i, ""); | 1786 | rc = verbose_mount("", argv[0], "", i, ""); |
1751 | if (rc) bb_simple_perror_msg_and_die(argv[0]); | 1787 | if (rc) bb_simple_perror_msg_and_die(argv[0]); |
1752 | goto clean_up; | 1788 | goto clean_up; |
1753 | } | 1789 | } |