Skip to content

Commit 84407d3

Browse files
authored
bugfix:解决touch命令失败的问题 (#199)
* bug fix : 解决touch命令失败的问题
1 parent 004e86f commit 84407d3

File tree

7 files changed

+34
-43
lines changed

7 files changed

+34
-43
lines changed

kernel/src/filesystem/fat/fs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,6 @@ impl IndexNode for LockedFATInode {
15831583
if guard.metadata.file_type != FileType::Dir {
15841584
return Err(-(ENOTDIR as i32));
15851585
}
1586-
15871586
match ino {
15881587
0 => {
15891588
return Ok(String::from("."));

kernel/src/filesystem/vfs/core.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ fn do_migrate(
112112
mountpoint
113113
.mount(fs.inner_filesystem())
114114
.expect(format!("Failed to migrate {mountpoint_name}").as_str());
115-
116115
return Ok(());
117116
}
118117

kernel/src/filesystem/vfs/file.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,41 @@ bitflags! {
3838
pub struct FileMode: u32{
3939
/* File access modes for `open' and `fcntl'. */
4040
/// Open Read-only
41-
const O_RDONLY = 0;
41+
const O_RDONLY = 0o0;
4242
/// Open Write-only
43-
const O_WRONLY = 1;
43+
const O_WRONLY = 0o1;
4444
/// Open read/write
45-
const O_RDWR = 2;
45+
const O_RDWR = 0o2;
4646
/// Mask for file access modes
47-
const O_ACCMODE = 00000003;
47+
const O_ACCMODE = 0o00000003;
4848

4949
/* Bits OR'd into the second argument to open. */
5050
/// Create file if it does not exist
51-
const O_CREAT = 00000100;
51+
const O_CREAT = 0o00000100;
5252
/// Fail if file already exists
53-
const O_EXCL = 00000200;
53+
const O_EXCL = 0o00000200;
5454
/// Do not assign controlling terminal
55-
const O_NOCTTY = 00000400;
55+
const O_NOCTTY = 0o00000400;
5656
/// 文件存在且是普通文件,并以O_RDWR或O_WRONLY打开,则它会被清空
57-
const O_TRUNC = 00001000;
57+
const O_TRUNC = 0o00001000;
5858
/// 文件指针会被移动到文件末尾
59-
const O_APPEND = 00002000;
59+
const O_APPEND = 0o00002000;
6060
/// 非阻塞式IO模式
61-
const O_NONBLOCK = 00004000;
61+
const O_NONBLOCK = 0o00004000;
6262
/// used to be O_SYNC, see below
63-
const O_DSYNC = 00010000;
63+
const O_DSYNC = 0o00010000;
6464
/// fcntl, for BSD compatibility
65-
const FASYNC = 00020000;
65+
const FASYNC = 0o00020000;
6666
/* direct disk access hint */
67-
const O_DIRECT = 00040000;
68-
const O_LARGEFILE = 00100000;
67+
const O_DIRECT = 0o00040000;
68+
const O_LARGEFILE = 0o00100000;
6969
/// 打开的必须是一个目录
70-
const O_DIRECTORY = 00200000;
70+
const O_DIRECTORY = 0o00200000;
7171
/// Do not follow symbolic links
72-
const O_NOFOLLOW = 00400000;
73-
const O_NOATIME = 01000000;
72+
const O_NOFOLLOW = 0o00400000;
73+
const O_NOATIME = 0o01000000;
7474
/// set close_on_exec
75-
const O_CLOEXEC = 02000000;
75+
const O_CLOEXEC = 0o02000000;
7676
}
7777
}
7878

kernel/src/filesystem/vfs/mount.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use alloc::{
77

88
use crate::{
99
include::bindings::bindings::{EBUSY, ENOTDIR},
10-
libs::spinlock::SpinLock, kdebug,
10+
libs::spinlock::SpinLock,
1111
};
1212

1313
use super::{FilePrivateData, FileSystem, FileType, IndexNode, InodeId};
@@ -157,9 +157,7 @@ impl IndexNode for MountFSInode {
157157
buf: &mut [u8],
158158
data: &mut FilePrivateData,
159159
) -> Result<usize, i32> {
160-
return self
161-
.inner_inode
162-
.read_at(offset, len, buf, data);
160+
return self.inner_inode.read_at(offset, len, buf, data);
163161
}
164162

165163
fn write_at(
@@ -237,16 +235,16 @@ impl IndexNode for MountFSInode {
237235
}
238236

239237
#[inline]
240-
fn rmdir(&self, name: &str) ->Result<(), i32> {
238+
fn rmdir(&self, name: &str) -> Result<(), i32> {
241239
let inode_id = self.inner_inode.find(name)?.metadata()?.inode_id;
242-
kdebug!("rmdir {name}");
240+
243241
// 先检查这个inode是否为一个挂载点,如果当前inode是一个挂载点,那么就不能删除这个inode
244242
if self.mount_fs.mountpoints.lock().contains_key(&inode_id) {
245243
return Err(-(EBUSY as i32));
246244
}
247245
// 调用内层的rmdir的方法来删除这个inode
248246
let r = self.inner_inode.rmdir(name);
249-
kdebug!("r={r:?}");
247+
250248
return r;
251249
}
252250

kernel/src/filesystem/vfs/syscall.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use core::ffi::{c_char, CStr};
22

3-
use alloc::{
4-
boxed::Box,
5-
string::{String, ToString},
6-
};
3+
use alloc::{boxed::Box, string::ToString};
74

85
use crate::{
96
arch::asm::{current::current_pcb, ptrace::user_mode},
@@ -12,7 +9,7 @@ use crate::{
129
EPERM, PAGE_2M_SIZE, PAGE_4K_SIZE, PROC_MAX_FD_NUM, SEEK_CUR, SEEK_END, SEEK_MAX, SEEK_SET,
1310
},
1411
io::SeekFrom,
15-
kdebug, kerror,
12+
kerror,
1613
};
1714

1815
use super::{
@@ -36,7 +33,6 @@ pub extern "C" fn sys_open(regs: &pt_regs) -> u64 {
3633
}
3734
let path: &str = path.unwrap();
3835
let flags = regs.r9;
39-
4036
let open_flags: FileMode = FileMode::from_bits_truncate(flags as u32);
4137
let r: Result<i32, i32> = do_open(path, open_flags);
4238

@@ -191,7 +187,6 @@ pub extern "C" fn sys_chdir(regs: &pt_regs) -> u64 {
191187

192188
let dest_path: &str = dest_path.unwrap();
193189

194-
kdebug!("chdir: dest_path={dest_path}");
195190
if dest_path.len() == 0 {
196191
return (-(EINVAL as i32)) as u64;
197192
} else if dest_path.len() >= PAGE_4K_SIZE as usize {
@@ -286,7 +281,7 @@ pub extern "C" fn sys_mkdir(regs: &pt_regs) -> u64 {
286281
return (-(EINVAL as i32)) as u64;
287282
}
288283

289-
return match do_mkdir(&path, FileMode::from_bits_truncate(mode as u32)) {
284+
return match do_mkdir(&path.trim(), FileMode::from_bits_truncate(mode as u32)) {
290285
Err(err) => {
291286
kerror!("Failed in do_mkdir, Error Code = {}", err);
292287
err as u64

kernel/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern crate lazy_static;
3939
#[macro_use]
4040
extern crate bitflags;
4141

42+
4243
use mm::allocator::KernelAllocator;
4344

4445
// <3>

kernel/src/syscall/syscall.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ extern uint64_t sys_chdir(struct pt_regs *regs);
289289
*/
290290
extern uint64_t sys_getdents(struct pt_regs *regs);
291291

292-
293292
/**
294293
* @brief 执行新的程序
295294
*
@@ -407,13 +406,13 @@ void do_syscall_int(struct pt_regs *regs, unsigned long error_code)
407406
ul ret = system_call_table[regs->rax](regs);
408407
regs->rax = ret; // 返回码
409408
}
410-
uint64_t sys_pipe(struct pt_regs *regs){
409+
uint64_t sys_pipe(struct pt_regs *regs)
410+
{
411411
return -ENOTSUP;
412412
}
413413

414414
extern uint64_t sys_mkdir(struct pt_regs *regs);
415415

416-
417416
system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
418417
[0] = system_call_not_exists,
419418
[1] = sys_put_string,
@@ -427,18 +426,18 @@ system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] = {
427426
[9] = sys_brk,
428427
[10] = sys_sbrk,
429428
[11] = sys_reboot,
430-
[12] = sys_chdir,
431-
[13] = sys_getdents,
429+
[12] = sys_chdir,
430+
[13] = sys_getdents,
432431
[14] = sys_execve,
433432
[15] = sys_wait4,
434433
[16] = sys_exit,
435-
[17] = sys_mkdir,
434+
[17] = sys_mkdir,
436435
[18] = sys_nanosleep,
437436
[19] = sys_clock,
438437
[20] = sys_pipe,
439438
[21] = sys_mstat,
440-
[22] = sys_unlink_at,
441-
[23] = sys_kill,
439+
[22] = sys_unlink_at,
440+
[23] = sys_kill,
442441
[24] = sys_sigaction,
443442
[25] = sys_rt_sigreturn,
444443
[26] = sys_getpid,

0 commit comments

Comments
 (0)