From 892428918f098752156f082161fa8229b02bea11 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 20 May 2007 16:24:40 +0000 Subject: close() did not close driver git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@233 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/fs/fs_close.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3