Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rcore-os
RCore Tutorial V3
提交
0a8bd2c3
R
RCore Tutorial V3
项目概览
rcore-os
/
RCore Tutorial V3
上一次同步 1 年多
通知
15
Star
793
Fork
260
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
RCore Tutorial V3
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0a8bd2c3
编写于
4月 15, 2021
作者:
Y
Yifan Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed a bug that the efs lock was not be held correctly
上级
bfa6a807
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
10 deletion
+19
-10
easy-fs/src/efs.rs
easy-fs/src/efs.rs
+5
-1
easy-fs/src/vfs.rs
easy-fs/src/vfs.rs
+14
-9
未找到文件。
easy-fs/src/efs.rs
浏览文件 @
0a8bd2c3
...
...
@@ -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
,
)
...
...
easy-fs/src/vfs.rs
浏览文件 @
0a8bd2c3
...
...
@@ -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
)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录