-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Change FIOC_MMAP, FIOC_MUNMAP and FIOC_TRUNCATE into file operation c… #8000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change FIOC_MMAP, FIOC_MUNMAP and FIOC_TRUNCATE into file operation c… #8000
Conversation
f0fe4c0 to
37682c0
Compare
|
Will gradually fix any issues in CI for this PR, lets review when it passes |
8821e1b to
e459aed
Compare
|
I think all drivers are now fixed for the changed struct definition. @xiaoxiang781216, this is the change I proposed on the nuttx-dev list. |
|
Sure, I will review in the weekend, thanks to provide a general solution. |
a67fc33 to
8933509
Compare
|
forgot to revert changes to fs_rammap.* , that is now back to the original. |
8933509 to
2b08741
Compare
|
rebased agains current master |
|
@jlaitine many drivers don't need change if all callbacks after ioctl are NULL. |
|
Here I must disagree. You definitely need to change these, since they currently look like this: Not changing it would leave misleading comments (/* poll / is not the pointer to poll, / unlink */ is not a pointer to unlink etc.). There are really just two options:
I do the 2) because this preserves the current style |
2b08741 to
30e5980
Compare
Yes, that's why I prepare this patch: #8016 to remove the trailing NULL pointer. |
30e5980 to
8451b50
Compare
- Add truncate into file_operations - Move truncate to be common for mountpt_operations and file_operations - Modify all drivers to initialize the operations struct accordingly Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
0da2f4d to
7026cc6
Compare
9ce80ba to
163fafc
Compare
- Add mmap into file_operations and remove it from ioctl definitions. - Add mm_map structure definitions to support future unmapping - Modify all drivers to initialize the operations struct accordingly Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
163fafc to
2868628
Compare
| FAR video_mng_t *priv = (FAR video_mng_t *)inode->i_private; | ||
| int ret = -EINVAL; | ||
|
|
||
| if (map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add after get_bufsize:
static size_t get_heapsize(FAR video_type_inf_t *type_inf)
{
return type_inf->bufinf.container_size *
get_bufsize(&type_inf->fmt[VIDEO_FMT_MAIN]);
}
and do more check here:
if (map->offset >= 0 && map->offset < get_heapsize(&priv->video_inf) &&
map->offset + map->length <= get_heapsize(&priv->video_inf))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @xiaoxiang781216, I think you add it while I was hitting the merge button!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create a patch fix the remain issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the patch: #8021
| ret = filep->f_inode->u.i_ops->mmap(filep, &map); | ||
| if (ret == OK) | ||
| { | ||
| *mapped = (void *)map.vaddr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add FAR to void *
| NULL, /* sq_entry_t */ | ||
| start, length, offset, | ||
| prot, flags, | ||
| NULL, /* priv */ | ||
| NULL /* munmap */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix indentations and place 1 init per line
…alls
Add truncate, mmap and munmap into file_operations and remove them from ioctl definitions.
Move truncate to be common for mountpt_operations and file_operations
Modify all drivers to initialize the operations struct accordingly
Signed-off-by: Jukka Laitinen jukkax@ssrc.tii.ae
Summary
IOCTLs are ment for communication from userspace application to the drivers. It doesn't make sense for an application to perform a direct IOCTL (such as FIOC_MMAP, FIOC_MUNMAP or FIOC_TRUNCATE). Application should always use posix mmap, munmap and truncate calls instead.
For mmap, munmap and truncate there is a syscall lookup already in place in nuttx - there is no ioctl needed for the userspace-kernel communication
Especially for "unmap", the ioctl doesn't make sense, since file_ioctl is supposed to work on a file pointer. But unmap cannot be done on a file. Even when unmapping a previously mapped "file", unmap can only work on inode, since there may not be an open file, or even a linked inode present. It must be possible to do "munmap" for a mapped file, even if the actual file is closed and/or deleted after mapping.
Impact
Cleanup of the interfaces, doesn't change the current functionality but makes it easier to add new
Testing
Inspected only.