Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
0b6ffac6
提交
0b6ffac6
3月 07, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Misc file clean up
上级
b9682048
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
64 行增加
和
67 行删除
+64
-67
file.hh
include/file.hh
+7
-5
filetable.hh
include/filetable.hh
+2
-2
kernel.hh
include/kernel.hh
+0
-9
file.cc
kernel/file.cc
+44
-40
pipe.cc
kernel/pipe.cc
+3
-3
sysfile.cc
kernel/sysfile.cc
+8
-8
没有找到文件。
include/file.hh
浏览文件 @
0b6ffac6
...
@@ -9,12 +9,11 @@
...
@@ -9,12 +9,11 @@
u64
namehash
(
const
strbuf
<
DIRSIZ
>&
);
u64
namehash
(
const
strbuf
<
DIRSIZ
>&
);
struct
file
:
public
referenced
{
struct
file
:
public
referenced
{
file
()
:
type
(
file
::
FD_NONE
),
readable
(
0
),
writable
(
0
),
static
file
*
alloc
();
socket
(
0
),
pipe
(
nullptr
),
ip
(
nullptr
),
off
(
0
)
{
inc
();
}
file
*
dup
();
file
*
dup
();
void
close
();
int
stat
(
struct
stat
*
);
int
read
(
char
*
addr
,
int
n
);
int
write
(
char
*
addr
,
int
n
);
enum
{
FD_NONE
,
FD_PIPE
,
FD_INODE
,
FD_SOCKET
}
type
;
enum
{
FD_NONE
,
FD_PIPE
,
FD_INODE
,
FD_SOCKET
}
type
;
...
@@ -27,6 +26,9 @@ struct file : public referenced {
...
@@ -27,6 +26,9 @@ struct file : public referenced {
u32
off
;
u32
off
;
NEW_DELETE_OPS
(
file
);
NEW_DELETE_OPS
(
file
);
private
:
file
();
protected
:
protected
:
virtual
void
onzero
()
const
;
virtual
void
onzero
()
const
;
};
};
...
...
include/filetable.hh
浏览文件 @
0b6ffac6
...
@@ -21,7 +21,7 @@ public:
...
@@ -21,7 +21,7 @@ public:
~
filetable
()
{
~
filetable
()
{
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
for
(
int
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
if
(
ofile_
[
fd
]){
if
(
ofile_
[
fd
]){
ofile_
[
fd
]
->
close
();
ofile_
[
fd
]
->
dec
();
ofile_
[
fd
]
=
0
;
ofile_
[
fd
]
=
0
;
}
}
}
}
...
@@ -63,7 +63,7 @@ public:
...
@@ -63,7 +63,7 @@ public:
acquire
(
&
lock_
);
acquire
(
&
lock_
);
ofile_
[
fd
]
=
nullptr
;
ofile_
[
fd
]
=
nullptr
;
release
(
&
lock_
);
release
(
&
lock_
);
f
->
close
();
f
->
dec
();
}
}
void
decref
()
{
void
decref
()
{
...
...
include/kernel.hh
浏览文件 @
0b6ffac6
...
@@ -86,15 +86,6 @@ void e1000hwaddr(u8 *hwaddr);
...
@@ -86,15 +86,6 @@ void e1000hwaddr(u8 *hwaddr);
// exec.c
// exec.c
int
exec
(
const
char
*
,
char
**
);
int
exec
(
const
char
*
,
char
**
);
// file.c
struct
file
*
filealloc
(
void
);
void
fileclose
(
struct
file
*
);
struct
file
*
filedup
(
struct
file
*
);
void
fileinit
(
void
);
int
fileread
(
struct
file
*
,
char
*
,
int
n
);
int
filestat
(
struct
file
*
,
struct
stat
*
);
int
filewrite
(
struct
file
*
,
char
*
,
int
n
);
// fs.c
// fs.c
int
namecmp
(
const
char
*
,
const
char
*
);
int
namecmp
(
const
char
*
,
const
char
*
);
struct
inode
*
dirlookup
(
struct
inode
*
,
char
*
);
struct
inode
*
dirlookup
(
struct
inode
*
,
char
*
);
...
...
kernel/file.cc
浏览文件 @
0b6ffac6
...
@@ -9,8 +9,21 @@
...
@@ -9,8 +9,21 @@
struct
devsw
__mpalign__
devsw
[
NDEV
];
struct
devsw
__mpalign__
devsw
[
NDEV
];
file
*
file
::
alloc
(
void
)
{
return
new
file
();
}
file
::
file
(
void
)
:
type
(
file
::
FD_NONE
),
readable
(
0
),
writable
(
0
),
socket
(
0
),
pipe
(
nullptr
),
ip
(
nullptr
),
off
(
0
)
{
inc
();
}
void
void
file
::
onzero
()
const
file
::
onzero
(
void
)
const
{
{
if
(
type
==
file
::
FD_PIPE
)
if
(
type
==
file
::
FD_PIPE
)
pipeclose
(
pipe
,
writable
);
pipeclose
(
pipe
,
writable
);
...
@@ -23,12 +36,6 @@ file::onzero() const
...
@@ -23,12 +36,6 @@ file::onzero() const
delete
this
;
delete
this
;
}
}
void
file
::
close
(
void
)
{
dec
();
}
file
*
file
*
file
::
dup
(
void
)
file
::
dup
(
void
)
{
{
...
@@ -36,65 +43,62 @@ file::dup(void)
...
@@ -36,65 +43,62 @@ file::dup(void)
return
this
;
return
this
;
}
}
// Get metadata about file f.
int
int
file
stat
(
struct
file
*
f
,
struct
stat
*
st
)
file
::
stat
(
struct
stat
*
st
)
{
{
if
(
f
->
type
==
file
::
FD_INODE
){
if
(
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
0
);
ilock
(
ip
,
0
);
if
(
f
->
ip
->
type
==
0
)
if
(
ip
->
type
==
0
)
panic
(
"filestat"
);
panic
(
"filestat"
);
stati
(
f
->
ip
,
st
);
stati
(
ip
,
st
);
iunlock
(
f
->
ip
);
iunlock
(
ip
);
return
0
;
return
0
;
}
}
return
-
1
;
return
-
1
;
}
}
// Read from file f. Addr is kernel address.
int
int
file
read
(
struct
file
*
f
,
char
*
addr
,
int
n
)
file
::
read
(
char
*
addr
,
int
n
)
{
{
int
r
;
int
r
;
if
(
f
->
readable
==
0
)
if
(
readable
==
0
)
return
-
1
;
return
-
1
;
if
(
f
->
type
==
file
::
FD_PIPE
)
if
(
type
==
file
::
FD_PIPE
)
return
piperead
(
f
->
pipe
,
addr
,
n
);
return
piperead
(
pipe
,
addr
,
n
);
if
(
f
->
type
==
file
::
FD_INODE
){
if
(
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
0
);
ilock
(
ip
,
0
);
if
(
f
->
ip
->
type
==
0
)
if
(
ip
->
type
==
0
)
panic
(
"fileread"
);
panic
(
"fileread"
);
if
((
r
=
readi
(
f
->
ip
,
addr
,
f
->
off
,
n
))
>
0
)
if
((
r
=
readi
(
ip
,
addr
,
off
,
n
))
>
0
)
f
->
off
+=
r
;
off
+=
r
;
iunlock
(
f
->
ip
);
iunlock
(
ip
);
return
r
;
return
r
;
}
}
if
(
f
->
type
==
file
::
FD_SOCKET
)
if
(
type
==
file
::
FD_SOCKET
)
return
netread
(
f
->
socket
,
addr
,
n
);
return
netread
(
socket
,
addr
,
n
);
panic
(
"fileread"
);
panic
(
"fileread"
);
}
}
// Write to file f. Addr is kernel address.
int
int
file
write
(
struct
file
*
f
,
char
*
addr
,
int
n
)
file
::
write
(
char
*
addr
,
int
n
)
{
{
int
r
;
int
r
;
if
(
f
->
writable
==
0
)
if
(
writable
==
0
)
return
-
1
;
return
-
1
;
if
(
f
->
type
==
file
::
FD_PIPE
)
if
(
type
==
file
::
FD_PIPE
)
return
pipewrite
(
f
->
pipe
,
addr
,
n
);
return
pipewrite
(
pipe
,
addr
,
n
);
if
(
f
->
type
==
file
::
FD_INODE
){
if
(
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
1
);
ilock
(
ip
,
1
);
if
(
f
->
ip
->
type
==
0
||
f
->
ip
->
type
==
T_DIR
)
if
(
ip
->
type
==
0
||
ip
->
type
==
T_DIR
)
panic
(
"filewrite but 0 or T_DIR"
);
panic
(
"filewrite but 0 or T_DIR"
);
if
((
r
=
writei
(
f
->
ip
,
addr
,
f
->
off
,
n
))
>
0
)
if
((
r
=
writei
(
ip
,
addr
,
off
,
n
))
>
0
)
f
->
off
+=
r
;
off
+=
r
;
iunlock
(
f
->
ip
);
iunlock
(
ip
);
return
r
;
return
r
;
}
}
if
(
f
->
type
==
file
::
FD_SOCKET
)
if
(
type
==
file
::
FD_SOCKET
)
return
netwrite
(
f
->
socket
,
addr
,
n
);
return
netwrite
(
socket
,
addr
,
n
);
panic
(
"filewrite"
);
panic
(
"filewrite"
);
}
}
kernel/pipe.cc
浏览文件 @
0b6ffac6
...
@@ -28,7 +28,7 @@ pipealloc(struct file **f0, struct file **f1)
...
@@ -28,7 +28,7 @@ pipealloc(struct file **f0, struct file **f1)
p
=
0
;
p
=
0
;
*
f0
=
*
f1
=
0
;
*
f0
=
*
f1
=
0
;
if
((
*
f0
=
new
file
())
==
0
||
(
*
f1
=
new
file
())
==
0
)
if
((
*
f0
=
file
::
alloc
())
==
0
||
(
*
f1
=
file
::
alloc
())
==
0
)
goto
bad
;
goto
bad
;
if
((
p
=
(
pipe
*
)
kmalloc
(
sizeof
(
*
p
)))
==
0
)
if
((
p
=
(
pipe
*
)
kmalloc
(
sizeof
(
*
p
)))
==
0
)
goto
bad
;
goto
bad
;
...
@@ -55,9 +55,9 @@ pipealloc(struct file **f0, struct file **f1)
...
@@ -55,9 +55,9 @@ pipealloc(struct file **f0, struct file **f1)
kmfree
((
char
*
)
p
,
sizeof
(
*
p
));
kmfree
((
char
*
)
p
,
sizeof
(
*
p
));
}
}
if
(
*
f0
)
if
(
*
f0
)
(
*
f0
)
->
close
();
(
*
f0
)
->
dec
();
if
(
*
f1
)
if
(
*
f1
)
(
*
f1
)
->
close
();
(
*
f1
)
->
dec
();
return
-
1
;
return
-
1
;
}
}
...
...
kernel/sysfile.cc
浏览文件 @
0b6ffac6
...
@@ -49,7 +49,7 @@ sys_read(int fd, char *p, int n)
...
@@ -49,7 +49,7 @@ sys_read(int fd, char *p, int n)
if
(
!
getfile
(
fd
,
&
f
)
||
argcheckptr
(
p
,
n
)
<
0
)
if
(
!
getfile
(
fd
,
&
f
)
||
argcheckptr
(
p
,
n
)
<
0
)
return
-
1
;
return
-
1
;
return
f
ileread
(
f
.
ptr
(),
p
,
n
);
return
f
->
read
(
p
,
n
);
}
}
ssize_t
ssize_t
...
@@ -84,7 +84,7 @@ sys_write(int fd, char *p, int n)
...
@@ -84,7 +84,7 @@ sys_write(int fd, char *p, int n)
if
(
!
getfile
(
fd
,
&
f
)
||
argcheckptr
(
p
,
n
)
<
0
)
if
(
!
getfile
(
fd
,
&
f
)
||
argcheckptr
(
p
,
n
)
<
0
)
return
-
1
;
return
-
1
;
return
f
ilewrite
(
f
.
ptr
(),
p
,
n
);
return
f
->
write
(
p
,
n
);
}
}
long
long
...
@@ -105,7 +105,7 @@ sys_fstat(int fd, struct stat *st)
...
@@ -105,7 +105,7 @@ sys_fstat(int fd, struct stat *st)
if
(
!
getfile
(
fd
,
&
f
)
||
argcheckptr
(
st
,
sizeof
(
*
st
))
<
0
)
if
(
!
getfile
(
fd
,
&
f
)
||
argcheckptr
(
st
,
sizeof
(
*
st
))
<
0
)
return
-
1
;
return
-
1
;
return
f
ilestat
(
f
.
ptr
(),
st
);
return
f
->
stat
(
st
);
}
}
// Create the path new as a link to the same inode as old.
// Create the path new as a link to the same inode as old.
...
@@ -311,9 +311,9 @@ sys_openat(int dirfd, const char *path, int omode)
...
@@ -311,9 +311,9 @@ sys_openat(int dirfd, const char *path, int omode)
}
}
}
}
if
((
f
=
new
file
())
==
0
||
(
fd
=
fdalloc
(
f
))
<
0
){
if
((
f
=
file
::
alloc
())
==
0
||
(
fd
=
fdalloc
(
f
))
<
0
){
if
(
f
)
if
(
f
)
f
->
close
();
f
->
dec
();
iunlockput
(
ip
);
iunlockput
(
ip
);
return
-
1
;
return
-
1
;
}
}
...
@@ -410,7 +410,7 @@ sys_pipe(int *fd)
...
@@ -410,7 +410,7 @@ sys_pipe(int *fd)
if
((
fd0
=
fdalloc
(
rf
))
<
0
||
(
fd1
=
fdalloc
(
wf
))
<
0
){
if
((
fd0
=
fdalloc
(
rf
))
<
0
||
(
fd1
=
fdalloc
(
wf
))
<
0
){
if
(
fd0
>=
0
)
if
(
fd0
>=
0
)
myproc
()
->
ftable
->
close
(
fd0
);
myproc
()
->
ftable
->
close
(
fd0
);
wf
->
close
();
wf
->
dec
();
return
-
1
;
return
-
1
;
}
}
fd
[
0
]
=
fd0
;
fd
[
0
]
=
fd0
;
...
@@ -442,13 +442,13 @@ allocsocket(struct file **rf, int *rfd)
...
@@ -442,13 +442,13 @@ allocsocket(struct file **rf, int *rfd)
struct
file
*
f
;
struct
file
*
f
;
int
fd
;
int
fd
;
f
=
new
file
();
f
=
file
::
alloc
();
if
(
f
==
nullptr
)
if
(
f
==
nullptr
)
return
-
1
;
return
-
1
;
fd
=
fdalloc
(
f
);
fd
=
fdalloc
(
f
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
f
->
close
();
f
->
dec
();
return
fd
;
return
fd
;
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论