Commit cc5c32ed authored by WAHearer's avatar WAHearer
Browse files

file文件

parent 7ab0c8bb
No related merge requests found
Showing with 72 additions and 12 deletions
+72 -12
use crate::kernel::{fs,param};
use fs::NDIRECT;
use param::NDEV;
enum Filetype{
FD_NONE,
FD_PIPE,
FD_INODE,
FD_DEVICE,
}
pub struct Inode{
dev:u32,// Device number
inum:u32,// Inode number
refcnt:i32,// Reference count
lock:Sleeplock,// protects everything below here
valid:bool,// inode has been read from disk?
inode_type:i16,// copy of disk inode
major:i16,
minor:i16,
nlink:i16,
size:u32,
addrs:[u32;NDIRECT+1]
}
pub struct File{
file_type:Filetype,
refcnt:i32,// reference count
readable:bool,
writable:bool,
pipe:Option<&'static Pipe>,// FD_PIPE
ip:Option<&'static Inode>,// FD_INODE and FD_DEVICE
off:u32,// FD_INODE
major:i16,// FD_DEVICE
}
// map major device number to device functions.
pub struct Devsw{
read:Option<Box<dyn FnMut(i32,u64,i32)>>,
write:Option<Box<dyn FnMut(i32,u64,i32)>>,
}
impl Default for Devsw{
fn default()->Self{
Self{
read:None,
write:None,
}
}
}
pub static mut devsw:[Devsw;NDEV]=[Devsw::default();NDEV];
#[macro_export] macro_rules! major{
($dex:expr)=>{((dev)>>16)&0xFFFF};
}
#[macro_export] macro_rules! minor{
($dex:expr)=>{(dev)&0xFFFF};
}
#[macro_export] macro_rules! mkdev{
($m:expr,$n:expr)=>{(m)<<16|(n)};
}
pub const CONSOLE:i32=1;
\ No newline at end of file
pub const ROOTINO
\ No newline at end of file
pub mod device;
pub mod memlayout;
pub mod proc;
pub mod spinlock;
pub mod param;
\ No newline at end of file
mod device;
mod memlayout;
mod proc;
mod spinlock;
mod param;
mod file;
mod fs;
\ No newline at end of file
......@@ -48,7 +48,7 @@ pub struct Proc{
kstack:usize,// Virtual address of kernel stack
sz:usize,// Size of process memory (bytes)
pagetable:usize,// User page table
trapframe:&'static Trapframe,// data page for trampoline.S
trapframe:Option<&'static Trapframe>,// data page for trampoline.S
context:Context,// switch() here to run process
ofile:Option<&'static[File;NOFILE]>,// Open files
cwd:Option<&'static mut Inode>,// Current directory
......@@ -67,7 +67,7 @@ impl Default for Proc{
kstack,
sz,
pagetable,
trapframe:&Trapframe::default(),
trapframe:None,
context:Context::default(),
ofile:None,
cwd:None,
......@@ -88,11 +88,11 @@ impl Proc{
kstack,
sz,
pagetable,
trapframe:match(parent){
trapframe:match parent{
Some(_)=>parent.unwrap().trapframe.clone(),
None()=>&Trapframe::default(),
None()=>None,
},
context:match(parent){
context:match parent{
Some(_)=>parent.unwrap().context.clone(),
None()=>Context::default(),
},
......@@ -102,5 +102,5 @@ impl Proc{
}
}
}
static mut CPUS:[Cpu;NCPU]=[Cpu::default();NCPU];
static mut PROC:[Proc;NPROC]=[Proc::default();NPROC];
pub static mut cpus:[Cpu;NCPU]=[Cpu::default();NCPU];
pub static mut proc:[Proc;NPROC]=[Proc::default();NPROC];
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment