Skip to content

Commit e2f4151

Browse files
authored
Merge branch 'dev' into update_virtio
2 parents 8af3e62 + c5650c9 commit e2f4151

46 files changed

Lines changed: 6748 additions & 194 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ compile_commands.json
1010
/fw_dynamic.bin
1111

1212
*.asm
13-
disk.img
13+
*.img
1414
actual.out
15-
qemu.log
15+
*.log
1616
rusty-tags.vi
1717
apps/c/redis/
1818
apps/c/iperf/

Cargo.lock

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,10 @@ else ifeq ($(FS), fat32)
270270
$(call make_disk_image,fat32,$(DISK_IMG))
271271
else ifeq ($(FS), ext4)
272272
$(call make_disk_image,ext4,$(DISK_IMG))
273+
else ifeq ($(FS), exfat)
274+
$(call make_disk_image,exfat,$(DISK_IMG))
273275
else
274-
$(error "FS" must be one of "fat32" or "ext4")
276+
$(error "FS" must be one of "fat32" or "ext4" or "exfat")
275277
endif
276278

277279
clean: clean_c clean_musl

api/ruxfeat/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ sched_cfs = ["ruxtask/sched_cfs", "irq"]
5555
# File system
5656
fs = ["alloc", "dep:ruxfs", "ruxruntime/fs"]
5757
blkfs = ["ruxdriver/virtio-blk", "ruxruntime/blkfs", "ruxfs/blkfs"]
58+
fusefs = ["ruxruntime/fusefs"]
5859
myfs = ["ruxfs?/myfs"]
5960
9pfs = []
6061
fatfs = ["ruxfs?/fatfs"]
@@ -114,6 +115,8 @@ ruxdriver = { path = "../../modules/ruxdriver", optional = true }
114115
ruxfs = { path = "../../modules/ruxfs", optional = true }
115116
rux9p = { path = "../../modules/rux9p", optional = true }
116117
ruxnet = { path = "../../modules/ruxnet", optional = true }
118+
ruxfuse = { path = "../../modules/ruxfuse", optional = true }
119+
ruxvda = { path = "../../modules/ruxvda", optional = true }
117120
ruxdisplay = { path = "../../modules/ruxdisplay", optional = true }
118121
axsync = { path = "../../modules/axsync", optional = true }
119122
ruxtask = { path = "../../modules/ruxtask", optional = true }

api/ruxos_posix_api/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ default = []
2020
smp = ["ruxfeat/smp"]
2121
alloc = ["dep:axalloc", "ruxfeat/alloc"]
2222
paging = ["alloc", "ruxfeat/paging", "ruxmm"]
23-
multitask = ["ruxfeat/multitask", "ruxtask/multitask", "dep:ruxfutex"]
23+
multitask = ["ruxfeat/multitask", "ruxfuse/multitask", "ruxtask/multitask", "dep:ruxfutex"]
2424
fd = ["alloc"]
25-
fs = ["dep:ruxfs", "ruxfeat/fs", "fd"]
25+
fs = ["dep:ruxfs", "ruxfeat/fs", "fd", "ruxfuse"]
2626
net = ["dep:ruxnet", "ruxfeat/net", "fd"]
2727
signal = ["ruxruntime/signal", "ruxhal/signal", "ruxtask/signal"]
2828
pipe = ["fd"]
@@ -50,6 +50,7 @@ ruxtask = { path = "../../modules/ruxtask", features = [
5050
"notest",
5151
], optional = true }
5252
ruxfs = { path = "../../modules/ruxfs", optional = true }
53+
ruxfuse = { path = "../../modules/ruxfuse", optional = true }
5354
ruxnet = { path = "../../modules/ruxnet", optional = true }
5455

5556
# Other crates

api/ruxos_posix_api/src/imp/fd_ops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl From<ctypes::timespec> for RuxTimeSpec {
2626
}
2727

