You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/12/12 15:35:40 UTC
[GitHub] [nuttx] anchao opened a new pull request, #7855: sim/windows: add hostfs support for windows
anchao opened a new pull request, #7855:
URL: https://github.com/apache/nuttx/pull/7855
## Summary
sim/windows: add hostfs support for windows
fs/hostfs: mode_t of mkdir(2) should use the nuttx prototype
## Impact
N/A
## Testing
cmake + visual studio 2022


--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] anchao commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1046794818
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
Review Comment:
Done
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
Review Comment:
Done
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1047965134
##########
arch/xtensa/src/common/xtensa_hostfs.c:
##########
@@ -204,7 +204,7 @@ int host_unlink(const char *pathname)
return -ENOSYS;
}
-int host_mkdir(const char *pathname, mode_t mode)
+int host_mkdir(const char *pathname, int mode)
Review Comment:
hostfs implementation on other platforms can reference nuttx header files directly without conflict, but sim can't do the same thing because there is huge conflict between host's libc and nuttx's. Please check the code guarded by `__SIM__` macro in include/nuttx/fs/hostfs.h.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1047644661
##########
arch/xtensa/src/common/xtensa_hostfs.c:
##########
@@ -204,7 +204,7 @@ int host_unlink(const char *pathname)
return -ENOSYS;
}
-int host_mkdir(const char *pathname, mode_t mode)
+int host_mkdir(const char *pathname, int mode)
Review Comment:
why `int` here and not `nuttx_mode_t`?
##########
arch/risc-v/src/common/riscv_hostfs.c:
##########
@@ -297,7 +297,7 @@ int host_unlink(const char *pathname)
return host_call(HOST_REMOVE, &remove, sizeof(remove));
}
-int host_mkdir(const char *pathname, mode_t mode)
+int host_mkdir(const char *pathname, int mode)
Review Comment:
why `int` and not `nuttx_mode_t`?
##########
arch/arm/src/common/arm_hostfs.c:
##########
@@ -297,7 +297,7 @@ int host_unlink(const char *pathname)
return host_call(HOST_REMOVE, &remove, sizeof(remove));
}
-int host_mkdir(const char *pathname, mode_t mode)
+int host_mkdir(const char *pathname, int mode)
Review Comment:
why `int` here and not `nuttx_mode_t`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1046757129
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
Review Comment:
should we return errno when fail?
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
Review Comment:
FALSE
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
+ }
+
+ strncpy(entry->d_name, FileData.cFileName,
+ sizeof(entry->d_name) - 1);
+
+ if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ entry->d_type = NUTTX_DTYPE_DIRECTORY;
+ }
+ else
+ {
+ entry->d_type = NUTTX_DTYPE_FILE;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: host_rewinddir
+ ****************************************************************************/
+
+void host_rewinddir(void *dirp)
+{
+}
+
+/****************************************************************************
+ * Name: host_closedir
+ ****************************************************************************/
+
+int host_closedir(void *dirp)
+{
+ if (FindClose(dirp))
+ {
+ return 0;
+ }
+
+ return -EBADF;
+}
+
+/****************************************************************************
+ * Name: host_statfs
+ ****************************************************************************/
+
+int host_statfs(const char *path, struct nuttx_statfs_s *buf)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_unlink
+ ****************************************************************************/
+
+int host_unlink(const char *pathname)
+{
+ int ret = _unlink(pathname);
+ if (ret < 0)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_mkdir
+ ****************************************************************************/
+
+int host_mkdir(const char *pathname, nuttx_mode_t mode)
+{
+ /* Just call the host's mkdir routine */
+
+ int ret = _mkdir(pathname, mode);
+ if (ret < 0)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_rmdir
+ ****************************************************************************/
+
+int host_rmdir(const char *pathname)
+{
+ int ret = _rmdir(pathname);
+ if (ret < 0)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_rename
+ ****************************************************************************/
+
+int host_rename(const char *oldpath, const char *newpath)
+{
+ if (MoveFile(oldpath, newpath))
+ {
+ return 0;
+ }
+
+ return -EINVAL;
Review Comment:
return HRESULT_FROM_WIN32(GetLastError());
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
Review Comment:
move int ret to the begin?
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
Review Comment:
return GetLastError() == ERROR_NO_MORE_FILES ? -ENOENT : HRESULT_FROM_WIN32(GetLastError());
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
+ }
+
+ strncpy(entry->d_name, FileData.cFileName,
+ sizeof(entry->d_name) - 1);
+
+ if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ entry->d_type = NUTTX_DTYPE_DIRECTORY;
+ }
+ else
+ {
+ entry->d_type = NUTTX_DTYPE_FILE;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: host_rewinddir
+ ****************************************************************************/
+
+void host_rewinddir(void *dirp)
+{
+}
+
+/****************************************************************************
+ * Name: host_closedir
+ ****************************************************************************/
+
+int host_closedir(void *dirp)
+{
+ if (FindClose(dirp))
+ {
+ return 0;
+ }
+
+ return -EBADF;
Review Comment:
return HRESULT_FROM_WIN32(GetLastError());
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#issuecomment-1347665574
Please rebase to the last mater to fix ci broken.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] anchao commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1046794671
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
Review Comment:
Done
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
+ }
+
+ strncpy(entry->d_name, FileData.cFileName,
+ sizeof(entry->d_name) - 1);
+
+ if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ entry->d_type = NUTTX_DTYPE_DIRECTORY;
+ }
+ else
+ {
+ entry->d_type = NUTTX_DTYPE_FILE;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: host_rewinddir
+ ****************************************************************************/
+
+void host_rewinddir(void *dirp)
+{
+}
+
+/****************************************************************************
+ * Name: host_closedir
+ ****************************************************************************/
+
+int host_closedir(void *dirp)
+{
+ if (FindClose(dirp))
+ {
+ return 0;
+ }
+
+ return -EBADF;
+}
+
+/****************************************************************************
+ * Name: host_statfs
+ ****************************************************************************/
+
+int host_statfs(const char *path, struct nuttx_statfs_s *buf)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_unlink
+ ****************************************************************************/
+
+int host_unlink(const char *pathname)
+{
+ int ret = _unlink(pathname);
+ if (ret < 0)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_mkdir
+ ****************************************************************************/
+
+int host_mkdir(const char *pathname, nuttx_mode_t mode)
+{
+ /* Just call the host's mkdir routine */
+
+ int ret = _mkdir(pathname, mode);
+ if (ret < 0)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_rmdir
+ ****************************************************************************/
+
+int host_rmdir(const char *pathname)
+{
+ int ret = _rmdir(pathname);
+ if (ret < 0)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_rename
+ ****************************************************************************/
+
+int host_rename(const char *oldpath, const char *newpath)
+{
+ if (MoveFile(oldpath, newpath))
+ {
+ return 0;
+ }
+
+ return -EINVAL;
Review Comment:
Done
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,432 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s/*", name);
+
+ return FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
+ }
+
+ strncpy(entry->d_name, FileData.cFileName,
+ sizeof(entry->d_name) - 1);
+
+ if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ entry->d_type = NUTTX_DTYPE_DIRECTORY;
+ }
+ else
+ {
+ entry->d_type = NUTTX_DTYPE_FILE;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: host_rewinddir
+ ****************************************************************************/
+
+void host_rewinddir(void *dirp)
+{
+}
+
+/****************************************************************************
+ * Name: host_closedir
+ ****************************************************************************/
+
+int host_closedir(void *dirp)
+{
+ if (FindClose(dirp))
+ {
+ return 0;
+ }
+
+ return -EBADF;
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1047965134
##########
arch/xtensa/src/common/xtensa_hostfs.c:
##########
@@ -204,7 +204,7 @@ int host_unlink(const char *pathname)
return -ENOSYS;
}
-int host_mkdir(const char *pathname, mode_t mode)
+int host_mkdir(const char *pathname, int mode)
Review Comment:
hostfs implementation on other platforms can reference nuttx header files directly without conflict, but sim can't do the same thing because there is huge conflict between host's libc and nuttx's. Please check the code guarded by __SIM__ macro in include/nuttx/fs/hostfs.h.
##########
arch/xtensa/src/common/xtensa_hostfs.c:
##########
@@ -204,7 +204,7 @@ int host_unlink(const char *pathname)
return -ENOSYS;
}
-int host_mkdir(const char *pathname, mode_t mode)
+int host_mkdir(const char *pathname, int mode)
Review Comment:
hostfs implementation on other platforms can reference nuttx header files directly without conflict, but sim can't do the same thing because there is huge conflict between host's libc and nuttx's. Please check the code guarded by __SIM__ macro in include/nuttx/fs/hostfs.h.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#issuecomment-1348130735
Let's ignore macOS ci broken which is fixed here: https://github.com/apache/nuttx/pull/7864.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] anchao commented on pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
anchao commented on PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#issuecomment-1346737240
Please ignore the ci warning since the api name of MSVC vcruntime is implemented in mixed case
```
arch/sim/src/sim/win/sim_hostfs.c:277:17: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:286:18: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:289:8: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:289:28: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:295:25: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:295:34: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:298:6: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:298:15: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:324:12: error: Mixed case identifier found
arch/sim/src/sim/win/sim_hostfs.c:395:6: error: Mixed case identifier found
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] anchao commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
anchao commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1046072135
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,433 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s//*", name);
+
+ return (void *)FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
+ }
+
+ strncpy(entry->d_name, FileData.cFileName,
+ sizeof(entry->d_name) - 1);
+
+ if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ entry->d_type = NUTTX_DTYPE_DIRECTORY;
+ }
+ else
+ {
+ entry->d_type = NUTTX_DTYPE_FILE;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: host_rewinddir
+ ****************************************************************************/
+
+void host_rewinddir(void *dirp)
+{
+}
+
+/****************************************************************************
+ * Name: host_closedir
+ ****************************************************************************/
+
+int host_closedir(void *dirp)
+{
+ int ret = FindClose(dirp);
Review Comment:
Done
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,433 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s//*", name);
+
+ return (void *)FindFirstFile(namebuf, &data);
Review Comment:
Done
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,433 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s//*", name);
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7855:
URL: https://github.com/apache/nuttx/pull/7855#discussion_r1046016522
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,433 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s//*", name);
+
+ return (void *)FindFirstFile(namebuf, &data);
+}
+
+/****************************************************************************
+ * Name: host_readdir
+ ****************************************************************************/
+
+int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
+{
+ WIN32_FIND_DATA FileData;
+ BOOL ret;
+
+ ret = FindNextFile(dirp, &FileData);
+ if (ret == 0)
+ {
+ return -ENOENT;
+ }
+
+ strncpy(entry->d_name, FileData.cFileName,
+ sizeof(entry->d_name) - 1);
+
+ if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ entry->d_type = NUTTX_DTYPE_DIRECTORY;
+ }
+ else
+ {
+ entry->d_type = NUTTX_DTYPE_FILE;
+ }
+
+ return 0;
+}
+
+/****************************************************************************
+ * Name: host_rewinddir
+ ****************************************************************************/
+
+void host_rewinddir(void *dirp)
+{
+}
+
+/****************************************************************************
+ * Name: host_closedir
+ ****************************************************************************/
+
+int host_closedir(void *dirp)
+{
+ int ret = FindClose(dirp);
Review Comment:
FindClose return bool value
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,433 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s//*", name);
Review Comment:
//->/
##########
arch/sim/src/sim/win/sim_hostfs.c:
##########
@@ -0,0 +1,433 @@
+/****************************************************************************
+ * arch/sim/src/sim/win/sim_hostfs.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <io.h>
+#include <windows.h>
+
+#include "hostfs.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_stat_convert
+ ****************************************************************************/
+
+static void host_stat_convert(struct _stat *hostbuf,
+ struct nuttx_stat_s *buf)
+{
+ /* Map the return values */
+
+ buf->st_mode = hostbuf->st_mode & 07777;
+
+ if (hostbuf->st_mode & _S_IFDIR)
+ {
+ buf->st_mode |= NUTTX_S_IFDIR;
+ }
+ else if (hostbuf->st_mode & _S_IFREG)
+ {
+ buf->st_mode |= NUTTX_S_IFREG;
+ }
+ else if (hostbuf->st_mode & _S_IFCHR)
+ {
+ buf->st_mode |= NUTTX_S_IFCHR;
+ }
+
+ buf->st_dev = hostbuf->st_dev;
+ buf->st_ino = hostbuf->st_ino;
+ buf->st_nlink = hostbuf->st_nlink;
+ buf->st_uid = hostbuf->st_uid;
+ buf->st_gid = hostbuf->st_gid;
+ buf->st_rdev = hostbuf->st_rdev;
+ buf->st_size = hostbuf->st_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: host_open
+ ****************************************************************************/
+
+int host_open(const char *pathname, int flags, nuttx_mode_t mode)
+{
+ int mapflags = 0;
+
+ /* Perform flag mapping */
+
+ if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR)
+ {
+ mapflags = O_RDWR;
+ }
+ else if (flags & NUTTX_O_RDONLY)
+ {
+ mapflags = O_RDONLY;
+ }
+ else if (flags & NUTTX_O_WRONLY)
+ {
+ mapflags = O_WRONLY;
+ }
+
+ if (flags & NUTTX_O_APPEND)
+ {
+ mapflags |= O_APPEND;
+ }
+
+ if (flags & NUTTX_O_CREAT)
+ {
+ mapflags |= O_CREAT;
+ }
+
+ if (flags & NUTTX_O_EXCL)
+ {
+ mapflags |= O_EXCL;
+ }
+
+ if (flags & NUTTX_O_TRUNC)
+ {
+ mapflags |= O_TRUNC;
+ }
+
+ int ret = _open(pathname, mapflags, mode);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_close
+ ****************************************************************************/
+
+int host_close(int fd)
+{
+ /* Just call the close routine */
+
+ int ret = _close(fd);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_read
+ ****************************************************************************/
+
+nuttx_ssize_t host_read(int fd, void *buf, nuttx_size_t count)
+{
+ /* Just call the read routine */
+
+ nuttx_ssize_t ret = _read(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_write
+ ****************************************************************************/
+
+nuttx_ssize_t host_write(int fd, const void *buf, nuttx_size_t count)
+{
+ /* Just call the write routine */
+
+ nuttx_ssize_t ret = _write(fd, buf, count);
+ if (ret == -1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_lseek
+ ****************************************************************************/
+
+nuttx_off_t host_lseek(int fd, nuttx_off_t offset, int whence)
+{
+ /* Just call the lseek routine */
+
+ nuttx_off_t ret = _lseek(fd, offset, whence);
+ if (ret == (nuttx_off_t)-1)
+ {
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_ioctl
+ ****************************************************************************/
+
+int host_ioctl(int fd, int request, unsigned long arg)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_sync
+ ****************************************************************************/
+
+void host_sync(int fd)
+{
+}
+
+/****************************************************************************
+ * Name: host_dup
+ ****************************************************************************/
+
+int host_dup(int fd)
+{
+ return _dup(fd);
+}
+
+/****************************************************************************
+ * Name: host_fstat
+ ****************************************************************************/
+
+int host_fstat(int fd, struct nuttx_stat_s *buf)
+{
+ struct _stat hostbuf;
+ int ret;
+
+ /* Call the host's stat routine */
+
+ ret = _fstat(fd, &hostbuf);
+ if (ret < 0)
+ {
+ return -errno;
+ }
+
+ /* Map the return values */
+
+ host_stat_convert(&hostbuf, buf);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: host_fchstat
+ ****************************************************************************/
+
+int host_fchstat(int fd, const struct nuttx_stat_s *buf, int flags)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_truncate
+ ****************************************************************************/
+
+int host_ftruncate(int fd, nuttx_off_t length)
+{
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Name: host_opendir
+ ****************************************************************************/
+
+void *host_opendir(const char *name)
+{
+ char namebuf[CONFIG_PATH_MAX + 4];
+ WIN32_FIND_DATA data;
+
+ snprintf(namebuf, sizeof(namebuf), "%s//*", name);
+
+ return (void *)FindFirstFile(namebuf, &data);
Review Comment:
remove (void *)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 merged pull request #7855: sim/windows: add hostfs support for windows
Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7855:
URL: https://github.com/apache/nuttx/pull/7855
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org