[PATCH 1/3] Filesystem: PR1398: Fix lseek() mechanic
Chris Johns
chrisj at rtems.org
Mon May 7 22:52:33 UTC 2012
On 8/05/12 1:09 AM, sebastian.huber at embedded-brains.de wrote:
> From: Sebastian Huber<sebastian.huber at embedded-brains.de>
>
> 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 on 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().
Looks good. It is nice to have this sorted. Thanks.
Minor formatting issue below.
> ---
> cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c | 39 +-----------
> diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
> index 0a15652..c189269 100644
> --- a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
> +++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
> @@ -72,7 +72,6 @@ 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);
> rtems_rfs_rtems_set_iop_file_handle (iop, file);
>
> rtems_rfs_rtems_unlock (fs);
> @@ -245,8 +244,6 @@ rtems_rfs_rtems_file_write (rtems_libio_t* iop,
> }
> }
>
> - iop->size = rtems_rfs_file_size (file);
> -
> rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
>
> return write;
> @@ -282,26 +279,31 @@ rtems_rfs_rtems_file_lseek (rtems_libio_t* iop,
> int whence)
> {
> rtems_rfs_file_handle* file = rtems_rfs_rtems_get_iop_file_handle (iop);
> - rtems_rfs_pos pos;
> - int rc;
> + off_t old_offset;
> + off_t new_offset;
>
> if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK))
> printf("rtems-rfs: file-lseek: handle:%p offset:%" PRIdoff_t "\n", file, offset);
>
> rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
>
> - pos = iop->offset;
> + old_offset = iop->offset;
> + new_offset = rtems_filesystem_default_lseek_file (iop, offset, whence);
> + if (new_offset != -1) {
^ not consistent with the RFS formatting :)
> + rtems_rfs_pos pos = iop->offset;
> + int rc = rtems_rfs_file_seek (file, pos,&pos);
>
> - rc = rtems_rfs_file_seek (file, pos,&pos);
> - if (rc)
> - {
> - rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
> - return rtems_rfs_rtems_error ("file_lseek: lseek", rc);
> + if (rc)
> + {
> + rtems_rfs_rtems_error ("file_lseek: lseek", rc);
> + iop->offset = old_offset;
> + new_offset = -1;
> + }
> }
>
> rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
>
> - return iop->offset;
> + return new_offset;
> }
>
More information about the devel
mailing list