Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ compile_commands.json
/fw_dynamic.bin

*.asm
disk.img
*.img
actual.out
qemu.log
*.log
rusty-tags.vi
apps/c/redis/
apps/c/iperf/
Expand Down
50 changes: 50 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ else ifeq ($(FS), fat32)
$(call make_disk_image,fat32,$(DISK_IMG))
else ifeq ($(FS), ext4)
$(call make_disk_image,ext4,$(DISK_IMG))
else ifeq ($(FS), exfat)
$(call make_disk_image,exfat,$(DISK_IMG))
else
$(error "FS" must be one of "fat32" or "ext4")
$(error "FS" must be one of "fat32" or "ext4" or "exfat")
endif

clean: clean_c clean_musl
Expand Down
3 changes: 3 additions & 0 deletions api/ruxfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sched_cfs = ["ruxtask/sched_cfs", "irq"]
# File system
fs = ["alloc", "dep:ruxfs", "ruxruntime/fs"]
blkfs = ["ruxdriver/virtio-blk", "ruxruntime/blkfs", "ruxfs/blkfs"]
fusefs = ["ruxruntime/fusefs"]
myfs = ["ruxfs?/myfs"]
9pfs = []
fatfs = ["ruxfs?/fatfs"]
Expand Down Expand Up @@ -120,6 +121,8 @@ ruxdriver = { path = "../../modules/ruxdriver", optional = true }
ruxfs = { path = "../../modules/ruxfs", optional = true }
rux9p = { path = "../../modules/rux9p", optional = true }
ruxnet = { path = "../../modules/ruxnet", optional = true }
ruxfuse = { path = "../../modules/ruxfuse", optional = true }
ruxvda = { path = "../../modules/ruxvda", optional = true }
ruxdisplay = { path = "../../modules/ruxdisplay", optional = true }
axsync = { path = "../../modules/axsync", optional = true }
ruxtask = { path = "../../modules/ruxtask", optional = true }
Expand Down
5 changes: 3 additions & 2 deletions api/ruxos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ default = []
smp = ["ruxfeat/smp"]
alloc = ["dep:axalloc", "ruxfeat/alloc"]
paging = ["alloc", "ruxfeat/paging", "ruxmm"]
multitask = ["ruxfeat/multitask", "ruxtask/multitask", "dep:ruxfutex"]
multitask = ["ruxfeat/multitask", "ruxfuse/multitask", "ruxtask/multitask", "dep:ruxfutex"]
fd = ["alloc"]
fs = ["dep:ruxfs", "ruxfeat/fs", "fd"]
fs = ["dep:ruxfs", "ruxfeat/fs", "fd", "ruxfuse"]
net = ["dep:ruxnet", "ruxfeat/net", "fd"]
signal = ["ruxruntime/signal", "ruxhal/signal", "ruxtask/signal"]
pipe = ["fd"]
Expand Down Expand Up @@ -50,6 +50,7 @@ ruxtask = { path = "../../modules/ruxtask", features = [
"notest",
], optional = true }
ruxfs = { path = "../../modules/ruxfs", optional = true }
ruxfuse = { path = "../../modules/ruxfuse", optional = true }
ruxnet = { path = "../../modules/ruxnet", optional = true }

# Other crates
Expand Down
90 changes: 85 additions & 5 deletions api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
* See the Mulan PSL v2 for more details.
*/

use alloc::string::String;
use alloc::sync::Arc;
use core::{
ffi::{c_char, c_int, c_long, c_void, CStr},
ffi::{c_char, c_int, c_long, c_ulong, c_void, CStr},
str,
};

use ruxfs::{api::FileType, fops::lookup, FilePerm};
use ruxfs::{api::FileType, fops::lookup, FilePerm, MountPoint};

use axerrno::{LinuxError, LinuxResult};
use axio::{Error, SeekFrom};
Expand All @@ -23,7 +24,7 @@ use ruxfs::{
AbsPath, DirEntry, Directory, File, RelPath,
};

use crate::ctypes;
use crate::{ctypes, utils::char_ptr_to_str};
use ruxtask::fs::{add_file_like, get_file_like, get_umask};

