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
Chufan Chen
OSKernel2021-trash
Commits
81559f70
Commit
81559f70
authored
4 years ago
by
Yifan Wu
Browse files
Options
Download
Plain Diff
Merge branch 'dev' into main
parents
e7f120ba
0a8bd2c3
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
easy-fs/src/efs.rs
+5
-1
easy-fs/src/efs.rs
easy-fs/src/vfs.rs
+14
-9
easy-fs/src/vfs.rs
with
19 additions
and
10 deletions
+19
-10
easy-fs/src/efs.rs
+
5
−
1
View file @
81559f70
...
...
@@ -112,8 +112,12 @@ impl EasyFileSystem {
pub
fn
root_inode
(
efs
:
&
Arc
<
Mutex
<
Self
>>
)
->
Inode
{
let
block_device
=
Arc
::
clone
(
&
efs
.lock
()
.block_device
);
// acquire efs lock temporarily
let
(
block_id
,
block_offset
)
=
efs
.lock
()
.get_disk_inode_pos
(
0
);
// release efs lock
Inode
::
new
(
0
,
block_id
,
block_offset
,
Arc
::
clone
(
efs
),
block_device
,
)
...
...
This diff is collapsed.
Click to expand it.
easy-fs/src/vfs.rs
+
14
−
9
View file @
81559f70
...
...
@@ -20,12 +20,13 @@ pub struct Inode {
}
impl
Inode
{
/// We should not acquire efs lock here.
pub
fn
new
(
inode_id
:
u32
,
block_id
:
u32
,
block_offset
:
usize
,
fs
:
Arc
<
Mutex
<
EasyFileSystem
>>
,
block_device
:
Arc
<
dyn
BlockDevice
>
,
)
->
Self
{
let
(
block_id
,
block_offset
)
=
fs
.lock
()
.get_disk_inode_pos
(
inode_id
);
Self
{
block_id
:
block_id
as
usize
,
block_offset
,
...
...
@@ -74,12 +75,14 @@ impl Inode {
}
pub
fn
find
(
&
self
,
name
:
&
str
)
->
Option
<
Arc
<
Inode
>>
{
let
_
=
self
.fs
.lock
();
let
fs
=
self
.fs
.lock
();
self
.read_disk_inode
(|
disk_inode
|
{
self
.find_inode_id
(
name
,
disk_inode
)
.map
(|
inode_id
|
{
let
(
block_id
,
block_offset
)
=
fs
.get_disk_inode_pos
(
inode_id
);
Arc
::
new
(
Self
::
new
(
inode_id
,
block_id
,
block_offset
,
self
.fs
.clone
(),
self
.block_device
.clone
(),
))
...
...
@@ -140,18 +143,20 @@ impl Inode {
&
self
.block_device
,
);
});
// release efs lock manually because we will acquire it again in Inode::new
drop
(
fs
);
let
(
block_id
,
block_offset
)
=
fs
.get_disk_inode_pos
(
new_inode_id
);
// return inode
Some
(
Arc
::
new
(
Self
::
new
(
new_inode_id
,
block_id
,
block_offset
,
self
.fs
.clone
(),
self
.block_device
.clone
(),
)))
// release efs lock automatically by compiler
}
pub
fn
ls
(
&
self
)
->
Vec
<
String
>
{
let
_
=
self
.fs
.lock
();
let
_
fs
=
self
.fs
.lock
();
self
.read_disk_inode
(|
disk_inode
|
{
let
file_count
=
(
disk_inode
.size
as
usize
)
/
DIRENT_SZ
;
let
mut
v
:
Vec
<
String
>
=
Vec
::
new
();
...
...
@@ -172,7 +177,7 @@ impl Inode {
}
pub
fn
read_at
(
&
self
,
offset
:
usize
,
buf
:
&
mut
[
u8
])
->
usize
{
let
_
=
self
.fs
.lock
();
let
_
fs
=
self
.fs
.lock
();
self
.read_disk_inode
(|
disk_inode
|
{
disk_inode
.read_at
(
offset
,
buf
,
&
self
.block_device
)
})
...
...
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