Implement read_dir_entry () VFS op, CE add ls command
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <desc.h>
|
||||
#include <device/device.h>
|
||||
#include <dir_entry.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/reschedule.h>
|
||||
@@ -40,4 +41,7 @@ int tarfs_describe (struct vfs_volume* volume, const char* path, struct desc* de
|
||||
int tarfs_read (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
|
||||
size_t size);
|
||||
|
||||
int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
|
||||
size_t entry_num);
|
||||
|
||||
#endif // _KERNEL_FS_TARFS_H
|
||||
|
||||
@@ -56,6 +56,7 @@ int vfs_create_volume (const char* key, int fs_type, struct device* back_device,
|
||||
volume->driver_ops.mount = &tarfs_mount;
|
||||
volume->driver_ops.describe = &tarfs_describe;
|
||||
volume->driver_ops.read = &tarfs_read;
|
||||
volume->driver_ops.read_dir_entry = &tarfs_read_dir_entry;
|
||||
} break;
|
||||
default: {
|
||||
free (volume);
|
||||
@@ -147,7 +148,7 @@ int vfs_volume_close (struct proc* proc, const char* volume_name, struct resched
|
||||
}
|
||||
|
||||
int vfs_read (struct proc* proc, const char* volume_name, const char* path, uint8_t* buffer,
|
||||
size_t off, size_t size, struct reschedule_ctx* rctx) {
|
||||
size_t off, size_t size) {
|
||||
struct vfs_volume* volume = vfs_find_volume (volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
@@ -165,8 +166,7 @@ int vfs_read (struct proc* proc, const char* volume_name, const char* path, uint
|
||||
return volume->driver_ops.read (volume, path, buffer, off, size);
|
||||
}
|
||||
|
||||
int vfs_describe (struct proc* proc, const char* volume_name, const char* path, struct desc* desc,
|
||||
struct reschedule_ctx* rctx) {
|
||||
int vfs_describe (struct proc* proc, const char* volume_name, const char* path, struct desc* desc) {
|
||||
struct vfs_volume* volume = vfs_find_volume (volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
@@ -184,6 +184,25 @@ int vfs_describe (struct proc* proc, const char* volume_name, const char* path,
|
||||
return volume->driver_ops.describe (volume, path, desc);
|
||||
}
|
||||
|
||||
int vfs_read_dir_entry (struct proc* proc, const char* volume_name, const char* path,
|
||||
struct dir_entry* entry, size_t entry_num) {
|
||||
struct vfs_volume* volume = vfs_find_volume (volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
spin_lock (&volume->lock);
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
spin_unlock (&volume->lock);
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
spin_unlock (&volume->lock);
|
||||
|
||||
return volume->driver_ops.read_dir_entry (volume, path, entry, entry_num);
|
||||
}
|
||||
|
||||
void vfs_init (void) {
|
||||
memset (&volume_table, 0, sizeof (volume_table));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <desc.h>
|
||||
#include <device/device.h>
|
||||
#include <dir_entry.h>
|
||||
#include <libk/hash.h>
|
||||
#include <libk/list.h>
|
||||
#include <libk/rbtree.h>
|
||||
@@ -35,6 +36,9 @@ struct vfs_volume {
|
||||
|
||||
int (*read) (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
|
||||
size_t size);
|
||||
|
||||
int (*read_dir_entry) (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
|
||||
size_t entry_num);
|
||||
} driver_ops;
|
||||
struct device* back_device;
|
||||
void* udata
|
||||
@@ -53,10 +57,12 @@ int vfs_volume_open (struct proc* proc, const char* volume, struct reschedule_ct
|
||||
int vfs_volume_close (struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
|
||||
|
||||
int vfs_read (struct proc* proc, const char* volume, const char* path, uint8_t* buffer, size_t off,
|
||||
size_t size, struct reschedule_ctx* rctx);
|
||||
size_t size);
|
||||
|
||||
int vfs_describe (struct proc* proc, const char* volume, const char* path, struct desc* desc,
|
||||
struct reschedule_ctx* rctx);
|
||||
int vfs_describe (struct proc* proc, const char* volume, const char* path, struct desc* desc);
|
||||
|
||||
int vfs_read_dir_entry (struct proc* proc, const char* volume, const char* path,
|
||||
struct dir_entry* entry, size_t entry_num);
|
||||
|
||||
void vfs_init (void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user