Major rewrite of mount, umount, losetup.  Untangled lots of code, shrunk
things down a bit, fixed a number of funky corner cases, added support for
several new features (things like mount --move, mount --bind, lazy unounts,
automatic detection of loop mounts, and so on).  Probably broke several
other things, but it's fixable.  (Bang on it, tell me what doesn't work for
you...)

Note: you no longer need to say "-o loop".  It does that for you when
necessary.

Still need to add "user mount" support, which involves making mount suid.  Not
too hard to do under the new infrastructure, just haven't done it yet...

The previous code had the following notes, that belong in the version
control comments:

- * 3/21/1999   Charles P. Wright <cpwright@cpwright.com>
- *             searches through fstab when -a is passed
- *             will try mounting stuff with all fses when passed -t auto
- *
- * 1999-04-17  Dave Cinege...Rewrote -t auto. Fixed ro mtab.
- *
- * 1999-10-07  Erik Andersen <andersen@codepoet.org>.
- *              Rewrite of a lot of code. Removed mtab usage (I plan on
- *              putting it back as a compile-time option some time),
- *              major adjustments to option parsing, and some serious
- *              dieting all around.
- *
- * 1999-11-06  mtab support is back - andersee
- *
- * 2000-01-12   Ben Collins <bcollins@debian.org>, Borrowed utils-linux's
- *              mount to add loop support.
- *
- * 2000-04-30  Dave Cinege <dcinege@psychosis.com>
- *             Rewrote fstab while loop and lower mount section. Can now do
- *             single mounts from fstab. Can override fstab options for single
- *             mount. Common mount_one call for single mounts and 'all'. Fixed
- *             mtab updating and stale entries. Removed 'remount' default.
- *


diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 2600ce5..7ff65bb 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -25,65 +25,25 @@
 #include <stdlib.h>
 #include "libbb.h"
 
-
-
-extern char *find_real_root_device_name(void)
+extern char *find_block_device(char *path)
 {
 	DIR *dir;
 	struct dirent *entry;
-	struct stat statBuf, rootStat;
-	char *fileName = NULL;
+	struct stat st;
 	dev_t dev;
+	char *retpath=NULL;
 
-	if (stat("/", &rootStat) != 0)
-		bb_perror_msg("could not stat '/'");
-	else {
-		/* This check is here in case they pass in /dev name */
-		if ((rootStat.st_mode & S_IFMT) == S_IFBLK)
-			dev = rootStat.st_rdev;
-		else
-			dev = rootStat.st_dev;
-
-		dir = opendir("/dev");
-		if (!dir)
-			bb_perror_msg("could not open '/dev'");
-		else {
-			while((entry = readdir(dir)) != NULL) {
-				const char *myname = entry->d_name;
-				/* Must skip ".." since that is "/", and so we
-				 * would get a false positive on ".."  */
-				if (myname[0] == '.' && myname[1] == '.' && !myname[2])
-					continue;
-#ifdef CONFIG_FEATURE_DEVFS
-				/* if there is a link named /dev/root skip that too */
-				if (strcmp(myname, "root")==0)
-					continue;
-#endif
-				fileName = concat_path_file("/dev", myname);
-
-				/* Some char devices have the same dev_t as block
-				 * devices, so make sure this is a block device */
-				if (stat(fileName, &statBuf) == 0 &&
-						S_ISBLK(statBuf.st_mode)!=0 &&
-						statBuf.st_rdev == dev)
-					break;
-				free(fileName);
-				fileName=NULL;
-			}
-			closedir(dir);
+	if(stat(path, &st) || !(dir = opendir("/dev"))) return NULL;
+	dev = (st.st_mode & S_IFMT) == S_IFBLK ? st.st_rdev : st.st_dev;
+	while((entry = readdir(dir)) != NULL) {
+		char devpath[PATH_MAX];
+		sprintf(devpath,"/dev/%s", entry->d_name);
+		if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) {
+			retpath = bb_xstrdup(devpath);
+			break;
 		}
 	}
-	if(fileName==NULL)
-		fileName = bb_xstrdup("/dev/root");
-	return fileName;
+	closedir(dir);
+
+	return retpath;
 }
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/