fs/mmap: Remove the duplication rammap handling

and minor ifx for style and format

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-01-11 00:48:45 +08:00 committed by Petro Karashchenko
parent 120594079a
commit ab67d6a75b
3 changed files with 18 additions and 42 deletions

View File

@ -85,15 +85,6 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
return -ENOSYS;
}
#ifndef CONFIG_FS_RAMMAP
if ((flags & MAP_PRIVATE) != 0)
{
ferr("ERROR: MAP_PRIVATE is not supported without file mapping"
"emulation\n");
return -ENOSYS;
}
#endif /* CONFIG_FS_RAMMAP */
/* A length of 0 is invalid. */
if (length == 0)
@ -103,8 +94,7 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
}
#endif /* CONFIG_DEBUG_FEATURES */
if ((filep->f_oflags & O_WROK) == 0 && prot == PROT_WRITE &&
(flags & MAP_SHARED) != 0)
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);
@ -128,45 +118,30 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
return map_anonymous(&entry, kernel);
}
if ((flags & MAP_PRIVATE) != 0)
{
#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 rammap(filep, &entry, kernel);
#endif
}
/* 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 private mapping. Or not directly mappable,
* probably because the underlying media doesn't support random access.
*/
#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 rammap(filep, &entry, kernel);
#else
ferr("ERROR: mmap not supported \n");
return -ENOSYS;
#endif
}
/* Return */

View File

@ -51,9 +51,9 @@ static int unmap_rammap(FAR struct task_group_s *group,
size_t length)
{
FAR void *newaddr;
unsigned int offset;
bool kernel = entry->priv.i != 0 ? true : false;
int ret;
off_t offset;
bool kernel = entry->priv.i;
int ret = OK;
/* Get the offset from the beginning of the region and the actual number
* of bytes to "unmap". All mappings must extend to the end of the region.
@ -111,9 +111,8 @@ static int unmap_rammap(FAR struct task_group_s *group,
}
DEBUGASSERT(newaddr == entry->vaddr);
UNUSED(newaddr); /* May not be used */
entry->vaddr = newaddr;
entry->length = length;
ret = OK;
}
return ret;
@ -176,7 +175,7 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
rdbuffer = kernel ? kmm_malloc(length) : kumm_malloc(length);
if (!rdbuffer)
{
ferr("ERROR: Region allocation failed, length: %d\n", (int)length);
ferr("ERROR: Region allocation failed, length: %zu\n", length);
return -ENOMEM;
}
@ -189,7 +188,7 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
* the correct response.
*/
ferr("ERROR: Seek to position %d failed\n", (int)entry->offset);
ferr("ERROR: Seek to position %zu failed\n", (size_t)entry->offset);
ret = fpos;
goto errout_with_region;
}
@ -209,8 +208,8 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
{
/* All other read errors are bad. */
ferr("ERROR: Read failed: offset=%d ret=%d\n",
(int)entry->offset, (int)nread);
ferr("ERROR: Read failed: offset=%zu ret=%zd\n",
(size_t)entry->offset, nread);
ret = nread;
goto errout_with_region;
@ -237,7 +236,7 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
/* Add the buffer to the list of regions */
entry->vaddr = rdbuffer;
entry->priv.i = kernel ? 1 : 0;
entry->priv.i = kernel;
entry->munmap = unmap_rammap;
ret = mm_map_add(entry);

View File

@ -89,6 +89,8 @@
int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry,
bool kernel);
#else
# define rammap(file, entry, kernel) (-ENOSYS)
#endif /* CONFIG_FS_RAMMAP */
#endif /* __FS_MMAP_FS_RAMMAP_H */