Implement read_dir_entry () VFS op, CE add ls command

This commit is contained in:
2026-02-25 16:25:43 +01:00
parent 704db2dfa4
commit 29bbcea435
12 changed files with 189 additions and 23 deletions

View File

@@ -4,6 +4,7 @@
#include <fs/vfs.h>
#include <libk/align.h>
#include <libk/minmax.h>
#include <libk/printf.h>
#include <libk/std.h>
#include <libk/string.h>
#include <limine/requests.h>
@@ -114,22 +115,35 @@ int tarfs_mount (struct vfs_volume* volume, struct proc* proc, struct reschedule
}
int tarfs_describe (struct vfs_volume* volume, const char* path, struct desc* desc) {
(void)volume;
struct tarfs* tarfs = volume->udata;
const char* filename = path_basename (path);
if (strncmp (path, "/", PATH_MAX) == 0) {
desc->size = 0;
desc->type = FS_DIR;
if (filename == NULL)
return -ST_BAD_PATH;
for (size_t i = 0; i < TARFS_FILES_MAX; i++) {
if (tarfs->tarfs_files[i].header != NULL) {
desc->size++;
}
}
struct tar_file* file = tar_get_file ((struct tarfs*)volume->udata, filename);
return ST_OK;
} else {
const char* filename = path_basename (path);
if (file == NULL)
return -ST_NOT_FOUND;
if (filename == NULL)
return -ST_BAD_PATH;
desc->size = file->size;
desc->type = FS_FILE;
struct tar_file* file = tar_get_file (tarfs, filename);
return ST_OK;
if (file == NULL)
return -ST_NOT_FOUND;
desc->size = file->size;
desc->type = FS_FILE;
return ST_OK;
}
}
int tarfs_read (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
@@ -150,3 +164,30 @@ int tarfs_read (struct vfs_volume* volume, const char* path, uint8_t* buffer, si
return ST_OK;
}
int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num) {
struct tarfs* tarfs = volume->udata;
if (strncmp (path, "/", PATH_MAX) != 0) {
return -ST_NOT_DIR;
}
struct tar_file* tar_file = NULL;
size_t entry_counter = 0;
for (size_t i = 0; i < TARFS_FILES_MAX; i++) {
if ((tarfs->tarfs_files[i].header != NULL) && (entry_num == entry_counter)) {
tar_file = &tarfs->tarfs_files[i];
break;
}
entry_counter++;
}
if (tar_file != NULL) {
sprintf (entry->path, "/%s", tar_file->header->filename);
return ST_NOT_DIR;
}
return ST_DIR_NO_ENTRIES;
}