添加mount系统调用 (#561)

* Modify dadk config to switch NovaShell revision

* finish primary build of mount(2), usable now

* 使用read_from_cstr函数优化代码可读性 , 针对文件系统新增错误EUNSUPFS

* small changes

* 添加系统调用文档

* cargo fmt

* Revert "small changes"

This reverts commit e1991314ce.

* 修复用户程序参数传入错误

* Revert "small changes"

This reverts commit e1991314ce.

* 解决合并冲突,最终提交

* 将dadk_config切换为相对路径以修复依赖问题

* Update settings.json

* Delete user/apps/test-mount/LICENSE

* 换用更好的c字符串读取函数,优化系统调用函数注释,修复错误处理bug,删除无用文件,修改测试程序readme

* 修改用户程序readme

* 代码格式化,初级版本

* 初级版本,未实现文件系统管理器,未支持设备挂载

* 为文件系统添加name方法,返回文件系统名字字符串,为挂载查询服务

* mount系统调用:添加统一文件系统初始化管理器

* null

* 解除冲突

* 删除无用kdebug
This commit is contained in:
Donkey Kane
2024-03-20 15:31:20 +08:00
committed by GitHub
parent 1cd9bb43f0
commit 1d37ca6d17
19 changed files with 265 additions and 16 deletions

3
user/apps/test-mount/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/target
Cargo.lock
/install/

View File

@ -0,0 +1,11 @@
[package]
name = "test-mount"
version = "0.1.0"
edition = "2021"
description = "test the new mount syscall"
authors = [ "xiaolin2004 <1553367438@qq.com>" ]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc="0.2"

View File

@ -0,0 +1,56 @@
TOOLCHAIN="+nightly-2023-08-15-x86_64-unknown-linux-gnu"
RUSTFLAGS+=""
ifdef DADK_CURRENT_BUILD_DIR
# 如果是在dadk中编译那么安装到dadk的安装目录中
INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR)
else
# 如果是在本地编译那么安装到当前目录下的install目录中
INSTALL_DIR = ./install
endif
ifeq ($(ARCH), x86_64)
export RUST_TARGET=x86_64-unknown-linux-musl
else ifeq ($(ARCH), riscv64)
export RUST_TARGET=riscv64gc-unknown-linux-gnu
else
# 默认为x86_86用于本地编译
export RUST_TARGET=x86_64-unknown-linux-musl
endif
run:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET)
build:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET)
clean:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET)
test:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET)
doc:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) doc --target $(RUST_TARGET)
fmt:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt
fmt-check:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) fmt --check
run-release:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) run --target $(RUST_TARGET) --release
build-release:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release
clean-release:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) clean --target $(RUST_TARGET) --release
test-release:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) test --target $(RUST_TARGET) --release
.PHONY: install
install:
RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) install --target $(RUST_TARGET) --path . --no-track --root $(INSTALL_DIR) --force

View File

@ -0,0 +1,3 @@
# test-mount
用于测试mount系统调用的用户程序

View File

@ -0,0 +1,17 @@
use core::ffi::{c_char, c_void};
use libc::{mount, MS_BIND};
fn main() {
let source = b"\0".as_ptr() as *const c_char;
let target = b"/mnt/tmp\0".as_ptr() as *const c_char;
let fstype = b"ramfs\0".as_ptr() as *const c_char;
let flags = MS_BIND;
let data = std::ptr::null() as *const c_void;
let result = unsafe { mount(source, target, fstype, flags, data) };
if result == 0 {
println!("Mount successful");
} else {
println!("Mount failed");
}
}