mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[CHKDSK][VFATLIB] Chkdsk should not write unless using "-F" switch. (#8826)
CORE-20539 Before calling "fs_write" test if we are in a read-write mode by checking "rw". I intend to re-evaluate this to try and reduce the difference to dosfschk in the future. Co-authored-by: Hermès BÉLUSCA - MAÏTO <[email protected]>
This commit is contained in:
co-authored by
Hermès BÉLUSCA - MAÏTO
parent
57664f1c1e
commit
2a2aaf98d4
@@ -118,11 +118,21 @@ void read_fat(DOS_FS * fs)
|
||||
second_ok = (second_media.value & FAT_EXTD(fs)) == FAT_EXTD(fs);
|
||||
if (first_ok && !second_ok) {
|
||||
printf("FATs differ - using first FAT.\n");
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
#else
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
#endif
|
||||
}
|
||||
if (!first_ok && second_ok) {
|
||||
printf("FATs differ - using second FAT.\n");
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(fs->fat_start, eff_size, second);
|
||||
#else
|
||||
fs_write(fs->fat_start, eff_size, second);
|
||||
#endif
|
||||
memcpy(first, second, eff_size);
|
||||
}
|
||||
if (first_ok && second_ok) {
|
||||
@@ -130,15 +140,30 @@ void read_fat(DOS_FS * fs)
|
||||
printf("FATs differ but appear to be intact. Use which FAT ?\n"
|
||||
"1) Use first FAT\n2) Use second FAT\n");
|
||||
if (get_key("12", "?") == '1') {
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
#else
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(fs->fat_start, eff_size, second);
|
||||
#else
|
||||
fs_write(fs->fat_start, eff_size, second);
|
||||
#endif
|
||||
memcpy(first, second, eff_size);
|
||||
}
|
||||
} else {
|
||||
printf("FATs differ but appear to be intact. Using first "
|
||||
"FAT.\n");
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
#else
|
||||
fs_write(fs->fat_start + fs->fat_size, eff_size, first);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (!first_ok && !second_ok) {
|
||||
@@ -249,10 +274,17 @@ void set_fat(DOS_FS * fs, uint32_t cluster, int32_t new)
|
||||
default:
|
||||
die("Bad FAT entry size: %d bits.", fs->fat_bits);
|
||||
}
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
{
|
||||
#endif
|
||||
fs_write(offs, size, data);
|
||||
if (fs->nfats > 1) {
|
||||
fs_write(offs + fs->fat_size, size, data);
|
||||
}
|
||||
#ifdef __REACTOS__
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int bad_cluster(DOS_FS * fs, uint32_t cluster)
|
||||
@@ -514,7 +546,12 @@ void reclaim_file(DOS_FS * fs)
|
||||
de.size = htole32(le32toh(de.size) + fs->cluster_size);
|
||||
reclaimed++;
|
||||
}
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(offset, sizeof(DIR_ENT), &de);
|
||||
#else
|
||||
fs_write(offset, sizeof(DIR_ENT), &de);
|
||||
#endif
|
||||
}
|
||||
if (reclaimed)
|
||||
printf("Reclaimed %d unused cluster%s (%llu bytes) in %d chain%s.\n",
|
||||
@@ -556,8 +593,10 @@ uint32_t update_free(DOS_FS * fs)
|
||||
else
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
#endif
|
||||
printf(" Auto-correcting.\n");
|
||||
#else
|
||||
printf(" Auto-correcting.\n");
|
||||
#endif
|
||||
#ifndef __REACTOS__
|
||||
if (!interactive || get_key("12", "?") == '1')
|
||||
#else
|
||||
@@ -580,6 +619,14 @@ uint32_t update_free(DOS_FS * fs)
|
||||
if (do_set) {
|
||||
uint32_t le_free = htole32(free);
|
||||
fs->free_clusters = free;
|
||||
#ifdef __REACTOS__
|
||||
if (rw)
|
||||
fs_write(fs->fsinfo_start + offsetof(struct info_sector, free_clusters),
|
||||
sizeof(le_free), &le_free);
|
||||
#else
|
||||
fs_write(fs->fsinfo_start + offsetof(struct info_sector, free_clusters),
|
||||
sizeof(le_free), &le_free);
|
||||
#endif
|
||||
fs_write(fs->fsinfo_start + offsetof(struct info_sector, free_clusters),
|
||||
sizeof(le_free), &le_free);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user