Skip to content

Commit a2722aa

Browse files
fix VFAT directory corruption
1 parent 392997e commit a2722aa

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

Diff for: system/libstm32l4_dragonfly/dosfs_core.c

+31-14
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,11 @@ static int dosfs_volume_commit(dosfs_volume_t *volume)
17201720
if (status == F_NO_ERROR)
17211721
{
17221722
status = dosfs_dir_cache_read(volume, blkno, &entry);
1723+
1724+
if (status == F_NO_ERROR)
1725+
{
1726+
dir = (dosfs_dir_t*)((void*)(entry->data));
1727+
}
17231728
}
17241729
}
17251730

@@ -1843,6 +1848,11 @@ static int dosfs_volume_commit(dosfs_volume_t *volume)
18431848
if (status == F_NO_ERROR)
18441849
{
18451850
status = dosfs_dir_cache_read(volume, blkno, &entry);
1851+
1852+
if (status == F_NO_ERROR)
1853+
{
1854+
dir = (dosfs_dir_t*)((void*)(entry->data));
1855+
}
18461856
}
18471857
}
18481858

@@ -2411,26 +2421,23 @@ static int dosfs_volume_format(dosfs_volume_t *volume)
24112421
* this CHS range, then use the maximum value. This can only happen with FAT32,
24122422
* in which case the partition type signals to use LBA anyway.
24132423
*/
2414-
if (sys_id == 0x0c)
2415-
{
2416-
start_c = 1023;
2417-
start_h = 254;
2418-
start_s = 63;
2424+
2425+
start_c = boot_blkno / (hpc * spt);
2426+
start_h = (boot_blkno - (start_c * hpc * spt)) / spt;
2427+
start_s = boot_blkno - (start_c * hpc * spt) - (start_h * spt) + 1;
24192428

2420-
end_c = 1023;
2421-
end_h = 254;
2422-
end_s = 63;
2423-
}
2424-
else
2429+
if (blkcnt <= 16450560)
24252430
{
2426-
start_c = boot_blkno / (hpc * spt);
2427-
start_h = (boot_blkno - (start_c * hpc * spt)) / spt;
2428-
start_s = boot_blkno - (start_c * hpc * spt) - (start_h * spt) + 1;
2429-
24302431
end_c = (blkcnt-1) / (hpc * spt);
24312432
end_h = ((blkcnt-1) - (end_c * hpc * spt)) / spt;
24322433
end_s = (blkcnt-1) - (end_c * hpc * spt) - (end_h * spt) + 1;
24332434
}
2435+
else
2436+
{
2437+
end_c = 1023;
2438+
end_h = 254;
2439+
end_s = 63;
2440+
}
24342441

24352442
/* Write the MBR */
24362443

@@ -7460,6 +7467,11 @@ static int dosfs_path_create_entry(dosfs_volume_t *volume, uint32_t clsno_d, uin
74607467
if (status == F_NO_ERROR)
74617468
{
74627469
status = dosfs_dir_cache_read(volume, blkno, &entry);
7470+
7471+
if (status == F_NO_ERROR)
7472+
{
7473+
dir = (dosfs_dir_t*)((void*)(entry->data));
7474+
}
74637475
}
74647476
}
74657477

@@ -7603,6 +7615,11 @@ static int dosfs_path_destroy_entry(dosfs_volume_t *volume, uint32_t clsno, uint
76037615
if (status == F_NO_ERROR)
76047616
{
76057617
status = dosfs_dir_cache_read(volume, blkno, &entry);
7618+
7619+
if (status == F_NO_ERROR)
7620+
{
7621+
dir = (dosfs_dir_t*)((void*)(entry->data));
7622+
}
76067623
}
76077624
}
76087625

Diff for: variants/dragonfly/libstm32l4_dragonfly.a

-432 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)