123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- use alloc::string::ToString;
- use alloc::vec::Vec;
- use crate::{
- arch::{
- interrupt::TrapFrame,
- syscall::nr::{SYS_SYNC, SYS_SYNCFS},
- },
- mm::page::page_reclaimer_lock_irqsave,
- syscall::table::{FormattedSyscallParam, Syscall},
- };
- /// sync() causes all pending modifications to filesystem metadata and
- /// cached file data to be written to the underlying filesystems.
- ///
- /// See https://man7.org/linux/man-pages/man2/sync.2.html
- pub struct SysSyncHandle;
- impl Syscall for SysSyncHandle {
- fn num_args(&self) -> usize {
- 0
- }
- fn handle(
- &self,
- _args: &[usize],
- _frame: &mut TrapFrame,
- ) -> Result<usize, system_error::SystemError> {
- page_reclaimer_lock_irqsave().flush_dirty_pages();
- Ok(0)
- }
- fn entry_format(&self, _args: &[usize]) -> Vec<FormattedSyscallParam> {
- vec![FormattedSyscallParam::new(
- "No arguments",
- "sync()".to_string(),
- )]
- }
- }
- syscall_table_macros::declare_syscall!(SYS_SYNC, SysSyncHandle);
- /// syncfs() is like sync(), but synchronizes just the filesystem
- /// containing file referred to by the open file descriptor fd.
- pub struct SysSyncFsHandle;
- impl Syscall for SysSyncFsHandle {
- fn num_args(&self) -> usize {
- 1
- }
- fn handle(
- &self,
- _args: &[usize],
- _frame: &mut TrapFrame,
- ) -> Result<usize, system_error::SystemError> {
- // TODO: now, we ignore the fd and sync all filesystems.
- // In the future, we should sync only the filesystem of the given fd.
- page_reclaimer_lock_irqsave().flush_dirty_pages();
- Ok(0)
- }
- fn entry_format(&self, args: &[usize]) -> Vec<FormattedSyscallParam> {
- vec![FormattedSyscallParam::new("fd", format!("{}", args[0]))]
- }
- }
- syscall_table_macros::declare_syscall!(SYS_SYNCFS, SysSyncHandle);
|