diff --git a/epicardium/fs/fileops.c b/epicardium/fs/fileops.c index 2d9c7ca3f2198421d825cdf67acfdb9b33f52a15..fc13417b4ca0b01826d96cf32d4f406778dc57be 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 3ae4cf4ef6e88e36fa10dce7ccc2967f6862bd8e..b3f3acb3aff0ede43523c4b4d337754f1d916e0d 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 82e04e20bc927d3fb647cfb0de8eca01ab98cdf8..a96198fee6fd018c05eb3aa31c6b8b31ac0aae16 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)