Skip to content
Snippets Groups Projects
Commit 8648f41d authored by swym's avatar swym Committed by rahix
Browse files

efs_lock_global: make signature more straight-forward

parent 4e22cb10
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
int epic_file_open(const char *filename, const char *mode) int epic_file_open(const char *filename, const char *mode)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_open(fs, filename, mode); res = efs_open(fs, filename, mode);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -22,8 +22,8 @@ int epic_file_open(const char *filename, const char *mode) ...@@ -22,8 +22,8 @@ int epic_file_open(const char *filename, const char *mode)
int epic_file_close(int fd) int epic_file_close(int fd)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_close(fs, fd); res = efs_close(fs, fd);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -33,8 +33,8 @@ int epic_file_close(int fd) ...@@ -33,8 +33,8 @@ int epic_file_close(int fd)
int epic_file_read(int fd, void *buf, size_t nbytes) int epic_file_read(int fd, void *buf, size_t nbytes)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_read(fs, fd, buf, nbytes); res = efs_read(fs, fd, buf, nbytes);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -44,8 +44,8 @@ int epic_file_read(int fd, void *buf, size_t nbytes) ...@@ -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) int epic_file_write(int fd, const void *buf, size_t nbytes)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_write(fs, fd, buf, nbytes); res = efs_write(fs, fd, buf, nbytes);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -55,8 +55,8 @@ int epic_file_write(int fd, const void *buf, size_t nbytes) ...@@ -55,8 +55,8 @@ int epic_file_write(int fd, const void *buf, size_t nbytes)
int epic_file_flush(int fd) int epic_file_flush(int fd)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_flush(fs, fd); res = efs_flush(fs, fd);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -66,8 +66,8 @@ int epic_file_flush(int fd) ...@@ -66,8 +66,8 @@ int epic_file_flush(int fd)
int epic_file_seek(int fd, long offset, int whence) int epic_file_seek(int fd, long offset, int whence)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_seek(fs, fd, offset, whence); res = efs_seek(fs, fd, offset, whence);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -77,8 +77,8 @@ int epic_file_seek(int fd, long offset, int whence) ...@@ -77,8 +77,8 @@ int epic_file_seek(int fd, long offset, int whence)
int epic_file_tell(int fd) int epic_file_tell(int fd)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_tell(fs, fd); res = efs_tell(fs, fd);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
...@@ -88,8 +88,8 @@ int epic_file_tell(int fd) ...@@ -88,8 +88,8 @@ int epic_file_tell(int fd)
int epic_file_stat(const char *filename, struct epic_stat *stat) int epic_file_stat(const char *filename, struct epic_stat *stat)
{ {
EpicFileSystem *fs; EpicFileSystem *fs;
int res; int res = efs_lock_global(&fs);
if (efs_lock_global(&fs, &res)) { if (res == 0) {
res = efs_stat(fs, filename, stat); res = efs_stat(fs, filename, stat);
efs_unlock_global(fs); efs_unlock_global(fs);
} }
......
...@@ -35,7 +35,7 @@ int efs_stat(EpicFileSystem *fs, const char *filename, struct epic_stat *stat); ...@@ -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 * 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. * 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); void efs_unlock_global(EpicFileSystem* fs);
#endif// EPICARCIUM_FS_INTERNAL_H_INCLUDED #endif// EPICARCIUM_FS_INTERNAL_H_INCLUDED
...@@ -139,9 +139,8 @@ int fatfs_attach() ...@@ -139,9 +139,8 @@ int fatfs_attach()
void fatfs_detach() void fatfs_detach()
{ {
FRESULT ff_res; FRESULT ff_res;
int rc;
EpicFileSystem *fs; EpicFileSystem *fs;
if (efs_lock_global(&fs, &rc)) { if (efs_lock_global(&fs) == 0) {
efs_close_all(fs); efs_close_all(fs);
//unmount by passing NULL as fs object, will destroy our sync object via ff_del_syncobj //unmount by passing NULL as fs object, will destroy our sync object via ff_del_syncobj
...@@ -188,21 +187,18 @@ static void globalLockRelease() ...@@ -188,21 +187,18 @@ static void globalLockRelease()
xSemaphoreGive(s_globalLock); xSemaphoreGive(s_globalLock);
} }
bool efs_lock_global(EpicFileSystem **fs, int *rc) int efs_lock_global(EpicFileSystem **fs)
{ {
*fs = NULL; *fs = NULL;
if (!globalLockAccquire()) { if (!globalLockAccquire()) {
*rc = -EBUSY; return -EBUSY;
return false;
} }
if (!s_globalFileSystem.initialized) { if (!s_globalFileSystem.initialized) {
globalLockRelease(); globalLockRelease();
*rc = -ENODEV; return -ENODEV;
return false;
} }
*fs = &s_globalFileSystem; *fs = &s_globalFileSystem;
*rc = 0; return 0;
return true;
} }
void efs_unlock_global(EpicFileSystem *fs) void efs_unlock_global(EpicFileSystem *fs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment