From 6eea55d645f44f9b1bd4add59938ccc1897d84e0 Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Wed, 8 Jan 2020 10:14:11 +0100 Subject: [PATCH] Update SMEMFS (add synchronous primitives) + Update GladFS (add synchronous primitives) --- include/kernel/atomic.h | 2 +- include/kernel/fs/filesystem.h | 2 +- src/kernel/bootstrap/start.c | 4 +- src/kernel/devices/display/write.c | 2 +- src/kernel/devices/tty/file_op/read.c | 6 +-- src/kernel/devices/tty/file_op/write.c | 2 +- src/kernel/fs/gladfs/file/file_pos.c | 2 + src/kernel/fs/gladfs/file/read.c | 6 ++- src/kernel/fs/gladfs/file/write.c | 28 ++++++++------ src/kernel/fs/gladfs/filesystem/mount.c | 38 +++++++++++++------ src/kernel/fs/gladfs/filesystem/umount.c | 2 + src/kernel/fs/gladfs/initialize.c | 2 +- src/kernel/fs/gladfs/inode/creat.c | 8 +++- src/kernel/fs/gladfs/inode/find_first_child.c | 9 +++++ .../fs/gladfs/inode/find_next_sibling.c | 4 ++ src/kernel/fs/gladfs/inode/find_parent.c | 4 ++ src/kernel/fs/gladfs/inode/get_mode.c | 1 + src/kernel/fs/gladfs/inode/get_name.c | 8 ++++ src/kernel/fs/gladfs/inode/mkdir.c | 8 +++- .../fs/gladfs/superblock/alloc_fragdata.c | 11 ++++++ src/kernel/fs/gladfs/superblock/alloc_inode.c | 11 ++++++ .../fs/gladfs/superblock/destroy_fragdata.c | 9 +++++ .../fs/gladfs/superblock/destroy_inode.c | 11 +++++- src/kernel/fs/smemfs/file/read.c | 12 +++++- src/kernel/fs/smemfs/filesystem/mount.c | 15 +++++++- src/kernel/fs/smemfs/filesystem/umount.c | 8 ++++ src/kernel/fs/smemfs/initialize.c | 2 +- src/kernel/fs/smemfs/inode/find_first_child.c | 25 ++++++++---- .../fs/smemfs/inode/find_next_sibling.c | 22 ++++++++--- src/kernel/fs/smemfs/inode/find_parent.c | 23 +++++++---- src/kernel/fs/smemfs/inode/get_mode.c | 21 +++++++--- src/kernel/fs/smemfs/inode/get_name.c | 12 ++++++ src/kernel/fs/smemfs/inode/walk.c | 1 + src/kernel/util/atomic.s | 8 ++-- src/kernel/util/kvram.c | 6 +-- src/kernel/util/timer.c | 4 +- 36 files changed, 262 insertions(+), 77 deletions(-) create mode 100644 src/kernel/fs/smemfs/filesystem/umount.c diff --git a/include/kernel/atomic.h b/include/kernel/atomic.h index 9a74e92..9b62cc2 100644 --- a/include/kernel/atomic.h +++ b/include/kernel/atomic.h @@ -5,6 +5,6 @@ #include extern uint32_t atomic_start(void); -extern uint32_t atomic_end(void); +extern uint32_t atomic_stop(void); #endif /*__KERNEL_ATOMIC_H__*/ diff --git a/include/kernel/fs/filesystem.h b/include/kernel/fs/filesystem.h index 074f991..8aae8df 100644 --- a/include/kernel/fs/filesystem.h +++ b/include/kernel/fs/filesystem.h @@ -15,7 +15,7 @@ struct file_system_operations { void *(*mount)(void); - void *(*umount)(void); + int (*umount)(void); }; // Internal super block operations diff --git a/src/kernel/bootstrap/start.c b/src/kernel/bootstrap/start.c index 70f3b78..dbd5a17 100644 --- a/src/kernel/bootstrap/start.c +++ b/src/kernel/bootstrap/start.c @@ -145,7 +145,7 @@ int start(void) atomic_start(); fx9860_context_save(&casio_context); vhex_context_set(); - atomic_end(); + atomic_stop(); // Internal FS init ! gladfs_initialize(); @@ -193,7 +193,7 @@ int start(void) // Restore Casio context. fx9860_context_restore(&casio_context); - atomic_end(); + atomic_stop(); // Casio VRAM workaround // @note: GetKey call Bdisp_PutDD_VRAM() diff --git a/src/kernel/devices/display/write.c b/src/kernel/devices/display/write.c index 29e2520..2a1af81 100644 --- a/src/kernel/devices/display/write.c +++ b/src/kernel/devices/display/write.c @@ -61,7 +61,7 @@ ssize_t display_write(const void *buffer, size_t count) //t6k11_display(vram); // End atomic operation. - atomic_end(); + atomic_stop(); // Return the number of written char. return (i); diff --git a/src/kernel/devices/tty/file_op/read.c b/src/kernel/devices/tty/file_op/read.c index 19fd1d2..dfec176 100644 --- a/src/kernel/devices/tty/file_op/read.c +++ b/src/kernel/devices/tty/file_op/read.c @@ -74,7 +74,7 @@ ssize_t tty_read(void *inode, void *buffer, size_t count) // Get next key. keynode = keynode->next; } - atomic_end(); + atomic_stop(); // Display buffer on TTY. tty_buffer_display(&keyboard); @@ -163,7 +163,7 @@ static int check_special(struct keyboard_obj_s *keyboard, key_t key) atomic_start(); fx9860_context_save(&vhex_context); fx9860_context_restore(&casio_context); - atomic_end(); + atomic_stop(); // Inject MENU key and call GetKey(). // TODO !!! @@ -178,7 +178,7 @@ static int check_special(struct keyboard_obj_s *keyboard, key_t key) atomic_start(); fx9860_context_save(&casio_context); fx9860_context_restore(&vhex_context); - atomic_end(); + atomic_stop(); return (1); } diff --git a/src/kernel/devices/tty/file_op/write.c b/src/kernel/devices/tty/file_op/write.c index 6e7959a..7e29010 100644 --- a/src/kernel/devices/tty/file_op/write.c +++ b/src/kernel/devices/tty/file_op/write.c @@ -171,7 +171,7 @@ static void tty_display(void) display_ioctl(DISPLAY_IOCTL_SETY, srow); // End atomic operation - atomic_end(); + atomic_stop(); } ssize_t tty_write(void *inode, const void *buffer, size_t count) diff --git a/src/kernel/fs/gladfs/file/file_pos.c b/src/kernel/fs/gladfs/file/file_pos.c index e27f6b5..ed75376 100644 --- a/src/kernel/fs/gladfs/file/file_pos.c +++ b/src/kernel/fs/gladfs/file/file_pos.c @@ -1,6 +1,8 @@ #include #include +/* gladfs_file_pos() - Get approriate file fragment date */ +/* @note: This function is internal of GladFS, do not call it ! */ struct gladfs_fragment_data_s **gladfs_file_pos(off_t *offset, struct gladfs_inode_s *inode, off_t pos) { struct gladfs_fragment_data_s **fragdata; diff --git a/src/kernel/fs/gladfs/file/read.c b/src/kernel/fs/gladfs/file/read.c index 2131785..c8fc638 100644 --- a/src/kernel/fs/gladfs/file/read.c +++ b/src/kernel/fs/gladfs/file/read.c @@ -5,6 +5,7 @@ // Internal helper extern struct gladfs_fragment_data_s **gladfs_file_pos(off_t *offset, struct gladfs_inode_s *inode, off_t pos); +/* gladfs_read() - GladFS inode read primitive (sync) */ ssize_t gladfs_read(void *inode, void *buf, size_t count, off_t pos) { struct gladfs_fragment_data_s **fragdata; @@ -19,7 +20,10 @@ ssize_t gladfs_read(void *inode, void *buf, size_t count, off_t pos) // Get appropriate data fragment fragdata = gladfs_file_pos(&offset, inode, pos); if (fragdata == NULL || *fragdata == NULL) + { + atomic_stop(); return (-1); + } // Walk into fragemented data current_size = 0; @@ -58,7 +62,7 @@ ssize_t gladfs_read(void *inode, void *buf, size_t count, off_t pos) } // End atomic operations - atomic_end(); + atomic_stop(); // Return read bytes return (current_size); diff --git a/src/kernel/fs/gladfs/file/write.c b/src/kernel/fs/gladfs/file/write.c index c6d64e8..bc10cd7 100644 --- a/src/kernel/fs/gladfs/file/write.c +++ b/src/kernel/fs/gladfs/file/write.c @@ -5,6 +5,7 @@ // Internal helper extern struct gladfs_fragment_data_s **gladfs_file_pos(off_t *offset, struct gladfs_inode_s *inode, off_t pos); +/* gladfs_write() - GladFS inode write primitive (sync) */ ssize_t gladfs_write(void *inode, const void *buf, size_t count, off_t pos) { extern struct gladfs_superblock_s gladfs_superblock; @@ -14,32 +15,37 @@ ssize_t gladfs_write(void *inode, const void *buf, size_t count, off_t pos) size_t write_size; off_t offset; + // Check error + if (inode == NULL) + return (-1); + + // Start atomic operation + atomic_start(); + // Get appropriate data fragment fragdata = gladfs_file_pos(&offset, inode, pos); if (fragdata == NULL) + { + atomic_stop(); return (-1); + } // Generate new indirect block if needed if (*fragdata == NULL) { - // @note: for now, the indirect block allocation is - // not really implemented :( + // @note: for now, the indirect block allocation (like + // ext2 file system) is not really implemented :( gladfs_superblock.super_op.alloc_fragdata(fragdata, 1); if (*fragdata == NULL) + { + atomic_stop(); return (-1); + } // Reset offset offset = 0; } - // Debug - kvram_clear(); - printk(0, 0, "Le sexe !"); - printk(0, 1, "offset = %d", offset); - printk(0, 2, "fragdata = %p", *fragdata); - kvram_display(); - DBG_WAIT; - // Walk into fragemented data current_size = 0; count = count - offset; @@ -86,7 +92,7 @@ ssize_t gladfs_write(void *inode, const void *buf, size_t count, off_t pos) } // End atomic operations - atomic_end(); + atomic_stop(); // Return written bytes. return (current_size); diff --git a/src/kernel/fs/gladfs/filesystem/mount.c b/src/kernel/fs/gladfs/filesystem/mount.c index 9943f85..d2ed87d 100644 --- a/src/kernel/fs/gladfs/filesystem/mount.c +++ b/src/kernel/fs/gladfs/filesystem/mount.c @@ -1,25 +1,41 @@ #include +#include #include +/* gladfs_mount() - GladFS mount primitive (sync) */ void *gladfs_mount(void) { extern struct gladfs_superblock_s gladfs_superblock; + void *root_inode; - // If already mounted, return the root inode - if (gladfs_superblock.root_inode != NULL) - return (gladfs_superblock.root_inode); + // Start atomic operation + atomic_start(); - // Try to create root inode. - gladfs_superblock.root_inode = gladfs_superblock.super_op.alloc_inode("/", GLADFS_INODE_TYPE_ROOT); + // If the root node does not exist... if (gladfs_superblock.root_inode == NULL) { - kvram_clear(); - kvram_print(0, 0, "GladFS: ROOT inode alloc error !"); - kvram_display(); - DBG_WAIT; - return (NULL); + // ...Try to create root inode. + gladfs_superblock.root_inode = gladfs_superblock.super_op.alloc_inode("/", GLADFS_INODE_TYPE_ROOT); + if (gladfs_superblock.root_inode == NULL) + { + kvram_clear(); + kvram_print(0, 0, "GladFS: ROOT inode alloc error !"); + kvram_display(); + DBG_WAIT; + } } + // Get root inode + // @note: In theroy, the super block is + // stored on the device so, to ensure the + // synchronous primitives, we get the root + // inode here to restore interrupt before + // leave. + root_inode = gladfs_superblock.root_inode; + + // Stop atomic operations + atomic_stop(); + // Return root inode - return (gladfs_superblock.root_inode); + return (root_inode); } diff --git a/src/kernel/fs/gladfs/filesystem/umount.c b/src/kernel/fs/gladfs/filesystem/umount.c index 4aef2dc..e9dd144 100644 --- a/src/kernel/fs/gladfs/filesystem/umount.c +++ b/src/kernel/fs/gladfs/filesystem/umount.c @@ -1,7 +1,9 @@ #include +/* gladfs_umount() - GladFS unmount primitives (asyn) */ int gladfs_umount(void) { // Do nothing for now + // TODO: free'd root inode ? return (0); } diff --git a/src/kernel/fs/gladfs/initialize.c b/src/kernel/fs/gladfs/initialize.c index e032c44..6b6cd92 100644 --- a/src/kernel/fs/gladfs/initialize.c +++ b/src/kernel/fs/gladfs/initialize.c @@ -12,7 +12,7 @@ struct file_system_type gladfs_filesystem = // FS specific openrations .filesystem_operations = { .mount = &gladfs_mount, - .umount = NULL + .umount = &gladfs_umount }, // File operations diff --git a/src/kernel/fs/gladfs/inode/creat.c b/src/kernel/fs/gladfs/inode/creat.c index 1e2abd3..644b79d 100644 --- a/src/kernel/fs/gladfs/inode/creat.c +++ b/src/kernel/fs/gladfs/inode/creat.c @@ -2,6 +2,7 @@ #include #include +/* gladfs_creat() - Create new "empty" inode (atomically, sync) */ void *gladfs_creat(void *parent_inode, const char *file_name, mode_t mode) { extern struct gladfs_superblock_s gladfs_superblock; @@ -14,7 +15,10 @@ void *gladfs_creat(void *parent_inode, const char *file_name, mode_t mode) // Create new inode new_inode = gladfs_superblock.super_op.alloc_inode(file_name, mode | __S_IFREG); if (new_inode == NULL) + { + atomic_stop(); return (NULL); + } // Update FHS parent = parent_inode; @@ -22,8 +26,8 @@ void *gladfs_creat(void *parent_inode, const char *file_name, mode_t mode) new_inode->next = parent->children; parent->children = new_inode; - // Stp atomic operation - atomic_end(); + // Stop atomic operation + atomic_stop(); // Return inode return(new_inode); diff --git a/src/kernel/fs/gladfs/inode/find_first_child.c b/src/kernel/fs/gladfs/inode/find_first_child.c index f1e957d..30c73fc 100644 --- a/src/kernel/fs/gladfs/inode/find_first_child.c +++ b/src/kernel/fs/gladfs/inode/find_first_child.c @@ -1,8 +1,17 @@ #include +#include +/* gladfs_find_first_child() - Return the first child of folder inode (async) */ void *gladfs_find_first_child(void *inode) { + // Check inode fault if (inode == NULL) return (NULL); + + // Check inode validity + if ((((struct gladfs_inode_s*)inode)->mode & __S_IFDIR) == 0) + return (NULL); + + // Return the first child of the directory. return (((struct gladfs_inode_s*)inode)->children); } diff --git a/src/kernel/fs/gladfs/inode/find_next_sibling.c b/src/kernel/fs/gladfs/inode/find_next_sibling.c index 36ca196..095c8d3 100644 --- a/src/kernel/fs/gladfs/inode/find_next_sibling.c +++ b/src/kernel/fs/gladfs/inode/find_next_sibling.c @@ -1,8 +1,12 @@ #include +/* gladfs_find_next_sibling() - Find the next file from the same parent (async) */ void *gladfs_find_next_sibling(void *inode) { + // Check inode fault if (inode == NULL) return (NULL); + + // Return the next inode return (((struct gladfs_inode_s*)inode)->next); } diff --git a/src/kernel/fs/gladfs/inode/find_parent.c b/src/kernel/fs/gladfs/inode/find_parent.c index d6b4a09..f09f37b 100644 --- a/src/kernel/fs/gladfs/inode/find_parent.c +++ b/src/kernel/fs/gladfs/inode/find_parent.c @@ -1,8 +1,12 @@ #include +/* gladfs_find_parent() - Retrun the parent inode of a file (async) */ void *gladfs_find_parent(void *inode) { + // Check inode fault if (inode == NULL) return (NULL); + + // Retrun the parent inode return (((struct gladfs_inode_s*)inode)->parent); } diff --git a/src/kernel/fs/gladfs/inode/get_mode.c b/src/kernel/fs/gladfs/inode/get_mode.c index a717410..0fe784b 100644 --- a/src/kernel/fs/gladfs/inode/get_mode.c +++ b/src/kernel/fs/gladfs/inode/get_mode.c @@ -1,5 +1,6 @@ #include +/* gladfs_get_mode() - Dump permission and type of a file (async) */ mode_t gladfs_get_mode(void *inode) { return (((struct gladfs_inode_s*)inode)->mode); diff --git a/src/kernel/fs/gladfs/inode/get_name.c b/src/kernel/fs/gladfs/inode/get_name.c index 83c667d..e09bdf1 100644 --- a/src/kernel/fs/gladfs/inode/get_name.c +++ b/src/kernel/fs/gladfs/inode/get_name.c @@ -1,6 +1,8 @@ #include +#include #include +/* gladfs_get_name() - Dump the name of a file (sync) */ int gladfs_get_name(void *inode, char *name, size_t count) { // Check potential error @@ -11,7 +13,13 @@ int gladfs_get_name(void *inode, char *name, size_t count) if (count > GLADFS_INODE_NAME_LENGHT) count = GLADFS_INODE_NAME_LENGHT; + // Start atomic operation + atomic_start(); + // Dump name strncpy(name, ((struct gladfs_inode_s*)inode)->name, count); + + // Stop atomic operation + atomic_stop(); return (0); } diff --git a/src/kernel/fs/gladfs/inode/mkdir.c b/src/kernel/fs/gladfs/inode/mkdir.c index 4208555..3217bff 100644 --- a/src/kernel/fs/gladfs/inode/mkdir.c +++ b/src/kernel/fs/gladfs/inode/mkdir.c @@ -2,6 +2,7 @@ #include #include +/* gladfs_mkdir() - Create new folder inode (atomically, sync) */ void *gladfs_mkdir(void *parent_inode, const char *file_name, mode_t mode) { extern struct gladfs_superblock_s gladfs_superblock; @@ -14,7 +15,10 @@ void *gladfs_mkdir(void *parent_inode, const char *file_name, mode_t mode) // Create new inode new_inode = gladfs_superblock.super_op.alloc_inode(file_name, mode | __S_IFDIR); if (new_inode == NULL) + { + atomic_stop(); return (NULL); + } // Update FHS parent = parent_inode; @@ -22,8 +26,8 @@ void *gladfs_mkdir(void *parent_inode, const char *file_name, mode_t mode) new_inode->next = parent->children; parent->children = new_inode; - // Stp atomic operation - atomic_end(); + // Stop atomic operation + atomic_stop(); // Return inode return(new_inode); diff --git a/src/kernel/fs/gladfs/superblock/alloc_fragdata.c b/src/kernel/fs/gladfs/superblock/alloc_fragdata.c index 93fce63..f4ab86d 100644 --- a/src/kernel/fs/gladfs/superblock/alloc_fragdata.c +++ b/src/kernel/fs/gladfs/superblock/alloc_fragdata.c @@ -1,6 +1,8 @@ #include #include +#include +/* gladfs_alloc_fragdata() - Superblock primitive to alloc "empty" fragment data block (sync) */ int gladfs_alloc_fragdata(struct gladfs_fragment_data_s **parent, int nb_block) { extern struct gladfs_superblock_s gladfs_superblock; @@ -9,14 +11,23 @@ int gladfs_alloc_fragdata(struct gladfs_fragment_data_s **parent, int nb_block) if (parent == NULL) return (-1); + // Start atomic opeation + atomic_start(); + // Try to alloc block *parent = pm_alloc(gladfs_superblock.block_size * nb_block); if (*parent == NULL) + { + atomic_stop(); return (-1); + } // Fill default value. (*parent)->next = 0x00000000; (*parent)->data_size = gladfs_superblock.block_size * nb_block; (*parent)->data_used = 0x00000000; + + // Stop atomic operation + atomic_stop(); return (0); } diff --git a/src/kernel/fs/gladfs/superblock/alloc_inode.c b/src/kernel/fs/gladfs/superblock/alloc_inode.c index c609f99..671e22a 100644 --- a/src/kernel/fs/gladfs/superblock/alloc_inode.c +++ b/src/kernel/fs/gladfs/superblock/alloc_inode.c @@ -1,15 +1,23 @@ #include #include +#include #include +/* gladfs_alloc_inode() - Superblock primitive to alloc "empty" inode (sync) */ struct gladfs_inode_s *gladfs_alloc_inode(const char *name, mode_t mode) { struct gladfs_inode_s *inode; + // Start atomic operation + atomic_start(); + // alloc memory inode = pm_alloc(sizeof(struct gladfs_inode_s)); if (inode == NULL) + { + atomic_stop(); return (NULL); + } // Fill inode. memset(inode, 0x00, sizeof(struct gladfs_inode_s)); @@ -21,5 +29,8 @@ struct gladfs_inode_s *gladfs_alloc_inode(const char *name, mode_t mode) inode->size = 0; inode->fragnumber = 0; inode->fragdata = NULL; + + // Stop atomic operation + atomic_stop(); return (inode); } diff --git a/src/kernel/fs/gladfs/superblock/destroy_fragdata.c b/src/kernel/fs/gladfs/superblock/destroy_fragdata.c index 61807b0..85d26ed 100644 --- a/src/kernel/fs/gladfs/superblock/destroy_fragdata.c +++ b/src/kernel/fs/gladfs/superblock/destroy_fragdata.c @@ -1,13 +1,22 @@ #include #include +#include +/* gladfs_destroy_fragdata() - Free'd allocated fragmented data (sync) */ +/* @note: *WARNING* no verification will be done, so do not use this primitive */ int gladfs_destroy_fragdata(struct gladfs_fragment_data_s *fragment) { // Check error if (fragment == NULL) return (-1); + // Start atomic operation + atomic_start(); + // Free'd allocated space pm_free(fragment); + + // Stop atomic operation + atomic_stop(); return (0); } diff --git a/src/kernel/fs/gladfs/superblock/destroy_inode.c b/src/kernel/fs/gladfs/superblock/destroy_inode.c index 5a32f43..b695fb4 100644 --- a/src/kernel/fs/gladfs/superblock/destroy_inode.c +++ b/src/kernel/fs/gladfs/superblock/destroy_inode.c @@ -1,6 +1,9 @@ #include #include +#include +/* gladfs_destroy_inode() - Free'd allocated inode (sync) */ +/* @note: *WARNING* no verification will be done, so do not use this primitive */ int gladfs_destroy_inode(struct gladfs_inode_s *inode) { struct gladfs_fragment_data_s *fragdata; @@ -10,13 +13,16 @@ int gladfs_destroy_inode(struct gladfs_inode_s *inode) if (inode == NULL) return (-1); + // Start atomic operations + atomic_start(); + // Free fragmented data fragdata = inode->fragdata; while (fragdata == NULL) { // Get next fragement next = (void *)fragdata->next; - pm_free(fragdata); + gladfs_destroy_fragdata(fragdata); // Update current fragment fragdata = next; @@ -24,5 +30,8 @@ int gladfs_destroy_inode(struct gladfs_inode_s *inode) // Free inode pm_free(inode); + + // Stop atomic operations + atomic_stop(); return (0); } diff --git a/src/kernel/fs/smemfs/file/read.c b/src/kernel/fs/smemfs/file/read.c index 80589ce..b2f9cf8 100644 --- a/src/kernel/fs/smemfs/file/read.c +++ b/src/kernel/fs/smemfs/file/read.c @@ -1,5 +1,6 @@ #include #include +#include #include /* casio_smem_data_base_address() - Generate the fragmented data address (0xa0000000 + offset) */ @@ -32,6 +33,9 @@ ssize_t smemfs_read(void *inode, void *buf, size_t count, off_t pos) if (inode == NULL || buf == NULL) return (-1); + // Start atomic operation + atomic_start(); + // Get the current data fragment. current_size = 0; fragment = (void *)((uint32_t)inode + sizeof(struct casio_smem_header_s)); @@ -44,7 +48,10 @@ ssize_t smemfs_read(void *inode, void *buf, size_t count, off_t pos) // Check fragment error if (fragment->magic != CASIO_SMEM_FRAGMENT_MAGIC) + { + atomic_stop(); return (-1); + } // Read file data current_size = 0; @@ -60,7 +67,7 @@ ssize_t smemfs_read(void *inode, void *buf, size_t count, off_t pos) // Get the data address. data_base_addr = casio_smem_get_data_base_address(fragment); if (data_base_addr == NULL) - return (current_size); + break; // Handle fragment data offset. if (fragment_data_offset != 0) @@ -76,5 +83,8 @@ ssize_t smemfs_read(void *inode, void *buf, size_t count, off_t pos) current_size = current_size + real_size; fragment = fragment + 1; } + + // Stop atomic operation + atomic_stop(); return (current_size); } diff --git a/src/kernel/fs/smemfs/filesystem/mount.c b/src/kernel/fs/smemfs/filesystem/mount.c index cd9b36e..365fbda 100644 --- a/src/kernel/fs/smemfs/filesystem/mount.c +++ b/src/kernel/fs/smemfs/filesystem/mount.c @@ -1,10 +1,21 @@ #include +#include -/* casio_smem_mount() - Get Block and Preheader Table addresses */ +/* casio_smem_mount() - Mount the file system (sync) */ void *smemfs_mount(void) { extern struct smemfs_superblock_s smemfs_superblock; + void *root_inode; + + // Start atomic operation + atomic_start(); + + // Get root inode + root_inode = smemfs_superblock.sector_table; + + // Stop atomic operation + atomic_stop(); // Return the sector table to simulate the root inode. - return ((void*)smemfs_superblock.sector_table); + return (root_inode); } diff --git a/src/kernel/fs/smemfs/filesystem/umount.c b/src/kernel/fs/smemfs/filesystem/umount.c new file mode 100644 index 0000000..e5a58c2 --- /dev/null +++ b/src/kernel/fs/smemfs/filesystem/umount.c @@ -0,0 +1,8 @@ +#include + +/* casio_smem_umount() - Unmount the File System */ +int smemfs_umount(void) +{ + // Do nothing for now + return (0); +} diff --git a/src/kernel/fs/smemfs/initialize.c b/src/kernel/fs/smemfs/initialize.c index 6279150..c312625 100644 --- a/src/kernel/fs/smemfs/initialize.c +++ b/src/kernel/fs/smemfs/initialize.c @@ -12,7 +12,7 @@ struct file_system_type smemfs_filesystem = // FS specific openrations .filesystem_operations = { .mount = &smemfs_mount, - .umount = NULL + .umount = &smemfs_umount }, // File operations diff --git a/src/kernel/fs/smemfs/inode/find_first_child.c b/src/kernel/fs/smemfs/inode/find_first_child.c index 7f47ddb..54d544f 100644 --- a/src/kernel/fs/smemfs/inode/find_first_child.c +++ b/src/kernel/fs/smemfs/inode/find_first_child.c @@ -1,34 +1,43 @@ #include +#include #include -/* smemfs_find_first_child() - Find the fist file in the (folder) inode */ +/* smemfs_find_first_child() - Find the fist file in the (folder) inode (sync) */ void *smemfs_find_first_child(void *inode) { extern struct smemfs_superblock_s smemfs_superblock; uint16_t folder_id; + void *child_inode; // Check error. if (inode == NULL) return (NULL); + // Start atomic operation + atomic_start(); + // Check root inode if (inode == smemfs_superblock.sector_table) { folder_id = CASIO_SMEM_ROOT_ID; } else { // Check inode validity - if (((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST) - return (NULL); - - // Check directory - if (((struct casio_smem_header_s *)inode)->type != CASIO_SMEM_HEADER_TYPE_DIRECTORY) + if (((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST || + ((struct casio_smem_header_s *)inode)->type != CASIO_SMEM_HEADER_TYPE_DIRECTORY) + { + atomic_stop(); return (NULL); + } // Get directory ID folder_id = ((struct casio_smem_header_s *)inode)->id; } // Return the first child of the file. - return (smemfs_walk(inode, smemfs_superblock.inode_table, - folder_id, WALK_FLAG_ID_CHECK_PARENT)); + child_inode = smemfs_walk(inode, smemfs_superblock.inode_table, + folder_id, WALK_FLAG_ID_CHECK_PARENT); + + // Stop atomic operation + atomic_stop(); + return (child_inode); } diff --git a/src/kernel/fs/smemfs/inode/find_next_sibling.c b/src/kernel/fs/smemfs/inode/find_next_sibling.c index b77f4fd..72a25ad 100644 --- a/src/kernel/fs/smemfs/inode/find_next_sibling.c +++ b/src/kernel/fs/smemfs/inode/find_next_sibling.c @@ -1,26 +1,36 @@ #include +#include #include +/* smemfs_find_next_sibling() - Find the next file from the same parent (sync) */ void *smemfs_find_next_sibling(void *inode) { extern struct smemfs_superblock_s smemfs_superblock; + void *sibling_inode; uint16_t folder_id; // Check error. if (inode == NULL) return (NULL); - // Check root inode - if (inode == smemfs_superblock.sector_table) - return (NULL); + // Start atomic operation + atomic_start(); - // Check inode validity - if (((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST) + // Check inode validity (and root) + if (inode == smemfs_superblock.sector_table || + ((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST) + { + atomic_stop(); return (NULL); + } // Get parent ID. folder_id = ((struct casio_smem_header_s *)inode)->parent.id; // Return the next file of the directory. - return (smemfs_walk(inode, inode, folder_id, WALK_FLAG_ID_CHECK_PARENT)); + sibling_inode = smemfs_walk(inode, inode, folder_id, WALK_FLAG_ID_CHECK_PARENT); + + // Stop atomic operation + atomic_stop(); + return (sibling_inode); } diff --git a/src/kernel/fs/smemfs/inode/find_parent.c b/src/kernel/fs/smemfs/inode/find_parent.c index 1199a7d..87881fd 100644 --- a/src/kernel/fs/smemfs/inode/find_parent.c +++ b/src/kernel/fs/smemfs/inode/find_parent.c @@ -1,27 +1,36 @@ #include +#include /* smemfs_find_parent() - Return the parent inode */ void *smemfs_find_parent(void *inode) { extern struct smemfs_superblock_s smemfs_superblock; + void *parent_inode; uint16_t folder_id; // Check error. if (inode == NULL) return (NULL); - // Check root inode - if (inode == smemfs_superblock.sector_table) - return (NULL); + // Start atomic operation + atomic_start(); - // Check inode validity - if (((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST) + // Check inode validity (and root) + if (inode == smemfs_superblock.sector_table || + ((struct casio_smem_header_s *)inode)->info != CASIO_SMEM_HEADER_INFO_EXIST) + { + atomic_stop(); return (NULL); + } // Get parent ID. folder_id = ((struct casio_smem_header_s *)inode)->parent.id; // Return first inode find - return (smemfs_walk(inode, smemfs_superblock.inode_table, folder_id, - WALK_FLAG_ID_CHECK_DIRECTORY)); + parent_inode = smemfs_walk(inode, smemfs_superblock.inode_table, folder_id, + WALK_FLAG_ID_CHECK_DIRECTORY); + + // Stop atomic operation + atomic_stop(); + return (parent_inode); } diff --git a/src/kernel/fs/smemfs/inode/get_mode.c b/src/kernel/fs/smemfs/inode/get_mode.c index 2a2fad5..31a86ca 100644 --- a/src/kernel/fs/smemfs/inode/get_mode.c +++ b/src/kernel/fs/smemfs/inode/get_mode.c @@ -1,31 +1,42 @@ #include #include +#include +/* smemfs_get_mode() - Return the permission dans the type of a file (sync) */ mode_t smemfs_get_mode(void *inode) { extern struct smemfs_superblock_s smemfs_superblock; struct casio_smem_header_s *header; - int inode_type; + mode_t inode_type; // Check error if (inode == NULL) return (-1); + // Start atomic opeartion + atomic_start(); + // Check root inode if (inode == smemfs_superblock.sector_table) + { + atomic_stop(); return (__S_IFDIR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + } // Check inode validity header = inode; if (header->info != CASIO_SMEM_HEADER_INFO_EXIST) + { + atomic_stop(); return (-1); + } // We can only check if the file is a // directory or not (Bfile limitation) - if (header->type == CASIO_SMEM_HEADER_TYPE_DIRECTORY) - inode_type = __S_IFDIR; - else - inode_type = __S_IFREG; + inode_type = (header->type == CASIO_SMEM_HEADER_TYPE_DIRECTORY) ? __S_IFDIR : __S_IFREG; + + // Stop atomic operation + atomic_stop(); // Return default permission and type return (inode_type | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); diff --git a/src/kernel/fs/smemfs/inode/get_name.c b/src/kernel/fs/smemfs/inode/get_name.c index c751714..d944080 100644 --- a/src/kernel/fs/smemfs/inode/get_name.c +++ b/src/kernel/fs/smemfs/inode/get_name.c @@ -1,5 +1,7 @@ #include +#include +/* smemfs_get_name() - Dump the name of a file (sync) */ int smemfs_get_name(void *inode, char *buf, size_t count) { extern struct smemfs_superblock_s smemfs_superblock; @@ -9,18 +11,25 @@ int smemfs_get_name(void *inode, char *buf, size_t count) if (inode == NULL) return (-1); + // Start atomic operation + atomic_start(); + // Check root inode if (inode == smemfs_superblock.sector_table) { buf[0] = '/'; buf[1] = '\0'; + atomic_stop(); return (0); } // Check inode validity header = inode; if (header->info != CASIO_SMEM_HEADER_INFO_EXIST) + { + atomic_stop(); return (-1); + } // Get "real" name size count = count - 1; @@ -35,5 +44,8 @@ int smemfs_get_name(void *inode, char *buf, size_t count) header->name[i] != 0xffff) buf[i] = header->name[i]; buf[i] = '\0'; + + // Start atomic operation + atomic_stop(); return (0); } diff --git a/src/kernel/fs/smemfs/inode/walk.c b/src/kernel/fs/smemfs/inode/walk.c index 155d5a5..7b42da7 100644 --- a/src/kernel/fs/smemfs/inode/walk.c +++ b/src/kernel/fs/smemfs/inode/walk.c @@ -1,6 +1,7 @@ #include /* smemfs_walk() - Find inode based on directory ID and flags */ +/* @note: This function is internal of smemFS, do not call it ! */ smemfs_inode_t *smemfs_walk(smemfs_inode_t *current, smemfs_inode_t *entry, uint16_t folder_id, int flags) { diff --git a/src/kernel/util/atomic.s b/src/kernel/util/atomic.s index bedf481..16df0fb 100644 --- a/src/kernel/util/atomic.s +++ b/src/kernel/util/atomic.s @@ -3,10 +3,10 @@ ##--- .text .global _atomic_start -.global _atomic_end +.global _atomic_stop .type _atomic_start, @function -.type _atomic_end, @function +.type _atomic_stop, @function .extern _sr_save .extern _atomic_counter @@ -48,12 +48,12 @@ atomic_start_exit: /*TODO: Fix reentrace corruption !!!*/ /* -** @proto: uint32_t atomic_end(void) +** @proto: uint32_t atomic_stop(void) ** @return: ** * Saved SR register if has been restored. ** * 0xffffffff otherwise. */ -_atomic_end: +_atomic_stop: ! Check if the calculator is currently ! into an atomic operation and update diff --git a/src/kernel/util/kvram.c b/src/kernel/util/kvram.c index 0686f22..f5db090 100644 --- a/src/kernel/util/kvram.c +++ b/src/kernel/util/kvram.c @@ -23,7 +23,7 @@ void kvram_clear(void) vram[i] = 0x00000000; // End of atomic operation - atomic_end(); + atomic_stop(); } /* kvram_display() - Disaplay Video RAM into screen */ @@ -64,7 +64,7 @@ void kvram_scroll(int lines) } // End of atomic operation - atomic_end(); + atomic_stop(); } /* kvram_reverse() - Reverse Video RAM area */ @@ -130,7 +130,7 @@ void kvram_reverse(int x, int y, int width, int height) } // End of atomic operation - atomic_end(); + atomic_stop(); } /* kvram_print() - Print string on Video RAM */ diff --git a/src/kernel/util/timer.c b/src/kernel/util/timer.c index 814a327..4cb127f 100644 --- a/src/kernel/util/timer.c +++ b/src/kernel/util/timer.c @@ -44,7 +44,7 @@ int timer_install(void *callback, void *arg, uint32_t delay_ms, uint8_t mode) // End of atomic operations. // and return the timer ID. - atomic_end(); + atomic_stop(); return (timer_ID); } @@ -73,6 +73,6 @@ int timer_uninstall(int timer_ID) timercache[timer_ID].status = TIMER_UNUSED; // Stop atomic operation and return. - atomic_end(); + atomic_stop(); return (0); }