Start 1.33.0 development cycle
[oweals/busybox.git] / libbb / find_mount_point.c
index 56637ad923502a0d52a4684558c56fb8cd466940..0e1be38204541c79c3bf49f9ebb8f331b31bbba5 100644 (file)
@@ -6,7 +6,6 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-
 #include "libbb.h"
 #include <mntent.h>
 
@@ -30,7 +29,8 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too)
 
        devno_of_name = s.st_dev;
        block_dev = 0;
-       if (S_ISBLK(s.st_mode)) {
+       /* Why S_ISCHR? - UBI volumes use char devices, not block */
+       if (S_ISBLK(s.st_mode) || S_ISCHR(s.st_mode)) {
                devno_of_name = s.st_rdev;
                block_dev = 1;
        }
@@ -56,11 +56,22 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too)
                        continue;
 
                /* Is device's dev_t == name's dev_t? */
-               if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == devno_of_name)
+               if (mountEntry->mnt_fsname[0] == '/'
+               /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+                * avoid stat'ing "sysfs", "proc", "none" and such,
+                * useless at best, can stat unrelated files at worst.
+                */
+                && stat(mountEntry->mnt_fsname, &s) == 0
+                && s.st_rdev == devno_of_name
+               ) {
                        break;
+               }
                /* Match the directory's mount point. */
-               if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == devno_of_name)
+               if (stat(mountEntry->mnt_dir, &s) == 0
+                && s.st_dev == devno_of_name
+               ) {
                        break;
+               }
        }
        endmntent(mtab_fp);