LingaoM commented on code in PR #19456:
URL: https://github.com/apache/nuttx/pull/19456#discussion_r3620140935


##########
fs/hostfs/hostfs.c:
##########
@@ -609,6 +609,29 @@ static int hostfs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
       return ret;
     }
 
+  /* POSIX file locks reach filesystems as private FIOC_* commands after
+   * fcntl() handling in VFS.  Backends that can forward non-blocking lock
+   * commands to the host may implement host_fcntl().  Other backends return
+   * -ENOTTY so VFS falls back to NuttX internal file locks.  Do not forward
+   * F_SETLKW because a blocking host fcntl() can stop the whole sim OS.
+   */
+
+  if (cmd == FIOC_GETLK)
+    {
+      ret = host_fcntl(hf->fd, F_GETLK, (FAR struct flock *)(uintptr_t)arg);
+      goto out;
+    }
+  else if (cmd == FIOC_SETLK)
+    {
+      ret = host_fcntl(hf->fd, F_SETLK, (FAR struct flock *)(uintptr_t)arg);
+      goto out;
+    }
+  else if (cmd == FIOC_SETLKW)
+    {
+      ret = -ENOTTY;

Review Comment:
   Done.



##########
arch/sim/src/sim/posix/sim_hostusrsock.c:
##########
@@ -92,26 +94,93 @@ static void host_usrsock_set_fd(int fd, fd_set *fds)
     }
 }
 
-static void sockaddr_to_native(const struct nuttx_sockaddr *addr,
-                               const nuttx_socklen_t addrlen,
-                               struct sockaddr *naddr,
-                               socklen_t *naddrlen)
+static int sockaddr_to_native(const struct nuttx_sockaddr *addr,
+                              const nuttx_socklen_t addrlen,
+                              struct sockaddr_storage *naddr,
+                              socklen_t *naddrlen)
 {
-  naddr->sa_family = addr->sa_family;
-  memcpy(naddr->sa_data, addr->sa_data, sizeof(naddr->sa_data));
+  if (addr == NULL || naddr == NULL || naddrlen == NULL)
+    {
+      return -EINVAL;
+    }
+
+  memset(naddr, 0, sizeof(*naddr));
+
+  if (addr->sa_family == NUTTX_AF_LOCAL)
+    {
+      const struct nuttx_sockaddr_un *un =
+        (const struct nuttx_sockaddr_un *)addr;
+      struct sockaddr_un *native = (struct sockaddr_un *)naddr;
+      size_t pathlen;
 
+      if (addrlen < offsetof(struct nuttx_sockaddr_un, sun_path) + 1)
+        {
+          return -EINVAL;
+        }
+
+      pathlen = strnlen(un->sun_path, sizeof(un->sun_path));
+      if (pathlen >= sizeof(native->sun_path))
+        {
+          return -ENAMETOOLONG;
+        }
+
+      native->sun_family = AF_UNIX;
+      memcpy(native->sun_path, un->sun_path, pathlen + 1);
+      *naddrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1;
+
+      return 0;
+    }
+
+  if (addrlen > sizeof(*naddr))
+    {
+      return -ENOSPC;
+    }
+
+  memcpy(naddr, addr, addrlen);
   *naddrlen = addrlen;
+
+  return 0;
 }
 
-static void sockaddr_to_nuttx(const struct sockaddr *naddr,
-                              const socklen_t naddrlen,
-                              struct nuttx_sockaddr *addr,
-                              nuttx_socklen_t *addrlen)
+static int sockaddr_to_nuttx(const struct sockaddr *naddr,

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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to