Whamcloud - gitweb
libext2fs: fix EXT2FS_PRETEND_* on non-Linux systems
authorTheodore Ts'o <tytso@mit.edu>
Tue, 7 Jun 2016 15:44:54 +0000 (11:44 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 7 Jun 2016 15:44:54 +0000 (11:44 -0400)
The debugging environment variables EXT2FS_PRETEND_* were implemented
in check_mntent_file(), and this function isn't called on all
operating systems.  Lift this code up to ext2fs_check_mount_point(),
so that these environment variables (which are used in the regression
test suite) will work on all platforms.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ismounted.c

index e0f69dd..bcac0f1 100644 (file)
@@ -102,19 +102,6 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
 
        *mount_flags = 0;
 
-       if (getenv("EXT2FS_PRETEND_RO_MOUNT")) {
-               *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_READONLY;
-               if (getenv("EXT2FS_PRETEND_ROOTFS"))
-                       *mount_flags = EXT2_MF_ISROOT;
-               return 0;
-       }
-       if (getenv("EXT2FS_PRETEND_RW_MOUNT")) {
-               *mount_flags = EXT2_MF_MOUNTED;
-               if (getenv("EXT2FS_PRETEND_ROOTFS"))
-                       *mount_flags = EXT2_MF_ISROOT;
-               return 0;
-       }
-
        if ((f = setmntent (mtab_file, "r")) == NULL) {
                if (errno == ENOENT) {
                        if (getenv("EXT2FS_NO_MTAB_OK"))
@@ -377,6 +364,19 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
 {
        errcode_t       retval = 0;
 
+       if (getenv("EXT2FS_PRETEND_RO_MOUNT")) {
+               *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_READONLY;
+               if (getenv("EXT2FS_PRETEND_ROOTFS"))
+                       *mount_flags = EXT2_MF_ISROOT;
+               return 0;
+       }
+       if (getenv("EXT2FS_PRETEND_RW_MOUNT")) {
+               *mount_flags = EXT2_MF_MOUNTED;
+               if (getenv("EXT2FS_PRETEND_ROOTFS"))
+                       *mount_flags = EXT2_MF_ISROOT;
+               return 0;
+       }
+
        if (is_swap_device(device)) {
                *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP;
                strncpy(mtpt, "<swap>", mtlen);