Create libioutil, implement a filewriter
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m21s

This commit is contained in:
2026-03-02 22:47:10 +01:00
parent 27afd57427
commit 58c515e90a
28 changed files with 231 additions and 29 deletions

View File

@@ -14,6 +14,7 @@
#include <path_defs.h>
#include <status.h>
#include <sys/debug.h>
#include <write_file.h>
static int fat1_diskio_read (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* buffer,
uint32_t sector_count) {
@@ -196,13 +197,18 @@ int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
}
int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size) {
size_t size, uint32_t flags) {
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+");
FL_FILE* file;
if ((flags & WF_APPEND))
file = fl_fopen (fatfs_ctx, path, "wb+");
else
file = fl_fopen (fatfs_ctx, path, "wb");
if (file == NULL)
return -ST_NOT_FOUND;

View File

@@ -22,7 +22,7 @@ int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
size_t size);
int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size);
size_t size, uint32_t flags);
int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num);

View File

@@ -199,8 +199,8 @@ int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
}
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size) {
(void)volume, (void)path, (void)buffer, (void)off, (void)size;
size_t size, uint32_t flags) {
(void)volume, (void)path, (void)buffer, (void)off, (void)size, (void)flags;
return ST_OK;
}

View File

@@ -44,7 +44,7 @@ int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
size_t size);
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size);
size_t size, uint32_t flags);
int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num);

View File

@@ -206,7 +206,7 @@ int vfs_read_file (struct proc* proc, const char* volume_name, const char* path,
}
int vfs_write_file (struct proc* proc, const char* volume_name, const char* path, uint8_t* buffer,
size_t off, size_t size) {
size_t off, size_t size, uint32_t flags) {
struct vfs_volume* volume = vfs_find_volume (volume_name);
if (volume == NULL)
@@ -221,7 +221,7 @@ int vfs_write_file (struct proc* proc, const char* volume_name, const char* path
spin_unlock (&volume->lock);
return volume->driver_ops.write_file (volume, path, buffer, off, size);
return volume->driver_ops.write_file (volume, path, buffer, off, size, flags);
}
int vfs_create_file (struct proc* proc, const char* volume_name, const char* path) {

View File

@@ -42,7 +42,7 @@ struct vfs_volume {
size_t size);
int (*write_file) (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
size_t size);
size_t size, uint32_t flags);
int (*read_dir_entry) (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
size_t entry_num);
@@ -70,7 +70,7 @@ int vfs_read_file (struct proc* proc, const char* volume, const char* path, uint
size_t off, size_t size);
int vfs_write_file (struct proc* proc, const char* volume, const char* path, uint8_t* buffer,
size_t off, size_t size);
size_t off, size_t size, uint32_t flags);
int vfs_describe (struct proc* proc, const char* volume, const char* path, struct desc* desc);

View File

@@ -21,6 +21,7 @@
#include <sys/proc.h>
#include <syscall/syscall.h>
#include <syscall_defs.h>
#include <write_file.h>
#define DEFINE_SYSCALL(name) \
uintptr_t name (struct proc* UNUSED proc, void* UNUSED regs, struct reschedule_ctx* UNUSED rctx, \
@@ -503,12 +504,13 @@ DEFINE_SYSCALL (sys_create_file) {
return SYSRESULT (ret);
}
/* int write_file (char* path, size_t off, uint8_t* buffer, size_t size) */
/* int write_file (char* path, size_t off, uint8_t* buffer, size_t size, uint32_t flags) */
DEFINE_SYSCALL (sys_write_file) {
uintptr_t uvaddr_path = a1;
size_t off = (size_t)a2;
uintptr_t uvaddr_buffer = a3;
size_t size = (size_t)a4;
uint32_t flags = (uint32_t)a5;
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
@@ -529,7 +531,7 @@ DEFINE_SYSCALL (sys_write_file) {
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
spin_lock (&proc->lock);
int ret = vfs_write_file (proc, proc->cwv, path, buffer, off, size);
int ret = vfs_write_file (proc, proc->cwv, path, buffer, off, size, flags);
spin_unlock (&proc->lock);
return SYSRESULT (ret);