mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-10 05:46:48 +00:00
Don't check access mode if the file is being created
This commit is contained in:
parent
fbf2afd799
commit
bffc34c94b
@ -70,7 +70,7 @@ impl FsResolver {
|
||||
let follow_tail_link = !(creation_flags.contains(CreationFlags::O_NOFOLLOW)
|
||||
|| creation_flags.contains(CreationFlags::O_CREAT)
|
||||
&& creation_flags.contains(CreationFlags::O_EXCL));
|
||||
let dentry = match self.lookup_inner(path, follow_tail_link) {
|
||||
let inode_handle = match self.lookup_inner(path, follow_tail_link) {
|
||||
Ok(dentry) => {
|
||||
let inode = dentry.inode();
|
||||
if inode.type_() == InodeType::SymLink
|
||||
@ -92,7 +92,11 @@ impl FsResolver {
|
||||
"O_DIRECTORY is specified but file is not a directory"
|
||||
);
|
||||
}
|
||||
dentry
|
||||
|
||||
if creation_flags.contains(CreationFlags::O_TRUNC) {
|
||||
dentry.resize(0)?;
|
||||
}
|
||||
InodeHandle::new(dentry, access_mode, status_flags)?
|
||||
}
|
||||
Err(e)
|
||||
if e.error() == Errno::ENOENT
|
||||
@ -109,17 +113,14 @@ impl FsResolver {
|
||||
if !dir_dentry.mode()?.is_writable() {
|
||||
return_errno_with_message!(Errno::EACCES, "file cannot be created");
|
||||
}
|
||||
dir_dentry.new_fs_child(&file_name, InodeType::File, inode_mode)?
|
||||
|
||||
let dentry = dir_dentry.new_fs_child(&file_name, InodeType::File, inode_mode)?;
|
||||
// Don't check access mode for newly created file
|
||||
InodeHandle::new_unchecked_access(dentry, access_mode, status_flags)?
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
if creation_flags.contains(CreationFlags::O_TRUNC) {
|
||||
dentry.resize(0)?;
|
||||
}
|
||||
|
||||
let inode_handle = InodeHandle::new(dentry, access_mode, status_flags)?;
|
||||
|
||||
Ok(inode_handle)
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,16 @@ impl InodeHandle<Rights> {
|
||||
if access_mode.is_writable() && !inode.mode()?.is_writable() {
|
||||
return_errno_with_message!(Errno::EACCES, "File is not writable");
|
||||
}
|
||||
|
||||
Self::new_unchecked_access(dentry, access_mode, status_flags)
|
||||
}
|
||||
|
||||
pub fn new_unchecked_access(
|
||||
dentry: Arc<Dentry>,
|
||||
access_mode: AccessMode,
|
||||
status_flags: StatusFlags,
|
||||
) -> Result<Self> {
|
||||
let inode = dentry.inode();
|
||||
if access_mode.is_writable() && inode.type_() == InodeType::Dir {
|
||||
return_errno_with_message!(Errno::EISDIR, "Directory cannot open to write");
|
||||
}
|
||||
|
4
test/syscall_test/blocklists.exfat/open_create_test
Normal file
4
test/syscall_test/blocklists.exfat/open_create_test
Normal file
@ -0,0 +1,4 @@
|
||||
CreateTest.ChmodReadToWriteBetweenOpens_NoRandomSave
|
||||
CreateTest.ChmodWriteToReadBetweenOpens_NoRandomSave
|
||||
CreateTest.CreateWithReadFlagNotAllowedByMode_NoRandomSave
|
||||
CreateTest.CreateWithWriteFlagNotAllowedByMode_NoRandomSave
|
@ -3,7 +3,3 @@ CreateTest.CreatWithOTrunc
|
||||
CreateTest.CreatDirWithOTruncAndReadOnly
|
||||
CreateTest.CreateFailsOnUnpermittedDir
|
||||
CreateTest.CreateFailsOnDirWithoutWritePerms
|
||||
CreateTest.ChmodReadToWriteBetweenOpens_NoRandomSave
|
||||
CreateTest.ChmodWriteToReadBetweenOpens_NoRandomSave
|
||||
CreateTest.CreateWithReadFlagNotAllowedByMode_NoRandomSave
|
||||
CreateTest.CreateWithWriteFlagNotAllowedByMode_NoRandomSave
|
Loading…
x
Reference in New Issue
Block a user