From 80c8fab4acd3dcdd301d39db7d16d2e5993c76af Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 20 May 2007 16:54:09 +0000 Subject: fixes git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@236 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/fs/fs_close.c | 31 ++++++++++++++++++------------- nuttx/fs/fs_mount.c | 7 +++++-- nuttx/fs/fs_read.c | 25 +++++++++++++++---------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/nuttx/fs/fs_close.c b/nuttx/fs/fs_close.c index 74f5e831b..97444c2f2 100644 --- a/nuttx/fs/fs_close.c +++ b/nuttx/fs/fs_close.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * fs_close.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include @@ -45,9 +45,9 @@ #include #include "fs_internal.h" -/************************************************************ +/**************************************************************************** * Global Functions - ************************************************************/ + ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 @@ -71,18 +71,21 @@ int close(int fd) { int ret = OK; - /* Close the driver. NOTES: (1) there is no semaphore protection - * here, the driver must be able to handle concurrent close and - * open operations. (2) The driver may have been opened numerous - * times (for different file descriptors) and must also handle - * being closed numerous times. + /* Close the driver or mountpoint. NOTES: (1) there is no + * exclusion mechanism here , the driver or mountpoint must be + * able to handle concurrent operations internally, (2) The driver + * may have been opened numerous times (for different file + * descriptors) and must also handle being closed numerous times. + * (3) for the case of the mountpoint, we depend on the close + * methods bing identical in signal and position in the operations + * vtable. */ if (inode->u.i_ops && inode->u.i_ops->close) { /* Perform the close operation (by the driver) */ - int status = inode->u.i_ops->close(fd); + int status = inode->u.i_ops->close(&list->fl_files[fd]); if (status < 0) { /* An error occurred while closing the driver */ @@ -96,7 +99,9 @@ int close(int fd) files_release(fd); - /* Then remove the inode, eliminating the name from the namespace */ + /* Decrement the reference count on the inode. This may remove the inode and + * eliminate the name from the namespace + */ inode_release(inode); return ret; diff --git a/nuttx/fs/fs_mount.c b/nuttx/fs/fs_mount.c index 753f9bac3..3e6a564b2 100644 --- a/nuttx/fs/fs_mount.c +++ b/nuttx/fs/fs_mount.c @@ -188,8 +188,8 @@ int mount(const char *source, const char *target, /* Make sure that the inode supports the requested access */ - if (!blkdrvr_inode->u.i_mops->read || - (!blkdrvr_inode->u.i_mops->write && (mountflags & MS_RDONLY) == 0)) + if (!blkdrvr_inode->u.i_bops->read || + (!blkdrvr_inode->u.i_bops->write && (mountflags & MS_RDONLY) == 0)) { errcode = EACCES; goto errout_with_blkdrvr; @@ -259,10 +259,13 @@ int mount(const char *source, const char *target, errout_with_mountpt: inode_release(mountpt_inode); + errout_with_semaphore: inode_semgive(); + errout_with_blkdrvr: inode_release(blkdrvr_inode); + errout: *get_errno_ptr() = errcode; return ERROR; diff --git a/nuttx/fs/fs_read.c b/nuttx/fs/fs_read.c index d5a97c553..4b1a2ce77 100644 --- a/nuttx/fs/fs_read.c +++ b/nuttx/fs/fs_read.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * fs_read.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,15 +31,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Compilation Switches - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include #include @@ -49,9 +49,9 @@ #include #include "fs_internal.h" -/************************************************************ +/**************************************************************************** * Global Functions - ************************************************************/ + ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 @@ -81,11 +81,16 @@ int read(int fd, void *buf, unsigned int nbytes) { struct inode *inode = this_file->f_inode; - /* Is a driver registered? Does it support the read method? */ + /* Is a driver or mountpoint registered? If so, does it support + * the read method? + */ if (inode && inode->u.i_ops && inode->u.i_ops->read) { - /* Yes, then let it perform the read */ + /* Yes, then let it perform the read. NOTE that for the case + * of the mountpoint, we depend on the read methods bing + * identical in signal and position in the operations vtable. + */ ret = (int)inode->u.i_ops->read(this_file, (char*)buf, (size_t)nbytes); } -- cgit v1.2.3