From 30d412469c930fe4150ad2b9a321eea2747ec6f4 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 7 May 2012 16:30:37 +0200 Subject: 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(). --- cpukit/libcsupport/include/rtems/libio.h | 50 ++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'cpukit/libcsupport/include/rtems/libio.h') diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h index 04ca52c4aa..a740a408f0 100644 --- a/cpukit/libcsupport/include/rtems/libio.h +++ b/cpukit/libcsupport/include/rtems/libio.h @@ -849,8 +849,9 @@ typedef int (*rtems_filesystem_ioctl_t)( * @retval non-negative The new offset from the beginning of the file. * @retval -1 An error occured. The errno is set to indicate the error. * - * @see rtems_filesystem_default_lseek() and - * rtems_filesystem_default_lseek_success(). + * @see rtems_filesystem_default_lseek(), + * rtems_filesystem_default_lseek_file(), and + * rtems_filesystem_default_lseek_directory(). */ typedef off_t (*rtems_filesystem_lseek_t)( rtems_libio_t *iop, @@ -1025,12 +1026,52 @@ off_t rtems_filesystem_default_lseek( int whence ); +/** + * @brief An offset 0 with a whence of SEEK_SET will perform a directory rewind + * operation. + * + * This function has no protection against concurrent access. + * + * @retval -1 The offset is not zero or the whence is not SEEK_SET. + * @retval 0 Successful rewind operation. + * + * @see rtems_filesystem_lseek_t. + */ +off_t rtems_filesystem_default_lseek_directory( + rtems_libio_t *iop, + off_t offset, + int whence +); + +/** + * @brief Default lseek() handler for files. + * + * The fstat() handler will be used to obtain the file size in case whence is + * SEEK_END. + * + * This function has no protection against concurrent access. + * + * @retval -1 An error occured. In case an integer overflow occured, then the + * errno will be set to EOVERFLOW. In case the new offset is negative, then + * the errno will be set to EINVAL. In case the whence is SEEK_END and the + * fstat() handler to obtain the current file size returned an error status, + * then the errno will be set by the fstat() handler. + * @retval offset The new offset. + * + * @see rtems_filesystem_lseek_t. + */ +off_t rtems_filesystem_default_lseek_file( + rtems_libio_t *iop, + off_t offset, + int whence +); + /** * @retval 0 Always. * * @see rtems_filesystem_lseek_t. */ -off_t rtems_filesystem_default_lseek_success( +off_t rtems_filesystem_default_lseek_file( rtems_libio_t *iop, off_t offset, int whence @@ -1157,11 +1198,10 @@ extern const rtems_filesystem_limits_and_options_t * It will be indexed by 'fd'. * * @todo Should really have a separate per/file data structure that this points - * to (eg: size, offset, driver, pathname should be in that) + * to (eg: offset, driver, pathname should be in that) */ struct rtems_libio_tt { rtems_driver_name_t *driver; - off_t size; /* size of file */ off_t offset; /* current offset into file */ uint32_t flags; rtems_filesystem_location_info_t pathinfo; -- cgit v1.2.3