OSDN Git Service

Allow mounting a read-only exFAT file system q-x86
authorserver158 <server158@openthos.org>
Mon, 1 Jun 2020 11:34:05 +0000 (19:34 +0800)
committerserver158 <server158@openthos.org>
Mon, 1 Jun 2020 11:34:05 +0000 (19:34 +0800)
If exfat::Check() fails, re-check the file system in read-only mode.
The logic is similar to exfat::Mount().

fs/Exfat.cpp

index 5cc6d36..4ed99b4 100644 (file)
@@ -42,17 +42,18 @@ bool IsSupported() {
 status_t Check(const std::string& source) {
     std::vector<std::string> cmd;
     cmd.push_back(kFsckPath);
+    cmd.push_back("-a");
     cmd.push_back(source);
 
     int rc = ForkExecvp(cmd, nullptr, sFsckUntrustedContext);
     if (rc == 0) {
         LOG(INFO) << "Check OK";
         return 0;
-    } else {
-        LOG(ERROR) << "Check failed (code " << rc << ")";
-        errno = EIO;
-        return -1;
     }
+
+    // don't write anything to the file system
+    cmd[1] = "-n";
+    return ForkExecvp(cmd, nullptr, sFsckUntrustedContext);
 }
 
 status_t Mount(const std::string& source, const std::string& target, int ownerUid, int ownerGid,