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/11 02:37:12 UTC

[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8075: Minor fs/mmap improvement

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


##########
fs/mmap/fs_mmap.c:
##########
@@ -128,45 +105,48 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
       return map_anonymous(&entry, kernel);
     }
 
-  if ((flags & MAP_PRIVATE) != 0)
+  if (filep == NULL)
     {
-#ifdef CONFIG_FS_RAMMAP
-      /* Allocate memory and copy the file into memory.  We would, of course,
-       * do much better in the KERNEL build using the MMU.
-       */
+      return -EBADF;
+    }
 
-      return rammap(filep, &entry, kernel);
-#endif
+  if ((filep->f_oflags & O_WROK) == 0 && prot == PROT_WRITE)
+    {
+      ferr("ERROR: Unsupported options for read-only file descriptor,"
+           "prot=%x flags=%04x\n", prot, flags);
+      return -EACCES;
+    }
+
+  if ((filep->f_oflags & O_RDOK) == 0)
+    {
+      ferr("ERROR: File descriptor does not have read permission\n");
+      return -EACCES;
     }
 
   /* Call driver's mmap to get the base address of the file in 'mapped'
    * in memory.
    */
 
-  if (filep->f_inode && filep->f_inode->u.i_ops->mmap != NULL)
+  if ((flags & MAP_PRIVATE) == 0 && filep->f_inode &&
+      filep->f_inode->u.i_ops->mmap != NULL)
     {
       ret = filep->f_inode->u.i_ops->mmap(filep, &entry);
       if (ret == OK)
         {
-          *mapped = (void *)entry.vaddr;
+          *mapped = entry.vaddr;
         }
     }
   else
     {
-      /* Not directly mappable, probably because the underlying media does
-       * not support random access.
+      /* Caller request the privated mapping. Or not directly mappable,

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