OSDN Git Service

Repairing: add repair hooks file.
authorrelan <relan@users.noreply.github.com>
Sat, 11 Mar 2017 06:33:46 +0000 (09:33 +0300)
committerrelan <relan@users.noreply.github.com>
Sat, 15 Sep 2018 04:51:11 +0000 (07:51 +0300)
libexfat/Makefile.am
libexfat/exfat.h
libexfat/repair.c [new file with mode: 0644]

index 4ec9df5..d639e13 100644 (file)
@@ -33,6 +33,7 @@ libexfat_a_SOURCES = \
        mount.c \
        node.c \
        platform.h \
+       repair.c \
        time.c \
        utf.c \
        utils.c
index e7022ca..ff68465 100644 (file)
@@ -64,6 +64,9 @@
 #define BMAP_CLR(bitmap, index) \
        ((bitmap)[BMAP_BLOCK(index)] &= ~BMAP_MASK(index))
 
+#define EXFAT_REPAIR(hook, ef, ...) \
+       (exfat_ask_to_fix(ef) && exfat_fix_ ## hook(ef, __VA_ARGS__))
+
 /* The size of off_t type must be 64 bits. File systems larger than 2 GB will
    be corrupted with 32-bit off_t. */
 STATIC_ASSERT(sizeof(off_t) == 8);
@@ -139,6 +142,7 @@ struct exfat_human_bytes
 };
 
 extern int exfat_errors;
+extern int exfat_errors_fixed;
 
 void exfat_bug(const char* format, ...) PRINTF NORETURN;
 void exfat_error(const char* format, ...) PRINTF;
@@ -229,4 +233,6 @@ void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time,
                uint8_t* centisec);
 void exfat_tzset(void);
 
+bool exfat_ask_to_fix(const struct exfat* ef);
+
 #endif /* ifndef EXFAT_H_INCLUDED */
diff --git a/libexfat/repair.c b/libexfat/repair.c
new file mode 100644 (file)
index 0000000..10ec865
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+       repair.c (09.03.17)
+       exFAT file system implementation library.
+
+       Free exFAT implementation.
+       Copyright (C) 2010-2018  Andrew Nayenko
+
+       This program is free software; you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation, either version 2 of the License, or
+       (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License along
+       with this program; if not, write to the Free Software Foundation, Inc.,
+       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "exfat.h"
+#include <strings.h>
+
+int exfat_errors_fixed;
+
+bool exfat_ask_to_fix(const struct exfat* ef)
+{
+       const char* question = "Fix (Y/N)?";
+       char answer[8];
+       bool yeah, nope;
+
+       switch (ef->repair)
+       {
+       case EXFAT_REPAIR_NO:
+               return false;
+       case EXFAT_REPAIR_YES:
+               printf("%s %s", question, "Y\n");
+               return true;
+       case EXFAT_REPAIR_ASK:
+               do
+               {
+                       printf("%s ", question);
+                       fflush(stdout);
+                       if (fgets(answer, sizeof(answer), stdin))
+                       {
+                               yeah = strcasecmp(answer, "Y\n") == 0;
+                               nope = strcasecmp(answer, "N\n") == 0;
+                       }
+                       else
+                       {
+                               yeah = false;
+                               nope = true;
+                       }
+               }
+               while (!yeah && !nope);
+               return yeah;
+       }
+       exfat_bug("invalid repair option value: %d", ef->repair);
+}