Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
04f26a8d
提交
04f26a8d
4月 26, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create doesn't touch parent director references
上级
11771df4
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
58 行增加
和
38 行删除
+58
-38
kernel.hh
include/kernel.hh
+1
-0
fs.cc
kernel/fs.cc
+7
-0
sysfile.cc
kernel/sysfile.cc
+50
-38
没有找到文件。
include/kernel.hh
浏览文件 @
04f26a8d
...
@@ -89,6 +89,7 @@ struct inode* dirlookup(struct inode*, char*);
...
@@ -89,6 +89,7 @@ struct inode* dirlookup(struct inode*, char*);
struct
inode
*
ialloc
(
u32
,
short
);
struct
inode
*
ialloc
(
u32
,
short
);
struct
inode
*
namei
(
inode
*
cwd
,
const
char
*
);
struct
inode
*
namei
(
inode
*
cwd
,
const
char
*
);
void
iput
(
struct
inode
*
);
void
iput
(
struct
inode
*
);
void
iput
(
inode
*
ip
,
bool
haveref
);
struct
inode
*
iget
(
u32
dev
,
u32
inum
);
struct
inode
*
iget
(
u32
dev
,
u32
inum
);
void
ilock
(
struct
inode
*
,
int
writer
);
void
ilock
(
struct
inode
*
,
int
writer
);
void
iunlockput
(
struct
inode
*
);
void
iunlockput
(
struct
inode
*
);
...
...
kernel/fs.cc
浏览文件 @
04f26a8d
...
@@ -476,6 +476,13 @@ iunlock(struct inode *ip)
...
@@ -476,6 +476,13 @@ iunlock(struct inode *ip)
release
(
&
ip
->
lock
);
release
(
&
ip
->
lock
);
}
}
void
iput
(
inode
*
ip
,
bool
haveref
)
{
if
(
haveref
)
iput
(
ip
);
}
// Caller holds reference to unlocked ip. Drop reference.
// Caller holds reference to unlocked ip. Drop reference.
void
void
iput
(
struct
inode
*
ip
)
iput
(
struct
inode
*
ip
)
...
...
kernel/sysfile.cc
浏览文件 @
04f26a8d
...
@@ -224,53 +224,65 @@ create(inode *cwd, const char *path, short type, short major, short minor)
...
@@ -224,53 +224,65 @@ create(inode *cwd, const char *path, short type, short major, short minor)
{
{
struct
inode
*
ip
,
*
dp
;
struct
inode
*
ip
,
*
dp
;
char
name
[
DIRSIZ
];
char
name
[
DIRSIZ
];
bool
haveref
=
false
;
mt_ascope
ascope
(
"%s(%d.%d,%s,%d,%d,%d)"
,
mt_ascope
ascope
(
"%s(%d.%d,%s,%d,%d,%d)"
,
__func__
,
cwd
->
dev
,
cwd
->
inum
,
__func__
,
cwd
->
dev
,
cwd
->
inum
,
path
,
type
,
major
,
minor
);
path
,
type
,
major
,
minor
);
retry:
retry:
if
((
dp
=
nameiparent
(
cwd
,
path
,
name
))
==
0
)
{
return
0
;
scoped_gc_epoch
e
;
if
(
dp
->
type
!=
T_DIR
)
if
((
dp
=
__nameiparent
(
cwd
,
path
,
name
,
&
haveref
))
==
0
)
panic
(
"create"
);
return
0
;
if
((
ip
=
dirlookup
(
dp
,
name
))
!=
0
){
if
(
dp
->
type
!=
T_DIR
)
iput
(
dp
);
panic
(
"create"
);
ilock
(
ip
,
1
);
if
(
type
==
T_FILE
&&
ip
->
type
==
T_FILE
)
if
((
ip
=
dirlookup
(
dp
,
name
))
!=
0
){
return
ip
;
iput
(
dp
,
haveref
);
iunlockput
(
ip
);
ilock
(
ip
,
1
);
return
nullptr
;
if
(
type
==
T_FILE
&&
ip
->
type
==
T_FILE
)
}
return
ip
;
iunlockput
(
ip
);
if
((
ip
=
ialloc
(
dp
->
dev
,
type
))
==
nullptr
)
return
nullptr
;
return
nullptr
;
}
ip
->
major
=
major
;
if
((
ip
=
ialloc
(
dp
->
dev
,
type
))
==
nullptr
)
ip
->
minor
=
minor
;
return
nullptr
;
ip
->
link
();
iupdate
(
ip
);
ip
->
major
=
major
;
ip
->
minor
=
minor
;
mtwriteavar
(
"inode:%x.%x"
,
ip
->
dev
,
ip
->
inum
);
ip
->
link
();
iupdate
(
ip
);
if
(
type
==
T_DIR
){
// Create . and .. entries.
dp
->
link
();
// for ".."
mtwriteavar
(
"inode:%x.%x"
,
ip
->
dev
,
ip
->
inum
);
iupdate
(
dp
);
// No ip->nlink++ for ".": avoid cyclic ref count.
if
(
type
==
T_DIR
){
// Create . and .. entries.
if
(
dirlink
(
ip
,
"."
,
ip
->
inum
)
<
0
||
dirlink
(
ip
,
".."
,
dp
->
inum
)
<
0
)
dp
->
link
();
// for ".."
panic
(
"create dots"
);
iupdate
(
dp
);
}
// No ip->nlink++ for ".": avoid cyclic ref count.
if
(
dirlink
(
ip
,
"."
,
ip
->
inum
)
<
0
||
dirlink
(
ip
,
".."
,
dp
->
inum
)
<
0
)
panic
(
"create dots"
);
}
if
(
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
)
{
// create race
ip
->
unlink
();
iunlockput
(
ip
);
iput
(
dp
,
haveref
);
goto
retry
;
}
if
(
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
)
{
if
(
!
dp
->
valid
())
{
// create race
// XXX(sbw) we need to undo everything we just did
ip
->
unlink
();
// (at least all the modifications to dp) and retry.
iunlockput
(
ip
);
panic
(
"create: race"
);
iput
(
dp
);
}
goto
retry
;
}
}
//nc_insert(dp, name, ip);
//nc_insert(dp, name, ip);
iput
(
dp
);
iput
(
dp
,
haveref
);
return
ip
;
return
ip
;
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论