Add macros support that will eventually allow dynamic allocation of strings need to support soft links.

This commit is contained in:
Gregory Nutt
2017-02-05 14:25:45 -06:00
parent 8f2c7198ed
commit 45fd98da88
24 changed files with 316 additions and 258 deletions
+8 -4
View File
@@ -107,8 +107,7 @@ int link(FAR const char *path1, FAR const char *path2)
* does not lie on a mounted volume.
*/
RESET_SEARCH(&desc);
desc.path = path2;
SETUP_SEARCH(&desc, path2, false);
ret = inode_find(&desc);
if (ret >= 0)
@@ -149,7 +148,7 @@ int link(FAR const char *path1, FAR const char *path2)
if (newpath2 == NULL)
{
errcode = ENOMEM;
goto errout;
goto errout_with_search;
}
/* Create an inode in the pseudo-filesystem at this path.
@@ -165,7 +164,7 @@ int link(FAR const char *path1, FAR const char *path2)
{
kmm_free(newpath2);
errcode = -ret;
goto errout;
goto errout_with_search;
}
/* Initialize the inode */
@@ -177,10 +176,15 @@ int link(FAR const char *path1, FAR const char *path2)
/* Symbolic link successfully created */
RELEASE_SEARCH(&desc);
return OK;
errout_with_inode:
inode_release(inode);
errout_with_search:
RELEASE_SEARCH(&desc);
errout:
set_errno(errcode);
return ERROR;
+9 -7
View File
@@ -86,13 +86,12 @@ int mkdir(const char *pathname, mode_t mode)
{
struct inode_search_s desc;
FAR struct inode *inode;
int errcode;
int ret;
int errcode;
int ret;
/* Find the inode that includes this path */
RESET_SEARCH(&desc);
desc.path = pathname;
SETUP_SEARCH(&desc, pathname, false);
ret = inode_find(&desc);
if (ret >= 0)
@@ -164,24 +163,27 @@ int mkdir(const char *pathname, mode_t mode)
if (ret < 0)
{
errcode = -ret;
goto errout;
goto errout_with_search;
}
}
#else
else
{
errcode = ENXIO;
goto errout;
goto errout_with_search;
}
#endif
/* Directory successfully created */
RELEASE_SEARCH(&desc);
return OK;
errout_with_inode:
inode_release(inode);
errout:
errout_with_search:
RELEASE_SEARCH(&desc);
set_errno(errcode);
return ERROR;
}
+12 -7
View File
@@ -121,8 +121,7 @@ int open(const char *path, int oflags, ...)
/* Get an inode for this file */
RESET_SEARCH(&desc);
desc.path = path;
SETUP_SEARCH(&desc, path, false);
ret = inode_find(&desc);
if (ret < 0)
@@ -133,7 +132,7 @@ int open(const char *path, int oflags, ...)
*/
ret = -ret;
goto errout;
goto errout_with_search;
}
/* Get the search results */
@@ -164,11 +163,12 @@ int open(const char *path, int oflags, ...)
if (fd < 0)
{
ret = fd;
goto errout;
goto errout_with_search;
}
/* Return the file descriptor */
RELEASE_SEARCH(&desc);
leave_cancellation_point();
return fd;
}
@@ -215,8 +215,7 @@ int open(const char *path, int oflags, ...)
{
/* The errno value has already been set */
leave_cancellation_point();
return ERROR;
goto errout;
}
/* Perform the driver open operation. NOTE that the open method may be
@@ -276,15 +275,21 @@ int open(const char *path, int oflags, ...)
}
#endif
RELEASE_SEARCH(&desc);
leave_cancellation_point();
return fd;
errout_with_fd:
files_release(fd);
errout_with_inode:
inode_release(inode);
errout:
errout_with_search:
RELEASE_SEARCH(&desc);
set_errno(ret);
errout:
leave_cancellation_point();
return ERROR;
}
+6 -7
View File
@@ -93,17 +93,13 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
* symbolic link node.
*/
RESET_SEARCH(&desc);
desc.path = path;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
SETUP_SEARCH(&desc, path, true);
ret = inode_find(&desc);
if (ret < 0)
{
errcode = -ret;
goto errout;
goto errout_with_search;
}
/* Get the search results */
@@ -131,11 +127,14 @@ ssize_t readlink(FAR const char *path, FAR char *buf, size_t bufsize)
/* Release our reference on the inode and return the length */
inode_release(node);
RELEASE_SEARCH(&desc);
return strlen(buf);
errout_with_inode:
inode_release(node);
errout:
errout_with_search:
RELEASE_SEARCH(&desc);
set_errno(errcode);
return ERROR;
}
+17 -15
View File
@@ -83,7 +83,9 @@
int rename(FAR const char *oldpath, FAR const char *newpath)
{
struct inode_search_s olddesc;
#ifndef CONFIG_DISABLE_MOUNTPOINT
struct inode_search_s newdesc;
#endif
FAR struct inode *oldinode;
FAR struct inode *newinode;
int errcode;
@@ -101,11 +103,7 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
/* Get an inode that includes the oldpath */
RESET_SEARCH(&olddesc);
olddesc.path = oldpath;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
olddesc.nofollow = true;
#endif
SETUP_SEARCH(&olddesc, oldpath, true);
ret = inode_find(&olddesc);
if (ret < 0)
@@ -113,7 +111,7 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
/* There is no inode that includes in this path */
errcode = -ret;
goto errout;
goto errout_with_oldsearch;
}
/* Get the search results */
@@ -130,11 +128,7 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
* mountpoint
*/
RESET_SEARCH(&newdesc);
newdesc.path = newpath;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
newdesc.nofollow = true;
#endif
SETUP_SEARCH(&newdesc, newpath, true);
ret = inode_find(&newdesc);
if (ret < 0)
@@ -142,7 +136,7 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
/* There is no mountpoint that includes in this path */
errcode = -ret;
goto errout_with_oldinode;
goto errout_with_newsearch;
}
/* Get the search results */
@@ -181,9 +175,10 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
/* Successfully renamed */
inode_release(newinode);
RELEASE_SEARCH(&newdesc);
}
else
#endif
#endif /* CONFIG_DISABLE_MOUNTPOINT */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
{
/* Create a new, empty inode at the destination location.
@@ -246,22 +241,29 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
#else
{
errcode = ENXIO;
goto errout;
goto errout_with_oldsearch;
}
#endif
/* Successfully renamed */
inode_release(oldinode);
RELEASE_SEARCH(&olddesc);
return OK;
#ifndef CONFIG_DISABLE_MOUNTPOINT
errout_with_newinode:
inode_release(newinode);
errout_with_newsearch:
RELEASE_SEARCH(&newdesc);
#endif
errout_with_oldinode:
inode_release(oldinode);
errout:
errout_with_oldsearch:
RELEASE_SEARCH(&olddesc);
set_errno(errcode);
return ERROR;
}
+5 -7
View File
@@ -93,11 +93,7 @@ int rmdir(FAR const char *pathname)
* on the inode if one is found.
*/
RESET_SEARCH(&desc);
desc.path = pathname;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
SETUP_SEARCH(&desc, pathname, true);
ret = inode_find(&desc);
if (ret < 0)
@@ -105,7 +101,7 @@ int rmdir(FAR const char *pathname)
/* There is no inode that includes in this path */
errcode = -ret;
goto errout;
goto errout_with_search;
}
/* Get the search results */
@@ -188,11 +184,13 @@ int rmdir(FAR const char *pathname)
/* Successfully removed the directory */
inode_release(inode);
RELEASE_SEARCH(&desc);
return OK;
errout_with_inode:
inode_release(inode);
errout:
errout_with_search:
RELEASE_SEARCH(&desc);
set_errno(errcode);
return ERROR;
}
+7 -6
View File
@@ -234,11 +234,7 @@ int stat(FAR const char *path, FAR struct stat *buf)
/* Get an inode for this file */
RESET_SEARCH(&desc);
desc.path = path;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
SETUP_SEARCH(&desc, path, true);
ret = inode_find(&desc);
if (ret < 0)
@@ -248,7 +244,7 @@ int stat(FAR const char *path, FAR struct stat *buf)
*/
ret = -ret;
goto errout;
goto errout_with_search;
}
/* Get the search results */
@@ -293,12 +289,17 @@ int stat(FAR const char *path, FAR struct stat *buf)
/* Successfully stat'ed the file */
inode_release(inode);
RELEASE_SEARCH(&desc);
return OK;
/* Failure conditions always set the errno appropriately */
errout_with_inode:
inode_release(inode);
errout_with_search:
RELEASE_SEARCH(&desc);
errout:
set_errno(ret);
return ERROR;
+7 -3
View File
@@ -105,8 +105,7 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
/* Get an inode for this file */
RESET_SEARCH(&desc);
desc.path = path;
SETUP_SEARCH(&desc, path, false);
ret = inode_find(&desc);
if (ret < 0)
@@ -116,7 +115,7 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
*/
ret = -ret;
goto errout;
goto errout_with_search;
}
/* Get the search results */
@@ -161,12 +160,17 @@ int statfs(FAR const char *path, FAR struct statfs *buf)
/* Successfully statfs'ed the file */
inode_release(inode);
RELEASE_SEARCH(&desc);
return OK;
/* Failure conditions always set the errno appropriately */
errout_with_inode:
inode_release(inode);
errout_with_search:
RELEASE_SEARCH(&desc);
errout:
set_errno(ret);
return ERROR;
+6 -7
View File
@@ -92,11 +92,7 @@ int unlink(FAR const char *pathname)
* which may be a symbolic link)
*/
RESET_SEARCH(&desc);
desc.path = pathname;
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
desc.nofollow = true;
#endif
SETUP_SEARCH(&desc, pathname, true);
ret = inode_find(&desc);
if (ret < 0)
@@ -104,7 +100,7 @@ int unlink(FAR const char *pathname)
/* There is no inode that includes in this path */
errcode = -ret;
goto errout;
goto errout_with_search;
}
/* Get the search results */
@@ -233,11 +229,14 @@ int unlink(FAR const char *pathname)
/* Successfully unlinked */
inode_release(inode);
RELEASE_SEARCH(&desc);
return OK;
errout_with_inode:
inode_release(inode);
errout:
errout_with_search:
RELEASE_SEARCH(&desc);
set_errno(errcode);
return ERROR;
}