Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
50e514be
提交
50e514be
9月 06, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fd_* => file_*
上级
9936bffa
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
41 行增加
和
41 行删除
+41
-41
defs.h
defs.h
+8
-8
file.c
file.c
+13
-13
main.c
main.c
+1
-1
pipe.c
pipe.c
+4
-4
proc.c
proc.c
+2
-2
sysfile.c
sysfile.c
+13
-13
没有找到文件。
defs.h
浏览文件 @
50e514be
...
...
@@ -92,14 +92,14 @@ int pipe_read(struct pipe*, char*, int);
// fd.c
struct
stat
;
void
f
d_
init
(
void
);
int
fd
_u
alloc
(
void
);
struct
file
*
f
d_
alloc
(
void
);
void
f
d_
close
(
struct
file
*
);
int
f
d_
read
(
struct
file
*
,
char
*
,
int
n
);
int
f
d_
write
(
struct
file
*
,
char
*
,
int
n
);
int
f
d_
stat
(
struct
file
*
,
struct
stat
*
);
void
f
d_
incref
(
struct
file
*
);
void
f
ile
init
(
void
);
int
fdalloc
(
void
);
struct
file
*
f
ile
alloc
(
void
);
void
f
ile
close
(
struct
file
*
);
int
f
ile
read
(
struct
file
*
,
char
*
,
int
n
);
int
f
ile
write
(
struct
file
*
,
char
*
,
int
n
);
int
f
ile
stat
(
struct
file
*
,
struct
stat
*
);
void
f
ile
incref
(
struct
file
*
);
// ide.c
void
ide_init
(
void
);
...
...
file.c
浏览文件 @
50e514be
...
...
@@ -17,14 +17,14 @@ struct devsw devsw[NDEV];
struct
file
file
[
NFILE
];
void
f
d_
init
(
void
)
f
ile
init
(
void
)
{
initlock
(
&
fd_table_lock
,
"fd_table"
);
}
// Allocate a file descriptor number for curproc.
int
fd
_u
alloc
(
void
)
fdalloc
(
void
)
{
int
fd
;
struct
proc
*
p
=
curproc
[
cpu
()];
...
...
@@ -36,7 +36,7 @@ fd_ualloc(void)
// Allocate a file descriptor structure
struct
file
*
f
d_
alloc
(
void
)
f
ile
alloc
(
void
)
{
int
i
;
...
...
@@ -56,7 +56,7 @@ fd_alloc(void)
// Write to file descriptor;
// addr is a kernel address, pointing into some process's p->mem.
int
f
d_
write
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
f
ile
write
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
{
if
(
fd
->
writable
==
0
)
return
-
1
;
...
...
@@ -71,14 +71,14 @@ fd_write(struct file *fd, char *addr, int n)
iunlock
(
fd
->
ip
);
return
r
;
}
else
{
panic
(
"f
d_
write"
);
panic
(
"f
ile
write"
);
return
-
1
;
}
}
// Read from file descriptor.
int
f
d_
read
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
f
ile
read
(
struct
file
*
fd
,
char
*
addr
,
int
n
)
{
if
(
fd
->
readable
==
0
)
return
-
1
;
...
...
@@ -92,19 +92,19 @@ fd_read(struct file *fd, char *addr, int n)
iunlock
(
fd
->
ip
);
return
cc
;
}
else
{
panic
(
"f
d_
read"
);
panic
(
"f
ile
read"
);
return
-
1
;
}
}
// Close file descriptor.
void
f
d_
close
(
struct
file
*
fd
)
f
ile
close
(
struct
file
*
fd
)
{
acquire
(
&
fd_table_lock
);
if
(
fd
->
ref
<
1
||
fd
->
type
==
FD_CLOSED
)
panic
(
"f
d_
close"
);
panic
(
"f
ile
close"
);
if
(
--
fd
->
ref
==
0
){
struct
file
dummy
=
*
fd
;
...
...
@@ -118,7 +118,7 @@ fd_close(struct file *fd)
}
else
if
(
dummy
.
type
==
FD_FILE
){
idecref
(
dummy
.
ip
);
}
else
{
panic
(
"f
d_
close"
);
panic
(
"f
ile
close"
);
}
}
else
{
release
(
&
fd_table_lock
);
...
...
@@ -127,7 +127,7 @@ fd_close(struct file *fd)
// Get metadata about file descriptor.
int
f
d_
stat
(
struct
file
*
fd
,
struct
stat
*
st
)
f
ile
stat
(
struct
file
*
fd
,
struct
stat
*
st
)
{
if
(
fd
->
type
==
FD_FILE
){
ilock
(
fd
->
ip
);
...
...
@@ -140,11 +140,11 @@ fd_stat(struct file *fd, struct stat *st)
// Increment file descriptor reference count.
void
f
d_
incref
(
struct
file
*
fd
)
f
ile
incref
(
struct
file
*
fd
)
{
acquire
(
&
fd_table_lock
);
if
(
fd
->
ref
<
1
||
fd
->
type
==
FD_CLOSED
)
panic
(
"f
d_
incref"
);
panic
(
"f
ile
incref"
);
fd
->
ref
++
;
release
(
&
fd_table_lock
);
}
main.c
浏览文件 @
50e514be
...
...
@@ -49,7 +49,7 @@ main0(void)
kinit
();
// physical memory allocator
tvinit
();
// trap vectors
idtinit
();
// this CPU's interrupt descriptor table
f
d_
init
();
f
ile
init
();
iinit
();
// i-node table
// initialize process 0
...
...
pipe.c
浏览文件 @
50e514be
...
...
@@ -24,9 +24,9 @@ pipe_alloc(struct file **fd1, struct file **fd2)
*
fd1
=
*
fd2
=
0
;
struct
pipe
*
p
=
0
;
if
((
*
fd1
=
f
d_
alloc
())
==
0
)
if
((
*
fd1
=
f
ile
alloc
())
==
0
)
goto
oops
;
if
((
*
fd2
=
f
d_
alloc
())
==
0
)
if
((
*
fd2
=
f
ile
alloc
())
==
0
)
goto
oops
;
if
((
p
=
(
struct
pipe
*
)
kalloc
(
PAGE
))
==
0
)
goto
oops
;
...
...
@@ -49,11 +49,11 @@ pipe_alloc(struct file **fd1, struct file **fd2)
kfree
((
char
*
)
p
,
PAGE
);
if
(
*
fd1
){
(
*
fd1
)
->
type
=
FD_NONE
;
f
d_
close
(
*
fd1
);
f
ile
close
(
*
fd1
);
}
if
(
*
fd2
){
(
*
fd2
)
->
type
=
FD_NONE
;
f
d_
close
(
*
fd2
);
f
ile
close
(
*
fd2
);
}
return
-
1
;
}
...
...
proc.c
浏览文件 @
50e514be
...
...
@@ -127,7 +127,7 @@ copyproc(struct proc *p)
for
(
i
=
0
;
i
<
NOFILE
;
i
++
){
np
->
ofile
[
i
]
=
p
->
ofile
[
i
];
if
(
np
->
ofile
[
i
])
f
d_
incref
(
np
->
ofile
[
i
]);
f
ile
incref
(
np
->
ofile
[
i
]);
}
np
->
cwd
=
p
->
cwd
;
...
...
@@ -329,7 +329,7 @@ proc_exit(void)
// Close all open files.
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
if
(
cp
->
ofile
[
fd
]){
f
d_
close
(
cp
->
ofile
[
fd
]);
f
ile
close
(
cp
->
ofile
[
fd
]);
cp
->
ofile
[
fd
]
=
0
;
}
}
...
...
sysfile.c
浏览文件 @
50e514be
...
...
@@ -25,10 +25,10 @@ sys_pipe(void)
if
(
pipe_alloc
(
&
rfd
,
&
wfd
)
<
0
)
goto
oops
;
if
((
f1
=
fd
_u
alloc
())
<
0
)
if
((
f1
=
fdalloc
())
<
0
)
goto
oops
;
p
->
ofile
[
f1
]
=
rfd
;
if
((
f2
=
fd
_u
alloc
())
<
0
)
if
((
f2
=
fdalloc
())
<
0
)
goto
oops
;
p
->
ofile
[
f2
]
=
wfd
;
if
(
fetcharg
(
0
,
&
fdp
)
<
0
)
...
...
@@ -41,9 +41,9 @@ sys_pipe(void)
oops:
if
(
rfd
)
f
d_
close
(
rfd
);
f
ile
close
(
rfd
);
if
(
wfd
)
f
d_
close
(
wfd
);
f
ile
close
(
wfd
);
if
(
f1
>=
0
)
p
->
ofile
[
f1
]
=
0
;
if
(
f2
>=
0
)
...
...
@@ -67,7 +67,7 @@ sys_write(void)
if
(
addr
+
n
>
p
->
sz
)
return
-
1
;
ret
=
f
d_
write
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
ret
=
f
ile
write
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
return
ret
;
}
...
...
@@ -86,7 +86,7 @@ sys_read(void)
return
-
1
;
if
(
addr
+
n
>
p
->
sz
)
return
-
1
;
ret
=
f
d_
read
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
ret
=
f
ile
read
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
return
ret
;
}
...
...
@@ -102,7 +102,7 @@ sys_close(void)
return
-
1
;
if
(
p
->
ofile
[
fd
]
==
0
)
return
-
1
;
f
d_
close
(
p
->
ofile
[
fd
]);
f
ile
close
(
p
->
ofile
[
fd
]);
p
->
ofile
[
fd
]
=
0
;
return
0
;
}
...
...
@@ -146,13 +146,13 @@ sys_open(void)
return
-
1
;
}
if
((
fd
=
f
d_
alloc
())
==
0
){
if
((
fd
=
f
ile
alloc
())
==
0
){
iput
(
ip
);
return
-
1
;
}
if
((
ufd
=
fd
_u
alloc
())
<
0
){
if
((
ufd
=
fdalloc
())
<
0
){
iput
(
ip
);
f
d_
close
(
fd
);
f
ile
close
(
fd
);
return
-
1
;
}
...
...
@@ -310,7 +310,7 @@ sys_fstat(void)
return
-
1
;
if
(
addr
+
sizeof
(
struct
stat
)
>
cp
->
sz
)
return
-
1
;
r
=
f
d_
stat
(
cp
->
ofile
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
r
=
f
ile
stat
(
cp
->
ofile
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
return
r
;
}
...
...
@@ -326,10 +326,10 @@ sys_dup(void)
return
-
1
;
if
(
cp
->
ofile
[
fd
]
==
0
)
return
-
1
;
if
((
ufd1
=
fd
_u
alloc
())
<
0
)
if
((
ufd1
=
fdalloc
())
<
0
)
return
-
1
;
cp
->
ofile
[
ufd1
]
=
cp
->
ofile
[
fd
];
f
d_
incref
(
cp
->
ofile
[
ufd1
]);
f
ile
incref
(
cp
->
ofile
[
ufd1
]);
return
ufd1
;
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论