arch/sim/src/up_hostfs.c: Support S_IFSOCK, DT_LNK, O_DIRECT and O_SYNC

This commit is contained in:
Xiang Xiao 2018-11-09 09:13:55 -06:00 committed by Gregory Nutt
parent a82f073892
commit 28abd336da
2 changed files with 25 additions and 4 deletions

View File

@ -37,7 +37,7 @@
* Included Files
****************************************************************************/
#define _BSD_SOURCE
#define _GNU_SOURCE 1
#include <sys/types.h>
#include <sys/stat.h>
@ -88,10 +88,14 @@ static void host_stat_convert(struct stat *hostbuf, struct nuttx_stat_s *buf)
{
buf->st_mode |= NUTTX_S_IFLNK;
}
else /* if (hostbuf->st_mode & S_IFIFO) */
else if (hostbuf->st_mode & S_IFIFO)
{
buf->st_mode |= NUTTX_S_IFIFO;
}
else if (hostbuf->st_mode & S_IFSOCK)
{
buf->st_mode |= NUTTX_S_IFSOCK;
}
buf->st_size = hostbuf->st_size;
buf->st_blksize = hostbuf->st_blksize;
@ -153,6 +157,16 @@ int host_open(const char *pathname, int flags, int mode)
mapflags |= O_NONBLOCK;
}
if (flags & NUTTX_O_SYNC)
{
mapflags |= O_SYNC;
}
if (flags & NUTTX_O_DIRECT)
{
mapflags |= O_DIRECT;
}
return open(pathname, mapflags, mode);
}
@ -219,7 +233,7 @@ void host_sync(int fd)
{
/* Just call the sync routine */
sync();
fsync(fd);
}
/****************************************************************************
@ -306,6 +320,10 @@ int host_readdir(void* dirp, struct nuttx_dirent_s* entry)
{
entry->d_type = NUTTX_DTYPE_DIRECTORY;
}
else if (ent->d_type == DT_LNK)
{
entry->d_type = NUTTX_DTYPE_LINK;
}
return 0;
}

View File

@ -62,14 +62,16 @@
#define NUTTX_DTYPE_CHR 0x02
#define NUTTX_DTYPE_BLK 0x04
#define NUTTX_DTYPE_DIRECTORY 0x08
#define NUTTX_DTYPE_LINK 0x10
/* These must exactly match the definitions from include/sys/stat.h: */
#define NUTTX_S_IFIFO 0
#define NUTTX_S_IFIFO (0 << 11)
#define NUTTX_S_IFCHR (1 << 11)
#define NUTTX_S_IFDIR (2 << 11)
#define NUTTX_S_IFBLK (3 << 11)
#define NUTTX_S_IFREG (4 << 11)
#define NUTTX_S_IFSOCK (8 << 11)
#define NUTTX_S_IFLNK (1 << 15)
/* These must exactly match the definitions from include/fcntl.h: */
@ -83,6 +85,7 @@
#define NUTTX_O_NONBLOCK (1 << 6) /* Don't wait for data */
#define NUTTX_O_SYNC (1 << 7) /* Synchronize output on write */
#define NUTTX_O_BINARY (1 << 8) /* Open the file in binary mode. */
#define NUTTX_O_DIRECT (1 << 9) /* Avoid caching, write directly to hardware */
#define NUTTX_O_RDWR (NUTTX_O_RDONLY | NUTTX_O_WRONLY)