Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
写一辈子OS
OSKernel2025-Issyo-OS
Commits
cc5c32ed
Commit
cc5c32ed
authored
4 days ago
by
WAHearer
Browse files
Options
Download
Patches
Plain Diff
file文件
parent
7ab0c8bb
main
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/kernel/file.rs
+57
-0
src/kernel/file.rs
src/kernel/fs.rs
+1
-0
src/kernel/fs.rs
src/kernel/mod.rs
+7
-5
src/kernel/mod.rs
src/kernel/proc.rs
+7
-7
src/kernel/proc.rs
with
72 additions
and
12 deletions
+72
-12
src/kernel/file.rs
0 → 100644
+
57
−
0
View file @
cc5c32ed
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
This diff is collapsed.
Click to expand it.
src/kernel/fs.rs
0 → 100644
+
1
−
0
View file @
cc5c32ed
pub
const
ROOTINO
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/kernel/mod.rs
+
7
−
5
View file @
cc5c32ed
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
This diff is collapsed.
Click to expand it.
src/kernel/proc.rs
+
7
−
7
View file @
cc5c32ed
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets