This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 29de982ed4f6b5a5f38af232eed2740dac72c1d8
Author: yintao <[email protected]>
AuthorDate: Thu Nov 7 23:01:15 2024 +0800

    fs/rpmsgfs: let the client pass a file offset with read and write
    
    The server reads and writes at the position of its own file, so a
    client has to keep that position in step with lseek. A client that
    tracks the position itself, as the Linux rpmsgfs client does, has no
    way to say where a read or write should happen.
    
    Add an offset to the read and write messages. The server seeks to it
    before the transfer when it is not negative; the NuttX client sends -1
    and keeps using the server's position. This changes the message layout,
    so both sides of a link must run the same version.
    
    Signed-off-by: yintao <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 fs/rpmsgfs/rpmsgfs.h        | 2 ++
 fs/rpmsgfs/rpmsgfs_client.c | 2 ++
 fs/rpmsgfs/rpmsgfs_server.c | 9 +++++++++
 3 files changed, 13 insertions(+)

diff --git a/fs/rpmsgfs/rpmsgfs.h b/fs/rpmsgfs/rpmsgfs.h
index f285e219985..9ac9ff77760 100644
--- a/fs/rpmsgfs/rpmsgfs.h
+++ b/fs/rpmsgfs/rpmsgfs.h
@@ -28,6 +28,7 @@
  ****************************************************************************/
 
 #include <dirent.h>
+#include <stdint.h>
 #include <sys/stat.h>
 #include <sys/statfs.h>
 #include <sys/param.h>
@@ -96,6 +97,7 @@ begin_packed_struct struct rpmsgfs_read_s
   struct rpmsgfs_header_s header;
   int32_t                 fd;
   uint32_t                count;
+  int64_t                 offset;
   char                    buf[0];
 } end_packed_struct;
 
diff --git a/fs/rpmsgfs/rpmsgfs_client.c b/fs/rpmsgfs/rpmsgfs_client.c
index bf6f43f4924..508edebee6b 100644
--- a/fs/rpmsgfs/rpmsgfs_client.c
+++ b/fs/rpmsgfs/rpmsgfs_client.c
@@ -551,6 +551,7 @@ ssize_t rpmsgfs_client_read(FAR void *handle, int fd,
   msg.header.cookie  = (uintptr_t)&cookie;
   msg.fd             = fd;
   msg.count          = count;
+  msg.offset         = -1;
 
   ret = rpmsg_send(&priv->ept, &msg, sizeof(msg));
   if (ret < 0)
@@ -614,6 +615,7 @@ ssize_t rpmsgfs_client_write(FAR void *handle, int fd,
       msg->header.result  = -ENXIO;
       msg->fd             = fd;
       msg->count          = space;
+      msg->offset         = -1;
       memcpy(msg->buf, buf + written, space);
 
       ret = rpmsg_send_nocopy(&priv->ept, msg, sizeof(*msg) + space);
diff --git a/fs/rpmsgfs/rpmsgfs_server.c b/fs/rpmsgfs/rpmsgfs_server.c
index c2f1a6bea93..26a68e974ed 100644
--- a/fs/rpmsgfs/rpmsgfs_server.c
+++ b/fs/rpmsgfs/rpmsgfs_server.c
@@ -443,6 +443,10 @@ static int rpmsgfs_read_handler(FAR struct rpmsg_endpoint 
*ept,
   uint32_t space;
 
   filep = rpmsgfs_get_file(priv, msg->fd);
+  if (filep != NULL && msg->offset >= 0)
+    {
+      file_seek(filep, msg->offset, SEEK_SET);
+    }
 
   while (read < msg->count)
     {
@@ -496,6 +500,11 @@ static int rpmsgfs_write_handler(FAR struct rpmsg_endpoint 
*ept,
     {
       size_t written = 0;
 
+      if (msg->offset >= 0)
+        {
+          file_seek(filep, msg->offset, SEEK_SET);
+        }
+
       while (written < msg->count)
         {
           ret = file_write(filep, msg->buf + written, msg->count - written);

Reply via email to