Skip to content

Commit

Permalink
fix: statx (unfinished)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikaidou-Shinku committed Mar 29, 2024
1 parent fb6c9e0 commit ba978e9
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 68 deletions.
4 changes: 1 addition & 3 deletions os/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ target = "loongarch64-unknown-linux-gnu"
[target.loongarch64-unknown-linux-gnu]
rustflags = ["-Clink-arg=-Tsrc/linker.ld", "-Clink-arg=-nostdlib", "-Clink-arg=-static"]
# Add "-Ctarget-feature=-unaligned-access" when ready.
linker = "loongarch64-linux-gnu-gcc"


linker = "loongarch64-unknown-linux-gnu-gcc"
4 changes: 2 additions & 2 deletions os/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ifeq ($(BOARD), 2K1000)
endif

# Binutils
OBJCOPY := loongarch64-linux-gnu-objcopy
OBJDUMP := loongarch64-linux-gnu-objdump
OBJCOPY := loongarch64-unknown-linux-gnu-objcopy
OBJDUMP := loongarch64-unknown-linux-gnu-objdump
READELF := loongarch64-linux-gnu-readelf

ifndef LOG
Expand Down
2 changes: 1 addition & 1 deletion os/buildfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ try_copy(){

for programname in $(ls ../user/src/bin)
do
echo ${programname%.rs} copied.
"$SUDO" cp -r ../user/target/${TARGET}/${MODE}/${programname%.rs} ${U_FAT32_DIR}/fs/${programname%.rs}
done

Expand All @@ -82,4 +83,3 @@ try_copy ../user/disk/${ARCH} ${U_FAT32_DIR}/fs/

"$SUDO" umount ${U_FAT32_DIR}/fs
echo "DONE"
return 0
1 change: 1 addition & 0 deletions os/cpio.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bash: line 1: cpio: command not found
12 changes: 6 additions & 6 deletions os/la_fat
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ expect "Bytes transferred"
expect "=>"
send "bootm\n"

proc test_cmd {file_name num} {
expect "\[1m\[32mNPUcore-IMPACT\[0m:\[1m\[34m/\[0m#"
sleep $num
send $file_name
}
# proc test_cmd {file_name num} {
# expect "\[1m\[32mNPUcore-IMPACT\[0m:\[1m\[34m/\[0m#"
# sleep $num
# send $file_name
# }


# test_cmd "run-all.sh\n" 0
# test_cmd "busybox_testcode.sh\n" $sleep_time
# test_cmd "lmbench_testcode.sh\n" $sleep_time

interact
interact
2 changes: 1 addition & 1 deletion os/src/arch/la64/trap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn trap_handler() -> ! {
let cause = get_exception_cause();
let stval = get_bad_addr();
let badi = get_bad_instruction();
log::info!("[trap_handler]Cause:{:?}", cause);
log::debug!("[trap_handler]Cause:{:?}", cause);
match cause {
Trap::Exception(Exception::Syscall) => {
// jump to next instruction anyway
Expand Down
72 changes: 72 additions & 0 deletions os/src/fs/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,78 @@ impl Stat {
}
}

#[derive(Clone, Copy, Debug)]
#[repr(C)]
struct StatxTimestamp {
tv_sec: i64,
tv_nsec: u32,
}

impl From<TimeSpec> for StatxTimestamp {
fn from(value: TimeSpec) -> Self {
Self {
tv_sec: value.tv_sec as i64,
tv_nsec: value.tv_nsec as u32,
}
}
}

#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct Statx {
stx_mask: u32,
stx_blksize: u32,
stx_attributes: u64,
stx_nlink: u32,
stx_uid: u32,
stx_gid: u32,
stx_mode: u16,
stx_ino: u64,
stx_size: u64,
stx_blocks: u64,
stx_attributes_mask: u64,
stx_atime: StatxTimestamp,
stx_btime: StatxTimestamp,
stx_ctime: StatxTimestamp,
stx_mtime: StatxTimestamp,
stx_rdev_major: u32,
stx_rdev_minor: u32,
stx_dev_major: u32,
stx_dev_minor: u32,
stx_mnt_id: u64,
stx_dio_mem_align: u32,
stx_dio_offset_align: u32,
}

impl From<Stat> for Statx {
fn from(value: Stat) -> Self {
Self {
stx_mask: 0, // TODO
stx_blksize: value.st_blksize,
stx_attributes: 0, // TODO
stx_nlink: value.st_nlink,
stx_uid: value.st_uid,
stx_gid: value.st_gid,
stx_mode: (value.st_mode & u16::MAX as u32) as u16,
stx_ino: value.st_ino,
stx_size: value.st_size as u64,
stx_blocks: value.st_blocks,
stx_attributes_mask: 0,
stx_atime: value.st_atime.into(),
stx_btime: TimeSpec::new().into(), // TODO
stx_ctime: value.st_ctime.into(),
stx_mtime: value.st_mtime.into(),
stx_rdev_major: value.st_rdev as u32, // TODO
stx_rdev_minor: 0, // TODO
stx_dev_major: value.st_dev as u32, // TODO
stx_dev_minor: 0, // TODO
stx_mnt_id: 0, // TODO
stx_dio_mem_align: 0, // TODO
stx_dio_offset_align: 0, // TODO
}
}
}

const NAME_LIMIT: usize = 128;
#[derive(Clone, Copy, Debug)]
#[repr(C)]
Expand Down
5 changes: 4 additions & 1 deletion os/src/mm/map_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,10 @@ impl MapArea {
) -> Option<(VirtPageNum, VirtPageNum)> {
let area_start_vpn = self.inner.vpn_range.get_start();
let area_end_vpn = self.inner.vpn_range.get_end();
if end_vpn < area_start_vpn || start_vpn >= area_end_vpn {
if start_vpn == area_end_vpn {
warn!("[check_overlapping] Is this correct?");
}
if end_vpn < area_start_vpn || start_vpn > area_end_vpn {
return None;
} else {
let start = if start_vpn > area_start_vpn {
Expand Down
32 changes: 15 additions & 17 deletions os/src/syscall/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ pub fn sys_pipe2(pipefd: usize, flags: u32) -> isize {
Ok(fd) => fd,
Err(errno) => {
println!("error pipe");
return errno
},
return errno;
}
};

info!(
Expand Down Expand Up @@ -545,9 +545,6 @@ pub fn sys_dup3(oldfd: usize, newfd: usize, flags: u32) -> isize {
Ok(fd) => fd as isize,
Err(errno) => errno,
}



}

// This syscall is not complete at all, only /read proc/self/exe
Expand Down Expand Up @@ -662,21 +659,22 @@ pub fn sys_fstat(fd: usize, statbuf: *mut u8) -> isize {
SUCCESS
}

pub fn sys_statx(dirfd: usize, path: *const u8, buf: *mut u8, flags: u32,) -> isize {
pub fn sys_statx(dirfd: usize, path: *const u8, buf: *mut u8, _flags: u32) -> isize {
let token = current_user_token();
let path = match translated_str(token, path) {
Ok(path) => path,
Err(errno) => return errno,
};

info!("[sys_statx] dirfd: {dirfd}, path: {path}");

let flags = match OpenFlags::from_bits(flags) {
Some(flags) => flags,
None => {
warn!("[sys_statx] unknown flags");
return EINVAL;
}
};
// let flags = match OpenFlags::from_bits(flags) {
// Some(flags) => flags,
// None => {
// warn!("[sys_statx] unknown flags: {flags}");
// return EINVAL;
// }
// };

let task = current_task().unwrap();
let file_descriptor = match dirfd {
Expand All @@ -690,9 +688,11 @@ pub fn sys_statx(dirfd: usize, path: *const u8, buf: *mut u8, flags: u32,) -> is
}
};

match file_descriptor.open(&path, flags, false) {
match file_descriptor.open(&path, OpenFlags::O_RDONLY, false) {
Ok(file_descriptor) => {
if copy_to_user(token, &file_descriptor.get_stat(), buf as *mut Stat).is_err() {
let stat = file_descriptor.get_stat().into();
info!("[sys_statx] stat: {stat:?}");
if copy_to_user(token, &stat, buf as *mut Statx).is_err() {
log::error!("[sys_fstatat] Failed to copy to {:?}", buf);
return EFAULT;
};
Expand All @@ -702,8 +702,6 @@ pub fn sys_statx(dirfd: usize, path: *const u8, buf: *mut u8, flags: u32,) -> is
}
}



#[repr(C)]
#[derive(Clone, Copy)]
pub struct Statfs {
Expand Down
2 changes: 1 addition & 1 deletion os/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 6]) -> isize {
&& ![
//black list
SYSCALL_YIELD,
// SYSCALL_READ,
SYSCALL_READ,
SYSCALL_WRITE,
SYSCALL_GETDENTS64,
SYSCALL_READV,
Expand Down
Empty file modified user/busybox_lua_testsuites/loongarch64/bin/bash
100644 → 100755
Empty file.
Empty file modified user/loongarch64/statx
100644 → 100755
Empty file.
75 changes: 39 additions & 36 deletions user/src/bin/initproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// use std::println;

use user_lib::{exit, exec, fork, wait, waitpid, yield_, shutdown};
use user_lib::{exec, exit, fork, shutdown, wait, waitpid, yield_};

#[no_mangle]
#[link_section = ".text.entry"]
Expand Down Expand Up @@ -32,43 +32,46 @@ fn main() -> i32 {
"LD_LIBRARY_PATH=/\0".as_ptr(),
core::ptr::null(),
];
// if fork() == 0 {
// exec(path, &[path.as_ptr() as *const u8, core::ptr::null()], &environ);
// } else {
// loop {
// let mut exit_code: i32 = 0;
// let pid = wait(&mut exit_code);
// // ECHLD is -10
// if pid == -10 {
// yield_();
// continue;
// }
// user_lib::println!(
// "[initproc] Released a zombie process, pid={}, exit_code={}",
// pid,
// exit_code,
// );
// }
// }
let schedule_text: &str= "
run-all.sh\0
"
;
let mut exit_code: i32 = 0;
for line in schedule_text.lines(){
let argv = [
path.as_ptr(),
"-c\0".as_ptr(),
line.as_ptr(),
core::ptr::null(),
];
let pid = fork();
if pid == 0 {
exec(path, &argv, &environ);
} else {
waitpid(pid as usize, &mut exit_code);
if fork() == 0 {
exec(
path,
&[path.as_ptr() as *const u8, core::ptr::null()],
&environ,
);
} else {
loop {
let mut exit_code: i32 = 0;
let pid = wait(&mut exit_code);
// ECHLD is -10
if pid == -10 {
yield_();
continue;
}
user_lib::println!(
"[initproc] Released a zombie process, pid={}, exit_code={}",
pid,
exit_code,
);
}
}
// let schedule_text: &str = "
// run-all.sh\0
// ";
// let mut exit_code: i32 = 0;
// for line in schedule_text.lines() {
// let argv = [
// path.as_ptr(),
// "-c\0".as_ptr(),
// line.as_ptr(),
// core::ptr::null(),
// ];
// let pid = fork();
// if pid == 0 {
// exec(path, &argv, &environ);
// } else {
// waitpid(pid as usize, &mut exit_code);
// }
// }

shutdown();
0
Expand Down
Empty file modified util/qemu/bin/qemu-loongarch64
100644 → 100755
Empty file.

0 comments on commit ba978e9

Please sign in to comment.