From 17dea00ea8fb8fc4b4fad858b58e828a44f8bab8 Mon Sep 17 00:00:00 2001 From: swym <0xfd000000@gmail.com> Date: Wed, 7 Aug 2019 17:45:06 +0200 Subject: [PATCH] efs_lock_global: make signature more straight-forward --- epicardium/fs/fileops.c | 32 ++++++++++++++--------------- epicardium/fs/internal.h | 2 +- epicardium/modules/filesystem_fat.c | 14 +++++-------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/epicardium/fs/fileops.c b/epicardium/fs/fileops.c index 2d9c7ca3f..fc13417b4 100644 --- a/epicardium/fs/fileops.c +++ b/epicardium/fs/fileops.c @@ -11,8 +11,8 @@ int epic_file_open(const char *filename, const char *mode) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_open(fs, filename, mode); efs_unlock_global(fs); } @@ -22,8 +22,8 @@ int epic_file_open(const char *filename, const char *mode) int epic_file_close(int fd) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_close(fs, fd); efs_unlock_global(fs); } @@ -33,8 +33,8 @@ int epic_file_close(int fd) int epic_file_read(int fd, void *buf, size_t nbytes) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_read(fs, fd, buf, nbytes); efs_unlock_global(fs); } @@ -44,8 +44,8 @@ int epic_file_read(int fd, void *buf, size_t nbytes) int epic_file_write(int fd, const void *buf, size_t nbytes) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_write(fs, fd, buf, nbytes); efs_unlock_global(fs); } @@ -55,8 +55,8 @@ int epic_file_write(int fd, const void *buf, size_t nbytes) int epic_file_flush(int fd) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_flush(fs, fd); efs_unlock_global(fs); } @@ -66,8 +66,8 @@ int epic_file_flush(int fd) int epic_file_seek(int fd, long offset, int whence) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_seek(fs, fd, offset, whence); efs_unlock_global(fs); } @@ -77,8 +77,8 @@ int epic_file_seek(int fd, long offset, int whence) int epic_file_tell(int fd) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_tell(fs, fd); efs_unlock_global(fs); } @@ -88,8 +88,8 @@ int epic_file_tell(int fd) int epic_file_stat(const char *filename, struct epic_stat *stat) { EpicFileSystem *fs; - int res; - if (efs_lock_global(&fs, &res)) { + int res = efs_lock_global(&fs); + if (res == 0) { res = efs_stat(fs, filename, stat); efs_unlock_global(fs); } diff --git a/epicardium/fs/internal.h b/epicardium/fs/internal.h index 3ae4cf4ef..b3f3acb3a 100644 --- a/epicardium/fs/internal.h +++ b/epicardium/fs/internal.h @@ -35,7 +35,7 @@ int efs_stat(EpicFileSystem *fs, const char *filename, struct epic_stat *stat); * Upon successful return, the filesystem has to be re-locked with epic_fs_unlock_global * In case of error, the filesystem will be left in a locked state. */ -bool efs_lock_global(EpicFileSystem** fs, int* ec); +int efs_lock_global(EpicFileSystem** fs); void efs_unlock_global(EpicFileSystem* fs); #endif// EPICARCIUM_FS_INTERNAL_H_INCLUDED diff --git a/epicardium/modules/filesystem_fat.c b/epicardium/modules/filesystem_fat.c index 82e04e20b..a96198fee 100644 --- a/epicardium/modules/filesystem_fat.c +++ b/epicardium/modules/filesystem_fat.c @@ -139,9 +139,8 @@ int fatfs_attach() void fatfs_detach() { FRESULT ff_res; - int rc; EpicFileSystem *fs; - if (efs_lock_global(&fs, &rc)) { + if (efs_lock_global(&fs) == 0) { efs_close_all(fs); //unmount by passing NULL as fs object, will destroy our sync object via ff_del_syncobj @@ -188,21 +187,18 @@ static void globalLockRelease() xSemaphoreGive(s_globalLock); } -bool efs_lock_global(EpicFileSystem **fs, int *rc) +int efs_lock_global(EpicFileSystem **fs) { *fs = NULL; if (!globalLockAccquire()) { - *rc = -EBUSY; - return false; + return -EBUSY; } if (!s_globalFileSystem.initialized) { globalLockRelease(); - *rc = -ENODEV; - return false; + return -ENODEV; } *fs = &s_globalFileSystem; - *rc = 0; - return true; + return 0; } void efs_unlock_global(EpicFileSystem *fs) -- GitLab