forked from Imagelibrary/rtems
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.
This commit is contained in:
@@ -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>
|
2011-03-08 Joel Sherrill <joel.sherrilL@OARcorp.com>
|
||||||
|
|
||||||
PR 1759/cpukit
|
PR 1759/cpukit
|
||||||
|
|||||||
@@ -192,6 +192,12 @@ typedef struct rtems_rfs_block_size_s
|
|||||||
(_b)->block = 0; \
|
(_b)->block = 0; \
|
||||||
if ((_b)->boff) --(_b)->bno; } while (0)
|
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.
|
* Zero a block size.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -162,11 +162,6 @@ typedef struct rtems_rfs_block_map_s
|
|||||||
*/
|
*/
|
||||||
#define rtems_rfs_block_map_size_offset(_m) ((_m)->size.offset)
|
#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 ?
|
* Are we at the last block in the map ?
|
||||||
*/
|
*/
|
||||||
@@ -195,6 +190,33 @@ typedef struct rtems_rfs_block_map_s
|
|||||||
*/
|
*/
|
||||||
#define rtems_rfs_block_map_block_offset(_m) ((_m)->bpos.boff)
|
#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
|
* 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
|
* map. The buffer handles are opened. The block position is set to the start
|
||||||
|
|||||||
@@ -172,8 +172,10 @@ rtems_rfs_file_close (rtems_rfs_file_system* fs,
|
|||||||
handle->shared->mtime);
|
handle->shared->mtime);
|
||||||
rtems_rfs_inode_set_ctime (&handle->shared->inode,
|
rtems_rfs_inode_set_ctime (&handle->shared->inode,
|
||||||
handle->shared->ctime);
|
handle->shared->ctime);
|
||||||
handle->shared->map.size.count = handle->shared->size.count;
|
if (!rtems_rfs_block_size_equal (&handle->shared->size,
|
||||||
handle->shared->map.size.offset = handle->shared->size.offset;
|
&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);
|
rc = rtems_rfs_block_map_close (fs, &handle->shared->map);
|
||||||
@@ -420,7 +422,7 @@ 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
|
* This means the file needs to set the file size to the pos only when a
|
||||||
* write occurs.
|
* write occurs.
|
||||||
*/
|
*/
|
||||||
if (pos <= rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
|
if (pos < rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
|
||||||
handle->shared))
|
handle->shared))
|
||||||
rtems_rfs_file_set_bpos (handle, pos);
|
rtems_rfs_file_set_bpos (handle, pos);
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ rtems_rfs_rtems_file_open (rtems_libio_t* iop,
|
|||||||
if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
|
if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
|
||||||
printf("rtems-rfs: file-open: handle:%p\n", file);
|
printf("rtems-rfs: file-open: handle:%p\n", file);
|
||||||
|
|
||||||
|
iop->size = rtems_rfs_file_size (file);
|
||||||
iop->file_info = file;
|
iop->file_info = file;
|
||||||
|
|
||||||
rtems_rfs_rtems_unlock (fs);
|
rtems_rfs_rtems_unlock (fs);
|
||||||
@@ -195,21 +196,25 @@ rtems_rfs_rtems_file_write (rtems_libio_t* iop,
|
|||||||
pos = iop->offset;
|
pos = iop->offset;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the iop position is past the physical end of the file we need to set the
|
* If the iop position is past the physical end of the file we need to set
|
||||||
* file size to the new length before writing.
|
* 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)
|
if (rc)
|
||||||
{
|
{
|
||||||
rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
|
rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
|
||||||
return rtems_rfs_rtems_error ("file-write: write extend", rc);
|
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)
|
while (count)
|
||||||
{
|
{
|
||||||
size_t size = count;
|
size_t size = count;
|
||||||
|
|||||||
Reference in New Issue
Block a user