2017-02-03 18:23:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/inode/fs_inodesearch.c
|
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-02-03 18:23:57 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-02-03 18:23:57 +01:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-02-03 18:23:57 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
#include <stdio.h>
|
2017-02-04 18:21:44 +01:00
|
|
|
#include <string.h>
|
2020-09-13 19:15:05 +02:00
|
|
|
#include <stdlib.h>
|
2017-02-04 19:51:14 +01:00
|
|
|
#include <limits.h>
|
2017-02-03 18:23:57 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
|
|
|
|
#include "inode/inode.h"
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int _inode_compare(FAR const char *fname, FAR struct inode *node);
|
|
|
|
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
|
|
|
|
static int _inode_linktarget(FAR struct inode *node,
|
2017-02-06 17:06:46 +01:00
|
|
|
FAR struct inode_search_s *desc);
|
2017-02-04 23:35:49 +01:00
|
|
|
#endif
|
|
|
|
static int _inode_search(FAR struct inode_search_s *desc);
|
2020-09-13 19:15:05 +02:00
|
|
|
static FAR const char *_inode_getcwd(void);
|
2017-02-04 23:35:49 +01:00
|
|
|
|
2017-02-03 18:23:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct inode *g_root_inode = NULL;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: _inode_compare
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Compare two inode names
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
static int _inode_compare(FAR const char *fname, FAR struct inode *node)
|
2017-02-03 18:23:57 +01:00
|
|
|
{
|
|
|
|
char *nname = node->i_name;
|
|
|
|
|
|
|
|
if (!nname)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fname)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; ; )
|
|
|
|
{
|
2019-02-09 17:00:37 +01:00
|
|
|
/* At the end of the node name? */
|
2017-02-03 18:23:57 +01:00
|
|
|
|
|
|
|
if (!*nname)
|
|
|
|
{
|
2019-02-09 17:00:37 +01:00
|
|
|
/* Yes.. also at the end of find name? */
|
2017-02-03 18:23:57 +01:00
|
|
|
|
|
|
|
if (!*fname || *fname == '/')
|
|
|
|
{
|
|
|
|
/* Yes.. return match */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No... return find name > node name */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 17:00:37 +01:00
|
|
|
/* At end of the find name? */
|
2017-02-03 18:23:57 +01:00
|
|
|
|
|
|
|
else if (!*fname || *fname == '/')
|
|
|
|
{
|
|
|
|
/* Yes... return find name < node name */
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for non-matching characters */
|
|
|
|
|
|
|
|
else if (*fname > *nname)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (*fname < *nname)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not at the end of either string and all of the
|
|
|
|
* characters still match. keep looking.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fname++;
|
|
|
|
nname++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
/****************************************************************************
|
2017-02-04 23:35:49 +01:00
|
|
|
* Name: _inode_linktarget
|
2017-02-04 18:21:44 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-09-16 20:01:42 +02:00
|
|
|
* If the inode is a soft link, then (1) recursively look-up the inode
|
|
|
|
* referenced by the soft link, and (2) return the inode referenced by
|
|
|
|
* the soft link.
|
2017-02-04 18:21:44 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The caller holds the g_inode_sem semaphore
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
|
2017-02-04 23:35:49 +01:00
|
|
|
static int _inode_linktarget(FAR struct inode *node,
|
2017-02-06 17:06:46 +01:00
|
|
|
FAR struct inode_search_s *desc)
|
2017-02-04 18:21:44 +01:00
|
|
|
{
|
|
|
|
unsigned int count = 0;
|
2017-02-04 19:51:14 +01:00
|
|
|
bool save;
|
2017-02-04 18:21:44 +01:00
|
|
|
int ret = -ENOENT;
|
|
|
|
|
|
|
|
DEBUGASSERT(desc != NULL && node != NULL);
|
|
|
|
|
2020-09-16 20:01:42 +02:00
|
|
|
/* An infinite loop is avoided only by the loop count. */
|
2017-02-04 18:21:44 +01:00
|
|
|
|
2017-02-04 19:51:14 +01:00
|
|
|
save = desc->nofollow;
|
2017-02-04 18:21:44 +01:00
|
|
|
while (INODE_IS_SOFTLINK(node))
|
|
|
|
{
|
2017-02-06 15:46:43 +01:00
|
|
|
FAR const char *link = (FAR const char *)node->u.i_link;
|
|
|
|
|
2017-02-04 19:51:14 +01:00
|
|
|
/* Reset and reinitialize the search descriptor. */
|
2017-02-04 18:21:44 +01:00
|
|
|
|
2017-02-05 21:25:45 +01:00
|
|
|
RELEASE_SEARCH(desc);
|
2017-02-06 15:46:43 +01:00
|
|
|
SETUP_SEARCH(desc, link, true);
|
2017-02-04 18:21:44 +01:00
|
|
|
|
2017-02-04 19:51:14 +01:00
|
|
|
/* Look up inode associated with the target of the symbolic link */
|
2017-02-04 18:21:44 +01:00
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
ret = _inode_search(desc);
|
2017-02-04 18:21:44 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit the number of symbolic links that we pass through */
|
|
|
|
|
|
|
|
if (++count > SYMLOOP_MAX)
|
|
|
|
{
|
|
|
|
ret = -ELOOP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up for the next time through the loop */
|
|
|
|
|
|
|
|
node = desc->node;
|
2017-02-06 17:06:46 +01:00
|
|
|
DEBUGASSERT(node != NULL);
|
2017-02-04 18:21:44 +01:00
|
|
|
}
|
|
|
|
|
2017-02-04 19:51:14 +01:00
|
|
|
desc->nofollow = save;
|
2017-02-04 18:21:44 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-03 18:23:57 +01:00
|
|
|
/****************************************************************************
|
2017-02-04 23:35:49 +01:00
|
|
|
* Name: _inode_search
|
2017-02-03 18:23:57 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find the inode associated with 'path' returning the inode references
|
2017-02-04 23:35:49 +01:00
|
|
|
* and references to its companion nodes. This is the internal, common
|
|
|
|
* implementation of inode_search().
|
2017-02-03 18:23:57 +01:00
|
|
|
*
|
2017-02-04 19:51:14 +01:00
|
|
|
* If a mountpoint is encountered in the search prior to encountering the
|
|
|
|
* terminal node, the search will terminate at the mountpoint inode. That
|
|
|
|
* inode and the relative path from the mountpoint, 'relpath' will be
|
|
|
|
* returned.
|
|
|
|
*
|
2017-02-03 22:50:41 +01:00
|
|
|
* If a soft link is encountered that is not the terminal node in the path,
|
2017-02-04 19:51:14 +01:00
|
|
|
* that link WILL be deferenced unconditionally.
|
2017-02-03 18:23:57 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The caller holds the g_inode_sem semaphore
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
static int _inode_search(FAR struct inode_search_s *desc)
|
2017-02-03 18:23:57 +01:00
|
|
|
{
|
2017-02-04 18:21:44 +01:00
|
|
|
FAR const char *name;
|
|
|
|
FAR struct inode *node = g_root_inode;
|
|
|
|
FAR struct inode *left = NULL;
|
|
|
|
FAR struct inode *above = NULL;
|
|
|
|
FAR const char *relpath = NULL;
|
|
|
|
int ret = -ENOENT;
|
|
|
|
|
|
|
|
/* Get the search path, skipping over the leading '/'. The leading '/' is
|
2020-02-23 09:50:23 +01:00
|
|
|
* mandatory because only absolute paths are expected in this context.
|
2017-02-04 18:21:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(desc != NULL && desc->path != NULL);
|
|
|
|
name = desc->path;
|
|
|
|
|
|
|
|
if (*name != '/')
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:23:57 +01:00
|
|
|
/* Traverse the pseudo file system node tree until either (1) all nodes
|
|
|
|
* have been examined without finding the matching node, or (2) the
|
|
|
|
* matching node is found.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (node != NULL)
|
|
|
|
{
|
|
|
|
int result = _inode_compare(name, node);
|
|
|
|
|
|
|
|
/* Case 1: The name is less than the name of the node.
|
|
|
|
* Since the names are ordered, these means that there
|
|
|
|
* is no peer node with this name and that there can be
|
2019-02-09 17:00:37 +01:00
|
|
|
* no match in the filesystem.
|
2017-02-03 18:23:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
node = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Case 2: the name is greater than the name of the node.
|
|
|
|
* In this case, the name may still be in the list to the
|
|
|
|
* "right"
|
|
|
|
*/
|
|
|
|
|
|
|
|
else if (result > 0)
|
|
|
|
{
|
2017-02-03 22:50:41 +01:00
|
|
|
/* Continue looking to the "right" of this inode. */
|
2017-02-03 18:23:57 +01:00
|
|
|
|
|
|
|
left = node;
|
|
|
|
node = node->i_peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The names match */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Now there are three remaining possibilities:
|
|
|
|
* (1) This is the node that we are looking for.
|
|
|
|
* (2) The node we are looking for is "below" this one.
|
2019-02-09 17:00:37 +01:00
|
|
|
* (3) This node is a mountpoint and will absorb all requests
|
2017-02-03 18:23:57 +01:00
|
|
|
* below this one
|
|
|
|
*/
|
|
|
|
|
|
|
|
name = inode_nextname(name);
|
|
|
|
if (*name == '\0' || INODE_IS_MOUNTPT(node))
|
|
|
|
{
|
2019-02-09 17:00:37 +01:00
|
|
|
/* Either (1) we are at the end of the path, so this must be
|
|
|
|
* the node we are looking for or else (2) this node is a
|
|
|
|
* mountpoint and will handle the remaining part of the
|
|
|
|
* pathname
|
2017-02-03 18:23:57 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
relpath = name;
|
2017-02-04 19:51:14 +01:00
|
|
|
ret = OK;
|
2017-02-03 18:23:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-03 22:50:41 +01:00
|
|
|
/* More nodes to be examined in the path "below" this one. */
|
2017-02-03 18:23:57 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
|
2017-02-04 18:21:44 +01:00
|
|
|
/* Was the node a soft link? If so, then we need need to
|
|
|
|
* continue below the target of the link, not the link itself.
|
2017-02-03 18:23:57 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
if (INODE_IS_SOFTLINK(node))
|
2017-02-03 18:23:57 +01:00
|
|
|
{
|
2017-02-04 18:21:44 +01:00
|
|
|
int status;
|
2017-02-03 18:23:57 +01:00
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
/* If this intermediate inode in the is a soft link, then
|
2020-09-16 20:01:42 +02:00
|
|
|
* (1) recursively look-up the inode referenced by the
|
|
|
|
* soft link, and (2) continue searching with that inode
|
2020-09-15 11:42:42 +02:00
|
|
|
* instead.
|
2017-02-03 18:23:57 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-06 17:06:46 +01:00
|
|
|
status = _inode_linktarget(node, desc);
|
2017-02-04 18:21:44 +01:00
|
|
|
if (status < 0)
|
2017-02-03 23:34:50 +01:00
|
|
|
{
|
2017-05-11 21:15:13 +02:00
|
|
|
/* Probably means that the target of the symbolic link
|
|
|
|
* does not exist.
|
2017-02-03 23:34:50 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
ret = status;
|
2017-02-03 23:34:50 +01:00
|
|
|
break;
|
2017-02-03 18:23:57 +01:00
|
|
|
}
|
2017-02-04 18:21:44 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FAR struct inode *newnode = desc->node;
|
|
|
|
|
|
|
|
if (newnode != node)
|
|
|
|
{
|
|
|
|
/* The node was a valid symbolic link and we have
|
2017-05-11 21:15:13 +02:00
|
|
|
* jumped to a different, spot in the pseudo file
|
|
|
|
* system tree.
|
2017-02-04 18:21:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Check if this took us to a mountpoint. */
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
if (INODE_IS_MOUNTPT(newnode))
|
2017-02-04 18:21:44 +01:00
|
|
|
{
|
2017-02-06 17:06:46 +01:00
|
|
|
/* Return the mountpoint information.
|
|
|
|
* NOTE that the last path to the link target
|
|
|
|
* was already set by _inode_linktarget().
|
|
|
|
*/
|
2017-02-04 23:35:49 +01:00
|
|
|
|
|
|
|
node = newnode;
|
2020-09-16 20:01:42 +02:00
|
|
|
above = desc->parent;
|
|
|
|
left = desc->peer;
|
2017-02-04 18:21:44 +01:00
|
|
|
ret = OK;
|
2020-09-16 20:01:42 +02:00
|
|
|
|
|
|
|
if (*desc->relpath != '\0')
|
|
|
|
{
|
|
|
|
char *buffer = NULL;
|
|
|
|
|
|
|
|
asprintf(&buffer,
|
|
|
|
"%s/%s", desc->relpath, name);
|
|
|
|
if (buffer != NULL)
|
|
|
|
{
|
2023-03-23 07:20:22 +01:00
|
|
|
lib_free(desc->buffer);
|
2020-09-16 20:01:42 +02:00
|
|
|
desc->buffer = buffer;
|
|
|
|
relpath = buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
relpath = name;
|
|
|
|
}
|
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-02-04 23:35:49 +01:00
|
|
|
|
|
|
|
/* Continue from this new inode. */
|
|
|
|
|
|
|
|
node = newnode;
|
2017-02-04 18:21:44 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-03 18:23:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
2019-10-27 18:48:14 +01:00
|
|
|
|
2017-02-03 18:23:57 +01:00
|
|
|
/* Keep looking at the next level "down" */
|
|
|
|
|
|
|
|
above = node;
|
|
|
|
left = NULL;
|
|
|
|
node = node->i_child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 19:15:05 +02:00
|
|
|
/* The node may or may not be null as per one of the following four cases:
|
2017-02-12 15:37:28 +01:00
|
|
|
*
|
2017-02-03 18:23:57 +01:00
|
|
|
* With node = NULL
|
2017-02-12 15:37:28 +01:00
|
|
|
*
|
|
|
|
* (1) We went left past the final peer: The new node name is larger
|
|
|
|
* than any existing node name at that level.
|
|
|
|
* (2) We broke out in the middle of the list of peers because the name
|
|
|
|
* was not found in the ordered list.
|
|
|
|
* (3) We went down past the final parent: The new node name is
|
|
|
|
* "deeper" than anything that we currently have in the tree.
|
|
|
|
*
|
|
|
|
* With node != NULL
|
|
|
|
*
|
2017-02-03 18:23:57 +01:00
|
|
|
* (4) When the node matching the full path is found
|
|
|
|
*/
|
|
|
|
|
2017-02-04 18:21:44 +01:00
|
|
|
desc->path = name;
|
|
|
|
desc->node = node;
|
|
|
|
desc->peer = left;
|
|
|
|
desc->parent = above;
|
|
|
|
desc->relpath = relpath;
|
|
|
|
return ret;
|
2017-02-03 18:23:57 +01:00
|
|
|
}
|
|
|
|
|
2020-09-13 19:15:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: _inode_getcwd
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the current working directory
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR const char *_inode_getcwd(void)
|
|
|
|
{
|
|
|
|
FAR const char *pwd = "";
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
pwd = getenv("PWD");
|
|
|
|
if (pwd == NULL)
|
|
|
|
{
|
2021-08-01 09:27:08 +02:00
|
|
|
pwd = CONFIG_LIBC_HOMEDIR;
|
2020-09-13 19:15:05 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: inode_search
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find the inode associated with 'path' returning the inode references
|
|
|
|
* and references to its companion nodes.
|
|
|
|
*
|
|
|
|
* If a mountpoint is encountered in the search prior to encountering the
|
|
|
|
* terminal node, the search will terminate at the mountpoint inode. That
|
|
|
|
* inode and the relative path from the mountpoint, 'relpath' will be
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* inode_search will follow soft links in path leading up to the terminal
|
|
|
|
* node. Whether or no inode_search() will deference that terminal node
|
|
|
|
* depends on the 'nofollow' input.
|
|
|
|
*
|
|
|
|
* If a soft link is encountered that is not the terminal node in the path,
|
|
|
|
* that link WILL be deferenced unconditionally.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The caller holds the g_inode_sem semaphore
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int inode_search(FAR struct inode_search_s *desc)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Perform the common _inode_search() logic. This does everything except
|
|
|
|
* operations special operations that must be performed on the terminal
|
|
|
|
* node if node is a symbolic link.
|
|
|
|
*/
|
|
|
|
|
2020-09-13 19:15:05 +02:00
|
|
|
DEBUGASSERT(desc != NULL && desc->path != NULL);
|
|
|
|
|
|
|
|
/* Convert the relative path to the absolute path */
|
|
|
|
|
|
|
|
if (*desc->path != '/')
|
|
|
|
{
|
|
|
|
asprintf(&desc->buffer, "%s/%s", _inode_getcwd(), desc->path);
|
|
|
|
if (desc->buffer == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc->path = desc->buffer;
|
|
|
|
}
|
2017-02-04 23:35:49 +01:00
|
|
|
|
|
|
|
ret = _inode_search(desc);
|
|
|
|
|
|
|
|
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
FAR struct inode *node;
|
|
|
|
|
|
|
|
/* Search completed successfully */
|
|
|
|
|
|
|
|
node = desc->node;
|
|
|
|
DEBUGASSERT(node != NULL);
|
|
|
|
|
|
|
|
/* Is the terminal node a softlink? Should we follow it? */
|
|
|
|
|
|
|
|
if (!desc->nofollow && INODE_IS_SOFTLINK(node))
|
|
|
|
{
|
|
|
|
/* The terminating inode is a valid soft link: Return the inode,
|
2017-02-06 15:46:43 +01:00
|
|
|
* corresponding to link target. _inode_linktarget() will follow
|
|
|
|
* a link (or a series of links to links) and will return the
|
|
|
|
* link target of the final symbolic link in the series.
|
2017-02-04 23:35:49 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-06 17:06:46 +01:00
|
|
|
ret = _inode_linktarget(node, desc);
|
2017-02-04 23:35:49 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* The most likely cause for failure is that the target of the
|
|
|
|
* symbolic link does not exist.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:23:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: inode_nextname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Given a path with node names separated by '/', return the next path
|
|
|
|
* segment name.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR const char *inode_nextname(FAR const char *name)
|
|
|
|
{
|
|
|
|
/* Search for the '/' delimiter or the NUL terminator at the end of the
|
|
|
|
* path segment.
|
|
|
|
*/
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
while (*name != '\0' && *name != '/')
|
2017-02-03 18:23:57 +01:00
|
|
|
{
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we found the '/' delimiter, then the path segment we want begins at
|
|
|
|
* the next character (which might also be the NUL terminator).
|
|
|
|
*/
|
|
|
|
|
2017-02-04 23:35:49 +01:00
|
|
|
while (*name == '/')
|
2017-02-03 18:23:57 +01:00
|
|
|
{
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|