]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/Lib/exfat/src/libexfat/repair.c
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
);
64 bool exfat_fix_invalid_vbr_checksum(const struct exfat
* ef
, void* sector
,
65 uint32_t vbr_checksum
)
68 off_t sector_size
= SECTOR_SIZE(*ef
->sb
);
70 for (i
= 0; i
< sector_size
/ sizeof(vbr_checksum
); i
++)
71 ((le32_t
*) sector
)[i
] = cpu_to_le32(vbr_checksum
);
72 if (exfat_pwrite(ef
->dev
, sector
, sector_size
, 11 * sector_size
) < 0)
74 exfat_error("failed to write correct VBR checksum");
81 bool exfat_fix_invalid_node_checksum(const struct exfat
* ef
,
82 struct exfat_node
* node
)
84 /* checksum will be rewritten by exfat_flush_node() */
85 node
->is_dirty
= true;
91 bool exfat_fix_unknown_entry(struct exfat
* ef
, struct exfat_node
* dir
,
92 const struct exfat_entry
* entry
, off_t offset
)
94 struct exfat_entry deleted
= *entry
;
96 deleted
.type
&= ~EXFAT_ENTRY_VALID
;
97 if (exfat_generic_pwrite(ef
, dir
, &deleted
, sizeof(struct exfat_entry
),
98 offset
) != sizeof(struct exfat_entry
))
101 exfat_errors_fixed
++;