2828
impl From<ctypes::stat> for RuxStat {
29-
#[cfg(target_arch = "aarch64")]
29+
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
3030
fn from(cstat: ctypes::stat) -> Self {
3131
RuxStat {
3232
st_dev: cstat.st_dev,
@@ -48,7 +48,7 @@ impl From<ctypes::stat> for RuxStat {
4848
}
4949
}
5050

51-
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
51+
#[cfg(target_arch = "x86_64")]
5252
fn from(cstat: ctypes::stat) -> Self {
5353
RuxStat {
5454
st_dev: cstat.st_dev,
@@ -80,7 +80,7 @@ impl From<RuxTimeSpec> for ctypes::timespec {
8080
}
8181

8282
impl From<RuxStat> for ctypes::stat {
83-
#[cfg(target_arch = "aarch64")]
83+
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
8484
fn from(rstat: RuxStat) -> Self {
8585
ctypes::stat {
8686
st_dev: rstat.st_dev,
@@ -102,7 +102,7 @@ impl From<RuxStat> for ctypes::stat {
102102
}
103103
}
104104

105-
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
105+
#[cfg(target_arch = "x86_64")]
106106
fn from(rstat: RuxStat) -> Self {
107107
ctypes::stat {
108108
st_dev: rstat.st_dev,

api/ruxos_posix_api/src/imp/fs.rs

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
* See the Mulan PSL v2 for more details.
88
*/
99

10+
use alloc::string::String;
1011
use alloc::sync::Arc;
1112
use core::{
12-
ffi::{c_char, c_int, c_long, c_void, CStr},
13+
ffi::{c_char, c_int, c_long, c_ulong, c_void, CStr},
1314
str,
1415
};
1516

16-
use ruxfs::{api::FileType, fops::lookup, FilePerm};
17+
use ruxfs::{api::FileType, fops::lookup, FilePerm, MountPoint};
1718

1819
use axerrno::{LinuxError, LinuxResult};
1920
use axio::{Error, SeekFrom};
@@ -23,7 +24,7 @@ use ruxfs::{
2324
AbsPath, DirEntry, Directory, File, RelPath,
2425
};
2526

26-
use crate::ctypes;
27+
use crate::{ctypes, utils::char_ptr_to_str};
2728
use ruxtask::fs::{add_file_like, get_file_like, get_umask};
2829

2930
use super::stdio::{Stdin, Stdout};
@@ -256,6 +257,12 @@ pub unsafe fn sys_newfstatat(
256257
}
257258
let node = fops::lookup(&path)?;
258259
let st = RuxStat::from(node.get_attr()?);
260+
261+
// TODO: remove this initialization when fields are fully implemented
262+
unsafe {
263+
core::ptr::write_bytes(kst, 0, 1);
264+
}
265+
259266
unsafe {
260267
(*kst).st_dev = st.st_dev;
261268
(*kst).st_ino = st.st_ino;
@@ -278,7 +285,7 @@ pub fn sys_getcwd(buf: *mut c_char, size: usize) -> c_int {
278285
if buf.is_null() {
279286
return Err(LinuxError::EINVAL);
280287
}
281-
let dst = unsafe { core::slice::from_raw_parts_mut(buf as *mut u8, size as _) };
288+
let dst: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(buf as _, size as _) };
282289
let cwd = fops::current_dir()?;
283290
let cwd = cwd.as_bytes();
284291
if cwd.len() < size {
@@ -547,7 +554,7 @@ pub unsafe fn sys_getdents64(fd: c_int, dirp: *mut LinuxDirent64, count: ctypes:
547554

548555
let name = entry.name_as_bytes();
549556
let name_len = name.len();
550-
let entry_size = DIRENT64_FIXED_SIZE + name_len + 1;
557+
let entry_size = (DIRENT64_FIXED_SIZE + name_len + 1 + 7) & !7; // align to 8 bytes
551558

552559
// buf not big enough to hold the entry
553560
if written + entry_size > count {
@@ -562,7 +569,7 @@ pub unsafe fn sys_getdents64(fd: c_int, dirp: *mut LinuxDirent64, count: ctypes:
562569
unsafe { &mut *(buf.as_mut_ptr().add(written) as *mut LinuxDirent64) };
563570
// set fixed-size fields
564571
dirent.d_ino = 1;
565-
dirent.d_off = offset as i64;
572+
dirent.d_off = (offset + 1) as i64;
566573
dirent.d_reclen = entry_size as u16;
567574
dirent.d_type = entry.entry_type() as u8;
568575
// set file name
@@ -632,6 +639,85 @@ pub fn sys_chdir(path: *const c_char) -> c_int {
632639
})
633640
}
634641

642+
pub const MS_NODEV: u32 = 2;
643+
pub const MS_NOSUID: u32 = 4;
644+
645+
/// umount a filesystem at a specific location in the filesystem tree
646+
pub fn sys_umount2(target: *const c_char, flags: c_int) -> c_int {
647+
info!(
648+
"sys_umount2 <= target: {:?}, flags: {:#x}",
649+
char_ptr_to_str(target),
650+
flags
651+
);
652+
syscall_body!(sys_umount2, {
653+
let target = char_ptr_to_str(target)?;
654+
let dir = ruxtask::current()
655+
.fs
656+
.lock()
657+
.as_mut()
658+
.unwrap()
659+
.root_dir
660+
.clone();
661+
dir.umount(&AbsPath::new(target));
662+
Ok(0)
663+
})
664+
}
665+
666+
/// mount a filesystem at a specific location in the filesystem tree
667+
pub fn sys_mount(
668+
source: *const c_char,
669+
raw_target: *const c_char,
670+
filesystemtype: *const c_char,
671+
mountflags: c_ulong,
672+
data: *const c_void,
673+
) -> c_int {
674+
info!(
675+
"sys_mount <= source: {:?}, target: {:?}, filesystemtype: {:?}, mountflags: {:#x}, data: {:p}",
676+
char_ptr_to_str(source),
677+
char_ptr_to_str(raw_target),
678+
char_ptr_to_str(filesystemtype),
679+
mountflags,
680+
data
681+
);
682+
syscall_body!(sys_mount, {
683+
let f1 = MS_NODEV; //ctypes::MS_NODEV;
684+
let f2 = MS_NOSUID; //ctypes::MS_NOSUID;
685+
info!(
686+
"mount flags: {:#x}, f1: {:#}, f2: {:#}, flag: {:#}",
687+
mountflags,
688+
f1,
689+
f2,
690+
f1 | f2
691+
);
692+
if mountflags != (f1 | f2).into() {
693+
warn!("mount flags not supported: {:#x}", mountflags);
694+
}
695+
696+
let target = char_ptr_to_str(raw_target)?;
697+
let target = String::from(target);
698+
let dir = ruxtask::current()
699+
.fs
700+
.lock()
701+
.as_mut()
702+
.unwrap()
703+
.root_dir
704+
.clone();
705+
let vfsops = ruxfuse::fuse::fusefs();
706+
info!("mounting filesystem at {}", target);
707+
dir.mount(MountPoint {
708+
path: target,
709+
fs: vfsops,
710+
})?;
711+
Ok(0)
712+
})
713+
}
714+
715+
/// perform a memory barrier operation.
716+
pub fn sys_membarrier(cmd: c_int, flags: c_int) -> c_int {
717+
info!("sys_membarrier <= cmd: {}, flags: {}", cmd, flags);
718+
syscall_body!(sys_membarrier, Ok(0))
719+
}
720+
635721
/// from char_ptr get path_str
636722
fn char_ptr_to_path_str<'a>(ptr: *const c_char) -> LinuxResult<&'a str> {
637723
if ptr.is_null() {

api/ruxos_posix_api/src/imp/mmap/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn sys_mmap(
4444
off: ctypes::off_t,
4545
) -> *mut c_void {
4646
debug!(
47-
"sys_mmap <= start: {:p}, len: 0x{:x}, prot:0x{:x?}, flags:0x{:x?}, fd: {}",
48-
start, len, prot, flags, fd
47+
"sys_mmap <= start: {:p}, len: 0x{:x}, prot:0x{:x?}, flags:0x{:x?}, fd: {}, off: 0x{:x}",
48+
start, len, prot, flags, fd, off
4949
);
5050
syscall_body!(sys_mmap, {
5151
// transform C-type into rust-type

api/ruxos_posix_api/src/imp/mmap/trap.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ impl ruxhal::trap::TrapHandler for TrapHandlerImpl {
4444
let mut binding_mem_map = binding_task.mm.vma_map.lock();
4545
let vma_map = binding_mem_map.deref_mut();
4646
if let Some((_, vma)) = vma_map.upper_bound(Bound::Included(&vaddr)).peek_prev() {
47-
// error!("vaddr=({:#x?}, {:#x?}) {:#x?}", vma.start_addr, vma.end_addr, vaddr);
47+
trace!(
48+
"vaddr=({:#x?}, {:#x?}) {:#x?} {:#x?}",
49+
vma.start_addr,
50+
vma.end_addr,
51+
vaddr,
52+
cause
53+
);
4854
let vma_end_aligned = vma.end_addr;
4955
// Check if page existing in the vma, go to panic if not.
5056
if vma_end_aligned <= vaddr {

api/ruxos_posix_api/src/imp/stat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ pub fn sys_setpgid(pid: pid_t, pgid: pid_t) -> c_int {
6868
syscall_body!(sys_setpgid, Ok(0))
6969
}
7070

71-
/// set process sid (empty implementation)
71+
/// set process sid and create a new session (return 1000)
7272
///
7373
/// TODO:
74-
pub fn sys_setsid() -> c_int {
75-
warn!("sys_setsid: do nothing",);
76-
syscall_body!(sys_setsid, Ok(0))
74+
pub fn sys_setsid() -> pid_t {
75+
info!("sys_setsid: create a new session");
76+
syscall_body!(sys_setsid, Ok(1000))
7777
}

0 commit comments

Comments
 (0)