From 28abd336da17ed497777169c21f3a001b8603245 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 9 Nov 2018 09:13:55 -0600 Subject: [PATCH] arch/sim/src/up_hostfs.c: Support S_IFSOCK, DT_LNK, O_DIRECT and O_SYNC --- arch/sim/src/up_hostfs.c | 24 +++++++++++++++++++++--- include/nuttx/fs/hostfs.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/arch/sim/src/up_hostfs.c b/arch/sim/src/up_hostfs.c index df3a03da03..b906738084 100644 --- a/arch/sim/src/up_hostfs.c +++ b/arch/sim/src/up_hostfs.c @@ -37,7 +37,7 @@ * Included Files ****************************************************************************/ -#define _BSD_SOURCE +#define _GNU_SOURCE 1 #include #include @@ -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; } diff --git a/include/nuttx/fs/hostfs.h b/include/nuttx/fs/hostfs.h index a94d3e5daa..67bbd3a132 100644 --- a/include/nuttx/fs/hostfs.h +++ b/include/nuttx/fs/hostfs.h @@ -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)