Changeset d61b0a5 in rtems


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

Filesystem: PR1871: Fix O_APPEND

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/dosfs/msdos.h

    r30d4124 rd61b0a5  
    266266);
    267267
    268 int msdos_file_open(
    269   rtems_libio_t *iop,             /* IN  */
    270   const char    *pathname,        /* IN  */
    271   int            oflag,           /* IN  */
    272   mode_t         mode             /* IN  */
    273 );
    274 
    275268int msdos_file_close(rtems_libio_t *iop /* IN  */);
    276269
     
    301294
    302295int msdos_file_datasync(rtems_libio_t *iop);
    303 
    304 int msdos_dir_open(
    305   rtems_libio_t *iop,             /* IN  */
    306   const char    *pathname,        /* IN  */
    307   int            oflag,           /* IN  */
    308   mode_t         mode             /* IN  */
    309 );
    310 
    311 int msdos_dir_close(rtems_libio_t *iop /* IN  */);
    312296
    313297ssize_t msdos_dir_read(
  • cpukit/libfs/src/dosfs/msdos_dir.c

    r30d4124 rd61b0a5  
    3030
    3131#include "msdos.h"
    32 
    33 /* msdos_dir_open --
    34  *     Open fat-file which correspondes to the directory being opened and
    35  *     set offset field of file control block to zero.
    36  */
    37 int
    38 msdos_dir_open(rtems_libio_t *iop, const char *pathname, int oflag,
    39                mode_t mode)
    40 {
    41     int                rc = RC_OK;
    42     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    43     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    44     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    45 
    46     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    47                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    48     if (sc != RTEMS_SUCCESSFUL)
    49         rtems_set_errno_and_return_minus_one( EIO );
    50 
    51     rc = fat_file_reopen(fat_fd);
    52     if (rc != RC_OK)
    53     {
    54         rtems_semaphore_release(fs_info->vol_sema);
    55         return rc;
    56     }
    57 
    58     iop->offset = 0;
    59     rtems_semaphore_release(fs_info->vol_sema);
    60     return RC_OK;
    61 }
    62 
    63 /* msdos_dir_close --
    64  *     Close  fat-file which correspondes to the directory being closed
    65  *
    66  * PARAMETERS:
    67  *     iop - file control block
    68  *
    69  * RETURNS:
    70  *     RC_OK, if directory closed successfully, or -1 if error occured (errno
    71  *     set apropriately.
    72  */
    73 int
    74 msdos_dir_close(rtems_libio_t *iop)
    75 {
    76     int                rc = RC_OK;
    77     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    78     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    79     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    80 
    81     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    82                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    83     if (sc != RTEMS_SUCCESSFUL)
    84         rtems_set_errno_and_return_minus_one( EIO );
    85 
    86     rc = fat_file_close(iop->pathinfo.mt_entry, fat_fd);
    87     if (rc != RC_OK)
    88     {
    89         rtems_semaphore_release(fs_info->vol_sema);
    90         return rc;
    91     }
    92 
    93     rtems_semaphore_release(fs_info->vol_sema);
    94     return RC_OK;
    95 }
    9632
    9733/*  msdos_format_dirent_with_dot --
  • cpukit/libfs/src/dosfs/msdos_file.c

    r30d4124 rd61b0a5  
    2727
    2828#include "msdos.h"
    29 
    30 /* msdos_file_open --
    31  *     Open fat-file which correspondes to the file
    32  *
    33  * PARAMETERS:
    34  *     iop        - file control block
    35  *     pathname   - name
    36  *     flag       - flags
    37  *     mode       - mode
    38  *
    39  * RETURNS:
    40  *     RC_OK, if file opened successfully, or -1 if error occured
    41  *     and errno set appropriately
    42  */
    43 int
    44 msdos_file_open(rtems_libio_t *iop, const char *pathname, int oflag,
    45                 mode_t mode)
    46 {
    47     int                rc = RC_OK;
    48     rtems_status_code  sc = RTEMS_SUCCESSFUL;
    49     msdos_fs_info_t   *fs_info = iop->pathinfo.mt_entry->fs_info;
    50     fat_file_fd_t     *fat_fd = iop->pathinfo.node_access;
    51 
    52     sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
    53                                 MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
    54     if (sc != RTEMS_SUCCESSFUL)
    55         rtems_set_errno_and_return_minus_one(EIO);
    56 
    57     rc = fat_file_reopen(fat_fd);
    58     if (rc != RC_OK)
    59     {
    60         rtems_semaphore_release(fs_info->vol_sema);
    61         return rc;
    62     }
    63 
    64     if (iop->flags & LIBIO_FLAGS_APPEND)
    65         iop->offset = fat_fd->fat_file_size;
    66 
    67     rtems_semaphore_release(fs_info->vol_sema);
    68     return RC_OK;
    69 }
    7029
    7130/* msdos_file_close --
     
    12281    }
    12382
    124     rc = fat_file_close(iop->pathinfo.mt_entry, fat_fd);
    125 
    12683    rtems_semaphore_release(fs_info->vol_sema);
    12784    return rc;
     
    186143    if (sc != RTEMS_SUCCESSFUL)
    187144        rtems_set_errno_and_return_minus_one(EIO);
     145
     146    if ((iop->flags & LIBIO_FLAGS_APPEND) != 0)
     147        iop->offset = fat_fd->fat_file_size;
    188148
    189149    ret = fat_file_write(iop->pathinfo.mt_entry, fat_fd, iop->offset, count,
  • cpukit/libfs/src/dosfs/msdos_handlers_dir.c

    r30d4124 rd61b0a5  
    2020
    2121const rtems_filesystem_file_handlers_r msdos_dir_handlers = {
    22     msdos_dir_open,
    23     msdos_dir_close,
     22    rtems_filesystem_default_open,
     23    rtems_filesystem_default_close,
    2424    msdos_dir_read,
    2525    rtems_filesystem_default_write,
  • cpukit/libfs/src/dosfs/msdos_handlers_file.c

    r30d4124 rd61b0a5  
    2020
    2121const rtems_filesystem_file_handlers_r msdos_file_handlers = {
    22     msdos_file_open,
     22    rtems_filesystem_default_open,
    2323    msdos_file_close,
    2424    msdos_file_read,
  • cpukit/libfs/src/imfs/memfile.c

    r30d4124 rd61b0a5  
    9393   * Perform 'copy on write' for linear files
    9494   */
    95   if ((iop->flags & (LIBIO_FLAGS_WRITE | LIBIO_FLAGS_APPEND))
     95  if ((iop->flags & LIBIO_FLAGS_WRITE)
    9696   && (IMFS_type( the_jnode ) == IMFS_LINEAR_FILE)) {
    9797    uint32_t   count = the_jnode->info.linearfile.size;
     
    107107        return -1;
    108108  }
    109   if (iop->flags & LIBIO_FLAGS_APPEND)
    110     iop->offset = the_jnode->info.file.size;
    111109
    112110  return 0;
     
    146144
    147145  the_jnode = iop->pathinfo.node_access;
     146
     147  if ((iop->flags & LIBIO_FLAGS_APPEND) != 0)
     148    iop->offset = the_jnode->info.file.size;
    148149
    149150  status = IMFS_memfile_write( the_jnode, iop->offset, buffer, count );
  • cpukit/libfs/src/rfs/rtems-rfs-file.c

    r30d4124 rd61b0a5  
    423423   * write occurs.
    424424   */
    425   if (pos < rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
     425  if (pos <= rtems_rfs_file_shared_get_size (rtems_rfs_file_fs (handle),
    426426                                            handle->shared))
    427427  {
  • cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c

    r30d4124 rd61b0a5  
    186186  rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
    187187  rtems_rfs_pos          pos;
     188  rtems_rfs_pos          file_size;
    188189  const uint8_t*         data = buffer;
    189190  ssize_t                write = 0;
     
    196197
    197198  pos = iop->offset;
    198 
    199   /*
    200    * If the iop position is past the physical end of the file we need to set
    201    * the file size to the new length before writing. If the position equals the
    202    * size of file we are still past the end of the file as positions number
    203    * from 0. For a specific position we need a file that has a length of one
    204    * more.
    205    */
    206 
    207   if (pos >= rtems_rfs_file_size (file))
    208   {
    209     rc = rtems_rfs_file_set_size (file, pos + 1);
     199  file_size = rtems_rfs_file_size (file);
     200  if (pos > file_size)
     201  {
     202    /*
     203     * If the iop position is past the physical end of the file we need to set
     204     * the file size to the new length before writing.  The
     205     * rtems_rfs_file_io_end() will grow the file subsequently.
     206     */
     207    rc = rtems_rfs_file_set_size (file, pos);
    210208    if (rc)
    211209    {
     
    213211      return rtems_rfs_rtems_error ("file-write: write extend", rc);
    214212    }
    215   }
    216 
    217   rtems_rfs_file_set_bpos (file, pos);
     213
     214    rtems_rfs_file_set_bpos (file, pos);
     215  }
     216  else if (pos < file_size && (iop->flags & LIBIO_FLAGS_APPEND) != 0)
     217  {
     218    pos = file_size;
     219    rc = rtems_rfs_file_seek (file, pos, &pos);
     220    if (rc)
     221    {
     222      rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
     223      return rtems_rfs_rtems_error ("file-write: write append seek", rc);
     224    }
     225    iop->offset = pos;
     226  }
    218227
    219228  while (count)
  • testsuites/fstests/fsrdwr/init.c

    r30d4124 rd61b0a5  
    113113  pos = lseek (fd, 0, SEEK_CUR);
    114114  rtems_test_assert (pos == 2 * len);
     115  pos = lseek (fd, 0, SEEK_SET);
     116  rtems_test_assert (pos == 0);
     117  n = write (fd, databuf, len);
     118  rtems_test_assert (n == len);
     119  pos = lseek (fd, 0, SEEK_CUR);
     120  rtems_test_assert (pos == 3 * len);
    115121  status = close (fd);
    116122  rtems_test_assert (status == 0);
     
    124130  rtems_test_assert (n == len);
    125131  rtems_test_assert (!strncmp (databuf, readbuf, len));
    126 
     132  n = read (fd, readbuf, len);
     133  rtems_test_assert (n == len);
     134  rtems_test_assert (!strncmp (databuf, readbuf, len));
    127135  n = read (fd, readbuf, len);
    128136  rtems_test_assert (n == len);
Note: See TracChangeset for help on using the changeset viewer.