diff options
author | Chris Johns <chrisj@rtems.org> | 2011-03-14 05:07:19 +0000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2011-03-14 05:07:19 +0000 |
commit | d991d2f194b9e510630ef1223780a35718b79bfd (patch) | |
tree | 83366501e675b2719151ab1159ad7a6195c47efb /cpukit | |
parent | Regenerate. (diff) | |
download | rtems-d991d2f194b9e510630ef1223780a35718b79bfd.tar.bz2 |
2011-03-14 Chris Johns <chrisj@rtems.org>
PR 1757/filesystem
* libfs/src/rfs/rtems-rfs-block-pos.h,
libfs/src/rfs/rtems-rfs-block.h, libfs/src/rfs/rtems-rfs-file.c,
libfs/src/rfs/rtems-rfs-rtems-file.c: Set the file size in
iop-size when a file is open. Fix lseek to end of file then write
for sizes less than half the file system block size.
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/ChangeLog | 9 | ||||
-rw-r--r-- | cpukit/libfs/src/rfs/rtems-rfs-block-pos.h | 6 | ||||
-rw-r--r-- | cpukit/libfs/src/rfs/rtems-rfs-block.h | 32 | ||||
-rw-r--r-- | cpukit/libfs/src/rfs/rtems-rfs-file.c | 10 | ||||
-rw-r--r-- | cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c | 15 |
5 files changed, 58 insertions, 14 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index c985f557cc..ed413732fb 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,12 @@ +2011-03-14 Chris Johns <chrisj@rtems.org> + + PR 1757/filesystem + * libfs/src/rfs/rtems-rfs-block-pos.h, + libfs/src/rfs/rtems-rfs-block.h, libfs/src/rfs/rtems-rfs-file.c, + libfs/src/rfs/rtems-rfs-rtems-file.c: Set the file size in + iop-size when a file is open. Fix lseek to end of file then write + for sizes less than half the file system block size. + 2011-03-08 Joel Sherrill <joel.sherrilL@OARcorp.com> PR 1759/cpukit diff --git a/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h b/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h index bae67def3e..7f9955ae61 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h +++ b/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h @@ -193,6 +193,12 @@ typedef struct rtems_rfs_block_size_s if ((_b)->boff) --(_b)->bno; } while (0) /** + * Do the sizes match ? + */ +#define rtems_rfs_block_size_equal(_lhs, _rhs) \ + (((_lhs)->count == (_rhs)->count) && ((_lhs)->offset == (_rhs)->count)) + +/** * Zero a block size. * * @param size A pointer to the block size. diff --git a/cpukit/libfs/src/rfs/rtems-rfs-block.h b/cpukit/libfs/src/rfs/rtems-rfs-block.h index 79060f8a4c..e4e3f95830 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs-block.h +++ b/cpukit/libfs/src/rfs/rtems-rfs-block.h @@ -163,11 +163,6 @@ typedef struct rtems_rfs_block_map_s #define rtems_rfs_block_map_size_offset(_m) ((_m)->size.offset) /** - * Set the size offset for the map. - */ -#define rtems_rfs_block_map_set_size_offset(_m, _o) ((_m)->size.offset = (_o)) - -/** * Are we at the last block in the map ? */ #define rtems_rfs_block_map_last(_m) \ @@ -196,6 +191,33 @@ typedef struct rtems_rfs_block_map_s #define rtems_rfs_block_map_block_offset(_m) ((_m)->bpos.boff) /** + * Set the size offset for the map. The map is tagged as dirty. + * + * @param map Pointer to the open map to set the offset in. + * @param offset The offset to set in the map's size. + */ +static inline void +rtems_rfs_block_map_set_size_offset (rtems_rfs_block_map* map, + rtems_rfs_block_off offset) +{ + map->size.offset = offset; + map->dirty = true; +} + +/** + * Set the map's size. The map is tagged as dirty. + * + * @param map Pointer to the open map to set the offset in. + * @param size The size to set in the map's size. + */ +static inline void +rtems_rfs_block_map_set_size (rtems_rfs_block_map* map, + rtems_rfs_block_size* size) +{ + rtems_rfs_block_copy_size (&map->size, size); + map->dirty = true; +} +/** * Open a block map. The block map data in the inode is copied into the * map. The buffer handles are opened. The block position is set to the start * so a seek of offset 0 will return the first block. diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file.c b/cpukit/libfs/src/rfs/rtems-rfs-file.c index e17c705c8c..777726a23a 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs-file.c +++ b/cpukit/libfs/src/rfs/rtems-rfs-file.c @@ -172,8 +172,10 @@ rtems_rfs_file_close (rtems_rfs_file_system* fs, handle->shared->mtime); rtems_rfs_inode_set_ctime (&handle->shared->inode, handle->shared->ctime); - handle->shared->map.size.count = handle->shared->size.count; - handle->shared->map.size.offset = handle->shared->size.offset; + if (!rtems_rfs_block_size_equal (&handle->shared->size, + &handle->shared->map.size)) + rtems_rfs_block_map_set_size (&handle->shared->map, + &handle->shared->size); } rc = rtems_rfs_block_map_close (fs, &handle->shared->map); @@ -420,8 +422,8 @@ rtems_rfs_file_seek (rtems_rfs_file_handle* handle, * This means the file needs to set the file size to the pos only when a * write occurs. */ - if (pos <= rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle), - handle->shared)) + if (pos < rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle), + handle->shared)) rtems_rfs_file_set_bpos (handle, pos); *new_pos = pos; diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c index 5be618d8c6..90ef639300 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c +++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c @@ -70,6 +70,7 @@ rtems_rfs_rtems_file_open (rtems_libio_t* iop, if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN)) printf("rtems-rfs: file-open: handle:%p\n", file); + iop->size = rtems_rfs_file_size (file); iop->file_info = file; rtems_rfs_rtems_unlock (fs); @@ -195,21 +196,25 @@ rtems_rfs_rtems_file_write (rtems_libio_t* iop, pos = iop->offset; /* - * If the iop position is past the physical end of the file we need to set the - * file size to the new length before writing. + * If the iop position is past the physical end of the file we need to set + * the file size to the new length before writing. If the position equals the + * size of file we are still past the end of the file as positions number + * from 0. For a specific position we need a file that has a length of one + * more. */ - if (pos > rtems_rfs_file_size (file)) + if (pos >= rtems_rfs_file_size (file)) { - rc = rtems_rfs_file_set_size (file, pos); + rc = rtems_rfs_file_set_size (file, pos + 1); if (rc) { rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file)); return rtems_rfs_rtems_error ("file-write: write extend", rc); } - rtems_rfs_file_set_bpos (file, pos); } + rtems_rfs_file_set_bpos (file, pos); + while (count) { size_t size = count; |