fn handle_fileio(
    arg1: u64,
    arg2: u64,
    arg3: u64,
    arg4: u64,
    arg5: u64,
) -> Result<(u64, u64), KError> {
    let op = FileOperation::from(arg1);

    let kcb = super::kcb::get_kcb();
    let pid = kcb.arch.current_pid()?;

    match op {
        FileOperation::Create => {
            unreachable!("Create is changed to Open with O_CREAT flag in vibrio")
        }
        FileOperation::Open => {
            let pathname = arg2;
            let flags = arg3;
            let modes = arg4;
            let _r = user_virt_addr_valid(pid, pathname, 0)?;
            cnrfs::MlnrKernelNode::map_fd(pid, pathname, flags, modes)
        }
        FileOperation::Read | FileOperation::Write => {
            let fd = arg2;
            let buffer = arg3;
            let len = arg4;

            let _r = user_virt_addr_valid(pid, buffer, len)?;
            cnrfs::MlnrKernelNode::file_io(op, pid, fd, buffer, len, -1)
        }
        FileOperation::ReadAt | FileOperation::WriteAt => {
            let fd = arg2;
            let buffer = arg3;
            let len = arg4;
            let offset = arg5 as i64;

            let _r = user_virt_addr_valid(pid, buffer, len)?;
            cnrfs::MlnrKernelNode::file_io(op, pid, fd, buffer, len, offset)
        }
        FileOperation::Close => {
            let fd = arg2;
            cnrfs::MlnrKernelNode::unmap_fd(pid, fd)
        }
        FileOperation::GetInfo => {
            let name = arg2;
            let info_ptr = arg3;

            let _r = user_virt_addr_valid(pid, name, 0)?;
            cnrfs::MlnrKernelNode::file_info(pid, name, info_ptr)
        }
        FileOperation::Delete => {
            let name = arg2;

            let _r = user_virt_addr_valid(pid, name, 0)?;
            cnrfs::MlnrKernelNode::file_delete(pid, name)
        }
        FileOperation::WriteDirect => {
            let len = arg3;
            let mut offset = arg4 as usize;
            if arg5 == 0 {
                offset = 0;
            }

            let mut kernslice = crate::process::KernSlice::new(arg2, len as usize);
            let mut buffer = unsafe { Arc::get_mut_unchecked(&mut kernslice.buffer) };
            let cnrfs = super::kcb::get_kcb().arch.cnrfs.as_ref().unwrap();

            let len = cnrfs.write(2, &mut buffer, offset)?;

            Ok((len as u64, 0))
        }
        FileOperation::FileRename => {
            let oldname = arg2;
            let newname = arg3;

            let _r = user_virt_addr_valid(pid, oldname, 0)?;
            let _r = user_virt_addr_valid(pid, newname, 0)?;

            cnrfs::MlnrKernelNode::file_rename(pid, oldname, newname)
        }
        FileOperation::MkDir => {
            let pathname = arg2;
            let modes = arg3;
            let _r = user_virt_addr_valid(pid, pathname, 0)?;

            cnrfs::MlnrKernelNode::mkdir(pid, pathname, modes)
        }
        FileOperation::Unknown => {
            unreachable!("FileOperation not allowed");
            Err(KError::NotSupported)
        }
    }
}
/// System call handler for file operations
System call handler for file operations
System call handler for file operations
fn handle_fileio(
    arg1: u64,
    arg2: u64,
    arg3: u64,
    arg4: u64,
    arg5: u64,
) -> Result<(u64, u64), KError> {
    let op = FileOperation::from(arg1);
    let kcb = super::kcb::get_kcb();
    let pid = kcb.arch.current_pid()?;
    match op {
        FileOperation::Create => {
            unreachable!("Create is changed to Open with O_CREAT flag in vibrio")
        }
        FileOperation::Open => {
            let pathname = arg2;
            let flags = arg3;
            let modes = arg4;
            let _r = user_virt_addr_valid(pid, pathname, 0)?;
            cnrfs::MlnrKernelNode::map_fd(pid, pathname, flags, modes)
        }
        FileOperation::Read | FileOperation::Write => {
            let fd = arg2;
            let buffer = arg3;
            let len = arg4;
            let _r = user_virt_addr_valid(pid, buffer, len)?;
            cnrfs::MlnrKernelNode::file_io(op, pid, fd, buffer, len, -1)
        }
        FileOperation::ReadAt | FileOperation::WriteAt => {
            let fd = arg2;
            let buffer = arg3;
            let len = arg4;
            let offset = arg5 as i64;
            let _r = user_virt_addr_valid(pid, buffer, len)?;
            cnrfs::MlnrKernelNode::file_io(op, pid, fd, buffer, len, offset)
        }
        FileOperation::Close => {
            let fd = arg2;
            cnrfs::MlnrKernelNode::unmap_fd(pid, fd)
        }
        FileOperation::GetInfo => {
            let name = arg2;
            let info_ptr = arg3;
            let _r = user_virt_addr_valid(pid, name, 0)?;
            cnrfs::MlnrKernelNode::file_info(pid, name, info_ptr)
        }
        FileOperation::Delete => {
            let name = arg2;
            let _r = user_virt_addr_valid(pid, name, 0)?;
            cnrfs::MlnrKernelNode::file_delete(pid, name)
        }
        FileOperation::WriteDirect => {
            let len = arg3;
            let mut offset = arg4 as usize;
            if arg5 == 0 {
                offset = 0;
            }
            let mut kernslice = crate::process::KernSlice::new(arg2, len as usize);
            let mut buffer = unsafe { Arc::get_mut_unchecked(&mut kernslice.buffer) };
            let cnrfs = super::kcb::get_kcb().arch.cnrfs.as_ref().unwrap();
            let len = cnrfs.write(2, &mut buffer, offset)?;
            Ok((len as u64, 0))
        }
        FileOperation::FileRename => {
            let oldname = arg2;
            let newname = arg3;
            let _r = user_virt_addr_valid(pid, oldname, 0)?;
            let _r = user_virt_addr_valid(pid, newname, 0)?;
            cnrfs::MlnrKernelNode::file_rename(pid, oldname, newname)
        }
        FileOperation::MkDir => {
            let pathname = arg2;
            let modes = arg3;
            let _r = user_virt_addr_valid(pid, pathname, 0)?;
            cnrfs::MlnrKernelNode::mkdir(pid, pathname, modes)
        }
        FileOperation::Unknown => {
            unreachable!("FileOperation not allowed");
            Err(KError::NotSupported)
        }
    }
}
fn handle_fileio ( arg1 : u64 , arg2 : u64 , arg3 : u64 , arg4 : u64 , arg5 : u64 , ) -> Result < ( u64 , u64 ) , KError > { let op = FileOperation :: from ( arg1 ) ; let kcb = super :: kcb :: get_kcb ( ) ; let pid = kcb . arch . current_pid ( ) ? ; match op { FileOperation :: Create => { unreachable ! ( " " ) } FileOperation :: Open => { let pathname = arg2 ; let flags = arg3 ; let modes = arg4 ; let _r = user_virt_addr_valid ( pid , pathname , 0 ) ? ; cnrfs :: MlnrKernelNode :: map_fd ( pid , pathname , flags , modes ) } FileOperation :: Read | FileOperation :: Write => { let fd = arg2 ; let buffer = arg3 ; let len = arg4 ; let _r = user_virt_addr_valid ( pid , buffer , len ) ? ; cnrfs :: MlnrKernelNode :: file_io ( op , pid , fd , buffer , len , - 1 ) } FileOperation :: ReadAt | FileOperation :: WriteAt => { let fd = arg2 ; let buffer = arg3 ; let len = arg4 ; let offset = arg5 as i64 ; let _r = user_virt_addr_valid ( pid , buffer , len ) ? ; cnrfs :: MlnrKernelNode :: file_io ( op , pid , fd , buffer , len , offset ) } FileOperation :: Close => { let fd = arg2 ; cnrfs :: MlnrKernelNode :: unmap_fd ( pid , fd ) } FileOperation :: GetInfo => { let name = arg2 ; let info_ptr = arg3 ; let _r = user_virt_addr_valid ( pid , name , 0 ) ? ; cnrfs :: MlnrKernelNode :: file_info ( pid , name , info_ptr ) } FileOperation :: Delete => { let name = arg2 ; let _r = user_virt_addr_valid ( pid , name , 0 ) ? ; cnrfs :: MlnrKernelNode :: file_delete ( pid , name ) } FileOperation :: WriteDirect => { let len = arg3 ; let mut offset = arg4 as usize ; if arg5 == 0 { offset = 0 ; } let mut kernslice = crate :: process :: KernSlice :: new ( arg2 , len as usize ) ; let mut buffer = unsafe { Arc :: get_mut_unchecked ( & mut kernslice . buffer ) } ; let cnrfs = super :: kcb :: get_kcb ( ) . arch . cnrfs . as_ref ( ) . unwrap ( ) ; let len = cnrfs . write ( 2 , & mut buffer , offset ) ? ; Ok ( ( len as u64 , 0 ) ) } FileOperation :: FileRename => { let oldname = arg2 ; let newname = arg3 ; let _r = user_virt_addr_valid ( pid , oldname , 0 ) ? ; let _r = user_virt_addr_valid ( pid , newname , 0 ) ? ; cnrfs :: MlnrKernelNode :: file_rename ( pid , oldname , newname ) } FileOperation :: MkDir => { let pathname = arg2 ; let modes = arg3 ; let _r = user_virt_addr_valid ( pid , pathname , 0 ) ? ; cnrfs :: MlnrKernelNode :: mkdir ( pid , pathname , modes ) } FileOperation :: Unknown => { unreachable ! ( " " ) ; Err ( KError :: NotSupported ) } } }
System call handler for file operations
System call handler for file operations
arg1
u64
arg2
u64
arg3
u64
arg4
u64
arg5
u64
arg1
u64
arg2
u64
arg3
u64
arg4
u64
arg5
u64