summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/dosfs/msdos_file.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-12-13 16:15:25 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-02-02 15:01:22 +0100
commit3b77417ba7a6ad6cb6bbfaeccc4cfd0cd7198489 (patch)
tree1daaeda170261ef780e22e6bfd2545d8c423b68d /cpukit/libfs/src/dosfs/msdos_file.c
parentJFFS2: Use self-contained recursive mutex (diff)
downloadrtems-3b77417ba7a6ad6cb6bbfaeccc4cfd0cd7198489.tar.bz2
dosfs: Use self-contained recursive mutex
Update #2843.
Diffstat (limited to 'cpukit/libfs/src/dosfs/msdos_file.c')
-rw-r--r--cpukit/libfs/src/dosfs/msdos_file.c46
1 files changed, 12 insertions, 34 deletions
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;
}