mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 11:16:47 +00:00
parent
004e86ff19
commit
84407d3605
@ -1583,7 +1583,6 @@ impl IndexNode for LockedFATInode {
|
|||||||
if guard.metadata.file_type != FileType::Dir {
|
if guard.metadata.file_type != FileType::Dir {
|
||||||
return Err(-(ENOTDIR as i32));
|
return Err(-(ENOTDIR as i32));
|
||||||
}
|
}
|
||||||
|
|
||||||
match ino {
|
match ino {
|
||||||
0 => {
|
0 => {
|
||||||
return Ok(String::from("."));
|
return Ok(String::from("."));
|
||||||
|
@ -112,7 +112,6 @@ fn do_migrate(
|
|||||||
mountpoint
|
mountpoint
|
||||||
.mount(fs.inner_filesystem())
|
.mount(fs.inner_filesystem())
|
||||||
.expect(format!("Failed to migrate {mountpoint_name}").as_str());
|
.expect(format!("Failed to migrate {mountpoint_name}").as_str());
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,41 +38,41 @@ bitflags! {
|
|||||||
pub struct FileMode: u32{
|
pub struct FileMode: u32{
|
||||||
/* File access modes for `open' and `fcntl'. */
|
/* File access modes for `open' and `fcntl'. */
|
||||||
/// Open Read-only
|
/// Open Read-only
|
||||||
const O_RDONLY = 0;
|
const O_RDONLY = 0o0;
|
||||||
/// Open Write-only
|
/// Open Write-only
|
||||||
const O_WRONLY = 1;
|
const O_WRONLY = 0o1;
|
||||||
/// Open read/write
|
/// Open read/write
|
||||||
const O_RDWR = 2;
|
const O_RDWR = 0o2;
|
||||||
/// Mask for file access modes
|
/// Mask for file access modes
|
||||||
const O_ACCMODE = 00000003;
|
const O_ACCMODE = 0o00000003;
|
||||||
|
|
||||||
/* Bits OR'd into the second argument to open. */
|
/* Bits OR'd into the second argument to open. */
|
||||||
/// Create file if it does not exist
|
/// Create file if it does not exist
|
||||||
const O_CREAT = 00000100;
|
const O_CREAT = 0o00000100;
|
||||||
/// Fail if file already exists
|
/// Fail if file already exists
|
||||||
const O_EXCL = 00000200;
|
const O_EXCL = 0o00000200;
|
||||||
/// Do not assign controlling terminal
|
/// Do not assign controlling terminal
|
||||||
const O_NOCTTY = 00000400;
|
const O_NOCTTY = 0o00000400;
|
||||||
/// 文件存在且是普通文件,并以O_RDWR或O_WRONLY打开,则它会被清空
|
/// 文件存在且是普通文件,并以O_RDWR或O_WRONLY打开,则它会被清空
|
||||||
const O_TRUNC = 00001000;
|
const O_TRUNC = 0o00001000;
|
||||||
/// 文件指针会被移动到文件末尾
|
/// 文件指针会被移动到文件末尾
|
||||||
const O_APPEND = 00002000;
|
const O_APPEND = 0o00002000;
|
||||||
/// 非阻塞式IO模式
|
/// 非阻塞式IO模式
|
||||||
const O_NONBLOCK = 00004000;
|
const O_NONBLOCK = 0o00004000;
|
||||||
/// used to be O_SYNC, see below
|
/// used to be O_SYNC, see below
|
||||||
const O_DSYNC = 00010000;
|
const O_DSYNC = 0o00010000;
|
||||||
/// fcntl, for BSD compatibility
|
/// fcntl, for BSD compatibility
|
||||||
const FASYNC = 00020000;
|
const FASYNC = 0o00020000;
|
||||||
/* direct disk access hint */
|
/* direct disk access hint */
|
||||||
const O_DIRECT = 00040000;
|
const O_DIRECT = 0o00040000;
|
||||||
const O_LARGEFILE = 00100000;
|
const O_LARGEFILE = 0o00100000;
|
||||||
/// 打开的必须是一个目录
|
/// 打开的必须是一个目录
|
||||||
const O_DIRECTORY = 00200000;
|
const O_DIRECTORY = 0o00200000;
|
||||||
/// Do not follow symbolic links
|
/// Do not follow symbolic links
|
||||||
const O_NOFOLLOW = 00400000;
|
const O_NOFOLLOW = 0o00400000;
|
||||||
const O_NOATIME = 01000000;
|
const O_NOATIME = 0o01000000;
|
||||||
/// set close_on_exec
|
/// set close_on_exec
|
||||||
const O_CLOEXEC = 02000000;
|
const O_CLOEXEC = 0o02000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use alloc::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
include::bindings::bindings::{EBUSY, ENOTDIR},
|
include::bindings::bindings::{EBUSY, ENOTDIR},
|
||||||
libs::spinlock::SpinLock, kdebug,
|
libs::spinlock::SpinLock,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{FilePrivateData, FileSystem, FileType, IndexNode, InodeId};
|
use super::{FilePrivateData, FileSystem, FileType, IndexNode, InodeId};
|
||||||
@ -157,9 +157,7 @@ impl IndexNode for MountFSInode {
|
|||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
data: &mut FilePrivateData,
|
data: &mut FilePrivateData,
|
||||||
) -> Result<usize, i32> {
|
) -> Result<usize, i32> {
|
||||||
return self
|
return self.inner_inode.read_at(offset, len, buf, data);
|
||||||
.inner_inode
|
|
||||||
.read_at(offset, len, buf, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_at(
|
fn write_at(
|
||||||
@ -237,16 +235,16 @@ impl IndexNode for MountFSInode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rmdir(&self, name: &str) ->Result<(), i32> {
|
fn rmdir(&self, name: &str) -> Result<(), i32> {
|
||||||
let inode_id = self.inner_inode.find(name)?.metadata()?.inode_id;
|
let inode_id = self.inner_inode.find(name)?.metadata()?.inode_id;
|
||||||
kdebug!("rmdir {name}");
|
|
||||||
// 先检查这个inode是否为一个挂载点,如果当前inode是一个挂载点,那么就不能删除这个inode
|
// 先检查这个inode是否为一个挂载点,如果当前inode是一个挂载点,那么就不能删除这个inode
|
||||||
if self.mount_fs.mountpoints.lock().contains_key(&inode_id) {
|
if self.mount_fs.mountpoints.lock().contains_key(&inode_id) {
|
||||||
return Err(-(EBUSY as i32));
|
return Err(-(EBUSY as i32));
|
||||||
}
|
}
|
||||||
// 调用内层的rmdir的方法来删除这个inode
|
// 调用内层的rmdir的方法来删除这个inode
|
||||||
let r = self.inner_inode.rmdir(name);
|
let r = self.inner_inode.rmdir(name);
|
||||||
kdebug!("r={r:?}");
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
use core::ffi::{c_char, CStr};
|
use core::ffi::{c_char, CStr};
|
||||||
|
|
||||||
use alloc::{
|
use alloc::{boxed::Box, string::ToString};
|
||||||
boxed::Box,
|
|
||||||
string::{String, ToString},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::asm::{current::current_pcb, ptrace::user_mode},
|
arch::asm::{current::current_pcb, ptrace::user_mode},
|
||||||
@ -12,7 +9,7 @@ use crate::{
|
|||||||
EPERM, PAGE_2M_SIZE, PAGE_4K_SIZE, PROC_MAX_FD_NUM, SEEK_CUR, SEEK_END, SEEK_MAX, SEEK_SET,
|
EPERM, PAGE_2M_SIZE, PAGE_4K_SIZE, PROC_MAX_FD_NUM, SEEK_CUR, SEEK_END, SEEK_MAX, SEEK_SET,
|
||||||
},
|
},
|
||||||
io::SeekFrom,
|
io::SeekFrom,
|
||||||
kdebug, kerror,
|
kerror,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -36,7 +33,6 @@ pub extern "C" fn sys_open(regs: &pt_regs) -> u64 {
|
|||||||
}
|
}
|
||||||
let path: &str = path.unwrap();
|
let path: &str = path.unwrap();
|
||||||
let flags = regs.r9;
|
let flags = regs.r9;
|
||||||
|
|
||||||
let open_flags: FileMode = FileMode::from_bits_truncate(flags as u32);
|
let open_flags: FileMode = FileMode::from_bits_truncate(flags as u32);
|
||||||
let r: Result<i32, i32> = do_open(path, open_flags);
|
let r: Result<i32, i32> = do_open(path, open_flags);
|
||||||
|
|
||||||
@ -191,7 +187,6 @@ pub extern "C" fn sys_chdir(regs: &pt_regs) -> u64 {
|
|||||||
|
|
||||||
let dest_path: &str = dest_path.unwrap();
|
let dest_path: &str = dest_path.unwrap();
|
||||||
|
|
||||||
kdebug!("chdir: dest_path={dest_path}");
|
|
||||||
if dest_path.len() == 0 {
|
if dest_path.len() == 0 {
|
||||||
return (-(EINVAL as i32)) as u64;
|
return (-(EINVAL as i32)) as u64;
|
||||||
} else if dest_path.len() >= PAGE_4K_SIZE as usize {
|
} else if dest_path.len() >= PAGE_4K_SIZE as usize {
|
||||||
@ -286,7 +281,7 @@ pub extern "C" fn sys_mkdir(regs: &pt_regs) -> u64 {
|
|||||||
return (-(EINVAL as i32)) as u64;
|
return (-(EINVAL as i32)) as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
return match do_mkdir(&path, FileMode::from_bits_truncate(mode as u32)) {
|
return match do_mkdir(&path.trim(), FileMode::from_bits_truncate(mode as u32)) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
kerror!("Failed in do_mkdir, Error Code = {}", err);
|
kerror!("Failed in do_mkdir, Error Code = {}", err);
|
||||||
err as u64
|
err as u64
|
||||||
|
@ -39,6 +39,7 @@ extern crate lazy_static;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
|
|
||||||
|
|
||||||
use mm::allocator::KernelAllocator;
|
use mm::allocator::KernelAllocator;
|
||||||
|
|
||||||
// <3>
|
// <3>
|
||||||
|
@ -289,7 +289,6 @@ extern uint64_t sys_chdir(struct pt_regs *regs);
|
|||||||
*/
|
*/
|
||||||
extern uint64_t sys_getdents(struct pt_regs *regs);
|
extern uint64_t sys_getdents(struct pt_regs *regs);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 执行新的程序
|
* @brief 执行新的程序
|
||||||
*
|
*
|
||||||
@ -407,13 +406,13 @@ void do_syscall_int(struct pt_regs *regs, unsigned long error_code)
|
|||||||
ul ret = system_call_table[regs->rax](regs);
|
ul ret = system_call_table[regs->rax](regs);
|
||||||
regs->rax = ret; // 返回码
|
regs->rax = ret; // 返回码
|
||||||
}
|
}
|
||||||
uint64_t sys_pipe(struct pt_regs *regs){
|
uint64_t sys_pipe(struct pt_regs *regs)
|
||||||
|
{
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint64_t sys_mkdir(struct pt_regs *regs);
|
extern uint64_t sys_mkdir(struct pt_regs *regs);
|
||||||
|
|
||||||
|
|
||||||
system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
|
system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
|
||||||
[0] = system_call_not_exists,
|
[0] = system_call_not_exists,
|
||||||
[1] = sys_put_string,
|
[1] = sys_put_string,
|
||||||
@ -427,18 +426,18 @@ system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
|
|||||||
[9] = sys_brk,
|
[9] = sys_brk,
|
||||||
[10] = sys_sbrk,
|
[10] = sys_sbrk,
|
||||||
[11] = sys_reboot,
|
[11] = sys_reboot,
|
||||||
[12] = sys_chdir,
|
[12] = sys_chdir,
|
||||||
[13] = sys_getdents,
|
[13] = sys_getdents,
|
||||||
[14] = sys_execve,
|
[14] = sys_execve,
|
||||||
[15] = sys_wait4,
|
[15] = sys_wait4,
|
||||||
[16] = sys_exit,
|
[16] = sys_exit,
|
||||||
[17] = sys_mkdir,
|
[17] = sys_mkdir,
|
||||||
[18] = sys_nanosleep,
|
[18] = sys_nanosleep,
|
||||||
[19] = sys_clock,
|
[19] = sys_clock,
|
||||||
[20] = sys_pipe,
|
[20] = sys_pipe,
|
||||||
[21] = sys_mstat,
|
[21] = sys_mstat,
|
||||||
[22] = sys_unlink_at,
|
[22] = sys_unlink_at,
|
||||||
[23] = sys_kill,
|
[23] = sys_kill,
|
||||||
[24] = sys_sigaction,
|
[24] = sys_sigaction,
|
||||||
[25] = sys_rt_sigreturn,
|
[25] = sys_rt_sigreturn,
|
||||||
[26] = sys_getpid,
|
[26] = sys_getpid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user