xref: /DragonOS/kernel/src/filesystem/vfs/open.rs (revision bf4a48994a2b284ee34aa49a66b4dec1b6ebc07c)
1 use crate::{
2     process::ProcessManager,
3     syscall::{user_access::check_and_clone_cstr, SystemError},
4 };
5 
6 use super::{
7     fcntl::AtFlags, syscall::ModeType, utils::user_path_at, MAX_PATHLEN,
8     VFS_MAX_FOLLOW_SYMLINK_TIMES,
9 };
10 
11 pub(super) fn do_faccessat(
12     dirfd: i32,
13     path: *const u8,
14     mode: ModeType,
15     flags: u32,
16 ) -> Result<usize, SystemError> {
17     if (mode.bits() & (!ModeType::S_IRWXO.bits())) != 0 {
18         return Err(SystemError::EINVAL);
19     }
20 
21     if (flags
22         & (!((AtFlags::AT_EACCESS | AtFlags::AT_SYMLINK_NOFOLLOW | AtFlags::AT_EMPTY_PATH).bits()
23             as u32)))
24         != 0
25     {
26         return Err(SystemError::EINVAL);
27     }
28 
29     // let follow_symlink = flags & AtFlags::AT_SYMLINK_NOFOLLOW.bits() as u32 == 0;
30 
31     let path = check_and_clone_cstr(path, Some(MAX_PATHLEN))?;
32 
33     if path.len() == 0 {
34         return Err(SystemError::EINVAL);
35     }
36 
37     let (inode, path) = user_path_at(&ProcessManager::current_pcb(), dirfd, path)?;
38 
39     // 如果找不到文件,则返回错误码ENOENT
40     let _inode = inode.lookup_follow_symlink(path.as_str(), VFS_MAX_FOLLOW_SYMLINK_TIMES)?;
41 
42     // todo: 接着完善(可以借鉴linux 6.1.9的do_faccessat)
43     return Ok(0);
44 }
45 
46 pub fn do_fchmodat(dirfd: i32, path: *const u8, _mode: ModeType) -> Result<usize, SystemError> {
47     let path = check_and_clone_cstr(path, Some(MAX_PATHLEN))?;
48 
49     if path.len() == 0 {
50         return Err(SystemError::EINVAL);
51     }
52 
53     let (inode, path) = user_path_at(&ProcessManager::current_pcb(), dirfd, path)?;
54 
55     // 如果找不到文件,则返回错误码ENOENT
56     let _inode = inode.lookup_follow_symlink(path.as_str(), VFS_MAX_FOLLOW_SYMLINK_TIMES)?;
57 
58     kwarn!("do_fchmodat: not implemented yet\n");
59     // todo: 真正去改变文件的权限
60 
61     return Ok(0);
62 }
63