CeDOS - Commit 736fc6c9

fat12: Add DOS name support to FAT12 driver Reason: genimage/mtools does not support VFAT-style long file names Signed-off-by: Celina Sophie Kalus <hello@celinakalus.de>
Celina Sophie Kalus
Mon, 02 Jun 2025 23:14:39 +0200
3 files changed, 16 insertions(+), 8 deletions(-)
M boot/main.cboot/main.c

@@ -73,6 +73,7 @@ print_string(" ");

if (i <= 0) { return -1; } if (!(strcmp(buffer, "kernel.bin"))) { break; } + if (!(strcmp(buffer, "KERNEL.BIN"))) { break; } } // copy all clusters

@@ -86,4 +87,4 @@ if (cluster == 0xFFF || cluster == 0x000) { break; }

} return 0; -}+}
M common/fat12.ccommon/fat12.c

@@ -152,12 +152,19 @@ *first_cluster = dir_entry.start_of_clusters;

// if no VFAT LFN exists, use DOS name if (fname_buffer[0] == 0) { - memcpy(fname_buffer, dir_entry.name, 8); - fname_buffer[8] = '.'; - memcpy(fname_buffer + 9, dir_entry.ext, 3); - fname_buffer[12] = 0; + size_t fname_len = strrstrip(fname_buffer, + dir_entry.name, sizeof(dir_entry.name)); + + if (WHITESPACE(dir_entry.ext[0])) { + goto ret_index; + } + + fname_buffer[fname_len++] = '.'; + fname_len += strrstrip(fname_buffer + fname_len, + dir_entry.ext, sizeof(dir_entry.ext)); } +ret_index: return index + 1; } }

@@ -177,4 +184,4 @@ uint16_t low = (uint16_t)(sect[0]);

uint16_t high = (uint16_t)(sect[1] & 0x0F) << 8; return low | high; } -}+}
M kernel/fat.ckernel/fat.c

@@ -68,7 +68,7 @@

i = FAT12_root_dir_next(fat_desc, i, buffer, &first_cluster, &file_size); if (i <= 0) { return -1; } - if (strcmp(buffer, fname) == 0) { + if (sstrcmp(buffer, fname) == 0) { // file found handle->pos = 0; handle->size = file_size;

@@ -136,4 +136,4 @@ }

off_t FAT_tell(file_t *file) { return file->pos; -}+}