mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-20 04:56:32 +00:00
Add support for the sync and fsync syscall
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
9473889c6b
commit
5bc1312a91
@ -383,6 +383,11 @@ impl Dentry {
|
||||
self.inode.fs()
|
||||
}
|
||||
|
||||
/// Flushes all changes made to data and metadata to the device.
|
||||
pub fn sync(&self) -> Result<()> {
|
||||
self.inode.sync()
|
||||
}
|
||||
|
||||
/// Get the inode metadata
|
||||
pub fn inode_metadata(&self) -> Metadata {
|
||||
self.inode.metadata()
|
||||
|
@ -101,6 +101,18 @@ impl MountNode {
|
||||
self.mountpoint_dentry.as_ref()
|
||||
}
|
||||
|
||||
/// Flushes all pending filesystem metadata and cached file data to the device.
|
||||
pub fn sync(&self) -> Result<()> {
|
||||
let children = self.children.lock();
|
||||
for child in children.values() {
|
||||
child.sync()?;
|
||||
}
|
||||
drop(children);
|
||||
|
||||
self.fs.sync()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Try to get the parent mount node.
|
||||
pub fn parent(&self) -> Option<Arc<Self>> {
|
||||
self.mountpoint_dentry
|
||||
|
25
services/libs/aster-std/src/syscall/fsync.rs
Normal file
25
services/libs/aster-std/src/syscall/fsync.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use crate::log_syscall_entry;
|
||||
use crate::{
|
||||
fs::{file_table::FileDescripter, inode_handle::InodeHandle},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use super::SyscallReturn;
|
||||
use super::SYS_FSYNC;
|
||||
|
||||
pub fn sys_fsync(fd: FileDescripter) -> Result<SyscallReturn> {
|
||||
log_syscall_entry!(SYS_FSYNC);
|
||||
debug!("fd = {}", fd);
|
||||
|
||||
let dentry = {
|
||||
let current = current!();
|
||||
let file_table = current.file_table().lock();
|
||||
let file = file_table.get_file(fd)?;
|
||||
let inode_handle = file
|
||||
.downcast_ref::<InodeHandle>()
|
||||
.ok_or(Error::with_message(Errno::EINVAL, "not inode"))?;
|
||||
inode_handle.dentry().clone()
|
||||
};
|
||||
dentry.sync()?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
}
|
@ -17,6 +17,7 @@ use crate::syscall::exit::sys_exit;
|
||||
use crate::syscall::exit_group::sys_exit_group;
|
||||
use crate::syscall::fcntl::sys_fcntl;
|
||||
use crate::syscall::fork::sys_fork;
|
||||
use crate::syscall::fsync::sys_fsync;
|
||||
use crate::syscall::futex::sys_futex;
|
||||
use crate::syscall::getcwd::sys_getcwd;
|
||||
use crate::syscall::getdents64::sys_getdents64;
|
||||
@ -59,6 +60,7 @@ use crate::syscall::setpgid::sys_setpgid;
|
||||
use crate::syscall::stat::{sys_fstat, sys_fstatat, sys_lstat, sys_stat};
|
||||
use crate::syscall::statfs::{sys_fstatfs, sys_statfs};
|
||||
use crate::syscall::symlink::{sys_symlink, sys_symlinkat};
|
||||
use crate::syscall::sync::sys_sync;
|
||||
use crate::syscall::tgkill::sys_tgkill;
|
||||
use crate::syscall::time::sys_time;
|
||||
use crate::syscall::umask::sys_umask;
|
||||
@ -123,6 +125,7 @@ mod exit;
|
||||
mod exit_group;
|
||||
mod fcntl;
|
||||
mod fork;
|
||||
mod fsync;
|
||||
mod futex;
|
||||
mod getcwd;
|
||||
mod getdents64;
|
||||
@ -192,6 +195,7 @@ mod socketpair;
|
||||
mod stat;
|
||||
mod statfs;
|
||||
mod symlink;
|
||||
mod sync;
|
||||
mod tgkill;
|
||||
mod time;
|
||||
mod umask;
|
||||
@ -283,6 +287,7 @@ define_syscall_nums!(
|
||||
SYS_KILL = 62,
|
||||
SYS_UNAME = 63,
|
||||
SYS_FCNTL = 72,
|
||||
SYS_FSYNC = 74,
|
||||
SYS_GETCWD = 79,
|
||||
SYS_CHDIR = 80,
|
||||
SYS_FCHDIR = 81,
|
||||
@ -323,6 +328,7 @@ define_syscall_nums!(
|
||||
SYS_FSTATFS = 138,
|
||||
SYS_PRCTL = 157,
|
||||
SYS_ARCH_PRCTL = 158,
|
||||
SYS_SYNC = 162,
|
||||
SYS_GETTID = 186,
|
||||
SYS_TIME = 201,
|
||||
SYS_FUTEX = 202,
|
||||
@ -459,6 +465,7 @@ pub fn syscall_dispatch(
|
||||
SYS_KILL => syscall_handler!(2, sys_kill, args),
|
||||
SYS_UNAME => syscall_handler!(1, sys_uname, args),
|
||||
SYS_FCNTL => syscall_handler!(3, sys_fcntl, args),
|
||||
SYS_FSYNC => syscall_handler!(1, sys_fsync, args),
|
||||
SYS_GETCWD => syscall_handler!(2, sys_getcwd, args),
|
||||
SYS_CHDIR => syscall_handler!(1, sys_chdir, args),
|
||||
SYS_FCHDIR => syscall_handler!(1, sys_fchdir, args),
|
||||
@ -499,6 +506,7 @@ pub fn syscall_dispatch(
|
||||
SYS_FSTATFS => syscall_handler!(2, sys_fstatfs, args),
|
||||
SYS_PRCTL => syscall_handler!(5, sys_prctl, args),
|
||||
SYS_ARCH_PRCTL => syscall_handler!(2, sys_arch_prctl, args, context),
|
||||
SYS_SYNC => syscall_handler!(0, sys_sync),
|
||||
SYS_GETTID => syscall_handler!(0, sys_gettid),
|
||||
SYS_TIME => syscall_handler!(1, sys_time, args),
|
||||
SYS_FUTEX => syscall_handler!(6, sys_futex, args),
|
||||
|
12
services/libs/aster-std/src/syscall/sync.rs
Normal file
12
services/libs/aster-std/src/syscall/sync.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::log_syscall_entry;
|
||||
use crate::prelude::*;
|
||||
|
||||
use super::SyscallReturn;
|
||||
use super::SYS_SYNC;
|
||||
|
||||
pub fn sys_sync() -> Result<SyscallReturn> {
|
||||
log_syscall_entry!(SYS_SYNC);
|
||||
|
||||
crate::fs::rootfs::root_mount().sync()?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
}
|
Reference in New Issue
Block a user