[PATCH 09/12] dosfs: Use self-contained recursive mutex
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Dec 21 14:09:57 UTC 2017
Update #2843.
---
cpukit/libfs/src/dosfs/msdos.h | 21 ++++++++-------
cpukit/libfs/src/dosfs/msdos_dir.c | 26 +++++++-----------
cpukit/libfs/src/dosfs/msdos_file.c | 46 +++++++++-----------------------
cpukit/libfs/src/dosfs/msdos_fsunmount.c | 2 +-
cpukit/libfs/src/dosfs/msdos_init.c | 16 ++---------
cpukit/libfs/src/dosfs/msdos_initsupp.c | 17 ++----------
cpukit/libfs/src/dosfs/msdos_misc.c | 8 ++----
cpukit/libfs/src/dosfs/msdos_statvfs.c | 10 +++----
cpukit/sapi/include/confdefs.h | 7 -----
9 files changed, 43 insertions(+), 110 deletions(-)
diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h
index abfede8203..ea94954cac 100644
--- a/cpukit/libfs/src/dosfs/msdos.h
+++ b/cpukit/libfs/src/dosfs/msdos.h
@@ -24,6 +24,7 @@
#include <rtems.h>
#include <rtems/libio_.h>
#include <rtems/dosfs.h>
+#include <rtems/thread.h>
#include "fat.h"
#include "fat_file.h"
@@ -62,11 +63,7 @@ typedef struct msdos_fs_info_s
* nodes of file
* type
*/
- rtems_id vol_sema; /*
- * semaphore
- * associated with
- * the volume
- */
+ rtems_recursive_mutex vol_mutex;
uint8_t *cl_buf; /*
* just placeholder
* for anything
@@ -75,16 +72,22 @@ typedef struct msdos_fs_info_s
rtems_dosfs_convert_control *converter;
} msdos_fs_info_t;
+RTEMS_INLINE_ROUTINE void msdos_fs_lock(msdos_fs_info_t *fs_info)
+{
+ rtems_recursive_mutex_lock(&fs_info->vol_mutex);
+}
+
+RTEMS_INLINE_ROUTINE void msdos_fs_unlock(msdos_fs_info_t *fs_info)
+{
+ rtems_recursive_mutex_unlock(&fs_info->vol_mutex);
+}
+
/* a set of routines that handle the nodes which are directories */
extern const rtems_filesystem_file_handlers_r msdos_dir_handlers;
/* a set of routines that handle the nodes which are files */
extern const rtems_filesystem_file_handlers_r msdos_file_handlers;
-/* Volume semaphore timeout value. This value can be changed to a number
- * of ticks to help debugging or if you need such a */
-#define MSDOS_VOLUME_SEMAPHORE_TIMEOUT RTEMS_NO_TIMEOUT
-
/*
* Macros for fetching fields from 32 bytes long FAT Directory Entry
* Structure
diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c
index e07c723e83..535d5f56f0 100644
--- a/cpukit/libfs/src/dosfs/msdos_dir.c
+++ b/cpukit/libfs/src/dosfs/msdos_dir.c
@@ -65,7 +65,6 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
{
int rc = RC_OK;
int eno = 0;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
rtems_dosfs_convert_control *converter = fs_info->converter;
const rtems_dosfs_convert_handler *convert_handler = converter->handler;
@@ -87,10 +86,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
int lfn_entries = 0;
bool is_first_entry;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
/*
* cast start and count - protect against using sizes that are not exact
@@ -123,7 +119,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
bts2rd, fs_info->cl_buf);
if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
rtems_set_errno_and_return_minus_one(EIO);
}
@@ -137,7 +133,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
if ((*MSDOS_DIR_ENTRY_TYPE(entry)) ==
MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return cmpltd;
}
@@ -252,7 +248,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
j * bts2rd, &cur_cln);
if (rc != RC_OK)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
@@ -262,7 +258,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
rc = fat_file_open(&fs_info->fat, &dir_pos, &tmp_fat_fd);
if (rc != RC_OK)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
@@ -336,7 +332,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
rc = fat_file_close(&fs_info->fat, tmp_fat_fd);
if (rc != RC_OK)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
}
@@ -348,7 +344,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
j++;
}
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return cmpltd;
}
@@ -382,14 +378,10 @@ msdos_dir_stat(
struct stat *buf
)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = loc->mt_entry->fs_info;
fat_file_fd_t *fat_fd = loc->node_access;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
buf->st_ino = fat_fd->ino;
@@ -402,7 +394,7 @@ msdos_dir_stat(
buf->st_ctime = fat_fd->ctime;
buf->st_mtime = fat_fd->mtime;
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return RC_OK;
}
diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c
index d150a1ff22..d7b170a01a 100644
--- a/cpukit/libfs/src/dosfs/msdos_file.c
+++ b/cpukit/libfs/src/dosfs/msdos_file.c
@@ -47,21 +47,17 @@ ssize_t
msdos_file_read(rtems_libio_t *iop, void *buffer, size_t count)
{
ssize_t ret = 0;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
ret = fat_file_read(&fs_info->fat, fat_fd, iop->offset, count,
buffer);
if (ret > 0)
iop->offset += ret;
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return ret;
}
@@ -82,14 +78,10 @@ ssize_t
msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
{
ssize_t ret = 0;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
if (rtems_libio_iop_is_append(iop))
iop->offset = fat_fd->fat_file_size;
@@ -98,7 +90,7 @@ msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
buffer);
if (ret < 0)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return -1;
}
@@ -113,7 +105,7 @@ msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
if (ret > 0)
fat_file_set_ctime_mtime(fat_fd, time(NULL));
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return ret;
}
@@ -132,15 +124,11 @@ msdos_file_stat(
struct stat *buf
)
{
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = loc->mt_entry->fs_info;
fat_file_fd_t *fat_fd = loc->node_access;
uint32_t cl_mask = fs_info->fat.vol.bpc - 1;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
buf->st_ino = fat_fd->ino;
@@ -154,7 +142,7 @@ msdos_file_stat(
buf->st_ctime = fat_fd->ctime;
buf->st_mtime = fat_fd->mtime;
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return RC_OK;
}
@@ -172,15 +160,11 @@ int
msdos_file_ftruncate(rtems_libio_t *iop, off_t length)
{
int rc = RC_OK;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
uint32_t old_length;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
old_length = fat_fd->fat_file_size;
if (length < old_length) {
@@ -206,7 +190,7 @@ msdos_file_ftruncate(rtems_libio_t *iop, off_t length)
fat_file_set_ctime_mtime(fat_fd, time(NULL));
}
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
@@ -225,27 +209,21 @@ int
msdos_file_sync(rtems_libio_t *iop)
{
int rc = RC_OK;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
rc = fat_file_update(&fs_info->fat, fat_fd);
if (rc != RC_OK)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
rc = fat_sync(&fs_info->fat);
- rtems_semaphore_release(fs_info->vol_sema);
- if ( rc != 0 )
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_unlock(fs_info);
return RC_OK;
}
diff --git a/cpukit/libfs/src/dosfs/msdos_fsunmount.c b/cpukit/libfs/src/dosfs/msdos_fsunmount.c
index e3cef45824..6b44ab0fdb 100644
--- a/cpukit/libfs/src/dosfs/msdos_fsunmount.c
+++ b/cpukit/libfs/src/dosfs/msdos_fsunmount.c
@@ -54,7 +54,7 @@ msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry)
fat_shutdown_drive(&fs_info->fat);
- rtems_semaphore_delete(fs_info->vol_sema);
+ rtems_recursive_mutex_destroy(&fs_info->vol_mutex);
(*converter->handler->destroy)( converter );
free(fs_info->cl_buf);
free(temp_mt_entry->fs_info);
diff --git a/cpukit/libfs/src/dosfs/msdos_init.c b/cpukit/libfs/src/dosfs/msdos_init.c
index 59afaf15ef..6ae77c86ae 100644
--- a/cpukit/libfs/src/dosfs/msdos_init.c
+++ b/cpukit/libfs/src/dosfs/msdos_init.c
@@ -75,24 +75,12 @@ const rtems_filesystem_operations_table msdos_ops = {
void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry)
{
- msdos_fs_info_t *fs_info = mt_entry->fs_info;
- rtems_status_code sc = rtems_semaphore_obtain(
- fs_info->vol_sema,
- RTEMS_WAIT,
- RTEMS_NO_TIMEOUT
- );
- if (sc != RTEMS_SUCCESSFUL) {
- rtems_fatal_error_occurred(0xdeadbeef);
- }
+ msdos_fs_lock(mt_entry->fs_info);
}
void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry)
{
- msdos_fs_info_t *fs_info = mt_entry->fs_info;
- rtems_status_code sc = rtems_semaphore_release(fs_info->vol_sema);
- if (sc != RTEMS_SUCCESSFUL) {
- rtems_fatal_error_occurred(0xdeadbeef);
- }
+ msdos_fs_unlock(mt_entry->fs_info);
}
/* msdos_initialize --
diff --git a/cpukit/libfs/src/dosfs/msdos_initsupp.c b/cpukit/libfs/src/dosfs/msdos_initsupp.c
index b43e61dde0..a8451615d2 100644
--- a/cpukit/libfs/src/dosfs/msdos_initsupp.c
+++ b/cpukit/libfs/src/dosfs/msdos_initsupp.c
@@ -57,7 +57,6 @@ msdos_initialize_support(
)
{
int rc = RC_OK;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = NULL;
fat_file_fd_t *fat_fd = NULL;
fat_dir_pos_t root_pos;
@@ -133,20 +132,8 @@ msdos_initialize_support(
rtems_set_errno_and_return_minus_one(ENOMEM);
}
- sc = rtems_semaphore_create(3,
- 1,
- RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
- RTEMS_INHERIT_PRIORITY,
- 0,
- &fs_info->vol_sema);
- if (sc != RTEMS_SUCCESSFUL)
- {
- fat_file_close(&fs_info->fat, fat_fd);
- fat_shutdown_drive(&fs_info->fat);
- free(fs_info->cl_buf);
- free(fs_info);
- rtems_set_errno_and_return_minus_one( EIO );
- }
+ rtems_recursive_mutex_init(&fs_info->vol_mutex,
+ RTEMS_FILESYSTEM_TYPE_DOSFS);
temp_mt_entry->mt_fs_root->location.node_access = fat_fd;
temp_mt_entry->mt_fs_root->location.handlers = directory_handlers;
diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c
index 24eb2d11e0..20fcbb3b75 100644
--- a/cpukit/libfs/src/dosfs/msdos_misc.c
+++ b/cpukit/libfs/src/dosfs/msdos_misc.c
@@ -2072,16 +2072,12 @@ int
msdos_sync(rtems_libio_t *iop)
{
int rc = RC_OK;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
rc = fat_sync(&fs_info->fat);
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
diff --git a/cpukit/libfs/src/dosfs/msdos_statvfs.c b/cpukit/libfs/src/dosfs/msdos_statvfs.c
index 99f200f3b7..a9e61c568f 100644
--- a/cpukit/libfs/src/dosfs/msdos_statvfs.c
+++ b/cpukit/libfs/src/dosfs/msdos_statvfs.c
@@ -24,12 +24,8 @@ int msdos_statvfs(
{
msdos_fs_info_t *fs_info = root_loc->mt_entry->fs_info;
fat_vol_t *vol = &fs_info->fat.vol;
- rtems_status_code sc = RTEMS_SUCCESSFUL;
- sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
- MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_set_errno_and_return_minus_one(EIO);
+ msdos_fs_lock(fs_info);
sb->f_bsize = FAT_SECTOR512_SIZE;
sb->f_frsize = vol->bpc;
@@ -54,7 +50,7 @@ int msdos_statvfs(
rc = fat_get_fat_cluster(&fs_info->fat, cur_cl, &value);
if (rc != RC_OK)
{
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return rc;
}
@@ -71,6 +67,6 @@ int msdos_statvfs(
sb->f_bavail = vol->free_cls;
}
- rtems_semaphore_release(fs_info->vol_sema);
+ msdos_fs_unlock(fs_info);
return RC_OK;
}
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 27f5b3eedd..e86920b728 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -417,14 +417,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
#if !defined(CONFIGURE_FILESYSTEM_ENTRY_DOSFS) && \
defined(CONFIGURE_FILESYSTEM_DOSFS)
#include <rtems/dosfs.h>
- #if !defined(CONFIGURE_MAXIMUM_DOSFS_MOUNTS)
- #define CONFIGURE_MAXIMUM_DOSFS_MOUNTS 1
- #endif
#define CONFIGURE_FILESYSTEM_ENTRY_DOSFS \
{ RTEMS_FILESYSTEM_TYPE_DOSFS, rtems_dosfs_initialize }
- #define _CONFIGURE_SEMAPHORES_FOR_DOSFS CONFIGURE_MAXIMUM_DOSFS_MOUNTS
-#else
- #define _CONFIGURE_SEMAPHORES_FOR_DOSFS 0
#endif
/**
@@ -460,7 +454,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
#define _CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS \
(_CONFIGURE_SEMAPHORES_FOR_FIFOS + \
_CONFIGURE_SEMAPHORES_FOR_NFS + \
- _CONFIGURE_SEMAPHORES_FOR_DOSFS + \
_CONFIGURE_SEMAPHORES_FOR_RFS)
#ifdef CONFIGURE_INIT
--
2.12.3
More information about the devel
mailing list