use super::stdio::{Stdin, Stdout};
Expand Down Expand Up @@ -547,7 +548,7 @@ pub unsafe fn sys_getdents64(fd: c_int, dirp: *mut LinuxDirent64, count: ctypes:

let name = entry.name_as_bytes();
let name_len = name.len();
let entry_size = DIRENT64_FIXED_SIZE + name_len + 1;
let entry_size = (DIRENT64_FIXED_SIZE + name_len + 1 + 7) & !7; // align to 8 bytes

// buf not big enough to hold the entry
if written + entry_size > count {
Expand All @@ -562,7 +563,7 @@ pub unsafe fn sys_getdents64(fd: c_int, dirp: *mut LinuxDirent64, count: ctypes:
unsafe { &mut *(buf.as_mut_ptr().add(written) as *mut LinuxDirent64) };
// set fixed-size fields
dirent.d_ino = 1;
dirent.d_off = offset as i64;
dirent.d_off = (offset + 1) as i64;
dirent.d_reclen = entry_size as u16;
dirent.d_type = entry.entry_type() as u8;
// set file name
Expand Down Expand Up @@ -632,6 +633,85 @@ pub fn sys_chdir(path: *const c_char) -> c_int {
})
}

pub const MS_NODEV: u32 = 2;
pub const MS_NOSUID: u32 = 4;

/// umount a filesystem at a specific location in the filesystem tree
pub fn sys_umount2(target: *const c_char, flags: c_int) -> c_int {
info!(
"sys_umount2 <= target: {:?}, flags: {:#x}",
char_ptr_to_str(target),
flags
);
syscall_body!(sys_umount2, {
let target = char_ptr_to_str(target)?;
let dir = ruxtask::current()
.fs
.lock()
.as_mut()
.unwrap()
.root_dir
.clone();
dir.umount(&AbsPath::new(target));
Ok(0)
})
}

/// mount a filesystem at a specific location in the filesystem tree
pub fn sys_mount(
source: *const c_char,
raw_target: *const c_char,
filesystemtype: *const c_char,
mountflags: c_ulong,
data: *const c_void,
) -> c_int {
info!(
"sys_mount <= source: {:?}, target: {:?}, filesystemtype: {:?}, mountflags: {:#x}, data: {:p}",
char_ptr_to_str(source),
char_ptr_to_str(raw_target),
char_ptr_to_str(filesystemtype),
mountflags,
data
);
syscall_body!(sys_mount, {
let f1 = MS_NODEV; //ctypes::MS_NODEV;
let f2 = MS_NOSUID; //ctypes::MS_NOSUID;
info!(
"mount flags: {:#x}, f1: {:#}, f2: {:#}, flag: {:#}",
mountflags,
f1,
f2,
f1 | f2
);
if mountflags != (f1 | f2).into() {
warn!("mount flags not supported: {:#x}", mountflags);
}

let target = char_ptr_to_str(raw_target)?;
let target = String::from(target);
let dir = ruxtask::current()
.fs
.lock()
.as_mut()
.unwrap()
.root_dir
.clone();
let vfsops = ruxfuse::fuse::fusefs();
info!("mounting filesystem at {}", target);
dir.mount(MountPoint {
path: target,
fs: vfsops,
})?;
Ok(0)
})
}

/// perform a memory barrier operation.
pub fn sys_membarrier(cmd: c_int, flags: c_int) -> c_int {
info!("sys_membarrier <= cmd: {}, flags: {}", cmd, flags);
syscall_body!(sys_membarrier, Ok(0))
}

/// from char_ptr get path_str
fn char_ptr_to_path_str<'a>(ptr: *const c_char) -> LinuxResult<&'a str> {
if ptr.is_null() {
Expand Down
8 changes: 4 additions & 4 deletions api/ruxos_posix_api/src/imp/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ pub fn sys_setpgid(pid: pid_t, pgid: pid_t) -> c_int {
syscall_body!(sys_setpgid, Ok(0))
}

/// set process sid (empty implementation)
/// set process sid and create a new session (return 1000)
///
/// TODO:
pub fn sys_setsid() -> c_int {
warn!("sys_setsid: do nothing",);
syscall_body!(sys_setsid, Ok(0))
pub fn sys_setsid() -> pid_t {
info!("sys_setsid: create a new session");
syscall_body!(sys_setsid, Ok(1000))
}
7 changes: 4 additions & 3 deletions api/ruxos_posix_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl};
#[cfg(feature = "fs")]
pub use imp::fs::{
sys_chdir, sys_faccessat, sys_fchmodat, sys_fchownat, sys_fdatasync, sys_fstat, sys_fsync,
sys_ftruncate, sys_getcwd, sys_getdents64, sys_lseek, sys_lstat, sys_mkdir, sys_mkdirat,
sys_mknodat, sys_newfstatat, sys_open, sys_openat, sys_pread64, sys_preadv, sys_pwrite64,
sys_readlinkat, sys_rename, sys_renameat, sys_rmdir, sys_stat, sys_unlink, sys_unlinkat,
sys_ftruncate, sys_getcwd, sys_getdents64, sys_lseek, sys_lstat, sys_membarrier, sys_mkdir,
sys_mkdirat, sys_mknodat, sys_mount, sys_newfstatat, sys_open, sys_openat, sys_pread64,
sys_preadv, sys_pwrite64, sys_readlinkat, sys_rename, sys_renameat, sys_rmdir, sys_stat,
sys_umount2, sys_unlink, sys_unlinkat,
};
#[cfg(feature = "epoll")]
pub use imp::io_mpx::{sys_epoll_create1, sys_epoll_ctl, sys_epoll_pwait, sys_epoll_wait};
Expand Down
Empty file added apps/c/helloworld/features.txt
Empty file.
6 changes: 5 additions & 1 deletion crates/axerrno/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ pub enum AxError {
/// It is a temporary error code that usually returns when a non_blocking operation
/// is not completed, prompting the caller to try again later.
InProgress,
/// The function is not implemented.
FunctionNotImplemented,
/// Not a tty device
NoTty,
}
Expand Down Expand Up @@ -249,6 +251,7 @@ impl AxError {
WouldBlock => "Operation would block",
WriteZero => "Write zero",
InProgress => "non_blocking operation is not completed",
FunctionNotImplemented => "Function not implemented",
NoTty => "not a tty device",
}
}
Expand Down Expand Up @@ -302,6 +305,7 @@ impl From<AxError> for LinuxError {
UnexpectedEof | WriteZero => LinuxError::EIO,
WouldBlock => LinuxError::EAGAIN,
InProgress => LinuxError::EINPROGRESS,
FunctionNotImplemented => LinuxError::ENOSYS,
NoTty => LinuxError::ENOTTY,
}
}
Expand All @@ -325,7 +329,7 @@ mod tests {
#[test]
fn test_try_from() {
let max_code = core::mem::variant_count::<AxError>() as i32;
assert_eq!(max_code, 24);
assert_eq!(max_code, 25);
assert_eq!(max_code, AxError::NoTty.code());

assert_eq!(AxError::AddrInUse.code(), 1);
Expand Down
10 changes: 3 additions & 7 deletions crates/axfs_devfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub use self::random::RandomDev;
pub use self::zero::ZeroDev;

use alloc::sync::Arc;
use axfs_vfs::{AbsPath, VfsNodePerm, VfsNodeRef, VfsOps, VfsResult};
use axfs_vfs::{VfsNodePerm, VfsNodeRef, VfsOps, VfsResult};
use core::sync::atomic::AtomicU64;
use spin::once::Once;

Expand Down Expand Up @@ -87,12 +87,8 @@ impl DeviceFileSystem {
}

impl VfsOps for DeviceFileSystem {
fn mount(&self, _path: &AbsPath, mount_point: VfsNodeRef) -> VfsResult {
if let Some(parent) = mount_point.parent() {
self.root.set_parent(Some(self.parent.call_once(|| parent)));
} else {
self.root.set_parent(None);
}
fn mount(&self, parent: VfsNodeRef) -> VfsResult {
self.root.set_parent(Some(self.parent.call_once(|| parent)));
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions crates/axfs_devfs/src/pts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! Slave: Emulates physical terminal hardware for programs
use alloc::collections::BinaryHeap;
use alloc::sync::Arc;
use axfs_vfs::{AbsPath, VfsNodeRef, VfsOps, VfsResult};
use axfs_vfs::{VfsNodeRef, VfsOps, VfsResult};
use core::cmp::Reverse;
use master::PtyMaster;
use ptmx::Ptmx;
Expand Down Expand Up @@ -127,8 +127,8 @@ impl PtsFileSystem {
}

impl VfsOps for PtsFileSystem {
fn mount(&self, _path: &AbsPath, mount_point: VfsNodeRef) -> VfsResult {
self.root.set_parent(&mount_point.parent().unwrap());
fn mount(&self, parent: VfsNodeRef) -> VfsResult {
self.root.set_parent(&parent);
Ok(())
}

Expand Down
Loading
Loading