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.
#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;
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)
{
uid_t uid;
gid_t gid;
int ro;
+ int ro_fallback;
int noatime;
};
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)