Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Godones committed Nov 21, 2023
1 parent 8d34129 commit ce2d57c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
28 changes: 13 additions & 15 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ preprint = "0.1.0"
rslab = { version = "0.2.1" ,optional = true}

syscall-table = { git = "https://github.com/os-module/syscall-table.git" }

#syscall-table = {path = "../../os-modules/syscall-table",features = []}

plic = { git = "https://github.com/os-module/plic" }
pager = { git = "https://github.com/os-module/pager", default-features = false, optional = true }
gmanager = { path = "../modules/gmanager" }
kernel-sync = { git = "https://github.com/os-module/kernel-sync.git" }

#pconst = { git = "https://github.com/os-module/pconst.git", package = "pconst" }

pconst = { path = "../../os-modules/pconst",features = ["trick"]}
pconst = { git = "https://github.com/os-module/pconst.git",features = ["trick"] }
#pconst = { path = "../../os-modules/pconst",features = ["trick"]}

basemachine = { path = "../modules/basemachine" }
uart16550 = { version = "0.0.1", optional = true }
Expand All @@ -47,17 +44,18 @@ talc = { version = "1.0", optional = true }
buddy_system_allocator = { version = "0.9.0", optional = true }

downcast-rs = { version = "1.2.0", default-features = false }
#vfscore = {git = "https://github.com/os-module/rvfs.git"}
#devfs = {git = "https://github.com/os-module/rvfs.git"}
#dynfs = {git = "https://github.com/os-module/rvfs.git"}
#ramfs = {git = "https://github.com/os-module/rvfs.git"}
#fat-vfs = {git = "https://github.com/os-module/rvfs.git"}

vfscore = {path = "../../os-modules/rvfs/vfscore",features = ["linux_error"]}
devfs = {path = "../../os-modules/rvfs/devfs"}
dynfs = {path = "../../os-modules/rvfs/dynfs"}
ramfs = {path = "../../os-modules/rvfs/ramfs"}
fat-vfs = {path = "../../os-modules/rvfs/fat-vfs"}
vfscore = {git = "https://github.com/os-module/rvfs.git",features = ["linux_error"]}
devfs = {git = "https://github.com/os-module/rvfs.git"}
dynfs = {git = "https://github.com/os-module/rvfs.git"}
ramfs = {git = "https://github.com/os-module/rvfs.git"}
fat-vfs = {git = "https://github.com/os-module/rvfs.git"}

#vfscore = {path = "../../os-modules/rvfs/vfscore",features = ["linux_error"]}
#devfs = {path = "../../os-modules/rvfs/devfs"}
#dynfs = {path = "../../os-modules/rvfs/dynfs"}
#ramfs = {path = "../../os-modules/rvfs/ramfs"}
#fat-vfs = {path = "../../os-modules/rvfs/fat-vfs"}

simple-net = { path = "../modules/simple-net" }
[dependencies.smoltcp]
Expand Down
26 changes: 26 additions & 0 deletions kernel/src/device/rtc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::format;
use alloc::sync::Arc;
use core::cmp::min;
use pconst::io::TeletypeCommand;
use rtc::RtcTime;

use crate::fs::dev::DeviceId;
Expand All @@ -13,6 +14,7 @@ use vfscore::utils::{VfsFileStat, VfsNodeType};
use vfscore::VfsResult;

use crate::interrupt::DeviceBase;
use crate::task::current_task;

pub static RTC_DEVICE: Once<Arc<dyn RtcDevice>> = Once::new();

Expand Down Expand Up @@ -53,6 +55,30 @@ impl VfsFile for RTCDevice {
fn write_at(&self, _offset: u64, _buf: &[u8]) -> VfsResult<usize> {
todo!()
}
fn ioctl(&self, cmd: u32, arg: usize) -> VfsResult<usize> {
let task = current_task().unwrap();
let mut task_inner = task.access_inner();
let cmd = TeletypeCommand::try_from(cmd).map_err(|_| VfsError::Invalid)?;
match cmd {
TeletypeCommand::RTC_RD_TIME => {
let time = self.device.read_time_fmt();
let c_rtc_time = pconst::io::RtcTime{
sec: time.second as u32,
min: time.minute as u32,
hour: time.hour as u32,
mday: time.day as u32,
mon: time.month as u32,
year: time.year,
wday: 0,
yday: 0,
isdst: 0,
};
task_inner.copy_to_user(&c_rtc_time, arg as *mut pconst::io::RtcTime);
}
_ => return Err(VfsError::Invalid),
}
Ok(0)
}
fn flush(&self) -> VfsResult<()> {
Ok(())
}
Expand Down
5 changes: 2 additions & 3 deletions kernel/src/fs/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn sys_openat(dirfd: isize, path: *const u8, flag: usize, mode: u32) -> Alie

let path = process.transfer_str(path);
let path = user_path_at(dirfd, &path)?;
info!(
warn!(
"open file: {:?},flag:{:?}, mode:{:?}",
path, flag, file_mode
);
Expand All @@ -97,7 +97,7 @@ pub fn sys_openat(dirfd: isize, path: *const u8, flag: usize, mode: u32) -> Alie
let file = KernelFile::new(dentry, flag);

let fd = process.add_file(Arc::new(file));
info!("openat fd: {:?}", fd);
warn!("openat fd: {:?}", fd);
if fd.is_err() {
let error = ManagerError::from((fd.unwrap_err()) as usize);
info!("[vfs] openat error: {:?}", error);
Expand Down Expand Up @@ -576,7 +576,6 @@ pub fn sys_renameat2(
let process = current_task().unwrap();
let old_path = process.transfer_str(old_path);
let new_path = process.transfer_str(new_path);

let flag = Renameat2Flags::from_bits_truncate(flag);
info!(
"renameat2: {:?} {:?} {:?} {:?}, flag: {:?}",
Expand Down
6 changes: 5 additions & 1 deletion kernel/src/fs/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ pub fn sys_unlinkat(fd: isize, path: *const u8, flag: usize) -> AlienResult<isiz
let flag = UnlinkatFlags::from_bits_truncate(flag as u32);
info!("unlinkat path: {:?}, flag: {:?}", path, flag);
let path = user_path_at(fd, &path)?;
path.unlink()?;
if flag.contains(UnlinkatFlags::AT_REMOVEDIR){
path.rmdir()?;
}else{
path.unlink()?;
}
Ok(0)
}

Expand Down
15 changes: 7 additions & 8 deletions kernel/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,13 @@ fn user_path_at(fd: isize, path: &str) -> AlienResult<VfsPath> {
}

pub fn read_all(file_name: &str, buf: &mut Vec<u8>) -> bool {
// let task = current_task();
// let cwd = if task.is_some(){
// task.unwrap().access_inner().cwd().cwd
// }else {
//
// };

let path = VfsPath::new( SYSTEM_ROOT_FS.get().unwrap().clone())
let task = current_task();
let cwd = if task.is_some(){
task.unwrap().access_inner().cwd().cwd
}else {
SYSTEM_ROOT_FS.get().unwrap().clone()
};
let path = VfsPath::new( cwd)
.join(file_name)
.unwrap();
let dentry = path.open(None);
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/task/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub fn do_exec(path: *const u8, args_ptr: usize, env: usize) -> isize {
new_path.push('\0');
args.insert(0, new_path);
}
path_str = "/bin/busybox".to_string();
path_str = "./busybox".to_string();
args.insert(0, "sh\0".to_string());
}
let mut data = Vec::new();
Expand Down

0 comments on commit ce2d57c

Please sign in to comment.