Ticket #1757: pr1757-4.10-rfs-fix-seek.diff

File pr1757-4.10-rfs-fix-seek.diff, 5.9 KB (added by Chris Johns, on Mar 12, 2011 at 5:38:52 AM)

Fix size on open and seek

  • cpukit/libfs/src/rfs/rtems-rfs-block-pos.h

    RCS file: /usr1/CVS/rtems/cpukit/libfs/src/rfs/rtems-rfs-block-pos.h,v
    retrieving revision 1.1.2.3
    diff -p -u -u -r1.1.2.3 rtems-rfs-block-pos.h
    typedef struct rtems_rfs_block_size_s 
    193193       if ((_b)->boff) --(_b)->bno; } while (0)
    194194
    195195/**
     196 * Do the sizes match ?
     197 */
     198#define rtems_rfs_block_size_equal(_lhs, _rhs) \
     199  (((_lhs)->count == (_rhs)->count) && ((_lhs)->offset == (_rhs)->count))
     200
     201/**
    196202 * Zero a block size.
    197203 *
    198204 * @param size A pointer to the block size.
  • cpukit/libfs/src/rfs/rtems-rfs-block.h

    RCS file: /usr1/CVS/rtems/cpukit/libfs/src/rfs/rtems-rfs-block.h,v
    retrieving revision 1.1.2.2
    diff -p -u -u -r1.1.2.2 rtems-rfs-block.h
    typedef struct rtems_rfs_block_map_s 
    163163#define rtems_rfs_block_map_size_offset(_m) ((_m)->size.offset)
    164164
    165165/**
    166  * Set the size offset for the map.
    167  */
    168 #define rtems_rfs_block_map_set_size_offset(_m, _o) ((_m)->size.offset = (_o))
    169 
    170 /**
    171166 * Are we at the last block in the map ?
    172167 */
    173168#define rtems_rfs_block_map_last(_m) \
    typedef struct rtems_rfs_block_map_s 
    196191#define rtems_rfs_block_map_block_offset(_m) ((_m)->bpos.boff)
    197192
    198193/**
     194 * Set the size offset for the map. The map is tagged as dirty.
     195 *
     196 * @param map Pointer to the open map to set the offset in.
     197 * @param offset The offset to set in the map's size.
     198 */
     199static inline void
     200rtems_rfs_block_map_set_size_offset (rtems_rfs_block_map* map,
     201                                     rtems_rfs_block_off  offset)
     202{
     203  map->size.offset = offset;
     204  map->dirty = true;
     205}
     206
     207/**
     208 * Set the map's size. The map is tagged as dirty.
     209 *
     210 * @param map Pointer to the open map to set the offset in.
     211 * @param size The size to set in the map's size.
     212 */
     213static inline void
     214rtems_rfs_block_map_set_size (rtems_rfs_block_map*  map,
     215                              rtems_rfs_block_size* size)
     216{
     217  rtems_rfs_block_copy_size (&map->size, size);
     218  map->dirty = true;
     219}
     220/**
    199221 * Open a block map. The block map data in the inode is copied into the
    200222 * map. The buffer handles are opened. The block position is set to the start
    201223 * so a seek of offset 0 will return the first block.
  • cpukit/libfs/src/rfs/rtems-rfs-file.c

    RCS file: /usr1/CVS/rtems/cpukit/libfs/src/rfs/rtems-rfs-file.c,v
    retrieving revision 1.4.2.2
    diff -p -u -u -r1.4.2.2 rtems-rfs-file.c
    rtems_rfs_file_close (rtems_rfs_file_sys 
    172172                                 handle->shared->mtime);
    173173      rtems_rfs_inode_set_ctime (&handle->shared->inode,
    174174                                 handle->shared->ctime);
    175       handle->shared->map.size.count = handle->shared->size.count;
    176       handle->shared->map.size.offset = handle->shared->size.offset;
     175      if (!rtems_rfs_block_size_equal (&handle->shared->size,
     176                                       &handle->shared->map.size))
     177        rtems_rfs_block_map_set_size (&handle->shared->map,
     178                                      &handle->shared->size);
    177179    }
    178180   
    179181    rc = rtems_rfs_block_map_close (fs, &handle->shared->map);
    rtems_rfs_file_seek (rtems_rfs_file_hand 
    420422   * This means the file needs to set the file size to the pos only when a
    421423   * write occurs.
    422424   */
    423   if (pos <= rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
    424                                              handle->shared))
     425  if (pos < rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
     426                                            handle->shared))
    425427    rtems_rfs_file_set_bpos (handle, pos);
    426428 
    427429  *new_pos = pos;
  • cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c

    RCS file: /usr1/CVS/rtems/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c,v
    retrieving revision 1.4.2.2
    diff -p -u -u -r1.4.2.2 rtems-rfs-rtems-file.c
    rtems_rfs_rtems_file_open (rtems_libio_t 
    7070  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
    7171    printf("rtems-rfs: file-open: handle:%p\n", file);
    7272 
     73  iop->size = rtems_rfs_file_size (file);
    7374  iop->file_info = file;
    7475 
    7576  rtems_rfs_rtems_unlock (fs);
    rtems_rfs_rtems_file_write (rtems_libio_ 
    195196  pos = iop->offset;
    196197 
    197198  /*
    198    * If the iop position is past the physical end of the file we need to set the
    199    * file size to the new length before writing.
     199   * If the iop position is past the physical end of the file we need to set
     200   * the file size to the new length before writing. If the position equals the
     201   * size of file we are still past the end of the file as positions number
     202   * from 0. For a specific position we need a file that has a length of one
     203   * more.
    200204   */
    201205 
    202   if (pos > rtems_rfs_file_size (file))
     206  if (pos >= rtems_rfs_file_size (file))
    203207  {
    204     rc = rtems_rfs_file_set_size (file, pos);
     208    rc = rtems_rfs_file_set_size (file, pos + 1);
    205209    if (rc)
    206210    {
    207211      rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
    208212      return rtems_rfs_rtems_error ("file-write: write extend", rc);
    209213    }
    210     rtems_rfs_file_set_bpos (file, pos);
    211214  }
    212215 
     216  rtems_rfs_file_set_bpos (file, pos);
     217 
    213218  while (count)
    214219  {
    215220    size_t size = count;