svn commit: trunk/busybox/util-linux

vda at busybox.net vda at busybox.net
Mon Feb 18 12:07:51 UTC 2008


Author: vda
Date: 2008-02-18 04:07:49 -0800 (Mon, 18 Feb 2008)
New Revision: 21050

Log:
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



Modified:
   trunk/busybox/util-linux/Config.in
   trunk/busybox/util-linux/mount.c


Changeset:
Modified: trunk/busybox/util-linux/Config.in
===================================================================
--- trunk/busybox/util-linux/Config.in	2008-02-18 11:08:33 UTC (rev 21049)
+++ trunk/busybox/util-linux/Config.in	2008-02-18 12:07:49 UTC (rev 21050)
@@ -393,6 +393,15 @@
 	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

Modified: trunk/busybox/util-linux/mount.c
===================================================================
--- trunk/busybox/util-linux/mount.c	2008-02-18 11:08:33 UTC (rev 21049)
+++ trunk/busybox/util-linux/mount.c	2008-02-18 12:07:49 UTC (rev 21050)
@@ -50,9 +50,7 @@
 }
 #endif
 
-#define getmntent_buf bb_common_bufsiz1
 
-
 // Not real flags, but we want to be able to check for this.
 enum {
 	MOUNT_USERS  = (1<<28)*ENABLE_DESKTOP,
@@ -204,6 +202,44 @@
 	"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 @@
 	return list;
 }
 
-static llist_t *fslist;
-
 #if ENABLE_FEATURE_CLEAN_UP
 static void delete_block_backed_filesystems(void)
 {
@@ -333,9 +367,9 @@
 	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 @@
 
 #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 @@
 
 	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 @@
 
 	// 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 @@
 	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;
 	}




More information about the busybox-cvs mailing list