39 u32 entries_per_sector =
fat16.bytes_per_sector / 32;
40 u32 root_dir_sectors =
41 ((
fat16.root_entry_count * 32) +
fat16.bytes_per_sector - 1) /
42 fat16.bytes_per_sector;
45 for (
u32 i = 0; i < root_dir_sectors; i++) {
47 for (
u32 j = 0; j < entries_per_sector; j++) {
50 if (entry[0] == 0x00) {
54 if (entry[0] == 0xE5) {
60 Padname(filename, name_pad, 8);
61 Padname(ext, ext_pad, 3);
64 if (
Kmemcmp(entry, name_pad, 8) == 0 &&
65 Kmemcmp(entry + 8, ext_pad, 3) == 0) {
73 u16 cluster = entry[26] | (entry[27] << 8);
74 while (cluster >= 0x0002 && cluster <= 0xFFEF) {
75 u32 fat_offset = cluster * 2;
76 u32 fat_sector =
fat16.fat_start_lba + (fat_offset / 512);
77 u32 fat_index = fat_offset % 512;
84 fatbuf[fat_index] | (fatbuf[fat_index + 1] << 8);
87 fatbuf[fat_index] = 0x00;
88 fatbuf[fat_index + 1] = 0x00;
91 cluster = next_cluster;