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
+13 -3
View File
@@ -42,8 +42,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <stdbool.h> #include <stdbool.h>
#include <debug.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <debug.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
@@ -79,6 +80,7 @@
int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode **ppinode) int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode **ppinode)
{ {
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
int ret = 0; /* Assume success */ int ret = 0; /* Assume success */
@@ -94,14 +96,22 @@ int find_blockdriver(FAR const char *pathname, int mountflags, FAR struct inode
/* Find the inode registered with this pathname */ /* Find the inode registered with this pathname */
inode = inode_find(pathname, NULL, false); RESET_SEARCH(&desc);
if (!inode) desc.path = pathname;
ret = inode_find(&desc);
if (ret < 0)
{ {
ferr("ERROR: Failed to find %s\n", pathname); ferr("ERROR: Failed to find %s\n", pathname);
ret = -ENOENT; ret = -ENOENT;
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* Verify that the inode is a block driver. */ /* Verify that the inode is a block driver. */
if (!INODE_IS_BLOCK(inode)) if (!INODE_IS_BLOCK(inode))
+14 -6
View File
@@ -62,17 +62,20 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
{ {
struct fat_mountpt_s *fs; struct fat_mountpt_s *fs;
struct fat_dirinfo_s dirinfo; struct fat_dirinfo_s dirinfo;
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
const char *relpath = NULL;
uint8_t *direntry; uint8_t *direntry;
uint8_t oldattributes; uint8_t oldattributes;
uint8_t newattributes; uint8_t newattributes;
int ret; int ret;
/* Get an inode for this file */ /* Find the inode for this file */
inode = inode_find(path, &relpath, false); RESET_SEARCH(&desc);
if (!inode) desc.path = path;
ret = inode_find(&desc);
if (ret < 0)
{ {
/* There is no mountpoint that includes in this path */ /* There is no mountpoint that includes in this path */
@@ -80,6 +83,11 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* Verify that the inode is a valid mountpoint. */ /* Verify that the inode is a valid mountpoint. */
if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops || !inode->i_private) if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops || !inode->i_private)
@@ -101,9 +109,9 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
goto errout_with_semaphore; goto errout_with_semaphore;
} }
/* Find the file/directory entry for the oldrelpath */ /* Find the file/directory entry for the relpath */
ret = fat_finddirentry(fs, &dirinfo, relpath); ret = fat_finddirentry(fs, &dirinfo, desc.relpath);
if (ret != OK) if (ret != OK)
{ {
/* Some error occurred -- probably -ENOENT */ /* Some error occurred -- probably -ENOENT */
+6 -27
View File
@@ -56,55 +56,34 @@
* Description: * Description:
* This is called from the open() logic to get a reference to the inode * This is called from the open() logic to get a reference to the inode
* associated with a path. This is accomplished by calling inode_search(). * associated with a path. This is accomplished by calling inode_search().
* The primary difference between inode_find() and inode_search is (1) in * inode_find() is a simple wrapper around inode_search(). The primary
* the form of the input paramters and return value and (2) inode_find() * difference between inode_find() and inode_search is that inode_find()
* will lock the inode tree and increment the reference count on the inode. * will lock the inode tree and increment the reference count on the inode.
* *
****************************************************************************/ ****************************************************************************/
FAR struct inode *inode_find(FAR const char *path, FAR const char **relpath, int inode_find(FAR struct inode_search_s *desc)
bool nofollow)
{ {
struct inode_search_s desc;
FAR struct inode *node = NULL;
int ret; int ret;
if (path == NULL || *path != '/')
{
return NULL;
}
/* Find the node matching the path. If found, increment the count of /* Find the node matching the path. If found, increment the count of
* references on the node. * references on the node.
*/ */
RESET_SEARCH(&desc);
desc.path = path;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = nofollow;
#endif
inode_semtake(); inode_semtake();
ret = inode_search(&desc); ret = inode_search(desc);
if (ret >= 0) if (ret >= 0)
{ {
/* Found it */ /* Found it */
node = desc.node; FAR struct inode *node = desc->node;
DEBUGASSERT(node != NULL); DEBUGASSERT(node != NULL);
/* Increment the reference count on the inode */ /* Increment the reference count on the inode */
node->i_crefs++; node->i_crefs++;
/* Return any remaining relative path fragment */
if (relpath != NULL)
{
*relpath = desc.relpath;
}
} }
inode_semgive(); inode_semgive();
return node; return ret;
} }
+14 -15
View File
@@ -210,6 +210,20 @@ void inode_semgive(void);
int inode_search(FAR struct inode_search_s *desc); int inode_search(FAR struct inode_search_s *desc);
/****************************************************************************
* Name: inode_find
*
* Description:
* This is called from the open() logic to get a reference to the inode
* associated with a path. This is accomplished by calling inode_search().
* inode_find() is a simple wrapper around inode_search(). The primary
* difference between inode_find() and inode_search is that inode_find()
* will lock the inode tree and increment the reference count on the inode.
*
****************************************************************************/
int inode_find(FAR struct inode_search_s *desc);
/**************************************************************************** /****************************************************************************
* Name: inode_free * Name: inode_free
* *
@@ -286,21 +300,6 @@ FAR struct inode *inode_unlink(FAR const char *path);
int inode_remove(FAR const char *path); int inode_remove(FAR const char *path);
/****************************************************************************
* Name: inode_find
*
* Description:
* This is called from the open() logic to get a reference to the inode
* associated with a path. This is accomplished by calling inode_search().
* The primary difference between inode_find() and inode_search is (1) in
* the form of the input paramters and return value and (2) inode_find()
* will lock the inode tree and increment the reference count on the inode.
*
****************************************************************************/
FAR struct inode *inode_find(FAR const char *path, FAR const char **relpath,
bool nofollow);
/**************************************************************************** /****************************************************************************
* Name: inode_addref * Name: inode_addref
* *
+14 -4
View File
@@ -235,6 +235,9 @@ int mount(FAR const char *source, FAR const char *target,
#endif #endif
FAR struct inode *mountpt_inode; FAR struct inode *mountpt_inode;
FAR const struct mountpt_operations *mops; FAR const struct mountpt_operations *mops;
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
struct inode_search_s desc;
#endif
void *fshandle; void *fshandle;
int errcode; int errcode;
int ret; int ret;
@@ -281,13 +284,20 @@ int mount(FAR const char *source, FAR const char *target,
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
/* Check if the inode already exists */ /* Check if the inode already exists */
mountpt_inode = inode_find(target, NULL, false); RESET_SEARCH(&desc);
if (mountpt_inode != NULL) desc.path = target;
ret = inode_find(&desc);
if (ret >= 0)
{ {
/* Successfully found. The reference count on the inode has been /* Successfully found. The reference count on the inode has been
* incremented. * incremented.
* */
* But is it a directory node (i.e., not a driver or other special
mountpt_inode = desc.node;
DEBUGASSERT(mountpt_inode != NULL);
/* But is it a directory node (i.e., not a driver or other special
* node)? * node)?
*/ */
+11 -2
View File
@@ -74,6 +74,7 @@ int umount2(FAR const char *target, unsigned int flags)
{ {
FAR struct inode *mountpt_inode; FAR struct inode *mountpt_inode;
FAR struct inode *blkdrvr_inode = NULL; FAR struct inode *blkdrvr_inode = NULL;
struct inode_search_s desc;
int errcode = OK; int errcode = OK;
int ret; int ret;
@@ -87,13 +88,21 @@ int umount2(FAR const char *target, unsigned int flags)
/* Find the mountpt */ /* Find the mountpt */
mountpt_inode = inode_find(target, NULL, false); RESET_SEARCH(&desc);
if (!mountpt_inode) desc.path = target;
ret = inode_find(&desc);
if (ret < 0)
{ {
errcode = ENOENT; errcode = ENOENT;
goto errout; goto errout;
} }
/* Get the search results */
mountpt_inode = desc.node;
DEBUGASSERT(mountpt_inode != NULL);
/* Verify that the inode is a mountpoint */ /* Verify that the inode is a mountpoint */
if (!INODE_IS_MOUNTPT(mountpt_inode)) if (!INODE_IS_MOUNTPT(mountpt_inode))
+12 -4
View File
@@ -89,8 +89,8 @@
mqd_t mq_open(FAR const char *mq_name, int oflags, ...) mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR const char *relpath = NULL;
FAR struct mqueue_inode_s *msgq; FAR struct mqueue_inode_s *msgq;
struct inode_search_s desc;
char fullpath[MAX_MQUEUE_PATH]; char fullpath[MAX_MQUEUE_PATH];
va_list ap; va_list ap;
struct mq_attr *attr; struct mq_attr *attr;
@@ -133,10 +133,18 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
* have incremented the reference count on the inode. * have incremented the reference count on the inode.
*/ */
inode = inode_find(fullpath, &relpath, false); RESET_SEARCH(&desc);
if (inode) desc.path = fullpath;
ret = inode_find(&desc);
if (ret >= 0)
{ {
/* It exists. Verify that the inode is a message queue */ /* Something exists at this path. Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* Verify that the inode is a message queue */
if (!INODE_IS_MQUEUE(inode)) if (!INODE_IS_MQUEUE(inode))
{ {
+12 -4
View File
@@ -76,7 +76,7 @@
int mq_unlink(FAR const char *mq_name) int mq_unlink(FAR const char *mq_name)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR const char *relpath = NULL; struct inode_search_s desc;
char fullpath[MAX_MQUEUE_PATH]; char fullpath[MAX_MQUEUE_PATH];
int errcode; int errcode;
int ret; int ret;
@@ -87,16 +87,24 @@ int mq_unlink(FAR const char *mq_name)
/* Get the inode for this message queue. */ /* Get the inode for this message queue. */
RESET_SEARCH(&desc);
desc.path = fullpath;
sched_lock(); sched_lock();
inode = inode_find(fullpath, &relpath, false); ret = inode_find(&desc);
if (!inode) if (ret < 0)
{ {
/* There is no inode that includes in this path */ /* There is no inode that includes in this path */
errcode = ENOENT; errcode = -ret;
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* Verify that what we found is, indeed, a message queue */ /* Verify that what we found is, indeed, a message queue */
if (!INODE_IS_MQUEUE(inode)) if (!INODE_IS_MQUEUE(inode))
+14 -5
View File
@@ -103,11 +103,11 @@
FAR sem_t *sem_open (FAR const char *name, int oflags, ...) FAR sem_t *sem_open (FAR const char *name, int oflags, ...)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR const char *relpath = NULL;
mode_t mode;
FAR struct nsem_inode_s *nsem; FAR struct nsem_inode_s *nsem;
FAR sem_t *sem = (FAR sem_t *)ERROR; FAR sem_t *sem = (FAR sem_t *)ERROR;
struct inode_search_s desc;
char fullpath[MAX_SEMPATH]; char fullpath[MAX_SEMPATH];
mode_t mode;
unsigned value; unsigned value;
int errcode; int errcode;
int ret; int ret;
@@ -134,10 +134,19 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...)
* will have incremented the reference count on the inode. * will have incremented the reference count on the inode.
*/ */
inode = inode_find(fullpath, &relpath, false); RESET_SEARCH(&desc);
if (inode) desc.path = fullpath;
ret = inode_find(&desc);
if (ret >= 0)
{ {
/* It exists. Verify that the inode is a semaphore */ /* Something exists at this path. Get the search results */
inode = desc.node;
relpath = desc.relpath;
DEBUGASSERT(inode != NULL);
/* Verify that the inode is a semaphore */
if (!INODE_IS_NAMEDSEM(inode)) if (!INODE_IS_NAMEDSEM(inode))
{ {
+12 -4
View File
@@ -80,7 +80,7 @@
int sem_unlink(FAR const char *name) int sem_unlink(FAR const char *name)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR const char *relpath = NULL; struct inode_search_s desc;
char fullpath[MAX_SEMPATH]; char fullpath[MAX_SEMPATH];
int errcode; int errcode;
int ret; int ret;
@@ -91,16 +91,24 @@ int sem_unlink(FAR const char *name)
/* Get the inode for this semaphore. */ /* Get the inode for this semaphore. */
RESET_SEARCH(&desc);
desc.path = fullpath;
sched_lock(); sched_lock();
inode = inode_find(fullpath, &relpath, false); ret = inode_find(&desc);
if (!inode) if (ret < 0)
{ {
/* There is no inode that includes in this path */ /* There is no inode that includes in this path */
errcode = ENOENT; errcode = -ret;
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
/* Verify that what we found is, indeed, a semaphore */ /* Verify that what we found is, indeed, a semaphore */
if (!INODE_IS_NAMEDSEM(inode)) if (!INODE_IS_NAMEDSEM(inode))
+12 -3
View File
@@ -2442,17 +2442,26 @@ static int unionfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
static int unionfs_getmount(FAR const char *path, FAR struct inode **inode) static int unionfs_getmount(FAR const char *path, FAR struct inode **inode)
{ {
FAR struct inode *minode; FAR struct inode *minode;
struct inode_search_s desc;
/* Find the mountpt */ /* Find the mountpt */
minode = inode_find(path, NULL, false); RESET_SEARCH(&desc);
if (!minode) desc.path = path;
ret = inode_find(&desc);
if (ret < 0)
{ {
/* Mountpoint inode not found */ /* Mountpoint inode not found */
return -ENOENT; return ret;
} }
/* Get the search results */
minode = desc.node;
DEBUGASSERT(minode != NULL);
/* Verify that the inode is a mountpoint */ /* Verify that the inode is a mountpoint */
if (!INODE_IS_MOUNTPT(minode)) if (!INODE_IS_MOUNTPT(minode))
+10 -2
View File
@@ -88,6 +88,7 @@
int link(FAR const char *path1, FAR const char *path2) int link(FAR const char *path1, FAR const char *path2)
{ {
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
int errcode; int errcode;
int ret; int ret;
@@ -106,9 +107,16 @@ int link(FAR const char *path1, FAR const char *path2)
* does not lie on a mounted volume. * does not lie on a mounted volume.
*/ */
inode = inode_find(path2, NULL, false); RESET_SEARCH(&desc);
if (inode != NULL) 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 #ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a mountpoint. */ /* Check if the inode is a mountpoint. */
+11 -4
View File
@@ -42,6 +42,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
@@ -83,20 +84,26 @@
int mkdir(const char *pathname, mode_t mode) int mkdir(const char *pathname, mode_t mode)
{ {
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
const char *relpath = NULL;
int errcode; int errcode;
int ret; int ret;
/* Find the inode that includes this path */ /* Find the inode that includes this path */
inode = inode_find(pathname, &relpath, false); RESET_SEARCH(&desc);
if (inode) desc.path = pathname;
ret = inode_find(&desc);
if (ret >= 0)
{ {
/* An inode was found that includes this path and possibly refers to a /* An inode was found that includes this path and possibly refers to a
* mountpoint. * mountpoint.
*/ */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT #ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a valid 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) 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) if (ret < 0)
{ {
errcode = -ret; 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, ...) int open(const char *path, int oflags, ...)
{ {
struct inode_search_s desc;
FAR struct file *filep; FAR struct file *filep;
FAR struct inode *inode; FAR struct inode *inode;
FAR const char *relpath = NULL;
#if defined(CONFIG_FILE_MODE) || !defined(CONFIG_DISABLE_MOUNTPOINT) #if defined(CONFIG_FILE_MODE) || !defined(CONFIG_DISABLE_MOUNTPOINT)
mode_t mode = 0666; mode_t mode = 0666;
#endif #endif
@@ -121,18 +121,26 @@ int open(const char *path, int oflags, ...)
/* Get an inode for this file */ /* Get an inode for this file */
inode = inode_find(path, &relpath, false); RESET_SEARCH(&desc);
if (!inode) desc.path = path;
ret = inode_find(&desc);
if (ret < 0)
{ {
/* "O_CREAT is not set and the named file does not exist. Or, a /* "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 * directory component in pathname does not exist or is a dangling
* symbolic link." * symbolic link."
*/ */
ret = ENOENT; ret = -ret;
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && \ #if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && \
!defined(CONFIG_DISABLE_MOUNTPOINT) !defined(CONFIG_DISABLE_MOUNTPOINT)
/* If the inode is block driver, then we may return a character driver /* 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 #ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_MOUNTPT(inode)) 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 else
#endif #endif
+16 -4
View File
@@ -82,9 +82,10 @@
ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize) ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
{ {
struct inode_search_s desc;
FAR struct inode *node; FAR struct inode *node;
const char *relpath = NULL;
int errcode; int errcode;
int ret;
DEBUGASSERT(path != NULL && buf != NULL && bufsize > 0); 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. * symbolic link node.
*/ */
node = inode_find(path, &relpath, true); RESET_SEARCH(&desc);
if (node == NULL) desc.path = path;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
ret = inode_find(&desc);
if (ret < 0)
{ {
errcode = ENOENT; errcode = -ret;
goto errout; 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 /* An inode was found that includes this path and possibly refers to a
* symbolic link. * symbolic link.
* *
+32 -11
View File
@@ -82,12 +82,10 @@
int rename(FAR const char *oldpath, FAR const char *newpath) 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 *oldinode;
FAR struct inode *newinode; FAR struct inode *newinode;
const char *oldrelpath = NULL;
#ifndef CONFIG_DISABLE_MOUNTPOINT
const char *newrelpath = NULL;
#endif
int errcode; int errcode;
int ret; int ret;
@@ -103,15 +101,26 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
/* Get an inode that includes the oldpath */ /* Get an inode that includes the oldpath */
oldinode = inode_find(oldpath, &oldrelpath, true); RESET_SEARCH(&olddesc);
if (!oldinode) 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 */ /* There is no inode that includes in this path */
errcode = ENOENT; errcode = -ret;
goto errout; goto errout;
} }
/* Get the search results */
oldinode = olddesc.node;
DEBUGASSERT(oldinode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT #ifndef CONFIG_DISABLE_MOUNTPOINT
/* Verify that the old inode is a valid 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 * mountpoint
*/ */
newinode = inode_find(newpath, &newrelpath, true); RESET_SEARCH(&newdesc);
if (!newinode) 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 */ /* There is no mountpoint that includes in this path */
errcode = ENOENT; errcode = -ret;
goto errout_with_oldinode; 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 */ /* Verify that the two paths lie on the same mountpoint inode */
if (oldinode != newinode) if (oldinode != newinode)
@@ -144,7 +164,8 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
if (oldinode->u.i_mops->rename) 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) if (ret < 0)
{ {
errcode = -ret; errcode = -ret;
+19 -8
View File
@@ -41,6 +41,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
@@ -82,24 +83,36 @@
int rmdir(FAR const char *pathname) int rmdir(FAR const char *pathname)
{ {
struct inode_search_s desc;
FAR struct inode *inode; 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 /* Get an inode for the directory (or for the mountpoint containing the
* directory). inode_find() automatically increments the reference count * directory). inode_find() automatically increments the reference count
* on the inode if one is found. * on the inode if one is found.
*/ */
inode = inode_find(pathname, &relpath, true); RESET_SEARCH(&desc);
if (!inode) 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 */ /* There is no inode that includes in this path */
errcode = ENOENT; errcode = -ret;
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT #ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a valid 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) 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) if (ret < 0)
{ {
errcode = -ret; errcode = -ret;
@@ -134,8 +147,6 @@ int rmdir(FAR const char *pathname)
if (!inode->u.i_ops) if (!inode->u.i_ops)
{ {
int ret;
/* If the directory inode has children, however, then it cannot be /* If the directory inode has children, however, then it cannot be
* removed. * 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) int stat(FAR const char *path, FAR struct stat *buf)
{ {
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
const char *relpath = NULL; int ret = OK;
int ret = OK;
/* Sanity checks */ /* Sanity checks */
@@ -234,17 +234,28 @@ int stat(FAR const char *path, FAR struct stat *buf)
/* Get an inode for this file */ /* Get an inode for this file */
inode = inode_find(path, &relpath, true); RESET_SEARCH(&desc);
if (!inode) 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 /* This name does not refer to a psudeo-inode and there is no
* mountpoint that includes in this path. * mountpoint that includes in this path.
*/ */
ret = ENOENT; ret = -ret;
goto errout; 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 /* The way we handle the stat depends on the type of inode that we
* are dealing with. * are dealing with.
*/ */
@@ -260,7 +271,7 @@ int stat(FAR const char *path, FAR struct stat *buf)
{ {
/* Perform the stat() operation */ /* Perform the stat() operation */
ret = inode->u.i_mops->stat(inode, relpath, buf); ret = inode->u.i_mops->stat(inode, desc.relpath, buf);
} }
} }
else 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) int statfs(FAR const char *path, FAR struct statfs *buf)
{ {
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
FAR const char *relpath = NULL; int ret = OK;
int ret = OK;
/* Sanity checks */ /* Sanity checks */
@@ -105,17 +105,25 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
/* Get an inode for this file */ /* Get an inode for this file */
inode = inode_find(path, &relpath, false); RESET_SEARCH(&desc);
if (!inode) desc.path = path;
ret = inode_find(&desc);
if (ret < 0)
{ {
/* This name does not refer to a psudeo-inode and there is no /* This name does not refer to a psudeo-inode and there is no
* mountpoint that includes in this path. * mountpoint that includes in this path.
*/ */
ret = ENOENT; ret = -ret;
goto errout; 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 /* The way we handle the statfs depends on the type of inode that we
* are dealing with. * are dealing with.
*/ */
+19 -7
View File
@@ -41,6 +41,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
@@ -82,24 +83,35 @@
int unlink(FAR const char *pathname) int unlink(FAR const char *pathname)
{ {
struct inode_search_s desc;
FAR struct inode *inode; FAR struct inode *inode;
const char *relpath = NULL; int errcode;
int errcode; int ret;
int ret;
/* Get an inode for this file (without deference the final node in the path /* Get an inode for this file (without deference the final node in the path
* which may be a symbolic link) * which may be a symbolic link)
*/ */
inode = inode_find(pathname, &relpath, true); RESET_SEARCH(&desc);
if (!inode) 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 */ /* There is no inode that includes in this path */
errcode = ENOENT; errcode = -ret;
goto errout; goto errout;
} }
/* Get the search results */
inode = desc.node;
DEBUGASSERT(inode != NULL);
#ifndef CONFIG_DISABLE_MOUNTPOINT #ifndef CONFIG_DISABLE_MOUNTPOINT
/* Check if the inode is a valid 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) 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) if (ret < 0)
{ {
errcode = -ret; errcode = -ret;