inode_find: Now takes struct inode_desc_s type as input. This was necessary before that structure includes some data storage. It was used within inode_find(), but that means that the life of the data was the life of inode_find(). That data must persist longer. It is now provided by the caller so that the life of the data persists for the entire life of the caller.

This commit is contained in:
Gregory Nutt
2017-02-05 09:51:42 -06:00
parent 990bed903e
commit 8f2c7198ed
20 changed files with 284 additions and 129 deletions
+10 -2
View File
@@ -88,6 +88,7 @@
int link(FAR const char *path1, FAR const char *path2)
{
struct inode_search_s desc;
FAR struct inode *inode;
int errcode;
int ret;
@@ -106,9 +107,16 @@ int link(FAR const char *path1, FAR const char *path2)
* does not lie on a mounted volume.
*/
inode = inode_find(path2, NULL, false);
if (inode != NULL)
RESET_SEARCH(&desc);
desc.path = path2;
ret = inode_find(&desc);
if (ret >= 0)
{
/* Something exists at the path2 where we are trying to create the
* link.
*/
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a mountpoint. */
+11 -4
View File
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
@@ -83,20 +84,26 @@
int mkdir(const char *pathname, mode_t mode)
{
struct inode_search_s desc;
FAR struct inode *inode;
const char *relpath = NULL;
int errcode;
int ret;
/* Find the inode that includes this path */
inode = inode_find(pathname, &relpath, false);
if (inode)
RESET_SEARCH(&desc);
desc.path = pathname;
ret = inode_find(&desc);
if (ret >= 0)
{
/* An inode was found that includes this path and possibly refers to a
* mountpoint.
*/
inode = desc.node;
DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a valid mountpoint. */
@@ -114,7 +121,7 @@ int mkdir(const char *pathname, mode_t mode)
if (inode->u.i_mops->mkdir)
{
ret = inode->u.i_mops->mkdir(inode, relpath, mode);
ret = inode->u.i_mops->mkdir(inode, desc.relpath, mode);
if (ret < 0)
{
errcode = -ret;
+13 -5
View File
@@ -90,9 +90,9 @@ int inode_checkflags(FAR struct inode *inode, int oflags)
int open(const char *path, int oflags, ...)
{
struct inode_search_s desc;
FAR struct file *filep;
FAR struct inode *inode;
FAR const char *relpath = NULL;
#if defined(CONFIG_FILE_MODE) || !defined(CONFIG_DISABLE_MOUNTPOINT)
mode_t mode = 0666;
#endif
@@ -121,18 +121,26 @@ int open(const char *path, int oflags, ...)
/* Get an inode for this file */
inode = inode_find(path, &relpath, false);
if (!inode)
RESET_SEARCH(&desc);
desc.path = path;
ret = inode_find(&desc);
if (ret < 0)
{
/* "O_CREAT is not set and the named file does not exist. Or, a
* directory component in pathname does not exist or is a dangling
* symbolic link."
*/
ret = ENOENT;
ret = -ret;
goto errout;
}
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && \
!defined(CONFIG_DISABLE_MOUNTPOINT)
/* If the inode is block driver, then we may return a character driver
@@ -222,7 +230,7 @@ int open(const char *path, int oflags, ...)
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_MOUNTPT(inode))
{
ret = inode->u.i_mops->open(filep, relpath, oflags, mode);
ret = inode->u.i_mops->open(filep, desc.relpath, oflags, mode);
}
else
#endif
+16 -4
View File
@@ -82,9 +82,10 @@
ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
{
struct inode_search_s desc;
FAR struct inode *node;
const char *relpath = NULL;
int errcode;
int ret;
DEBUGASSERT(path != NULL && buf != NULL && bufsize > 0);
@@ -92,13 +93,24 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
* symbolic link node.
*/
node = inode_find(path, &relpath, true);
if (node == NULL)
RESET_SEARCH(&desc);
desc.path = path;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
ret = inode_find(&desc);
if (ret < 0)
{
errcode = ENOENT;
errcode = -ret;
goto errout;
}
/* Get the search results */
node = desc.node;
DEBUGASSERT(node != NULL);
/* An inode was found that includes this path and possibly refers to a
* symbolic link.
*
+32 -11
View File
@@ -82,12 +82,10 @@
int rename(FAR const char *oldpath, FAR const char *newpath)
{
struct inode_search_s olddesc;
struct inode_search_s newdesc;
FAR struct inode *oldinode;
FAR struct inode *newinode;
const char *oldrelpath = NULL;
#ifndef CONFIG_DISABLE_MOUNTPOINT
const char *newrelpath = NULL;
#endif
int errcode;
int ret;
@@ -103,15 +101,26 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
/* Get an inode that includes the oldpath */
oldinode = inode_find(oldpath, &oldrelpath, true);
if (!oldinode)
RESET_SEARCH(&olddesc);
olddesc.path = oldpath;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
olddesc.nofollow = true;
#endif
ret = inode_find(&olddesc);
if (ret < 0)
{
/* There is no inode that includes in this path */
errcode = ENOENT;
errcode = -ret;
goto errout;
}
/* Get the search results */
oldinode = olddesc.node;
DEBUGASSERT(oldinode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* Verify that the old inode is a valid mountpoint. */
@@ -121,15 +130,26 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
* mountpoint
*/
newinode = inode_find(newpath, &newrelpath, true);
if (!newinode)
RESET_SEARCH(&newdesc);
newdesc.path = newpath;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
newdesc.nofollow = true;
#endif
ret = inode_find(&newdesc);
if (ret < 0)
{
/* There is no mountpoint that includes in this path */
errcode = ENOENT;
errcode = -ret;
goto errout_with_oldinode;
}
/* Get the search results */
newinode = newdesc.node;
DEBUGASSERT(newinode != NULL);
/* Verify that the two paths lie on the same mountpoint inode */
if (oldinode != newinode)
@@ -144,7 +164,8 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
if (oldinode->u.i_mops->rename)
{
ret = oldinode->u.i_mops->rename(oldinode, oldrelpath, newrelpath);
ret = oldinode->u.i_mops->rename(oldinode, olddesc.relpath,
newdesc.relpath);
if (ret < 0)
{
errcode = -ret;
+19 -8
View File
@@ -41,6 +41,7 @@
#include <stdbool.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
@@ -82,24 +83,36 @@
int rmdir(FAR const char *pathname)
{
struct inode_search_s desc;
FAR struct inode *inode;
const char *relpath = NULL;
int errcode;
int errcode;
int ret;
/* Get an inode for the directory (or for the mountpoint containing the
* directory). inode_find() automatically increments the reference count
* on the inode if one is found.
*/
inode = inode_find(pathname, &relpath, true);
if (!inode)
RESET_SEARCH(&desc);
desc.path = pathname;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
ret = inode_find(&desc);
if (ret < 0)
{
/* There is no inode that includes in this path */
errcode = ENOENT;
errcode = -ret;
goto errout;
}
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a valid mountpoint. */
@@ -111,7 +124,7 @@ int rmdir(FAR const char *pathname)
if (inode->u.i_mops->rmdir)
{
int ret = inode->u.i_mops->rmdir(inode, relpath);
ret = inode->u.i_mops->rmdir(inode, desc.relpath);
if (ret < 0)
{
errcode = -ret;
@@ -134,8 +147,6 @@ int rmdir(FAR const char *pathname)
if (!inode->u.i_ops)
{
int ret;
/* If the directory inode has children, however, then it cannot be
* removed.
*/
+17 -6
View File
@@ -207,9 +207,9 @@ static inline int statroot(FAR struct stat *buf)
int stat(FAR const char *path, FAR struct stat *buf)
{
struct inode_search_s desc;
FAR struct inode *inode;
const char *relpath = NULL;
int ret = OK;
int ret = OK;
/* Sanity checks */
@@ -234,17 +234,28 @@ int stat(FAR const char *path, FAR struct stat *buf)
/* Get an inode for this file */
inode = inode_find(path, &relpath, true);
if (!inode)
RESET_SEARCH(&desc);
desc.path = path;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
ret = inode_find(&desc);
if (ret < 0)
{
/* This name does not refer to a psudeo-inode and there is no
* mountpoint that includes in this path.
*/
ret = ENOENT;
ret = -ret;
goto errout;
}
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* The way we handle the stat depends on the type of inode that we
* are dealing with.
*/
@@ -260,7 +271,7 @@ int stat(FAR const char *path, FAR struct stat *buf)
{
/* Perform the stat() operation */
ret = inode->u.i_mops->stat(inode, relpath, buf);
ret = inode->u.i_mops->stat(inode, desc.relpath, buf);
}
}
else
+13 -5
View File
@@ -85,9 +85,9 @@ static inline int statpseudofs(FAR struct inode *inode, FAR struct statfs *buf)
int statfs(FAR const char *path, FAR struct statfs *buf)
{
struct inode_search_s desc;
FAR struct inode *inode;
FAR const char *relpath = NULL;
int ret = OK;
int ret = OK;
/* Sanity checks */
@@ -105,17 +105,25 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
/* Get an inode for this file */
inode = inode_find(path, &relpath, false);
if (!inode)
RESET_SEARCH(&desc);
desc.path = path;
ret = inode_find(&desc);
if (ret < 0)
{
/* This name does not refer to a psudeo-inode and there is no
* mountpoint that includes in this path.
*/
ret = ENOENT;
ret = -ret;
goto errout;
}
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* The way we handle the statfs depends on the type of inode that we
* are dealing with.
*/
+19 -7
View File
@@ -41,6 +41,7 @@
#include <stdbool.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
@@ -82,24 +83,35 @@
int unlink(FAR const char *pathname)
{
struct inode_search_s desc;
FAR struct inode *inode;
const char *relpath = NULL;
int errcode;
int ret;
int errcode;
int ret;
/* Get an inode for this file (without deference the final node in the path
* which may be a symbolic link)
*/
inode = inode_find(pathname, &relpath, true);
if (!inode)
RESET_SEARCH(&desc);
desc.path = pathname;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
ret = inode_find(&desc);
if (ret < 0)
{
/* There is no inode that includes in this path */
errcode = ENOENT;
errcode = -ret;
goto errout;
}
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a valid mountpoint. */
@@ -111,7 +123,7 @@ int unlink(FAR const char *pathname)
if (inode->u.i_mops->unlink)
{
ret = inode->u.i_mops->unlink(inode, relpath);
ret = inode->u.i_mops->unlink(inode, desc.relpath);
if (ret < 0)
{
errcode = -ret;