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 2023/01/03 22:37:07 UTC

[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #8000: Change FIOC_MMAP, FIOC_MUNMAP and FIOC_TRUNCATE into file operation c…

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


##########
fs/mmap/fs_mmap.c:
##########
@@ -135,14 +135,33 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
 #endif
     }
 
-  /* Perform the ioctl to get the base address of the file in 'mapped'
-   * in memory. (casting to uintptr_t first eliminates complaints on some
-   * architectures where the sizeof long is different from the size of
-   * a pointer).
+  /* Call driver's mmap to get the base address of the file in 'mapped'
+   * in memory.
    */
 
-  ret = file_ioctl(filep, FIOC_MMAP, (unsigned long)((uintptr_t)&addr));
-  if (ret < 0)
+  if (filep->f_inode && filep->f_inode->u.i_ops->mmap != NULL)
+    {
+      /* Pass the information about the mapping in mm_map_entry_s structure.
+       * The driver may alter the structure, and if it supports unmap, it
+       * will also add it to the kernel maintained list of mappings.
+       */
+
+      struct mm_map_entry_s map =
+        {
+         NULL, /* sq_entry_t */
+         start, length, offset,
+         prot, flags,
+         NULL, /* priv */
+         NULL  /* munmap */

Review Comment:
   Need to fix indentations and place 1 init per line



##########
fs/mmap/fs_mmap.c:
##########
@@ -135,14 +135,33 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
 #endif
     }
 
-  /* Perform the ioctl to get the base address of the file in 'mapped'
-   * in memory. (casting to uintptr_t first eliminates complaints on some
-   * architectures where the sizeof long is different from the size of
-   * a pointer).
+  /* Call driver's mmap to get the base address of the file in 'mapped'
+   * in memory.
    */
 
-  ret = file_ioctl(filep, FIOC_MMAP, (unsigned long)((uintptr_t)&addr));
-  if (ret < 0)
+  if (filep->f_inode && filep->f_inode->u.i_ops->mmap != NULL)
+    {
+      /* Pass the information about the mapping in mm_map_entry_s structure.
+       * The driver may alter the structure, and if it supports unmap, it
+       * will also add it to the kernel maintained list of mappings.
+       */
+
+      struct mm_map_entry_s map =
+        {
+         NULL, /* sq_entry_t */
+         start, length, offset,
+         prot, flags,
+         NULL, /* priv */
+         NULL  /* munmap */
+        };
+
+      ret = filep->f_inode->u.i_ops->mmap(filep, &map);
+      if (ret == OK)
+        {
+          *mapped = (void *)map.vaddr;

Review Comment:
   Add `FAR` to `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