Tue, 25 Apr 2023 18:29:01 +0200
5 files changed,
11 insertions(+),
14 deletions(-)
M
include/cedos/fat.h
→
include/cedos/fat.h
@@ -6,7 +6,7 @@
#include "cedos/file.h" void FAT_init(); -int FAT_dir_next(int fd, int index, char *fname_buffer); +int FAT_dir_next(file_t *file, int index, char *fname_buffer); int FAT_openat(file_t *root, file_t *handle, const char *fname, int flags); uint32_t FAT_read(file_t *file, void *buffer, int count);
M
include/cedos/file.h
→
include/cedos/file.h
@@ -25,7 +25,7 @@ int (*open)(const char *pathname, int flags);
int (*openat)(file_t *root, file_t *handle, const char *fname, int flags); int (*read)(file_t *file, char *buffer, uint32_t size); int (*write)(file_t *file, char *buffer, uint32_t size); - int (*dir_next)(int fd, int index, char *fname_buffer); + int (*dir_next)(file_t *file, int index, char *fname_buffer); }; int file_init();
M
src/kernel/fat.c
→
src/kernel/fat.c
@@ -179,15 +179,12 @@ return index + 1;
} } -int FAT_dir_next(int fd, int index, char *fname_buffer) { +int FAT_dir_next(file_t *file, int index, char *fname_buffer) { uint16_t first_cluster; uint32_t file_size; - if (fd == 0x1000) { - return FAT_root_dir_next(index, fname_buffer, &first_cluster, &file_size); - } else { - return -1; - } + // TODO: subdirectories + return FAT_root_dir_next(index, fname_buffer, &first_cluster, &file_size); } uint16_t FAT_next_cluster(uint16_t cluster) {
M
src/kernel/file.c
→
src/kernel/file.c
@@ -78,9 +78,9 @@ file->fops->write(file, buffer, size);
} int file_dir_next(int fd, int index, char *fname_buffer) { - if (fd & 0x1000) { - return FAT_dir_next(fd, index, fname_buffer); - } else { - return -1; - } + file_t *file = &file_table[fd]; + + if (file->fops->dir_next == NULL) { return -1; } + + file->fops->dir_next(file, index, fname_buffer); }
M
src/shell/ls.c
→
src/shell/ls.c
@@ -9,7 +9,7 @@
int index = 0; while (1) { - int next = dir_next(0x1000, index, buffer); + int next = dir_next(2, index, buffer); if (next == -1) { return; }