Jelajahi Sumber

bugfix:解决touch命令失败的问题 (#199)

* bug fix : 解决touch命令失败的问题
login 2 tahun lalu
induk
melakukan
84407d3605

+ 0 - 1
kernel/src/filesystem/fat/fs.rs

@@ -1583,7 +1583,6 @@ impl IndexNode for LockedFATInode {
         if guard.metadata.file_type != FileType::Dir {
             return Err(-(ENOTDIR as i32));
         }
-
         match ino {
             0 => {
                 return Ok(String::from("."));

+ 0 - 1
kernel/src/filesystem/vfs/core.rs

@@ -112,7 +112,6 @@ fn do_migrate(
     mountpoint
         .mount(fs.inner_filesystem())
         .expect(format!("Failed to migrate {mountpoint_name}").as_str());
-
     return Ok(());
 }
 

+ 18 - 18
kernel/src/filesystem/vfs/file.rs

@@ -38,41 +38,41 @@ bitflags! {
     pub struct FileMode: u32{
     /* File access modes for `open' and `fcntl'.  */
     /// Open Read-only
-    const O_RDONLY = 0;
+    const O_RDONLY = 0o0;
     /// Open Write-only
-    const O_WRONLY = 1;
+    const O_WRONLY = 0o1;
     /// Open read/write
-    const O_RDWR = 2;
+    const O_RDWR = 0o2;
     /// Mask for file access modes
-    const O_ACCMODE = 00000003;
+    const O_ACCMODE = 0o00000003;
 
     /* Bits OR'd into the second argument to open.  */
     /// Create file if it does not exist
-    const O_CREAT = 00000100;
+    const O_CREAT = 0o00000100;
     /// Fail if file already exists
-    const O_EXCL = 00000200;
+    const O_EXCL = 0o00000200;
     /// Do not assign controlling terminal
-    const O_NOCTTY = 00000400;
+    const O_NOCTTY = 0o00000400;
     /// 文件存在且是普通文件,并以O_RDWR或O_WRONLY打开,则它会被清空
-    const O_TRUNC = 00001000;
+    const O_TRUNC = 0o00001000;
     /// 文件指针会被移动到文件末尾
-    const O_APPEND = 00002000;
+    const O_APPEND = 0o00002000;
     /// 非阻塞式IO模式
-    const O_NONBLOCK = 00004000;
+    const O_NONBLOCK = 0o00004000;
     /// used to be O_SYNC, see below
-    const O_DSYNC = 00010000;
+    const O_DSYNC = 0o00010000;
     /// fcntl, for BSD compatibility
-    const FASYNC = 00020000;
+    const FASYNC = 0o00020000;
     /* direct disk access hint */
-    const O_DIRECT = 00040000;
-    const O_LARGEFILE = 00100000;
+    const O_DIRECT = 0o00040000;
+    const O_LARGEFILE = 0o00100000;
     /// 打开的必须是一个目录
-    const O_DIRECTORY = 00200000;
+    const O_DIRECTORY = 0o00200000;
     /// Do not follow symbolic links
-    const O_NOFOLLOW = 00400000;
-    const O_NOATIME = 01000000;
+    const O_NOFOLLOW = 0o00400000;
+    const O_NOATIME = 0o01000000;
     /// set close_on_exec
-    const O_CLOEXEC = 02000000;
+    const O_CLOEXEC = 0o02000000;
     }
 }
 

+ 5 - 7
kernel/src/filesystem/vfs/mount.rs

@@ -7,7 +7,7 @@ use alloc::{
 
 use crate::{
     include::bindings::bindings::{EBUSY, ENOTDIR},
-    libs::spinlock::SpinLock, kdebug,
+    libs::spinlock::SpinLock,
 };
 
 use super::{FilePrivateData, FileSystem, FileType, IndexNode, InodeId};
@@ -157,9 +157,7 @@ impl IndexNode for MountFSInode {
         buf: &mut [u8],
         data: &mut FilePrivateData,
     ) -> Result<usize, i32> {
-        return self
-            .inner_inode
-            .read_at(offset, len, buf, data);
+        return self.inner_inode.read_at(offset, len, buf, data);
     }
 
     fn write_at(
@@ -237,16 +235,16 @@ impl IndexNode for MountFSInode {
     }
 
     #[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;
-        kdebug!("rmdir {name}");
+
         // 先检查这个inode是否为一个挂载点,如果当前inode是一个挂载点,那么就不能删除这个inode
         if self.mount_fs.mountpoints.lock().contains_key(&inode_id) {
             return Err(-(EBUSY as i32));
         }
         // 调用内层的rmdir的方法来删除这个inode
         let r = self.inner_inode.rmdir(name);
-        kdebug!("r={r:?}");
+
         return r;
     }
 

+ 3 - 8
kernel/src/filesystem/vfs/syscall.rs

@@ -1,9 +1,6 @@
 use core::ffi::{c_char, CStr};
 
-use alloc::{
-    boxed::Box,
-    string::{String, ToString},
-};
+use alloc::{boxed::Box, string::ToString};
 
 use crate::{
     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,
     },
     io::SeekFrom,
-    kdebug, kerror,
+    kerror,
 };
 
 use super::{
@@ -36,7 +33,6 @@ pub extern "C" fn sys_open(regs: &pt_regs) -> u64 {
     }
     let path: &str = path.unwrap();
     let flags = regs.r9;
-
     let open_flags: FileMode = FileMode::from_bits_truncate(flags as u32);
     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();
 
-    kdebug!("chdir: dest_path={dest_path}");
     if dest_path.len() == 0 {
         return (-(EINVAL as i32)) as u64;
     } 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 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) => {
             kerror!("Failed in do_mkdir, Error Code = {}", err);
             err as u64

+ 1 - 0
kernel/src/lib.rs

@@ -39,6 +39,7 @@ extern crate lazy_static;
 #[macro_use]
 extern crate bitflags;
 
+
 use mm::allocator::KernelAllocator;
 
 // <3>

+ 7 - 8
kernel/src/syscall/syscall.c

@@ -289,7 +289,6 @@ extern uint64_t sys_chdir(struct pt_regs *regs);
  */
 extern uint64_t sys_getdents(struct pt_regs *regs);
 
-
 /**
  * @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);
     regs->rax = ret; // 返回码
 }
-uint64_t sys_pipe(struct pt_regs *regs){
+uint64_t sys_pipe(struct pt_regs *regs)
+{
     return -ENOTSUP;
 }
 
 extern uint64_t sys_mkdir(struct pt_regs *regs);
 
-
 system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
     [0] = system_call_not_exists,
     [1] = sys_put_string,
@@ -427,18 +426,18 @@ system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
     [9] = sys_brk,
     [10] = sys_sbrk,
     [11] = sys_reboot,
-    [12] = sys_chdir,    
-    [13] = sys_getdents, 
+    [12] = sys_chdir,
+    [13] = sys_getdents,
     [14] = sys_execve,
     [15] = sys_wait4,
     [16] = sys_exit,
-    [17] = sys_mkdir, 
+    [17] = sys_mkdir,
     [18] = sys_nanosleep,
     [19] = sys_clock,
     [20] = sys_pipe,
     [21] = sys_mstat,
-    [22] = sys_unlink_at,  
-    [23] = sys_kill, 
+    [22] = sys_unlink_at,
+    [23] = sys_kill,
     [24] = sys_sigaction,
     [25] = sys_rt_sigreturn,
     [26] = sys_getpid,