aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-18 12:07:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-18 12:07:49 +0000
commitf732e96757090253fe4ed481674779864df95cfa (patch)
tree5c487ed65e3638622f400b26c68d8824e93490e4 /util-linux
parentc9ca0a32745a43eaa6cb6b7b460718de8ccb84f2 (diff)
downloadbusybox-f732e96757090253fe4ed481674779864df95cfa.tar.gz
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
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/Config.in9
-rw-r--r--util-linux/mount.c60
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
help
Enable support for faking a file system mount.
+config FEATURE_MOUNT_VERBOSE
+ bool "mount -v option"
+ default n
+ depends on MOUNT
+ help
+ Enable multi-level -v[vv...] verbose messages. Useful if you
+ debug mount problems and want to see what is exactly passed
+ to the kernel.
+
config FEATURE_MOUNT_HELPERS
bool "Support mount helpers"
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
}
#endif
-#define getmntent_buf bb_common_bufsiz1
-
// Not real flags, but we want to be able to check for this.
enum {
@@ -204,6 +202,44 @@ static const char mount_option_str[] =
"remount" "\0" // action flag
;
+
+struct globals {
+#if ENABLE_FEATURE_MOUNT_NFS
+ smalluint nfs_mount_version;
+#endif
+#if ENABLE_FEATURE_MOUNT_VERBOSE
+ unsigned verbose;
+#endif
+ llist_t *fslist;
+ char getmntent_buf[sizeof(bb_common_bufsiz1) - 8*3];
+
+};
+#define G (*(struct globals*)&bb_common_bufsiz1)
+#define nfs_mount_version (G.nfs_mount_version)
+#define verbose (G.verbose )
+#define fslist (G.fslist )
+#define getmntent_buf (G.getmntent_buf )
+
+
+#if ENABLE_FEATURE_MOUNT_VERBOSE
+static int verbose_mount(const char *source, const char *target,
+ const char *filesystemtype,
+ unsigned long mountflags, const void *data)
+{
+ int rc;
+
+ errno = 0;
+ rc = mount(source, target, filesystemtype, mountflags, data);
+ if (verbose >= 2)
+ bb_perror_msg("mount('%s','%s','%s',0x%08lx,'%s'):%d",
+ source, target, filesystemtype,
+ mountflags, (char*)data, rc);
+ return rc;
+}
+#else
+#define verbose_mount(...) mount(__VA_ARGS__)
+#endif
+
/* Append mount options to string */
static void append_mount_options(char **oldopts, const char *newopts)
{
@@ -313,8 +349,6 @@ static llist_t *get_block_backed_filesystems(void)
return list;
}
-static llist_t *fslist;
-
#if ENABLE_FEATURE_CLEAN_UP
static void delete_block_backed_filesystems(void)
{
@@ -333,9 +367,9 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
if (fakeIt) goto mtab;
// Mount, with fallback to read-only if necessary.
-
for (;;) {
- rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
+ errno = 0;
+ rc = verbose_mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
vfsflags, filteropts);
// If mount failed, try
@@ -738,8 +772,6 @@ static bool_t xdr_mountres3(XDR *xdrs, mountres3 *objp)
#define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2)
-static smalluint nfs_mount_version;
-
/*
* Unfortunately, the kernel prints annoying console messages
* in case of an unexpected nfs mount version (instead of
@@ -1674,8 +1706,8 @@ int mount_main(int argc, char **argv)
sanitize_env_if_suid();
- /* parse long options, like --bind and --move. Note that -o option
- * and --option are synonymous. Yes, this means --remount,rw works. */
+ // Parse long options, like --bind and --move. Note that -o option
+ // and --option are synonymous. Yes, this means --remount,rw works.
for (i = j = 0; i < argc; i++) {
if (argv[i][0] == '-' && argv[i][1] == '-') {
@@ -1687,7 +1719,11 @@ int mount_main(int argc, char **argv)
// Parse remaining options
- opt = getopt32(argv, OPTION_STR, &opt_o, &fstype);
+#if ENABLE_FEATURE_MOUNT_VERBOSE
+ opt_complementary = "vv"; // -v is a counter
+#endif
+ opt = getopt32(argv, OPTION_STR, &opt_o, &fstype
+ USE_FEATURE_MOUNT_VERBOSE(, &verbose));
if (opt & OPT_o) append_mount_options(&cmdopts, opt_o); // -o
if (opt & OPT_r) append_mount_options(&cmdopts, "ro"); // -r
if (opt & OPT_w) append_mount_options(&cmdopts, "rw"); // -w
@@ -1747,7 +1783,7 @@ int mount_main(int argc, char **argv)
if (ENABLE_FEATURE_MOUNT_FLAGS
&& (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
) {
- rc = mount("", argv[0], "", i, "");
+ rc = verbose_mount("", argv[0], "", i, "");
if (rc) bb_simple_perror_msg_and_die(argv[0]);
goto clean_up;
}