xiaoxiang781216 commented on code in PR #8000:
URL: https://github.com/apache/nuttx/pull/8000#discussion_r1059666337


##########
include/nuttx/fs/fs.h:
##########
@@ -206,16 +207,21 @@ struct file_operations
    * treated like unions.
    */
 
-  int     (*close)(FAR struct file *filep);
-  ssize_t (*read)(FAR struct file *filep, FAR char *buffer, size_t buflen);
-  ssize_t (*write)(FAR struct file *filep, FAR const char *buffer,
-                   size_t buflen);
-  off_t   (*seek)(FAR struct file *filep, off_t offset, int whence);
-  int     (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
+  int      (*close)(FAR struct file *filep);
+  ssize_t  (*read)(FAR struct file *filep, FAR char *buffer, size_t buflen);
+  ssize_t  (*write)(FAR struct file *filep, FAR const char *buffer,
+                    size_t buflen);
+  off_t    (*seek)(FAR struct file *filep, off_t offset, int whence);
+  int      (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
+  int      (*truncate)(FAR struct file *filep, off_t length);
+  FAR void *(*mmap)(FAR struct file *filep, off_t start, size_t length);
+  int      (*munmap)(FAR struct task_group_s *group, FAR struct inode *inode,

Review Comment:
   The current design of mmap callback can't return a private pointer, which 
make the driver is hard to do the dynamic mapping. So, it may better to:
   ```
   struct mm_map_s
   {
    struct list_node node;
     FAR void *priv;
     FAR void *start;
     off_t offset;
     size_t length;
     int prot; /* the last two fields are optional */
     int flags;
   };
   
   FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
                  int fd, off_t offset)
   {
     ....
     map->start = start;
     map->offset = offset;
     map->length = length;
     map->prot = prot;
     map->flags = flags;
   
     ret = file->mmap(&map);
     return map->start;
   }
   ```
    Caller may set prefer address in start field, but callback make the 
decision and return the final result. The same map can pass to unmap.



-- 
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-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to