[rtems commit] Filesystem: PR1255: Move offset update to handlers
Sebastian Huber
sebh at rtems.org
Tue May 15 07:59:43 UTC 2012
Module: rtems
Branch: master
Commit: 53da07e436df21f078de665d90442ee5c7166ab7
Changeset: http://git.rtems.org/rtems/commit/?id=53da07e436df21f078de665d90442ee5c7166ab7
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon May 14 15:21:30 2012 +0200
Filesystem: PR1255: Move offset update to handlers
It is now the responsibility of the read() and write() handler to update
the offset field of the IO descriptor (rtems_libio_t). This change
makes it possible to protect the IO descriptor from concurrent access by
per file locks.
---
cpukit/libblock/src/blkdev-imfs.c | 2 ++
cpukit/libcsupport/include/rtems/libio.h | 4 ++++
cpukit/libcsupport/src/read.c | 8 +-------
cpukit/libcsupport/src/readv.c | 1 -
cpukit/libcsupport/src/sup_fs_deviceio.c | 4 ++++
cpukit/libcsupport/src/write.c | 8 +-------
cpukit/libcsupport/src/writev.c | 1 -
cpukit/libfs/src/dosfs/msdos_file.c | 7 +++++--
cpukit/libfs/src/imfs/memfile.c | 11 ++++++++++-
cpukit/libfs/src/nfsclient/src/nfs.c | 6 ++++++
cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c | 7 ++++++-
11 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/cpukit/libblock/src/blkdev-imfs.c b/cpukit/libblock/src/blkdev-imfs.c
index 8645593..c69542d 100644
--- a/cpukit/libblock/src/blkdev-imfs.c
+++ b/cpukit/libblock/src/blkdev-imfs.c
@@ -75,6 +75,7 @@ static ssize_t rtems_blkdev_imfs_read(
}
if (remaining >= 0) {
+ iop->offset += count;
rv = (ssize_t) count;
} else {
errno = EIO;
@@ -134,6 +135,7 @@ static ssize_t rtems_blkdev_imfs_write(
}
if (remaining >= 0) {
+ iop->offset += count;
rv = (ssize_t) count;
} else {
errno = EIO;
diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h
index 9268aed..b42ff93 100644
--- a/cpukit/libcsupport/include/rtems/libio.h
+++ b/cpukit/libcsupport/include/rtems/libio.h
@@ -786,6 +786,8 @@ typedef int (*rtems_filesystem_close_t)(
/**
* @brief Reads from a node.
*
+ * This handler is responsible to update the offset field of the IO descriptor.
+ *
* @param[in, out] iop The IO pointer.
* @param[out] buffer The buffer for read data.
* @param[in] count The size of the buffer in characters.
@@ -804,6 +806,8 @@ typedef ssize_t (*rtems_filesystem_read_t)(
/**
* @brief Writes to a node.
*
+ * This handler is responsible to update the offset field of the IO descriptor.
+ *
* @param[in, out] iop The IO pointer.
* @param[out] buffer The buffer for write data.
* @param[in] count The size of the buffer in characters.
diff --git a/cpukit/libcsupport/src/read.c b/cpukit/libcsupport/src/read.c
index 759133b..ee10166 100644
--- a/cpukit/libcsupport/src/read.c
+++ b/cpukit/libcsupport/src/read.c
@@ -22,7 +22,6 @@ ssize_t read(
size_t count
)
{
- ssize_t rc;
rtems_libio_t *iop;
rtems_libio_check_fd( fd );
@@ -35,12 +34,7 @@ ssize_t read(
/*
* Now process the read().
*/
- rc = (*iop->pathinfo.handlers->read_h)( iop, buffer, count );
-
- if ( rc > 0 )
- iop->offset += rc;
-
- return rc;
+ return (*iop->pathinfo.handlers->read_h)( iop, buffer, count );
}
/*
diff --git a/cpukit/libcsupport/src/readv.c b/cpukit/libcsupport/src/readv.c
index b23abd0..4e540d5 100644
--- a/cpukit/libcsupport/src/readv.c
+++ b/cpukit/libcsupport/src/readv.c
@@ -106,7 +106,6 @@ ssize_t readv(
return -1;
if ( bytes > 0 ) {
- iop->offset += bytes;
total += bytes;
}
diff --git a/cpukit/libcsupport/src/sup_fs_deviceio.c b/cpukit/libcsupport/src/sup_fs_deviceio.c
index aeff60e..74f92cb 100644
--- a/cpukit/libcsupport/src/sup_fs_deviceio.c
+++ b/cpukit/libcsupport/src/sup_fs_deviceio.c
@@ -72,6 +72,8 @@ ssize_t rtems_deviceio_read(
status = rtems_io_read( major, minor, &args );
if ( status == RTEMS_SUCCESSFUL ) {
+ iop->offset += args.bytes_moved;
+
return (ssize_t) args.bytes_moved;
} else {
return rtems_deviceio_errno( status );
@@ -98,6 +100,8 @@ ssize_t rtems_deviceio_write(
status = rtems_io_write( major, minor, &args );
if ( status == RTEMS_SUCCESSFUL ) {
+ iop->offset += args.bytes_moved;
+
return (ssize_t) args.bytes_moved;
} else {
return rtems_deviceio_errno( status );
diff --git a/cpukit/libcsupport/src/write.c b/cpukit/libcsupport/src/write.c
index b747388..dc12558 100644
--- a/cpukit/libcsupport/src/write.c
+++ b/cpukit/libcsupport/src/write.c
@@ -29,7 +29,6 @@ ssize_t write(
size_t count
)
{
- ssize_t rc;
rtems_libio_t *iop;
rtems_libio_check_fd( fd );
@@ -42,10 +41,5 @@ ssize_t write(
/*
* Now process the write() request.
*/
- rc = (*iop->pathinfo.handlers->write_h)( iop, buffer, count );
-
- if ( rc > 0 )
- iop->offset += rc;
-
- return rc;
+ return (*iop->pathinfo.handlers->write_h)( iop, buffer, count );
}
diff --git a/cpukit/libcsupport/src/writev.c b/cpukit/libcsupport/src/writev.c
index 8356c1e..47605a4 100644
--- a/cpukit/libcsupport/src/writev.c
+++ b/cpukit/libcsupport/src/writev.c
@@ -113,7 +113,6 @@ ssize_t writev(
return -1;
if ( bytes > 0 ) {
- iop->offset += bytes;
total += bytes;
}
diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c
index ac09e0f..e20b71b 100644
--- a/cpukit/libfs/src/dosfs/msdos_file.c
+++ b/cpukit/libfs/src/dosfs/msdos_file.c
@@ -117,6 +117,8 @@ msdos_file_read(rtems_libio_t *iop, void *buffer, size_t count)
ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, iop->offset, count,
buffer);
+ if (ret > 0)
+ iop->offset += ret;
rtems_semaphore_release(fs_info->vol_sema);
return ret;
@@ -163,8 +165,9 @@ msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
* update file size in both fat-file descriptor and file control block if
* file was extended
*/
- if (iop->offset + ret > fat_fd->fat_file_size)
- fat_fd->fat_file_size = iop->offset + ret;
+ iop->offset += ret;
+ if (iop->offset > fat_fd->fat_file_size)
+ fat_fd->fat_file_size = iop->offset;
rtems_semaphore_release(fs_info->vol_sema);
return ret;
diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/memfile.c
index fcbeed9..2eb7949 100644
--- a/cpukit/libfs/src/imfs/memfile.c
+++ b/cpukit/libfs/src/imfs/memfile.c
@@ -121,10 +121,16 @@ ssize_t memfile_read(
)
{
IMFS_jnode_t *the_jnode;
+ ssize_t status;
the_jnode = iop->pathinfo.node_access;
- return IMFS_memfile_read( the_jnode, iop->offset, buffer, count );
+ status = IMFS_memfile_read( the_jnode, iop->offset, buffer, count );
+
+ if ( status > 0 )
+ iop->offset += status;
+
+ return status;
}
/*
@@ -148,6 +154,9 @@ ssize_t memfile_write(
status = IMFS_memfile_write( the_jnode, iop->offset, buffer, count );
+ if ( status > 0 )
+ iop->offset += status;
+
return status;
}
diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c
index 1e25165..95613c0 100644
--- a/cpukit/libfs/src/nfsclient/src/nfs.c
+++ b/cpukit/libfs/src/nfsclient/src/nfs.c
@@ -2311,6 +2311,10 @@ static ssize_t nfs_file_read(
}
} while (count > 0);
+ if (rv > 0) {
+ iop->offset = offset;
+ }
+
return rv;
}
@@ -2419,6 +2423,8 @@ int e;
node->age = nowSeconds();
+ iop->offset += count;
+
return count;
}
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
index 525dcee..7de0403 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c
@@ -163,6 +163,9 @@ rtems_rfs_rtems_file_read (rtems_libio_t* iop,
}
}
+ if (read >= 0)
+ iop->offset = pos + read;
+
rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
return read;
@@ -220,7 +223,6 @@ rtems_rfs_rtems_file_write (rtems_libio_t* iop,
rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
return rtems_rfs_rtems_error ("file-write: write append seek", rc);
}
- iop->offset = pos;
}
while (count)
@@ -251,6 +253,9 @@ rtems_rfs_rtems_file_write (rtems_libio_t* iop,
}
}
+ if (write >= 0)
+ iop->offset = pos + write;
+
rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
return write;
More information about the vc
mailing list