mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
Implement getcwd()
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ea489252f4
commit
bdf89a5de3
@ -1,14 +1,27 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use super::SyscallReturn;
|
use super::SyscallReturn;
|
||||||
use crate::prelude::*;
|
use crate::{
|
||||||
|
fs::fs_resolver::{FsPath, AT_FDCWD},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn sys_getcwd(buf: Vaddr, len: usize, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_getcwd(buf: Vaddr, len: usize, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
// TODO: getcwd only return a fake result now
|
let current = ctx.process;
|
||||||
let fake_cwd = CString::new("/")?;
|
let dirent = current
|
||||||
let bytes = fake_cwd.as_bytes_with_nul();
|
.fs()
|
||||||
|
.read()
|
||||||
|
.lookup(&FsPath::new(AT_FDCWD, "").unwrap())
|
||||||
|
.unwrap();
|
||||||
|
let name = dirent.abs_path();
|
||||||
|
|
||||||
|
debug!("getcwd: {:?}", name);
|
||||||
|
|
||||||
|
let cwd = CString::new(name)?;
|
||||||
|
let bytes = cwd.as_bytes_with_nul();
|
||||||
let write_len = len.min(bytes.len());
|
let write_len = len.min(bytes.len());
|
||||||
ctx.get_user_space()
|
ctx.get_user_space()
|
||||||
.write_bytes(buf, &mut VmReader::from(&bytes[..write_len]))?;
|
.write_bytes(buf, &mut VmReader::from(&bytes[..write_len]))?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(write_len as _))
|
Ok(SyscallReturn::Return(write_len as _))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user