Skip to content

Commit

Permalink
sim_hostfs:add host_errno_convert API for convert result
Browse files Browse the repository at this point in the history
Signed-off-by: chenrun1 <[email protected]>
  • Loading branch information
crafcat7 authored and xiaoxiang781216 committed Jan 15, 2025
1 parent 027a570 commit 118f827
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions arch/sim/src/sim/posix/sim_hostfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: host_errno_convert
****************************************************************************/

static int host_errno_convert(int errcode)
{
/* Provide a common interface, which should have different conversions
* on different platforms.
*/

return errcode;
}

/****************************************************************************
* Name: host_stat_convert
****************************************************************************/
Expand Down Expand Up @@ -196,7 +209,7 @@ int host_open(const char *pathname, int flags, int mode)
int ret = open(pathname, mapflags, mode);
if (ret == -1)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -213,7 +226,7 @@ int host_close(int fd)
int ret = close(fd);
if (ret == -1)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -230,7 +243,7 @@ nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
nuttx_ssize_t ret = read(fd, buf, count);
if (ret == -1)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -247,7 +260,7 @@ nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
nuttx_ssize_t ret = write(fd, buf, count);
if (ret == -1)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -265,7 +278,7 @@ nuttx_off_t host_lseek(int fd, nuttx_off_t pos, nuttx_off_t offset,
nuttx_off_t ret = lseek(fd, offset, whence);
if (ret == (nuttx_off_t)-1)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -279,7 +292,13 @@ int host_ioctl(int fd, int request, unsigned long arg)
{
/* Just call the ioctl routine */

return ioctl(fd, request, arg);
int ret = ioctl(fd, request, arg);
if (ret < 0)
{
ret = host_errno_convert(-errno);
}

return ret;
}

/****************************************************************************
Expand All @@ -299,7 +318,13 @@ void host_sync(int fd)

int host_dup(int fd)
{
return dup(fd);
int ret = dup(fd);
if (ret < 0)
{
ret = host_errno_convert(-errno);
}

return ret;
}

/****************************************************************************
Expand All @@ -316,7 +341,7 @@ int host_fstat(int fd, struct nuttx_stat_s *buf)
ret = fstat(fd, &hostbuf);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

/* Map the return values */
Expand All @@ -339,7 +364,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
ret = fchmod(fd, buf->st_mode);
if (ret < 0)
{
return -errno;
return host_errno_convert(-errno);
}
}

Expand All @@ -348,7 +373,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
ret = fchown(fd, buf->st_uid, buf->st_gid);
if (ret < 0)
{
return -errno;
return host_errno_convert(-errno);
}
}

Expand Down Expand Up @@ -379,7 +404,7 @@ int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
ret = futimens(fd, times);
if (ret < 0)
{
return -errno;
return host_errno_convert(-errno);
}
}

Expand All @@ -395,7 +420,7 @@ int host_ftruncate(int fd, nuttx_off_t length)
int ret = ftruncate(fd, length);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand Down Expand Up @@ -491,7 +516,7 @@ int host_closedir(void *dirp)
int ret = closedir(dirp);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -511,7 +536,7 @@ int host_statfs(const char *path, struct nuttx_statfs_s *buf)
ret = statvfs(path, &hostbuf);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

/* Map the struct statfs value */
Expand All @@ -537,7 +562,7 @@ int host_unlink(const char *pathname)
int ret = unlink(pathname);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -554,7 +579,7 @@ int host_mkdir(const char *pathname, int mode)
int ret = mkdir(pathname, mode);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -569,7 +594,7 @@ int host_rmdir(const char *pathname)
int ret = rmdir(pathname);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -584,7 +609,7 @@ int host_rename(const char *oldpath, const char *newpath)
int ret = rename(oldpath, newpath);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

return ret;
Expand All @@ -604,7 +629,7 @@ int host_stat(const char *path, struct nuttx_stat_s *buf)
ret = stat(path, &hostbuf);
if (ret < 0)
{
ret = -errno;
ret = host_errno_convert(-errno);
}

/* Map the return values */
Expand All @@ -627,7 +652,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
ret = chmod(path, buf->st_mode);
if (ret < 0)
{
return -errno;
return host_errno_convert(-errno);
}
}

Expand All @@ -636,7 +661,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
ret = chown(path, buf->st_uid, buf->st_gid);
if (ret < 0)
{
return -errno;
return host_errno_convert(-errno);
}
}

Expand Down Expand Up @@ -667,7 +692,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
ret = utimensat(AT_FDCWD, path, times, 0);
if (ret < 0)
{
return -errno;
return host_errno_convert(-errno);
}
}

Expand Down

0 comments on commit 118f827

Please sign in to comment.