diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-20 16:24:40 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-20 16:24:40 +0000 |
commit | 892428918f098752156f082161fa8229b02bea11 (patch) | |
tree | d765240ebf073f95240f8ed63a2eab51974a9f8c | |
parent | 14a668aeb4737d86fb27a88ca13d85590d695c7c (diff) | |
download | nuttx-892428918f098752156f082161fa8229b02bea11.tar.gz nuttx-892428918f098752156f082161fa8229b02bea11.tar.bz2 nuttx-892428918f098752156f082161fa8229b02bea11.zip |
close() did not close driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@233 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/fs/fs_close.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/nuttx/fs/fs_close.c b/nuttx/fs/fs_close.c index d3fa1c0f2..1d1faa009 100644 --- a/nuttx/fs/fs_close.c +++ b/nuttx/fs/fs_close.c @@ -69,11 +69,45 @@ int close(int fd) FAR struct inode *inode = list->fl_files[fd].f_inode; if (inode) { + int ret = OK; + + /* Get then nullify the operations to prohibit any other + * use of the driver while it is closing. + */ + + struct file_operations *fops = inode->u.i_ops; + inode->u.i_ops = NULL; + + /* At this point, there can be no other access to the underlying + * driver. We can safely close the driver as well. + */ + + if (fops && fops->close) + { + /* Perform the close operation (by the driver) */ + + int status = fops->close(fd); + if (status < 0) + { + /* An error occurred while closing the driver */ + + inode->u.i_ops = fops; + *get_errno_ptr() = -status; + ret = ERROR; + } + } + + /* Release the file descriptor */ + files_release(fd); + + /* Then remove the inode, eliminating the name from the namespace */ + inode_release(inode); - return OK; + return ret; } } + *get_errno_ptr() = EBADF; return ERROR; } |