Skip to content
Snippets Groups Projects
Commit 17dea00e authored by swym's avatar swym
Browse files

efs_lock_global: make signature more straight-forward

parent bb431657
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment