From d22d5ab2e46b256448e08157a0835ee8c4774e07 Mon Sep 17 00:00:00 2001 From: kaguya Date: Sun, 26 Apr 2026 02:10:46 -0400 Subject: [PATCH] mp: separate VFS read and write functions into internal implementations with locking In preparation for the inevitable switch to a MP supported setup, I have added spinlocks to the VFS_Read and VFS_Write implementations If I had forgotten to do this, everything would've blown up, the world would have ended, and Israel would no longer exist. Signed-off-by: kaguya --- src/fs/vfs.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/fs/vfs.c b/src/fs/vfs.c index 72b12b3..e4f42d8 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -106,7 +106,7 @@ int VFS_Close(fd_t fd) { return resp; } -int VFS_Read(fd_t fd, uint8_t* buf, size_t size) +int VFS_Read_internal(fd_t fd, uint8_t* buf, size_t size) { if (fd < 0 || fd >= VFS_MAX_FDS) return -1; @@ -154,7 +154,16 @@ int VFS_Read(fd_t fd, uint8_t* buf, size_t size) } } -int VFS_Write(fd_t file, uint8_t* data, size_t size) +int VFS_Read(fd_t fd, uint8_t* buf, size_t size) +{ + uint64_t flags; + spinlock_acquire_irqsave(&s_vfs_lock, &flags); + int resp = VFS_Read_internal(fd, buf, size); + spinlock_release_irqrestore(&s_vfs_lock, flags); + return resp; +} + +int VFS_Write_internal(fd_t file, uint8_t* data, size_t size) { switch (file) { @@ -209,4 +218,13 @@ int VFS_Write(fd_t file, uint8_t* data, size_t size) } return -1; +} + +int VFS_Write(fd_t file, uint8_t* data, size_t size) +{ + uint64_t flags; + spinlock_acquire_irqsave(&s_vfs_lock, &flags); + int resp = VFS_Write_internal(file, data, size); + spinlock_release_irqrestore(&s_vfs_lock, flags); + return resp; } \ No newline at end of file