sim: Make hostfs build for macOS

* Ignore O_DIRECT if the host OS doesn't provide it.
* Use statvfs instead of statfs. The former is in POSIX and
  more widely available these days.
This commit is contained in:
YAMAMOTO Takashi 2020-02-12 12:05:04 +09:00 committed by Xiang Xiao
parent 7409f57d40
commit 1a3f59be58

View File

@ -41,7 +41,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/statfs.h> #include <sys/statvfs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <dirent.h> #include <dirent.h>
@ -168,10 +168,12 @@ int host_open(const char *pathname, int flags, int mode)
mapflags |= O_SYNC; mapflags |= O_SYNC;
} }
#ifdef O_DIRECT
if (flags & NUTTX_O_DIRECT) if (flags & NUTTX_O_DIRECT)
{ {
mapflags |= O_DIRECT; mapflags |= O_DIRECT;
} }
#endif
return open(pathname, mapflags, mode); return open(pathname, mapflags, mode);
} }
@ -377,16 +379,16 @@ int host_closedir(void *dirp)
int host_statfs(const char *path, struct nuttx_statfs_s *buf) int host_statfs(const char *path, struct nuttx_statfs_s *buf)
{ {
int ret; int ret;
struct statfs hostbuf; struct statvfs hostbuf;
/* Call the host's statfs routine */ /* Call the host's statfs routine */
ret = statfs(path, &hostbuf); ret = statvfs(path, &hostbuf);
/* Map the struct statfs value */ /* Map the struct statfs value */
buf->f_type = hostbuf.f_type; buf->f_type = 0; /* hostfs overwrites f_type anyway */
buf->f_namelen = hostbuf.f_namelen; buf->f_namelen = hostbuf.f_namemax;
buf->f_bsize = hostbuf.f_bsize; buf->f_bsize = hostbuf.f_bsize;
buf->f_blocks = hostbuf.f_blocks; buf->f_blocks = hostbuf.f_blocks;
buf->f_bfree = hostbuf.f_bfree; buf->f_bfree = hostbuf.f_bfree;