diff options
Diffstat (limited to 'cpukit/libfs')
-rw-r--r-- | cpukit/libfs/src/dosfs/fat_file.c | 59 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/fat_file.h | 5 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/msdos.h | 4 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/msdos_dir.c | 31 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/msdos_file.c | 116 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/msdos_handlers_dir.c | 4 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/msdos_handlers_file.c | 2 | ||||
-rw-r--r-- | cpukit/libfs/src/dosfs/msdos_misc.c | 31 |
8 files changed, 73 insertions, 179 deletions
diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c index a10347ccc4..73ea076819 100644 --- a/cpukit/libfs/src/dosfs/fat_file.c +++ b/cpukit/libfs/src/dosfs/fat_file.c @@ -774,65 +774,6 @@ fat_file_mark_removed( fat_fd->flags |= FAT_FILE_REMOVED; } -/* fat_file_datasync -- - * Synchronize fat-file - flush all buffered data to the media. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK on success, or -1 if error occured and errno set appropriately - */ -int -fat_file_datasync( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_fs_info_t *fs_info = mt_entry->fs_info; - uint32_t cur_cln = fat_fd->cln; - rtems_bdbuf_buffer *block = NULL; - uint32_t sec = 0; - uint32_t i = 0; - - if (fat_fd->fat_file_size == 0) - return RC_OK; - - /* - * we can use only one bdbuf :( and we also know that cache is useless - * for sync operation, so don't use it - */ - rc = fat_buf_release(fs_info); - if (rc != RC_OK) - return rc; - - /* for each cluster of the file ... */ - while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val) - { - sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln); - /* for each sector in cluster ... */ - for ( i = 0; i < fs_info->vol.spc; i++ ) - { - /* ... sync it */ - sc = rtems_bdbuf_read(fs_info->vol.dd, (sec + i), &block); - if (sc != RTEMS_SUCCESSFUL) - rtems_set_errno_and_return_minus_one( EIO ); - - sc = rtems_bdbuf_sync(block); - if ( sc != RTEMS_SUCCESSFUL ) - rtems_set_errno_and_return_minus_one( EIO ); - } - - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - return rc; - } - return rc; -} - /* fat_file_size -- * Calculate fat-file size - fat-file is nothing that clusters chain, so * go through all clusters in the chain and count it. Only diff --git a/cpukit/libfs/src/dosfs/fat_file.h b/cpukit/libfs/src/dosfs/fat_file.h index 30614c8f46..3a338a59ea 100644 --- a/cpukit/libfs/src/dosfs/fat_file.h +++ b/cpukit/libfs/src/dosfs/fat_file.h @@ -168,11 +168,6 @@ fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry, uint32_t new_length); int -fat_file_datasync(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - - -int fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry, fat_file_fd_t *fat_fd, int cmd, diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h index 0696b8f1fb..409c41897e 100644 --- a/cpukit/libfs/src/dosfs/msdos.h +++ b/cpukit/libfs/src/dosfs/msdos.h @@ -399,6 +399,10 @@ int msdos_get_dotdot_dir_info_cluster_num_and_offset( char *dir_entry ); +int msdos_sync_unprotected(msdos_fs_info_t *fs_info); + +int msdos_sync(rtems_libio_t *iop); + #ifdef __cplusplus } #endif diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c index 38ea6675f7..8bd807dc1b 100644 --- a/cpukit/libfs/src/dosfs/msdos_dir.c +++ b/cpukit/libfs/src/dosfs/msdos_dir.c @@ -457,34 +457,3 @@ msdos_dir_stat( * RETURNS: * */ - -/* msdos_dir_sync -- - * The following routine does a syncronization on a MSDOS directory node. - * DIR_WrtTime, DIR_WrtDate and DIR_fileSize fields of 32 Bytes Directory - * Entry Structure should not be updated for directories, so only call - * to corresponding fat-file routine. - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - */ -int -msdos_dir_sync(rtems_libio_t *iop) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_file_fd_t *fat_fd = iop->pathinfo.node_access; - 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); - - rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); - - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c index f68e44f948..176ec8e8db 100644 --- a/cpukit/libfs/src/dosfs/msdos_file.c +++ b/cpukit/libfs/src/dosfs/msdos_file.c @@ -27,30 +27,11 @@ #include "msdos.h" -/* msdos_file_close -- - * Close fat-file which correspondes to the file. If fat-file descriptor - * which correspondes to the file is not marked "removed", synchronize - * size, first cluster number, write time and date fields of the file. - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK, if file closed successfully, or -1 if error occured (errno set - * appropriately) - */ -int -msdos_file_close(rtems_libio_t *iop) +static int +msdos_file_update(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); + int rc = RC_OK; + fat_file_fd_t *fat_fd = iop->pathinfo.node_access; /* * if fat-file descriptor is not marked as "removed", synchronize @@ -61,25 +42,51 @@ msdos_file_close(rtems_libio_t *iop) rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { - rtems_semaphore_release(fs_info->vol_sema); return rc; } rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { - rtems_semaphore_release(fs_info->vol_sema); return rc; } rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { - rtems_semaphore_release(fs_info->vol_sema); return rc; } } + return rc; +} + +/* msdos_file_close -- + * Close fat-file which correspondes to the file. If fat-file descriptor + * which correspondes to the file is not marked "removed", synchronize + * size, first cluster number, write time and date fields of the file. + * + * PARAMETERS: + * iop - file control block + * + * RETURNS: + * RC_OK, if file closed successfully, or -1 if error occured (errno set + * appropriately) + */ +int +msdos_file_close(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); + + rc = msdos_file_update(iop); + rtems_semaphore_release(fs_info->vol_sema); return rc; } @@ -276,67 +283,14 @@ msdos_file_sync(rtems_libio_t *iop) if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); - /* synchronize file data */ - rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); + rc = msdos_file_update(iop); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } - /* - * if fat-file descriptor is not marked "removed" - synchronize file - * metadata - */ - if (!FAT_FILE_IS_REMOVED(fat_fd)) - { - rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - } - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_file_datasync -- - * Synchronize file - synchronize only file data (metadata is letf intact). - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -msdos_file_datasync(rtems_libio_t *iop) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_file_fd_t *fat_fd = iop->pathinfo.node_access; - 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); - - /* synchronize file data */ - fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); + rc = msdos_sync_unprotected(fs_info); rtems_semaphore_release(fs_info->vol_sema); return RC_OK; diff --git a/cpukit/libfs/src/dosfs/msdos_handlers_dir.c b/cpukit/libfs/src/dosfs/msdos_handlers_dir.c index 8c7dcdc0a5..7da9c1ec77 100644 --- a/cpukit/libfs/src/dosfs/msdos_handlers_dir.c +++ b/cpukit/libfs/src/dosfs/msdos_handlers_dir.c @@ -27,7 +27,7 @@ const rtems_filesystem_file_handlers_r msdos_dir_handlers = { rtems_filesystem_default_lseek_directory, msdos_dir_stat, rtems_filesystem_default_ftruncate_directory, - msdos_dir_sync, - msdos_dir_sync, + msdos_sync, + msdos_sync, rtems_filesystem_default_fcntl }; diff --git a/cpukit/libfs/src/dosfs/msdos_handlers_file.c b/cpukit/libfs/src/dosfs/msdos_handlers_file.c index 12cdaa048e..e4494f884e 100644 --- a/cpukit/libfs/src/dosfs/msdos_handlers_file.c +++ b/cpukit/libfs/src/dosfs/msdos_handlers_file.c @@ -28,6 +28,6 @@ const rtems_filesystem_file_handlers_r msdos_file_handlers = { msdos_file_stat, msdos_file_ftruncate, msdos_file_sync, - msdos_file_datasync, + msdos_sync, rtems_filesystem_default_fcntl }; diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c index d11bd83f52..511ac44dda 100644 --- a/cpukit/libfs/src/dosfs/msdos_misc.c +++ b/cpukit/libfs/src/dosfs/msdos_misc.c @@ -1646,3 +1646,34 @@ int msdos_find_node_by_cluster_num_in_fat_file( } return MSDOS_NAME_NOT_FOUND_ERR; } + +int +msdos_sync_unprotected(msdos_fs_info_t *fs_info) +{ + int rc = fat_buf_release(&fs_info->fat); + rtems_status_code sc = rtems_bdbuf_syncdev(fs_info->fat.vol.dd); + if (sc != RTEMS_SUCCESSFUL) { + errno = EIO; + rc = -1; + } + + return rc; +} + +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); + + rc = msdos_sync_unprotected(fs_info); + + rtems_semaphore_release(fs_info->vol_sema); + return rc; +} |