1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 08:06:17 +04:00

pass utime

This commit is contained in:
function2-llx 2020-06-06 02:39:45 +08:00
parent 75967f12c0
commit 0f2fae8590
6 changed files with 78 additions and 33 deletions

View File

@ -4,7 +4,7 @@ pub use crate::arch::consts::*;
use alloc::string::String;
pub const MAX_CPU_NUM: usize = 64;
pub const MAX_PROCESS_NUM: usize = 128;
pub const MAX_PROCESS_NUM: usize = 512;
pub const USEC_PER_TICK: usize = 10000;

View File

@ -1,5 +1,7 @@
use crate::signal::Signal;
use bitflags::*;
use bitflags::_core::fmt::Debug;
use core::fmt::Formatter;
pub const SIG_ERR: usize = usize::max_value() - 1;
pub const SIG_DFL: usize = 0;
@ -44,7 +46,7 @@ impl Sigset {
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
#[derive(Clone, Copy, Default)]
pub struct SignalAction {
pub handler: usize, // this field may be an union
pub mask: Sigset,
@ -52,6 +54,18 @@ pub struct SignalAction {
pub restorer: usize,
}
impl Debug for SignalAction {
fn fmt(&self, f: &mut Formatter) -> Result<(), core::fmt::Error> {
f.debug_struct("signal action")
.field("handler", &format!("{:#x}", self.handler))
.field("mask", &self.mask)
.field("flags", &SignalActionFlags::from_bits_truncate(self.flags))
.field("restorer", &format!("{:#x}", self.restorer))
.finish()
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SiginfoFields {

View File

@ -1137,33 +1137,52 @@ impl Syscall<'_> {
"utimensat(raw): dirfd: {}, pathname: {}, times: {}, flags: {:#x}",
dirfd as i64, pathname as usize, times as usize, flags
);
let pathname = check_and_clone_cstr(pathname)?;
let proc = self.process();
let times = if times.is_null() {
[TimeSpec::get_epoch(), TimeSpec::get_epoch()]
const UTIME_NOW: usize = 0x3fffffff;
const UTIME_OMIT: usize = 0x3ffffffe;
let mut proc = self.process();
let mut times = if times.is_null() {
let epoch = TimeSpec::get_epoch();
[epoch, epoch]
} else {
let times = unsafe { self.vm().check_read_array(times, 2)? };
[times[0], times[1]]
};
info!(
"utimensat: dirfd: {}, pathname: {}, times: {:?}, flags: {:#x}",
dirfd as i64, pathname, times, flags
);
let follow = match flags {
0 => true,
fcntl::AT_SYMLINK_NOFOLLOW => false,
_ => return Err(EINVAL),
let mut inode = if pathname.is_null() {
let fd = dirfd;
info!("futimens: fd: {}, times: {:?}", fd, times);
proc.get_file(fd)?.inode()
} else {
let pathname = check_and_clone_cstr(pathname)?;
info!(
"utimensat: dirfd: {}, pathname: {}, times: {:?}, flags: {:#x}",
dirfd as i64, pathname, times, flags
);
let follow = match flags {
0 => true,
fcntl::AT_SYMLINK_NOFOLLOW => false,
_ => return Err(EINVAL),
};
proc.lookup_inode_at(dirfd, &pathname, follow)?
};
let inode = proc.lookup_inode_at(dirfd, &pathname, follow)?;
let mut metadata = inode.metadata()?;
metadata.atime = Timespec {
sec: times[0].sec as i64,
nsec: times[0].nsec as i32,
};
metadata.mtime = Timespec {
sec: times[1].sec as i64,
nsec: times[1].nsec as i32,
};
if times[0].nsec != UTIME_OMIT {
if times[0].nsec == UTIME_NOW {
times[0] = TimeSpec::get_epoch();
}
metadata.atime = Timespec {
sec: times[0].sec as i64,
nsec: times[0].nsec as i32,
};
}
if times[1].nsec != UTIME_OMIT {
if times[1].nsec == UTIME_NOW {
times[1] = TimeSpec::get_epoch();
}
metadata.mtime = Timespec {
sec: times[1].sec as i64,
nsec: times[1].nsec as i32,
};
}
inode.set_metadata(&metadata)?;
Ok(0)
}
@ -1587,11 +1606,11 @@ pub struct Stat {
blocks: u64,
/// last access time
atime: Timespec,
atime: TimeSpec,
/// last modification time
mtime: Timespec,
mtime: TimeSpec,
/// last status change time
ctime: Timespec,
ctime: TimeSpec,
}
#[cfg(target_arch = "mips")]
@ -1764,9 +1783,18 @@ impl From<Metadata> for Stat {
size: info.size as u64,
blksize: info.blk_size as u64,
blocks: info.blocks as u64,
atime: info.atime,
mtime: info.mtime,
ctime: info.ctime,
atime: TimeSpec {
sec: info.atime.sec as usize,
nsec: info.atime.nsec as usize,
},
mtime: TimeSpec {
sec: info.mtime.sec as usize,
nsec: info.mtime.nsec as usize,
},
ctime: TimeSpec {
sec: info.ctime.sec as usize,
nsec: info.ctime.nsec as usize,
},
_pad0: 0,
}
}

View File

@ -2,8 +2,8 @@
use super::*;
use crate::fs::FileLike;
use crate::signal::{send_signal, Signal};
use crate::syscall::SysError::ESRCH;
use crate::signal::{send_signal, Signal, has_signal_to_do};
use crate::syscall::SysError::{ESRCH, EINTR};
use alloc::sync::Weak;
impl Syscall<'_> {
@ -350,6 +350,9 @@ impl Syscall<'_> {
if !time.is_zero() {
// TODO: handle spurious wakeup
thread::sleep(time.to_duration());
if has_signal_to_do() {
return Err(EINTR);
}
}
Ok(0)
}

View File

@ -178,7 +178,7 @@ impl Syscall<'_> {
Siginfo {
signo: signum as i32,
errno: 0,
code: SI_USER,
code: SI_TKILL,
field: Default::default(),
},
);

2
user

@ -1 +1 @@
Subproject commit 65daee81f66fefc4cdb97490756beadbd1f57e79
Subproject commit 12a9fb7d2509813465c9ffb0220c53f2566b2910