mirror of
https://github.com/apache/nuttx.git
synced 2026-10-06 11:03:16 +08:00
fs/hostfs: add link, symlink, readlink and lstat support
Implemented link(), symlink(), readlink() and lstat() in hostfs. Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
This commit is contained in:
@@ -370,3 +370,31 @@ int host_chstat(const char *path, const struct stat *buf, int flags)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2)
|
||||
{
|
||||
/* ARM semihosting doesn't support hard links */
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_symlink(const char *target, const char *linkpath)
|
||||
{
|
||||
/* ARM semihosting doesn't support symbolic links */
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ssize_t host_readlink(const char *path, char *buf, size_t bufsize)
|
||||
{
|
||||
/* ARM semihosting doesn't support symbolic links */
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
#endif /* CONFIG_FS_LINKS */
|
||||
|
||||
@@ -370,3 +370,25 @@ int host_chstat(const char *path, const struct stat *buf, int flags)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_symlink(const char *target, const char *linkpath)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ssize_t host_readlink(const char *path, char *buf, size_t bufsize)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
#endif /* CONFIG_FS_LINKS */
|
||||
|
||||
@@ -368,3 +368,25 @@ int host_chstat(const char *path, const struct stat *buf, int flags)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_symlink(const char *target, const char *linkpath)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ssize_t host_readlink(const char *path, char *buf, size_t bufsize)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
#endif /* CONFIG_FS_LINKS */
|
||||
|
||||
@@ -75,9 +75,11 @@ NXSYMBOLS(getpid)
|
||||
NXSYMBOLS(getsockopt)
|
||||
NXSYMBOLS(if_nametoindex)
|
||||
NXSYMBOLS(ioctl)
|
||||
NXSYMBOLS(link)
|
||||
NXSYMBOLS(listen)
|
||||
NXSYMBOLS(longjmp)
|
||||
NXSYMBOLS(lseek)
|
||||
NXSYMBOLS(lstat)
|
||||
NXSYMBOLS(malloc)
|
||||
NXSYMBOLS(malloc_size)
|
||||
NXSYMBOLS(malloc_usable_size)
|
||||
@@ -154,6 +156,7 @@ NXSYMBOLS(strchr)
|
||||
NXSYMBOLS(strerror)
|
||||
NXSYMBOLS(strlen)
|
||||
NXSYMBOLS(strtol)
|
||||
NXSYMBOLS(symlink)
|
||||
NXSYMBOLS(sysconf)
|
||||
NXSYMBOLS(syslog)
|
||||
NXSYMBOLS(system)
|
||||
|
||||
@@ -820,3 +820,74 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_link
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2)
|
||||
{
|
||||
int ret = link(path1, path2);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_symlink
|
||||
****************************************************************************/
|
||||
|
||||
int host_symlink(const char *target, const char *linkpath)
|
||||
{
|
||||
int ret = symlink(target, linkpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_readlink
|
||||
****************************************************************************/
|
||||
|
||||
nuttx_ssize_t host_readlink(const char *path, char *buf,
|
||||
nuttx_size_t bufsize)
|
||||
{
|
||||
ssize_t ret = readlink(path, buf, bufsize);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_lstat
|
||||
****************************************************************************/
|
||||
|
||||
int host_lstat(const char *path, struct nuttx_stat_s *buf)
|
||||
{
|
||||
struct stat hostbuf;
|
||||
int ret;
|
||||
|
||||
/* Call the host's lstat routine */
|
||||
|
||||
ret = lstat(path, &hostbuf);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
}
|
||||
|
||||
/* Map the return values */
|
||||
|
||||
host_stat_convert(&hostbuf, buf);
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_FS_LINKS */
|
||||
|
||||
@@ -461,3 +461,42 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_link
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_symlink
|
||||
****************************************************************************/
|
||||
|
||||
int host_symlink(const char *target, const char *linkpath)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_readlink
|
||||
****************************************************************************/
|
||||
|
||||
nuttx_ssize_t host_readlink(const char *path, char *buf,
|
||||
nuttx_size_t bufsize)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: host_lstat
|
||||
****************************************************************************/
|
||||
|
||||
int host_lstat(const char *path, struct nuttx_stat_s *buf)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
#endif /* CONFIG_FS_LINKS */
|
||||
|
||||
@@ -256,3 +256,25 @@ int host_chstat(const char *path, const struct stat *buf, int flags)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_symlink(const char *target, const char *linkpath)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ssize_t host_readlink(const char *path, char *buf, size_t bufsize)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int host_lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
#endif /* CONFIG_FS_LINKS */
|
||||
|
||||
+348
-24
File diff suppressed because it is too large
Load Diff
@@ -256,6 +256,13 @@ int host_rename(const char *oldpath, const char *newpath);
|
||||
int host_stat(const char *path, struct nuttx_stat_s *buf);
|
||||
int host_chstat(const char *path,
|
||||
const struct nuttx_stat_s *buf, int flags);
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2);
|
||||
int host_symlink(const char *target, const char *linkpath);
|
||||
nuttx_ssize_t host_readlink(const char *path, char *buf,
|
||||
nuttx_size_t bufsize);
|
||||
int host_lstat(const char *path, struct nuttx_stat_s *buf);
|
||||
#endif
|
||||
#else
|
||||
int host_open(const char *pathname, int flags, int mode);
|
||||
int host_close(int fd);
|
||||
@@ -280,6 +287,12 @@ int host_rename(const char *oldpath, const char *newpath);
|
||||
int host_stat(const char *path, struct stat *buf);
|
||||
int host_chstat(const char *path,
|
||||
const struct stat *buf, int flags);
|
||||
#ifdef CONFIG_FS_LINKS
|
||||
int host_link(const char *path1, const char *path2);
|
||||
int host_symlink(const char *target, const char *linkpath);
|
||||
ssize_t host_readlink(const char *path, char *buf, size_t bufsize);
|
||||
int host_lstat(const char *path, struct stat *buf);
|
||||
#endif
|
||||
#endif /* __SIM__ */
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_FS_HOSTFS_H */
|
||||
|
||||
Reference in New Issue
Block a user