-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat(time): Add syscall support for utime* #838
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,14 @@ use crate::{ | |
user_access::{self, check_and_clone_cstr, UserBufferWriter}, | ||
Syscall, | ||
}, | ||
time::PosixTimeSpec, | ||
time::{syscall::PosixTimeval, PosixTimeSpec}, | ||
}; | ||
|
||
use super::{ | ||
core::{do_mkdir_at, do_remove_dir, do_unlink_at}, | ||
fcntl::{AtFlags, FcntlCommand, FD_CLOEXEC}, | ||
file::{File, FileMode}, | ||
open::{do_faccessat, do_fchmodat, do_sys_open}, | ||
open::{do_faccessat, do_fchmodat, do_sys_open, do_utimensat, do_utimes}, | ||
utils::{rsplit_path, user_path_at}, | ||
Dirent, FileType, IndexNode, SuperBlock, FSMAKER, MAX_PATHLEN, ROOT_INODE, | ||
VFS_MAX_FOLLOW_SYMLINK_TIMES, | ||
|
@@ -323,6 +323,13 @@ bitflags! { | |
} | ||
} | ||
|
||
bitflags! { | ||
pub struct UtimensFlags: u32 { | ||
/// 不需要解释符号链接 | ||
const AT_SYMLINK_NOFOLLOW = 0x100; | ||
} | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct PosixStatfs { | ||
|
@@ -1620,6 +1627,44 @@ impl Syscall { | |
)?; | ||
return Ok(()); | ||
} | ||
|
||
pub fn sys_utimensat( | ||
dirfd: i32, | ||
pathname: *const u8, | ||
times: *const PosixTimeSpec, | ||
flags: u32, | ||
) -> Result<usize, SystemError> { | ||
let pathname = if pathname.is_null() { | ||
None | ||
} else { | ||
let pathname = check_and_clone_cstr(pathname, Some(MAX_PATHLEN))?; | ||
Some(pathname) | ||
}; | ||
let flags = UtimensFlags::from_bits(flags).ok_or(SystemError::EINVAL)?; | ||
let times = if times.is_null() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉好像不用判断空的,因为如果空指针的话userbuffer会报错 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里是允许times为空的 |
||
None | ||
} else { | ||
let atime = unsafe { times.read() }; | ||
let mtime = unsafe { times.add(1).read() }; | ||
Some([atime, mtime]) | ||
}; | ||
do_utimensat(dirfd, pathname, times, flags) | ||
} | ||
|
||
pub fn sys_utimes( | ||
pathname: *const u8, | ||
times: *const PosixTimeval, | ||
) -> Result<usize, SystemError> { | ||
let pathname = check_and_clone_cstr(pathname, Some(MAX_PATHLEN))?; | ||
let times = if times.is_null() { | ||
None | ||
} else { | ||
let atime = unsafe { times.read() }; | ||
let mtime = unsafe { times.add(1).read() }; | ||
Some([atime, mtime]) | ||
}; | ||
do_utimes(&pathname, times) | ||
} | ||
} | ||
|
||
#[repr(C)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
#[cfg(test)] | ||
#[macro_use] | ||
extern crate std; | ||
|
||
#[cfg(target_os = "none")] | ||
Chiichen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use core::panic::PanicInfo; | ||
|
||
/// 导出x86_64架构相关的代码,命名为arch模块 | ||
|
@@ -87,7 +87,7 @@ extern crate uefi; | |
extern crate uefi_raw; | ||
|
||
use crate::mm::allocator::kernel_allocator::KernelAllocator; | ||
|
||
#[cfg(target_os = "none")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这两个 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 但是 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这是为了消除cargo clippy的一个warning,确实是加不加都可以 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
那我觉得就没必要硬加了,确实有warning的话把这个lint禁掉吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
use crate::process::ProcessManager; | ||
|
||
#[cfg(all(feature = "backtrace", target_arch = "x86_64"))] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ use crate::{ | |
filesystem::vfs::{ | ||
fcntl::{AtFlags, FcntlCommand}, | ||
file::FileMode, | ||
syscall::{ModeType, PosixKstat}, | ||
syscall::{ModeType, PosixKstat, UtimensFlags}, | ||
MAX_PATHLEN, | ||
}, | ||
libs::align::page_align_up, | ||
|
@@ -1103,7 +1103,24 @@ impl Syscall { | |
|
||
Self::shmctl(id, cmd, user_buf, from_user) | ||
} | ||
|
||
SYS_UTIMENSAT => Self::sys_utimensat( | ||
args[0] as i32, | ||
args[1] as *const u8, | ||
args[2] as *const PosixTimeSpec, | ||
args[3] as u32, | ||
), | ||
#[cfg(target_arch = "x86_64")] | ||
SYS_FUTIMESAT => { | ||
let flags = UtimensFlags::empty(); | ||
Self::sys_utimensat( | ||
args[0] as i32, | ||
args[1] as *const u8, | ||
args[2] as *const PosixTimeSpec, | ||
flags.bits(), | ||
) | ||
} | ||
#[cfg(target_arch = "x86_64")] | ||
SYS_UTIMES => Self::sys_utimes(args[0] as *const u8, args[1] as *const PosixTimeval), | ||
Comment on lines
+1112
to
+1123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里条件编译的作用是什么,如果是架构特有的系统调用应该放在arch/<x86/riscv>/syscall下,不用条件编译 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 其它的系统调用不也是使用这种条件编译的方式吗?arch/<x86/riscv>/syscall目录不是系统调用实现的存放位置吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有两种情况,一种情况是这个系统调用是架构相关的,比如 SYS_RT_SIGRETURN,第二种情况是定义的系统调用是通用的系统调用,条件编译是因为目前只有X86下有实现,但是系统调用本身是架构无关的。你这两个系统调用SYS_UTIMENSAT 和 SYS_FUTIMESAT,在都是一个逻辑Self::sys_utimensat,但是一个条件编译一个不条件编译,所以才想知道你写条件编译的目的 |
||
_ => panic!("Unsupported syscall ID: {}", syscall_num), | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_utimensat |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ifeq ($(ARCH), x86_64) | ||
CROSS_COMPILE=x86_64-linux-musl- | ||
else ifeq ($(ARCH), riscv64) | ||
CROSS_COMPILE=riscv64-linux-musl- | ||
endif | ||
|
||
CC=$(CROSS_COMPILE)gcc | ||
|
||
.PHONY: all | ||
all: main.c | ||
$(CC) -static -o test_utimensat main.c | ||
|
||
.PHONY: install clean | ||
install: all | ||
mv test_utimensat $(DADK_CURRENT_BUILD_DIR)/test_utimensat | ||
|
||
clean: | ||
rm test_utimensat *.o | ||
|
||
fmt: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
|
||
int main(){ | ||
int res = utimensat(AT_FDCWD, "/bin/about.elf", NULL, 0); | ||
printf("utimensat res = %d\n", res); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "test_utimensat", | ||
"version": "0.1.0", | ||
"description": "test_utimensat", | ||
"task_type": { | ||
"BuildFromSource": { | ||
"Local": { | ||
"path": "apps/test_utimensat" | ||
} | ||
} | ||
}, | ||
"depends": [], | ||
"build": { | ||
"build_command": "make install" | ||
}, | ||
"install": { | ||
"in_dragonos_path": "/bin" | ||
}, | ||
"clean": { | ||
"clean_command": "make clean" | ||
}, | ||
"target_arch": ["x86_64"] | ||
} |
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.
这里传入的裸指针需要像其他的系统调用那样,用userbuffer结构体去校验合法性&读写
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.
ok