3 exFAT file system implementation library.
5 Free exFAT implementation.
6 Copyright (C) 2010-2018 Andrew Nayenko
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 int exfat_errors_fixed;
28 bool exfat_ask_to_fix(const struct exfat* ef)
30 const char* question = "Fix (Y/N)?";
38 case EXFAT_REPAIR_YES:
39 printf("%s %s", question, "Y\n");
41 case EXFAT_REPAIR_ASK:
44 printf("%s ", question);
46 if (fgets(answer, sizeof(answer), stdin))
48 yeah = strcasecmp(answer, "Y\n") == 0;
49 nope = strcasecmp(answer, "N\n") == 0;
57 while (!yeah && !nope);
60 exfat_bug("invalid repair option value: %d", ef->repair);
63 bool exfat_fix_invalid_vbr_checksum(const struct exfat* ef, void* sector,
64 uint32_t vbr_checksum)
67 off_t sector_size = SECTOR_SIZE(*ef->sb);
69 for (i = 0; i < sector_size / sizeof(vbr_checksum); i++)
70 ((le32_t*) sector)[i] = cpu_to_le32(vbr_checksum);
71 if (exfat_pwrite(ef->dev, sector, sector_size, 11 * sector_size) < 0)
73 exfat_error("failed to write correct VBR checksum");
80 bool exfat_fix_invalid_node_checksum(const struct exfat* ef,
81 struct exfat_node* node)
83 /* checksum will be rewritten by exfat_flush_node() */
84 node->is_dirty = true;
90 bool exfat_fix_unknown_entry(struct exfat* ef, struct exfat_node* dir,
91 const struct exfat_entry* entry, off_t offset)
93 struct exfat_entry deleted = *entry;
95 deleted.type &= ~EXFAT_ENTRY_VALID;
96 if (exfat_generic_pwrite(ef, dir, &deleted, sizeof(struct exfat_entry),
97 offset) != sizeof(struct exfat_entry))
100 exfat_errors_fixed++;