]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/ismounted: improve loopdev support
authorKarel Zak <kzak@redhat.com>
Wed, 19 Dec 2012 13:34:01 +0000 (14:34 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 19 Dec 2012 13:34:01 +0000 (14:34 +0100)
... to make it usable for situations when the same backing
file is mapped to more loop devices.

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/ismounted.c

index c2ad2434b43fea32c4ebc2b98e0f080ad92e6099..5611ab3855e722105dcb911430f3a7d3d3ad05a5 100644 (file)
@@ -44,7 +44,7 @@ static int check_mntent_file(const char *mtab_file, const char *file,
        struct mntent   *mnt;
        struct stat     st_buf;
        int             retval = 0;
-       dev_t           file_dev=0, file_rdev=0, lodev_dev=0;
+       dev_t           file_dev=0, file_rdev=0;
        ino_t           file_ino=0;
        FILE            *f;
        int             fd;
@@ -59,20 +59,6 @@ static int check_mntent_file(const char *mtab_file, const char *file,
                        file_rdev = st_buf.st_rdev;
 #endif /* __GNU__ */
                } else {
-#ifdef __linux__
-                       /*
-                        * Maybe the file is backing file for a loop device.
-                        *
-                        * For is_mounted() we complete ignore the fact that
-                        * the same backing file maybe mapped into more loop
-                        * devices by sizelimit and offset loop options. If you
-                        * want really robust code than use libmount...
-                        */
-                       char *name = loopdev_find_by_backing_file(file, 0, 0);
-                       if (name && stat(name, &st_buf) == 0)
-                               lodev_dev = st_buf.st_rdev;
-                       free(name);
-#endif
                        file_dev = st_buf.st_dev;
                        file_ino = st_buf.st_ino;
                }
@@ -88,10 +74,15 @@ static int check_mntent_file(const char *mtab_file, const char *file,
 
                if (S_ISBLK(st_buf.st_mode)) {
 #ifndef __GNU__
-                       if ((file_rdev && file_rdev == st_buf.st_rdev) ||
-                           (lodev_dev && lodev_dev == st_buf.st_rdev)) {
+                       if (file_rdev && file_rdev == st_buf.st_rdev)
                                break;
-                       }
+#ifdef __linux__
+                       /* maybe the file is loopdev backing file */
+                       if (file_dev
+                           && major(st_buf.st_rdev) == LOOPDEV_MAJOR
+                           && loopdev_is_used(mnt->mnt_fsname, file, 0, 0))
+                               break;
+#endif /* __linux__ */
 #endif /* __GNU__ */
                } else {
                        if (file_dev && ((file_dev == st_buf.st_dev) &&