diff --git a/src/fs/fugue/BFile_Ext_Stat.c b/src/fs/fugue/BFile_Ext_Stat.c index bde0c2a..275a38e 100644 --- a/src/fs/fugue/BFile_Ext_Stat.c +++ b/src/fs/fugue/BFile_Ext_Stat.c @@ -1,4 +1,5 @@ #include +#include #include "util.h" int BFile_Ext_Stat(uint16_t const *path, int *type, int *size) @@ -7,6 +8,7 @@ int BFile_Ext_Stat(uint16_t const *path, int *type, int *size) uint16_t found_file[256]; struct BFile_FileInfo fileinfo; + gint_world_enter(GINT_WORLD_OS); rc = BFile_FindFirst(path, &search_handle, found_file, &fileinfo); if(rc < 0) { if(type) *type = -1; @@ -20,5 +22,6 @@ int BFile_Ext_Stat(uint16_t const *path, int *type, int *size) } BFile_FindClose(search_handle); + gint_world_leave(); return rc; } diff --git a/src/fs/fugue/fugue.c b/src/fs/fugue/fugue.c index 00185da..b7cf505 100644 --- a/src/fs/fugue/fugue.c +++ b/src/fs/fugue/fugue.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -11,6 +12,8 @@ ssize_t fugue_read(void *data0, void *buf, size_t size) { + gint_world_enter(GINT_WORLD_OS); + fugue_fd_t *data = data0; int fugue_fd = data->fd; @@ -22,9 +25,12 @@ ssize_t fugue_read(void *data0, void *buf, size_t size) int rc = BFile_Read(fugue_fd, buf, size, -1); if(rc < 0) { errno = bfile_error_to_errno(rc); - return -1; - } - data->pos += rc; + size = -1; + } else { + data->pos += rc; + } + + gint_world_leave(); return size; } @@ -62,6 +68,7 @@ ssize_t fugue_write(void *data0, const void *buf, size_t size) return -1; } + gint_world_enter(GINT_WORLD_OS); while(written < size) { size_t block_size = min(size - written, alloc_size); memcpy(ram, buf + written, block_size); @@ -79,24 +86,31 @@ ssize_t fugue_write(void *data0, const void *buf, size_t size) /* Partial write */ if(rc < (int)block_size) break; } + gint_world_leave(); free(ram); return written; } /* Otherwise, we can write normally */ else { + gint_world_enter(GINT_WORLD_OS); int rc = BFile_Write(fugue_fd, buf, size); if(rc < 0) { errno = bfile_error_to_errno(rc); - return -1; - } - data->pos += rc; + rc = -1; + } else { + data->pos += rc; + rc = 0; + } + gint_world_leave(); return rc; } } off_t fugue_lseek(void *data0, off_t offset, int whence) { + gint_world_enter(GINT_WORLD_OS); + fugue_fd_t *data = data0; int fugue_fd = data->fd; @@ -114,9 +128,12 @@ off_t fugue_lseek(void *data0, off_t offset, int whence) int rc = BFile_Seek(fugue_fd, offset); if(rc < 0) { errno = bfile_error_to_errno(rc); - return -1; - } - data->pos = offset; + offset = -1; + } else { + data->pos = offset; + } + + gint_world_leave(); /* rc is the amount of space left in the file (including pre-allocated space), so instead just return offset directly */ @@ -125,16 +142,21 @@ off_t fugue_lseek(void *data0, off_t offset, int whence) int fugue_close(void *data0) { + gint_world_enter(GINT_WORLD_OS); + fugue_fd_t *data = data0; int fugue_fd = data->fd; int rc = BFile_Close(fugue_fd); if(rc < 0) { errno = bfile_error_to_errno(rc); - return -1; - } + rc = -1; + } else { + rc = 0; + } + gint_world_leave(); free(data); - return 0; + return rc; } const fs_descriptor_type_t fugue_descriptor_type = { diff --git a/src/fs/fugue/fugue_dir.c b/src/fs/fugue/fugue_dir.c index d8a8fc0..9dd218d 100644 --- a/src/fs/fugue/fugue_dir.c +++ b/src/fs/fugue/fugue_dir.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,8 @@ void *fugue_dir_explore(char const *path) /* We allocate by batches of 8 */ int sd=-1, rc, allocated=0; + gint_world_enter(GINT_WORLD_OS); + dir_t *dp = malloc(sizeof *dp); if(!dp) goto alloc_failure; @@ -157,5 +160,6 @@ end: free(fc_path); if(sd >= 0) BFile_FindClose(sd); + gint_world_leave(); return dp; } diff --git a/src/fs/fugue/fugue_mkdir.c b/src/fs/fugue/fugue_mkdir.c index 29f10b9..819ba8c 100644 --- a/src/fs/fugue/fugue_mkdir.c +++ b/src/fs/fugue/fugue_mkdir.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "util.h" @@ -14,13 +15,17 @@ int fugue_mkdir(char const *path, GUNUSED mode_t mode) return -1; } + gint_world_enter(GINT_WORLD_OS); int rc = BFile_Create(fcpath, BFile_Folder, NULL); if(rc < 0) { errno = bfile_error_to_errno(rc); free(fcpath); - return -1; - } + rc = -1; + } else { + rc = 0; + } + gint_world_leave(); free(fcpath); - return 0; + return rc; } diff --git a/src/fs/fugue/fugue_open.c b/src/fs/fugue/fugue_open.c index c9ecce4..89407d3 100644 --- a/src/fs/fugue/fugue_open.c +++ b/src/fs/fugue/fugue_open.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -32,6 +33,8 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode) /* Truncation requires the file to be removed/recreated */ bool trunc = (flags & O_TRUNC) && (flags & O_CREAT); + gint_world_enter(GINT_WORLD_OS); + /* Stat the entry. A special case is needed for the root, which doesn't respond well. fs_path_normalize_fc() normalizes the path so we just have to check for the fixed string "\\fls0\". */ @@ -142,6 +145,7 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode) } end: + gint_world_leave(); free(fcpath); return rc; } diff --git a/src/fs/fugue/fugue_rename.c b/src/fs/fugue/fugue_rename.c index 6eaded6..c77c77d 100644 --- a/src/fs/fugue/fugue_rename.c +++ b/src/fs/fugue/fugue_rename.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "util.h" @@ -24,12 +25,15 @@ int fugue_rename(char const *oldpath, char const *newpath) goto end; } + gint_world_enter(GINT_WORLD_OS); rc = BFile_Rename(fcpath_1, fcpath_2); if(rc < 0) { errno = bfile_error_to_errno(rc); rc = -1; - } - else rc = 0; + } else { + rc = 0; + } + gint_world_leave(); end: free(fcpath_1); diff --git a/src/fs/fugue/fugue_rmdir.c b/src/fs/fugue/fugue_rmdir.c index ceff28e..878fe5a 100644 --- a/src/fs/fugue/fugue_rmdir.c +++ b/src/fs/fugue/fugue_rmdir.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +40,15 @@ int fugue_rmdir(char const *path) return -1; } + gint_world_enter(GINT_WORLD_OS); int rc = BFile_Remove(fcpath); if(rc < 0) { errno = bfile_error_to_errno(rc); rc = -1; - } - else rc = 0; + } else { + rc = 0; + } + gint_world_leave(); free(fcpath); return rc; diff --git a/src/fs/fugue/fugue_stat.c b/src/fs/fugue/fugue_stat.c index 6cf43a9..afe0d76 100644 --- a/src/fs/fugue/fugue_stat.c +++ b/src/fs/fugue/fugue_stat.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "fugue.h" #include @@ -17,7 +18,9 @@ int fugue_stat(char const * restrict path, struct stat * restrict statbuf) } int type, size, rc; + gint_world_enter(GINT_WORLD_OS); rc = BFile_Ext_Stat(fcpath, &type, &size); + gint_world_leave(); free(fcpath); if(rc < 0) { diff --git a/src/fs/fugue/fugue_unlink.c b/src/fs/fugue/fugue_unlink.c index cff9cb8..73f8c65 100644 --- a/src/fs/fugue/fugue_unlink.c +++ b/src/fs/fugue/fugue_unlink.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "util.h" @@ -15,6 +16,8 @@ int fugue_unlink(char const *path) return -1; } + gint_world_enter(GINT_WORLD_OS); + int type, size, rc; rc = BFile_Ext_Stat(fcpath, &type, &size); if(rc < 0) { @@ -36,6 +39,7 @@ int fugue_unlink(char const *path) else rc = 0; end: + gint_world_leave(); free(fcpath); return rc; }