:: commit 7c4f71e5321e631e43c3fc52d157074b791e50f4

mintsuki <mintsuki@protonmail.com> — 2021-03-07 02:03

parents: d62e9a49a5

fat32: Fix base calculation for cluster sizes of more than 1 sector

diff --git a/limine-pxe.bin b/limine-pxe.bin
index fe440cf8..3f848d8d 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 2c71298e..3f9ab63e 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index d0b5a4fb..4f7aeed3 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/fs/fat32.c b/stage2/fs/fat32.c
index b36e000e..7dd84e56 100644
--- a/stage2/fs/fat32.c
+++ b/stage2/fs/fat32.c
@@ -95,17 +95,13 @@ static int fat32_init_context(struct fat32_context* context, struct part *part)
 }
 
 static int fat32_read_cluster_from_map(struct fat32_context* context, uint32_t cluster, uint32_t* out) {
-    const uint32_t sector = cluster / (FAT32_SECTOR_SIZE / 4);
-    const uint32_t offset = cluster % (FAT32_SECTOR_SIZE / 4);
-
-    uint32_t clusters[FAT32_SECTOR_SIZE / sizeof(uint32_t)];
-    int r = part_read(&context->part, &clusters[0], (context->fat_start_lba + sector) * FAT32_SECTOR_SIZE, sizeof(clusters));
+    int r = part_read(&context->part, out, context->fat_start_lba * FAT32_SECTOR_SIZE + cluster * sizeof(uint32_t), sizeof(uint32_t));
 
     if (r) {
         return r;
     }
 
-    *out = clusters[offset] & 0x0FFFFFFF;
+    *out &= 0x0fffffff;
     return 0;
 }
 
@@ -143,7 +139,7 @@ static bool read_cluster_chain(struct fat32_context *context,
         if (chunk > block_size - offset)
             chunk = block_size - offset;
 
-        uint64_t base = (context->data_start_lba + (cluster_chain[block] - 2)) * block_size;
+        uint64_t base = (context->data_start_lba + (cluster_chain[block] - 2) * context->sectors_per_cluster) * FAT32_SECTOR_SIZE;
         int r = part_read(&context->part, buf + progress, base + offset, chunk);
 
         if (r)
tab: 248 wrap: offon