dosfs: Use self-contained recursive mutex

Update #2843.
This commit is contained in:
Sebastian Huber
2017-12-13 16:15:25 +01:00
parent b17bcb3855
commit 3b77417ba7
9 changed files with 43 additions and 110 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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 --

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}