Changeset 30d4124 in rtems


Ignore:
Timestamp:
May 7, 2012, 2:30:37 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
d61b0a5
Parents:
eb7c6a84
git-author:
Sebastian Huber <sebastian.huber@…> (05/07/12 14:30:37)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/11/12 11:58:43)
Message:

Filesystem: PR1398: Fix lseek() mechanic

According to POSIX the lseek() function shall not, by itself, extend the
size of a file.

Remove the size field of rtems_libio_t. A file has only one size but
may have multiple open file descriptors. Thus a file size field in the
file descriptor may lead to inconsistencies.

New default handlers rtems_filesystem_default_lseek_file() and
rtems_filesystem_default_lseek_directory().

Files:
1 added
23 edited
1 moved

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/src/blkdev-imfs.c

    reb7c6a84 r30d4124  
    207207  .write_h = rtems_blkdev_imfs_write,
    208208  .ioctl_h = rtems_blkdev_imfs_ioctl,
    209   .lseek_h = rtems_filesystem_default_lseek_success,
     209  .lseek_h = rtems_filesystem_default_lseek_file,
    210210  .fstat_h = rtems_blkdev_imfs_fstat,
    211211  .ftruncate_h = rtems_filesystem_default_ftruncate,
  • cpukit/libcsupport/include/rtems/libio.h

    reb7c6a84 r30d4124  
    850850 * @retval -1 An error occured.  The errno is set to indicate the error.
    851851 *
    852  * @see rtems_filesystem_default_lseek() and
    853  * rtems_filesystem_default_lseek_success().
     852 * @see rtems_filesystem_default_lseek(),
     853 * rtems_filesystem_default_lseek_file(), and
     854 * rtems_filesystem_default_lseek_directory().
    854855 */
    855856typedef off_t (*rtems_filesystem_lseek_t)(
     
    10271028
    10281029/**
     1030 * @brief An offset 0 with a whence of SEEK_SET will perform a directory rewind
     1031 * operation.
     1032 *
     1033 * This function has no protection against concurrent access.
     1034 *
     1035 * @retval -1 The offset is not zero or the whence is not SEEK_SET.
     1036 * @retval 0 Successful rewind operation.
     1037 *
     1038 * @see rtems_filesystem_lseek_t.
     1039 */
     1040off_t rtems_filesystem_default_lseek_directory(
     1041  rtems_libio_t *iop,
     1042  off_t offset,
     1043  int whence
     1044);
     1045
     1046/**
     1047 * @brief Default lseek() handler for files.
     1048 *
     1049 * The fstat() handler will be used to obtain the file size in case whence is
     1050 * SEEK_END.
     1051 *
     1052 * This function has no protection against concurrent access.
     1053 *
     1054 * @retval -1 An error occured.  In case an integer overflow occured, then the
     1055 * errno will be set to EOVERFLOW.  In case the new offset is negative, then
     1056 * the errno will be set to EINVAL.  In case the whence is SEEK_END and the
     1057 * fstat() handler to obtain the current file size returned an error status,
     1058 * then the errno will be set by the fstat() handler.
     1059 * @retval offset The new offset.
     1060 *
     1061 * @see rtems_filesystem_lseek_t.
     1062 */
     1063off_t rtems_filesystem_default_lseek_file(
     1064  rtems_libio_t *iop,
     1065  off_t offset,
     1066  int whence
     1067);
     1068
     1069/**
    10291070 * @retval 0 Always.
    10301071 *
    10311072 * @see rtems_filesystem_lseek_t.
    10321073 */
    1033 off_t rtems_filesystem_default_lseek_success(
     1074off_t rtems_filesystem_default_lseek_file(
    10341075  rtems_libio_t *iop,
    10351076  off_t          offset,
     
    11581199 *
    11591200 * @todo Should really have a separate per/file data structure that this points
    1160  * to (eg: size, offset, driver, pathname should be in that)
     1201 * to (eg: offset, driver, pathname should be in that)
    11611202 */
    11621203struct rtems_libio_tt {
    11631204  rtems_driver_name_t                    *driver;
    1164   off_t                                   size;      /* size of file */
    11651205  off_t                                   offset;    /* current offset into file */
    11661206  uint32_t                                flags;
  • cpukit/libcsupport/src/lseek.c

    reb7c6a84 r30d4124  
    2222off_t lseek( int fd, off_t offset, int whence )
    2323{
    24   off_t rv = 0;
    2524  rtems_libio_t *iop;
    26   off_t reference_offset;
    27   off_t old_offset;
    28   off_t new_offset;
    2925
    3026  rtems_libio_check_fd( fd );
     
    3228  rtems_libio_check_is_open(iop);
    3329
    34   old_offset = iop->offset;
    35   switch ( whence ) {
    36     case SEEK_SET:
    37       reference_offset = 0;
    38       break;
    39     case SEEK_CUR:
    40       reference_offset = old_offset;
    41       break;
    42     case SEEK_END:
    43       reference_offset = iop->size;
    44       break;
    45     default:
    46       errno = EINVAL;
    47       rv = (off_t) -1;
    48       break;
    49   }
    50   new_offset = reference_offset + offset;
    51 
    52   if ( rv == 0 ) {
    53     if (
    54       (reference_offset >= 0 && new_offset >= offset)
    55         || (reference_offset < 0 && new_offset <= offset)
    56     ) {
    57       switch ( rtems_filesystem_node_type( &iop->pathinfo ) ) {
    58         case RTEMS_FILESYSTEM_DIRECTORY:
    59         case RTEMS_FILESYSTEM_MEMORY_FILE:
    60           if ( new_offset < 0 ) {
    61             errno = EINVAL;
    62             rv = (off_t) -1;
    63           }
    64           break;
    65         default:
    66           break;
    67       }
    68 
    69       if ( rv == 0 ) {
    70         iop->offset = new_offset;
    71         rv = (*iop->pathinfo.handlers->lseek_h)( iop, offset, whence );
    72         if ( rv == (off_t) -1 ) {
    73           iop->offset = old_offset;
    74         }
    75       }
    76     } else {
    77       errno = EOVERFLOW;
    78       rv = (off_t) -1;
    79     }
    80   }
    81 
    82   return rv;
     30  return (*iop->pathinfo.handlers->lseek_h)( iop, offset, whence );
    8331}
    8432
  • cpukit/libfs/Makefile.am

    reb7c6a84 r30d4124  
    2424    src/defaults/default_fcntl.c src/defaults/default_fsmount.c \
    2525    src/defaults/default_ftruncate.c src/defaults/default_lseek.c \
    26     src/defaults/default_lseek_success.c \
     26    src/defaults/default_lseek_file.c \
     27    src/defaults/default_lseek_directory.c \
    2728    src/defaults/default_readlink.c src/defaults/default_statvfs.c \
    2829    src/defaults/default_utime.c \
  • cpukit/libfs/src/defaults/default_lseek_directory.c

    reb7c6a84 r30d4124  
    1 
    21/*
    32 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
     
    2019#include <rtems/libio_.h>
    2120
    22 off_t rtems_filesystem_default_lseek_success(
     21off_t rtems_filesystem_default_lseek_directory(
    2322  rtems_libio_t *iop,
    2423  off_t offset,
     
    2625)
    2726{
    28   return 0;
     27  off_t rv = 0;
     28
     29  if ( offset == 0 && whence == SEEK_SET ) {
     30    iop->offset = 0;
     31  } else {
     32    errno = EINVAL;
     33    rv = -1;
     34  }
     35
     36  return rv;
    2937}
  • cpukit/libfs/src/devfs/devfs_init.c

    reb7c6a84 r30d4124  
    4343  .write_h = devFS_write,
    4444  .ioctl_h = devFS_ioctl,
    45   .lseek_h = rtems_filesystem_default_lseek,
     45  .lseek_h = rtems_filesystem_default_lseek_file,
    4646  .fstat_h = devFS_stat,
    4747  .ftruncate_h = rtems_filesystem_default_ftruncate,
  • cpukit/libfs/src/dosfs/msdos.h

    reb7c6a84 r30d4124  
    287287);
    288288
    289 off_t msdos_file_lseek(
    290   rtems_libio_t        *iop,              /* IN  */
    291   off_t                 offset,           /* IN  */
    292   int                   whence            /* IN  */
    293 );
    294 
    295289int msdos_file_stat(
    296290  const rtems_filesystem_location_info_t *loc,
     
    321315  void          *buffer,           /* IN  */
    322316  size_t         count             /* IN  */
    323 );
    324 
    325 off_t msdos_dir_lseek(
    326   rtems_libio_t        *iop,              /* IN  */
    327   off_t                 offset,           /* IN  */
    328   int                   whence            /* IN  */
    329317);
    330318
  • cpukit/libfs/src/dosfs/msdos_dir.c

    reb7c6a84 r30d4124  
    466466 */
    467467
    468 /* msdos_dir_lseek --
    469  *
    470  *  This routine will behave in one of three ways based on the state of
    471  *  argument whence. Based on the state of its value the offset argument will
    472  *  be interpreted using one of the following methods:
    473  *
    474  *     SEEK_SET - offset is the absolute byte offset from the start of the
    475  *                logical start of the dirent sequence that represents the
    476  *                directory
    477  *     SEEK_CUR - offset is used as the relative byte offset from the current
    478  *                directory position index held in the iop structure
    479  *     SEEK_END - N/A --> This will cause an assert.
    480  *
    481  * PARAMETERS:
    482  *     iop    - file control block
    483  *     offset - offset
    484  *     whence - predefine directive
    485  *
    486  * RETURNS:
    487  *     RC_OK on success, or -1 if error occured (errno
    488  *     set apropriately).
    489  */
    490 off_t
    491 msdos_dir_lseek(rtems_libio_t *iop, off_t offset, int whence)
    492 {
    493     if (iop->offset >= 0 && iop->offset <= iop->size) {
    494         return 0;
    495     } else {
    496         rtems_set_errno_and_return_minus_one(EINVAL);
    497     }
    498 }
    499 
    500468/* msdos_dir_stat --
    501469 *
  • cpukit/libfs/src/dosfs/msdos_file.c

    reb7c6a84 r30d4124  
    6464    if (iop->flags & LIBIO_FLAGS_APPEND)
    6565        iop->offset = fat_fd->fat_file_size;
    66 
    67     iop->size = fat_fd->fat_file_size;
    6866
    6967    rtems_semaphore_release(fs_info->vol_sema);
     
    204202        fat_fd->fat_file_size = iop->offset + ret;
    205203
    206     iop->size = fat_fd->fat_file_size;
    207 
    208204    rtems_semaphore_release(fs_info->vol_sema);
    209205    return ret;
    210 }
    211 
    212 /* msdos_file_lseek --
    213  *     Process lseek call to the file: extend file if lseek is up to the end
    214  *     of the file.
    215  *
    216  * PARAMETERS:
    217  *     iop    - file control block
    218  *     offset - new offset
    219  *     whence - predefine directive
    220  *
    221  * RETURNS:
    222  *     new offset on success, or -1 if error occured (errno set
    223  *     appropriately).
    224  */
    225 off_t
    226 msdos_file_lseek(rtems_libio_t *iop, off_t offset, int whence)
    227 {
    228     int                rc = RC_OK;
    229     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    230     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    231     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    232     uint32_t           real_size = 0;
    233 
    234     if (iop->offset < 0 || iop->offset > UINT32_MAX) {
    235         rtems_set_errno_and_return_minus_one(EINVAL);
    236     }
    237 
    238     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    239                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    240     if (sc != RTEMS_SUCCESSFUL)
    241         rtems_set_errno_and_return_minus_one(EIO);
    242 
    243     rc = fat_file_extend(iop->pathinfo.mt_entry, fat_fd, iop->offset,
    244                          &real_size);
    245     if (rc != RC_OK)
    246     {
    247         rtems_semaphore_release(fs_info->vol_sema);
    248         return rc;
    249     }
    250 
    251     if (real_size > fat_fd->fat_file_size)
    252         fat_fd->fat_file_size = iop->offset = real_size;
    253 
    254     iop->size = fat_fd->fat_file_size;
    255 
    256     rtems_semaphore_release(fs_info->vol_sema);
    257     return iop->offset;
    258206}
    259207
     
    333281     */
    334282    if (length < fat_fd->fat_file_size)
    335         iop->size = fat_fd->fat_file_size = length;
     283        fat_fd->fat_file_size = length;
    336284
    337285    rtems_semaphore_release(fs_info->vol_sema);
  • cpukit/libfs/src/dosfs/msdos_handlers_dir.c

    reb7c6a84 r30d4124  
    2525    rtems_filesystem_default_write,
    2626    rtems_filesystem_default_ioctl,
    27     msdos_dir_lseek,
     27    rtems_filesystem_default_lseek_directory,
    2828    msdos_dir_stat,
    2929    rtems_filesystem_default_ftruncate_directory,
  • cpukit/libfs/src/dosfs/msdos_handlers_file.c

    reb7c6a84 r30d4124  
    2525    msdos_file_write,
    2626    rtems_filesystem_default_ioctl,
    27     msdos_file_lseek,
     27    rtems_filesystem_default_lseek_file,
    2828    msdos_file_stat,
    2929    msdos_file_ftruncate,
  • cpukit/libfs/src/imfs/deviceio.c

    reb7c6a84 r30d4124  
    193193
    194194/*
    195  *  device_lseek
    196  *
    197  *  This handler eats all lseek() operations and does not create
    198  *  an error. It assumes all devices can handle the seek. The
    199  *  writes fail.
    200  */
    201 
    202 off_t device_lseek(
    203   rtems_libio_t *iop,
    204   off_t          offset,
    205   int            whence
    206 )
    207 {
    208   return offset;
    209 }
    210 
    211 /*
    212195 *  device_stat
    213196 *
  • cpukit/libfs/src/imfs/imfs.h

    reb7c6a84 r30d4124  
    419419);
    420420
    421 extern off_t imfs_dir_lseek(
    422   rtems_libio_t        *iop,              /* IN  */
    423   off_t                 offset,           /* IN  */
    424   int                   whence            /* IN  */
    425 );
    426 
    427421extern int memfile_open(
    428422  rtems_libio_t *iop,             /* IN  */
     
    450444);
    451445
    452 extern off_t memfile_lseek(
    453   rtems_libio_t        *iop,        /* IN  */
    454   off_t                 offset,     /* IN  */
    455   int                   whence      /* IN  */
    456 );
    457 
    458446extern int device_open(
    459447  rtems_libio_t *iop,            /* IN  */
     
    483471  uint32_t       command,           /* IN  */
    484472  void          *buffer             /* IN  */
    485 );
    486 
    487 extern off_t device_lseek(
    488   rtems_libio_t *iop,               /* IN  */
    489   off_t          offset,            /* IN  */
    490   int            whence             /* IN  */
    491473);
    492474
  • cpukit/libfs/src/imfs/imfs_directory.c

    reb7c6a84 r30d4124  
    100100   return bytes_transferred;
    101101}
    102 
    103 /*
    104  *  imfs_dir_lseek
    105  *
    106  *  This routine will behave in one of three ways based on the state of
    107  *  argument whence. Based on the state of its value the offset argument will
    108  *  be interpreted using one of the following methods:
    109  *
    110  *     SEEK_SET - offset is the absolute byte offset from the start of the
    111  *                logical start of the dirent sequence that represents the
    112  *                directory
    113  *     SEEK_CUR - offset is used as the relative byte offset from the current
    114  *                directory position index held in the iop structure
    115  *     SEEK_END - N/A --> This will cause an EINVAL to be returned.
    116  */
    117 
    118 off_t imfs_dir_lseek(
    119   rtems_libio_t  *iop,
    120   off_t           offset,
    121   int             whence
    122 )
    123 {
    124   switch( whence ) {
    125      case SEEK_SET:   /* absolute move from the start of the file */
    126      case SEEK_CUR:   /* relative move */
    127         iop->offset = (iop->offset/sizeof(struct dirent)) *
    128               sizeof(struct dirent);
    129         break;
    130 
    131      case SEEK_END:   /* Movement past the end of the directory via lseek */
    132                       /* is not a permitted operation                     */
    133       default:
    134         rtems_set_errno_and_return_minus_one( EINVAL );
    135         break;
    136   }
    137 
    138   return 0;
    139 }
  • cpukit/libfs/src/imfs/imfs_handlers_device.c

    reb7c6a84 r30d4124  
    3737  device_write,
    3838  device_ioctl,
    39   device_lseek,
     39  rtems_filesystem_default_lseek_file,
    4040  IMFS_stat_device,
    4141  device_ftruncate,
  • cpukit/libfs/src/imfs/imfs_handlers_directory.c

    reb7c6a84 r30d4124  
    5353  rtems_filesystem_default_write,
    5454  rtems_filesystem_default_ioctl,
    55   imfs_dir_lseek,
     55  rtems_filesystem_default_lseek_directory,
    5656  IMFS_stat_directory,
    5757  rtems_filesystem_default_ftruncate_directory,
  • cpukit/libfs/src/imfs/imfs_handlers_memfile.c

    reb7c6a84 r30d4124  
    3737  memfile_write,
    3838  memfile_ioctl,
    39   memfile_lseek,
     39  rtems_filesystem_default_lseek_file,
    4040  IMFS_stat_file,
    4141  memfile_ftruncate,
  • cpukit/libfs/src/imfs/memfile.c

    reb7c6a84 r30d4124  
    110110    iop->offset = the_jnode->info.file.size;
    111111
    112   iop->size = the_jnode->info.file.size;
    113112  return 0;
    114113}
     
    149148
    150149  status = IMFS_memfile_write( the_jnode, iop->offset, buffer, count );
    151   iop->size = the_jnode->info.file.size;
    152150
    153151  return status;
     
    171169
    172170/*
    173  *  memfile_lseek
    174  *
    175  *  This routine processes the lseek() system call.
    176  */
    177 off_t memfile_lseek(
    178   rtems_libio_t   *iop,
    179   off_t            offset,
    180   int              whence
    181 )
    182 {
    183   IMFS_jnode_t   *the_jnode;
    184 
    185   the_jnode = iop->pathinfo.node_access;
    186 
    187   if (IMFS_type( the_jnode ) == IMFS_LINEAR_FILE) {
    188     if (iop->offset > the_jnode->info.linearfile.size)
    189       iop->offset = the_jnode->info.linearfile.size;
    190   }
    191   else {  /* Must be a block file (IMFS_MEMORY_FILE). */
    192     if (IMFS_memfile_extend( the_jnode, iop->offset ))
    193       rtems_set_errno_and_return_minus_one( ENOSPC );
    194 
    195     iop->size = the_jnode->info.file.size;
    196   }
    197   return iop->offset;
    198 }
    199 
    200 /*
    201171 *  memfile_stat
    202172 *
     
    233203   */
    234204  the_jnode->info.file.size = length;
    235   iop->size = the_jnode->info.file.size;
    236205
    237206  IMFS_update_atime( the_jnode );
     
    266235   */
    267236  if ( new_length >= IMFS_MEMFILE_MAXIMUM_SIZE )
    268     rtems_set_errno_and_return_minus_one( EINVAL );
     237    rtems_set_errno_and_return_minus_one( EFBIG );
    269238
    270239  /*
     
    655624    status = IMFS_memfile_extend( the_jnode, last_byte );
    656625    if ( status )
    657       rtems_set_errno_and_return_minus_one( ENOSPC );
     626      return status;
    658627  }
    659628
  • cpukit/libfs/src/nfsclient/src/nfs.c

    reb7c6a84 r30d4124  
    24252425}
    24262426
    2427 static off_t nfs_file_lseek(
    2428         rtems_libio_t *iop,
    2429         off_t          length,
    2430         int            whence
    2431 )
    2432 {
    2433 #if DEBUG & DEBUG_SYSCALLS
    2434         fprintf(stderr,
    2435                         "lseek to %i (length %i, whence %i)\n",
    2436                         iop->offset,
    2437                         length,
    2438                         whence);
    2439 #endif
    2440         if ( SEEK_END == whence ) {
    2441                 /* rtems (4.6.2) libcsupport code 'lseek' uses iop->size to
    2442                  * compute the offset. We don't want to track the file size
    2443                  * by updating 'iop->size' constantly.
    2444                  * Since lseek is the only place using iop->size, we work
    2445                  * around this by tweaking the offset here...
    2446                  */
    2447                 NfsNode node = iop->pathinfo.node_access;
    2448                 fattr   *fa  = &SERP_ATTR(node);
    2449 
    2450                 if (updateAttr(node, 0 /* only if old */)) {
    2451                         return -1;
    2452                 }
    2453                 iop->offset = fa->size;
    2454         }
    2455 
    2456         /* this is particularly easy :-) */
    2457         return iop->offset;
    2458 }
    2459 
    24602427static off_t nfs_dir_lseek(
    24612428        rtems_libio_t *iop,
     
    24642431)
    24652432{
    2466 DirInfo di = iop->pathinfo.node_access_2;
    2467 
    2468         /* we don't support anything other than
    2469          * rewinding
    2470          */
    2471         if (SEEK_SET != whence || 0 != length) {
    2472                 errno = ENOTSUP;
    2473                 return -1;
    2474         }
    2475 
    2476         /* rewind cookie */
    2477         memset( &di->readdirargs.cookie,
    2478                 0,
    2479                 sizeof(di->readdirargs.cookie) );
    2480 
    2481         di->eofreached = FALSE;
    2482 
    2483         return iop->offset;
     2433        off_t rv = rtems_filesystem_default_lseek_directory(iop, length, whence);
     2434
     2435        if (rv == 0) {
     2436                DirInfo di = iop->pathinfo.node_access_2;
     2437                nfscookie *cookie = &di->readdirargs.cookie;
     2438
     2439                di->eofreached = FALSE;
     2440
     2441                /* rewind cookie */
     2442                memset(cookie, 0, sizeof(*cookie));
     2443        }
     2444
     2445        return rv;
    24842446}
    24852447
     
    27042666        .write_h     = nfs_file_write,
    27052667        .ioctl_h     = rtems_filesystem_default_ioctl,
    2706         .lseek_h     = nfs_file_lseek,
     2668        .lseek_h     = rtems_filesystem_default_lseek_file,
    27072669        .fstat_h     = nfs_fstat,
    27082670        .ftruncate_h = nfs_file_ftruncate,
  • cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c

    reb7c6a84 r30d4124  
    215215
    216216/**
    217  * This handler eats all lseek() operations and does not create an error. It
    218  * assumes all devices can handle the seek. The writes fail.
    219  *
    220  * @param iop
    221  * @param offset
    222  * @param whence
    223  * @return off_t
    224  */
    225 
    226 static off_t
    227 rtems_rfs_rtems_device_lseek (rtems_libio_t* iop,
    228                               off_t          offset,
    229                               int            whence)
    230 {
    231   return offset;
    232 }
    233 
    234 /**
    235217 * The consumes the truncate call. You cannot truncate device files.
    236218 *
     
    256238  .write_h     = rtems_rfs_rtems_device_write,
    257239  .ioctl_h     = rtems_rfs_rtems_device_ioctl,
    258   .lseek_h     = rtems_rfs_rtems_device_lseek,
     240  .lseek_h     = rtems_filesystem_default_lseek_file,
    259241  .fstat_h     = rtems_rfs_rtems_fstat,
    260242  .ftruncate_h = rtems_rfs_rtems_device_ftruncate,
  • cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c

    reb7c6a84 r30d4124  
    151151}
    152152
    153 /**
    154  * This routine will behave in one of three ways based on the state of argument
    155  * whence. Based on the state of its value the offset argument will be
    156  * interpreted using one of the following methods:
    157  *
    158  *   SEEK_SET - offset is the absolute byte offset from the start of the
    159  *              logical start of the dirent sequence that represents the
    160  *              directory
    161  *   SEEK_CUR - offset is used as the relative byte offset from the current
    162  *              directory position index held in the iop structure
    163  *   SEEK_END - N/A --> This will cause an assert.
    164  *
    165  * @param iop
    166  * @param offset
    167  * @param whence
    168  * return off_t
    169  */
    170 static off_t
    171 rtems_rfs_rtems_dir_lseek (rtems_libio_t* iop,
    172                            off_t          offset,
    173                            int            whence)
    174 {
    175   switch (whence)
    176   {
    177     case SEEK_SET:   /* absolute move from the start of the file */
    178     case SEEK_CUR:   /* relative move */
    179       break;
    180 
    181      case SEEK_END:   /* Movement past the end of the directory via lseek */
    182                       /* is not a permitted operation                     */
    183     default:
    184       return rtems_rfs_rtems_error ("dir_lseek: bad whence", EINVAL);
    185       break;
    186   }
    187   return 0;
    188 }
    189 
    190153/*
    191154 *  Set of operations handlers for operations on directories.
     
    198161  .write_h     = rtems_filesystem_default_write,
    199162  .ioctl_h     = rtems_filesystem_default_ioctl,
    200   .lseek_h     = rtems_rfs_rtems_dir_lseek,
     163  .lseek_h     = rtems_filesystem_default_lseek_directory,
    201164  .fstat_h     = rtems_rfs_rtems_fstat,
    202165  .ftruncate_h = rtems_filesystem_default_ftruncate_directory,
  • cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c

    reb7c6a84 r30d4124  
    7373    printf("rtems-rfs: file-open: handle:%p\n", file);
    7474
    75   iop->size = rtems_rfs_file_size (file);
    7675  rtems_rfs_rtems_set_iop_file_handle (iop, file);
    7776
     
    246245  }
    247246
    248   iop->size = rtems_rfs_file_size (file);
    249 
    250247  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
    251248
     
    283280{
    284281  rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
    285   rtems_rfs_pos          pos;
    286   int                    rc;
     282  off_t                  old_offset;
     283  off_t                  new_offset;
    287284
    288285  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK))
     
    291288  rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
    292289
    293   pos = iop->offset;
    294 
    295   rc = rtems_rfs_file_seek (file, pos, &pos);
    296   if (rc)
    297   {
    298     rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
    299     return rtems_rfs_rtems_error ("file_lseek: lseek", rc);
     290  old_offset = iop->offset;
     291  new_offset = rtems_filesystem_default_lseek_file (iop, offset, whence);
     292  if (new_offset != -1)
     293  {
     294    rtems_rfs_pos pos = iop->offset;
     295    int           rc = rtems_rfs_file_seek (file, pos, &pos);
     296
     297    if (rc)
     298    {
     299      rtems_rfs_rtems_error ("file_lseek: lseek", rc);
     300      iop->offset = old_offset;
     301      new_offset = -1;
     302    }
    300303  }
    301304
    302305  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
    303306
    304   return iop->offset;
     307  return new_offset;
    305308}
    306309
     
    327330  if (rc)
    328331    rc = rtems_rfs_rtems_error ("file_ftruncate: set size", rc);
    329 
    330   iop->size = rtems_rfs_file_size (file);
    331332
    332333  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
  • testsuites/fstests/fsrdwr/init.c

    reb7c6a84 r30d4124  
    372372  status = fstat (fd, &statbuf);
    373373  rtems_test_assert (status == 0);
    374   rtems_test_assert (statbuf.st_size == total_written + 1);
     374  rtems_test_assert (statbuf.st_size == total_written);
    375375
    376376  status = ftruncate (fd, total_written);
  • testsuites/psxtests/psximfs01/init.c

    reb7c6a84 r30d4124  
    5757    written = write( TestFd, Buffer, sizeof(Buffer) );
    5858    if ( written == -1 ) {
    59       if ( errno == ENOSPC ) {
     59      if ( errno == EFBIG ) {
    6060        printf( "Total written = %zd\n", TotalWritten );
    6161        return;
     
    9494      }
    9595      i++;
    96       continue;
    97     }
    98     /* Unsure if ENOSPC is the write error to be returned */
    99     if ( errno == ENOSPC && i == TotalWritten ) {
    100       puts( "File correctly read until ENOSPC returned\n" );
    101       return;
    102     }
    103     fprintf(
    104       stderr,
    105       "ERROR - at offset %d - returned %zd and error=%s\n",
    106       i,
    107       sc,
    108       strerror( errno )
    109     );
    110     rtems_test_exit(0);
    111   } while (1);
     96    } else if ( sc != 0 ) {
     97      fprintf(
     98        stderr,
     99        "ERROR - at offset %d - returned %zd and error=%s\n",
     100        i,
     101        sc,
     102        strerror( errno )
     103      );
     104      rtems_test_exit(0);
     105    }
     106  } while ( sc > 0 );
     107
     108  if ( i == TotalWritten ) {
     109    puts( "File correctly read until EOF returned\n" );
     110  }
    112111}
    113112
     
    144143}
    145144
    146 void extend_helper(void)
     145void extend_helper(int eno)
    147146{
    148147  off_t position;
     
    165164  do {
    166165    sc = lseek( TestFd, new, SEEK_SET );
    167     if( sc == -1 ) {
    168       if( errno == ENOSPC ) {
    169         break;
    170       }
    171       else {
    172         rtems_test_assert( 0 );
    173       }
    174     }
     166    rtems_test_assert( sc == new );
    175167
    176168    rc = ftruncate( TestFd, new );
    177169    if ( rc != 0 ) {
    178       if( errno != ENOSPC ) {
     170      if( errno != eno ) {
    179171        fprintf(
    180172          stderr,
     
    219211  int i;
    220212  void *alloc_ptr = (void *)0;
    221   int position = 0;
    222   int status = 0;
     213  off_t position;
     214  off_t new_position;
     215  char buf [1];
     216  ssize_t n;
    223217
    224218  puts( "\n\n*** TEST IMFS 01 ***" );
     
    245239  alloc_ptr = malloc( malloc_free_space() - 4 );
    246240
    247   extend_helper();
     241  extend_helper(ENOSPC);
    248242
    249243  /*
     
    252246  free(alloc_ptr);
    253247
    254   extend_helper();
     248  extend_helper(EFBIG);
    255249  position = lseek( TestFd , 0, SEEK_END );
    256   status = lseek( TestFd, position+2, SEEK_SET );
    257   rtems_test_assert( status == -1 );
    258   rtems_test_assert( errno == ENOSPC );
     250  new_position = lseek( TestFd, position + 2, SEEK_SET );
     251  rtems_test_assert( new_position == position + 2 );
     252
     253  n = write( TestFd, buf, sizeof(buf) );
     254  rtems_test_assert( n == -1 );
     255  rtems_test_assert( errno == EFBIG );
    259256
    260257  close_it();
Note: See TracChangeset for help on using the changeset viewer.