Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
f3685aa3
提交
f3685aa3
5月 31, 2009
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify
上级
7f399cca
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
16 行增加
和
29 行删除
+16
-29
file.h
file.h
+1
-1
pipe.c
pipe.c
+2
-6
sysfile.c
sysfile.c
+13
-22
没有找到文件。
file.h
浏览文件 @
f3685aa3
struct
file
{
struct
file
{
enum
{
FD_
CLOSED
,
FD_
NONE
,
FD_PIPE
,
FD_INODE
}
type
;
enum
{
FD_NONE
,
FD_PIPE
,
FD_INODE
}
type
;
int
ref
;
// reference count
int
ref
;
// reference count
char
readable
;
char
readable
;
char
writable
;
char
writable
;
...
...
pipe.c
浏览文件 @
f3685aa3
...
@@ -47,14 +47,10 @@ pipealloc(struct file **f0, struct file **f1)
...
@@ -47,14 +47,10 @@ pipealloc(struct file **f0, struct file **f1)
bad:
bad:
if
(
p
)
if
(
p
)
kfree
((
char
*
)
p
,
PAGE
);
kfree
((
char
*
)
p
,
PAGE
);
if
(
*
f0
){
if
(
*
f0
)
(
*
f0
)
->
type
=
FD_NONE
;
fileclose
(
*
f0
);
fileclose
(
*
f0
);
}
if
(
*
f1
)
if
(
*
f1
){
(
*
f1
)
->
type
=
FD_NONE
;
fileclose
(
*
f1
);
fileclose
(
*
f1
);
}
return
-
1
;
return
-
1
;
}
}
...
...
sysfile.c
浏览文件 @
f3685aa3
...
@@ -127,17 +127,17 @@ sys_link(void)
...
@@ -127,17 +127,17 @@ sys_link(void)
iunlock
(
ip
);
iunlock
(
ip
);
if
((
dp
=
nameiparent
(
new
,
name
))
==
0
)
if
((
dp
=
nameiparent
(
new
,
name
))
==
0
)
goto
bad
;
goto
bad
;
ilock
(
dp
);
ilock
(
dp
);
if
(
dp
->
dev
!=
ip
->
dev
||
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
)
if
(
dp
->
dev
!=
ip
->
dev
||
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
){
iunlockput
(
dp
);
goto
bad
;
goto
bad
;
}
iunlockput
(
dp
);
iunlockput
(
dp
);
iput
(
ip
);
iput
(
ip
);
return
0
;
return
0
;
bad:
bad:
if
(
dp
)
iunlockput
(
dp
);
ilock
(
ip
);
ilock
(
ip
);
ip
->
nlink
--
;
ip
->
nlink
--
;
iupdate
(
ip
);
iupdate
(
ip
);
...
@@ -212,7 +212,7 @@ sys_unlink(void)
...
@@ -212,7 +212,7 @@ sys_unlink(void)
}
}
static
struct
inode
*
static
struct
inode
*
create
(
char
*
path
,
int
canexist
,
short
type
,
short
major
,
short
minor
)
create
(
char
*
path
,
short
type
,
short
major
,
short
minor
)
{
{
uint
off
;
uint
off
;
struct
inode
*
ip
,
*
dp
;
struct
inode
*
ip
,
*
dp
;
...
@@ -222,10 +222,10 @@ create(char *path, int canexist, short type, short major, short minor)
...
@@ -222,10 +222,10 @@ create(char *path, int canexist, short type, short major, short minor)
return
0
;
return
0
;
ilock
(
dp
);
ilock
(
dp
);
if
(
canexist
&&
(
ip
=
dirlookup
(
dp
,
name
,
&
off
))
!=
0
){
if
((
ip
=
dirlookup
(
dp
,
name
,
&
off
))
!=
0
){
iunlockput
(
dp
);
iunlockput
(
dp
);
ilock
(
ip
);
ilock
(
ip
);
if
(
ip
->
type
!=
type
||
ip
->
major
!=
major
||
ip
->
minor
!=
minor
){
if
(
ip
->
type
!=
type
||
type
!=
T_FILE
){
iunlockput
(
ip
);
iunlockput
(
ip
);
return
0
;
return
0
;
}
}
...
@@ -250,17 +250,8 @@ create(char *path, int canexist, short type, short major, short minor)
...
@@ -250,17 +250,8 @@ create(char *path, int canexist, short type, short major, short minor)
panic
(
"create dots"
);
panic
(
"create dots"
);
}
}
if
(
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
){
if
(
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
)
if
(
type
==
T_DIR
){
panic
(
"create: dirlink"
);
dp
->
nlink
--
;
iupdate
(
dp
);
}
iunlockput
(
dp
);
ip
->
nlink
=
0
;
iunlockput
(
ip
);
return
0
;
}
iunlockput
(
dp
);
iunlockput
(
dp
);
return
ip
;
return
ip
;
...
@@ -278,13 +269,13 @@ sys_open(void)
...
@@ -278,13 +269,13 @@ sys_open(void)
return
-
1
;
return
-
1
;
if
(
omode
&
O_CREATE
){
if
(
omode
&
O_CREATE
){
if
((
ip
=
create
(
path
,
1
,
T_FILE
,
0
,
0
))
==
0
)
if
((
ip
=
create
(
path
,
T_FILE
,
0
,
0
))
==
0
)
return
-
1
;
return
-
1
;
}
else
{
}
else
{
if
((
ip
=
namei
(
path
))
==
0
)
if
((
ip
=
namei
(
path
))
==
0
)
return
-
1
;
return
-
1
;
ilock
(
ip
);
ilock
(
ip
);
if
(
ip
->
type
==
T_DIR
&&
(
omode
&
(
O_RDWR
|
O_WRONLY
))
){
if
(
ip
->
type
==
T_DIR
&&
omode
!=
O_RDONLY
){
iunlockput
(
ip
);
iunlockput
(
ip
);
return
-
1
;
return
-
1
;
}
}
...
@@ -318,7 +309,7 @@ sys_mknod(void)
...
@@ -318,7 +309,7 @@ sys_mknod(void)
if
((
len
=
argstr
(
0
,
&
path
))
<
0
||
if
((
len
=
argstr
(
0
,
&
path
))
<
0
||
argint
(
1
,
&
major
)
<
0
||
argint
(
1
,
&
major
)
<
0
||
argint
(
2
,
&
minor
)
<
0
||
argint
(
2
,
&
minor
)
<
0
||
(
ip
=
create
(
path
,
0
,
T_DEV
,
major
,
minor
))
==
0
)
(
ip
=
create
(
path
,
T_DEV
,
major
,
minor
))
==
0
)
return
-
1
;
return
-
1
;
iunlockput
(
ip
);
iunlockput
(
ip
);
return
0
;
return
0
;
...
@@ -330,7 +321,7 @@ sys_mkdir(void)
...
@@ -330,7 +321,7 @@ sys_mkdir(void)
char
*
path
;
char
*
path
;
struct
inode
*
ip
;
struct
inode
*
ip
;
if
(
argstr
(
0
,
&
path
)
<
0
||
(
ip
=
create
(
path
,
0
,
T_DIR
,
0
,
0
))
==
0
)
if
(
argstr
(
0
,
&
path
)
<
0
||
(
ip
=
create
(
path
,
T_DIR
,
0
,
0
))
==
0
)
return
-
1
;
return
-
1
;
iunlockput
(
ip
);
iunlockput
(
ip
);
return
0
;
return
0
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论