OSDN Git Service

Retry to mount FS in read-only mode if device is write-protected.
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sun, 27 Nov 2011 10:07:11 +0000 (10:07 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sun, 27 Nov 2011 10:07:11 +0000 (10:07 +0000)
This behavior is enabled by "ro_fallback" option. When an attempt to mount in RW mode fails and "ro_fallback" option is present, we try to mount in RO mode. If this succeeds, we set ro_fallback flag so that the caller could add "ro" option for FUSE.

git-svn-id: http://exfat.googlecode.com/svn/trunk@236 60bc1c72-a15a-11de-b98f-4500b42dc123

fuse/main.c
libexfat/exfat.h
libexfat/mount.c

index fe5666b..a813427 100644 (file)
@@ -37,7 +37,7 @@
        #error FUSE 2.6 or later is required
 #endif
 
-const char* default_options = "allow_other,blkdev";
+const char* default_options = "ro_fallback,allow_other,blkdev";
 
 struct exfat ef;
 
@@ -426,6 +426,16 @@ int main(int argc, char* argv[])
                return 1;
        }
 
+       if (ef.ro_fallback)
+       {
+               mount_options = add_option(mount_options, "ro", NULL);
+               if (mount_options == NULL)
+               {
+                       exfat_unmount(&ef);
+                       return 1;
+               }
+       }
+
        mount_options = add_fuse_options(mount_options, spec);
        if (mount_options == NULL)
        {
index b7ee139..de2e1a2 100644 (file)
@@ -92,6 +92,7 @@ struct exfat
        uid_t uid;
        gid_t gid;
        int ro;
+       int ro_fallback;
        int noatime;
 };
 
index 254a3e6..2b34508 100644 (file)
@@ -127,7 +127,15 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
 
        ef->fd = exfat_open(spec, ef->ro);
        if (ef->fd < 0)
-               return -EIO;
+       {
+               if (ef->ro || !match_option(options, "ro_fallback"))
+                       return -EIO;
+               ef->fd = exfat_open(spec, 1);
+               if (ef->fd < 0)
+                       return -EIO;
+               exfat_warn("device is write-protected, mounting read-only");
+               ef->ro_fallback = ef->ro = 1;
+       }
 
        ef->sb = malloc(sizeof(struct exfat_super_block));
        if (ef->sb == NULL)