From a4c485587e464d93f6e7a4ae039bca0e3809d4af Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sun, 1 Mar 2026 14:03:03 +0100 Subject: [PATCH] FatFS add dir checks --- ce/ce.c | 5 ++++- kernel/fs/fatfs.c | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ce/ce.c b/ce/ce.c index 831444a..e1f07dd 100644 --- a/ce/ce.c +++ b/ce/ce.c @@ -431,10 +431,13 @@ static void ls (struct context* context, const char* path_string) { cprintf (context, "\n"); for (size_t entry_num = 0; entry_num < entries; entry_num++) { + memset (&desc, 0, sizeof (desc)); + memset (&entry, 0, sizeof (entry)); + read_dir_entry (path, &entry, entry_num); describe (entry.path, &desc); - cprintf (context, "%-40s%c %-40zu\n", entry.path, (desc.type == FS_DIR ? '*' : ' '), desc.size); + cprintf (context, "%c%-40s %-40zu\n", (desc.type == FS_DIR ? '*' : ' '), entry.path, desc.size); } volume_close (); diff --git a/kernel/fs/fatfs.c b/kernel/fs/fatfs.c index 0626d8e..d5e7394 100644 --- a/kernel/fs/fatfs.c +++ b/kernel/fs/fatfs.c @@ -179,6 +179,9 @@ int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe size_t size) { struct fatfs_ctx* fatfs_ctx = volume->udata; + if (fl_is_dir (fatfs_ctx, path)) + return -ST_NOT_FOUND; + FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+"); if (file == NULL) @@ -196,6 +199,9 @@ int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buff size_t size) { struct fatfs_ctx* fatfs_ctx = volume->udata; + if (fl_is_dir (fatfs_ctx, path)) + return -ST_NOT_FOUND; + FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+"); if (file == NULL) @@ -214,6 +220,9 @@ int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di struct fatfs_ctx* fatfs_ctx = volume->udata; FL_DIR dir; + if (!fl_is_dir (fatfs_ctx, path)) + return -ST_NOT_FOUND; + if (fl_opendir (fatfs_ctx, path, &dir) == NULL) return -ST_NOT_FOUND;