kernel/fs: Handle O_RDONLY | O_TRUNC in the VFS rather than filesystems.
The POSIX specification says that the behavior of specifying O_TRUNC with O_RDONLY is "undefined", but the Linux manpages ominously state "On many systems the file is actually truncated." I tested this, and indeed on Linux the file is actually truncated. This doesn't seem like a very sensible behavior, so in this commit it's changed to return B_NOT_ALLOWED (EPERM) if those flags are specified together. The FAT driver already did this, but most other filesystem drivers just checked write access permissions and truncated the file anyway; so this is indeed a behavioral change. Change-Id: If2e76782743ee91d934dc7e0c2f306f37b159a0f Reviewed-on: https://review.haiku-os.org/c/haiku/+/8625 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]> Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
5941862c92
commit
4a87c95e0a
@@ -1368,8 +1368,7 @@ bfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
|
||||
if ((openMode & O_DIRECTORY) != 0 && !inode->IsDirectory())
|
||||
return B_NOT_A_DIRECTORY;
|
||||
|
||||
status_t status = inode->CheckPermissions(open_mode_to_access(openMode)
|
||||
| ((openMode & O_TRUNC) != 0 ? W_OK : 0));
|
||||
status_t status = inode->CheckPermissions(open_mode_to_access(openMode));
|
||||
if (status != B_OK)
|
||||
RETURN_ERROR(status);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user