Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
39593d2f
提交
39593d2f
9月 06, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
struct fd -> struct file
上级
89ebd895
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
52 行增加
和
55 行删除
+52
-55
defs.h
defs.h
+8
-8
fd.c
fd.c
+14
-14
fd.h
fd.h
+1
-3
param.h
param.h
+2
-2
pipe.c
pipe.c
+1
-1
proc.c
proc.c
+6
-6
proc.h
proc.h
+1
-1
syscall.h
syscall.h
+0
-1
sysfile.c
sysfile.c
+19
-19
没有找到文件。
defs.h
浏览文件 @
39593d2f
...
@@ -84,8 +84,8 @@ void load_icode(struct proc*, uchar*, uint);
...
@@ -84,8 +84,8 @@ void load_icode(struct proc*, uchar*, uint);
// pipe.c
// pipe.c
struct
pipe
;
struct
pipe
;
struct
f
d
;
struct
f
ile
;
int
pipe_alloc
(
struct
f
d
**
,
struct
fd
**
);
int
pipe_alloc
(
struct
f
ile
**
,
struct
file
**
);
void
pipe_close
(
struct
pipe
*
,
int
);
void
pipe_close
(
struct
pipe
*
,
int
);
int
pipe_write
(
struct
pipe
*
,
char
*
,
int
);
int
pipe_write
(
struct
pipe
*
,
char
*
,
int
);
int
pipe_read
(
struct
pipe
*
,
char
*
,
int
);
int
pipe_read
(
struct
pipe
*
,
char
*
,
int
);
...
@@ -94,12 +94,12 @@ int pipe_read(struct pipe*, char*, int);
...
@@ -94,12 +94,12 @@ int pipe_read(struct pipe*, char*, int);
struct
stat
;
struct
stat
;
void
fd_init
(
void
);
void
fd_init
(
void
);
int
fd_ualloc
(
void
);
int
fd_ualloc
(
void
);
struct
f
d
*
fd_alloc
(
void
);
struct
f
ile
*
fd_alloc
(
void
);
void
fd_close
(
struct
f
d
*
);
void
fd_close
(
struct
f
ile
*
);
int
fd_read
(
struct
f
d
*
,
char
*
,
int
n
);
int
fd_read
(
struct
f
ile
*
,
char
*
,
int
n
);
int
fd_write
(
struct
f
d
*
,
char
*
,
int
n
);
int
fd_write
(
struct
f
ile
*
,
char
*
,
int
n
);
int
fd_stat
(
struct
f
d
*
,
struct
stat
*
);
int
fd_stat
(
struct
f
ile
*
,
struct
stat
*
);
void
fd_incref
(
struct
f
d
*
);
void
fd_incref
(
struct
f
ile
*
);
// ide.c
// ide.c
void
ide_init
(
void
);
void
ide_init
(
void
);
...
...
fd.c
浏览文件 @
39593d2f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
struct
spinlock
fd_table_lock
;
struct
spinlock
fd_table_lock
;
struct
devsw
devsw
[
NDEV
];
struct
devsw
devsw
[
NDEV
];
struct
f
d
fds
[
NFD
];
struct
f
ile
file
[
NFILE
];
void
void
fd_init
(
void
)
fd_init
(
void
)
...
@@ -29,24 +29,24 @@ fd_ualloc(void)
...
@@ -29,24 +29,24 @@ fd_ualloc(void)
int
fd
;
int
fd
;
struct
proc
*
p
=
curproc
[
cpu
()];
struct
proc
*
p
=
curproc
[
cpu
()];
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
)
if
(
p
->
fds
[
fd
]
==
0
)
if
(
p
->
ofile
[
fd
]
==
0
)
return
fd
;
return
fd
;
return
-
1
;
return
-
1
;
}
}
// Allocate a file descriptor structure
// Allocate a file descriptor structure
struct
f
d
*
struct
f
ile
*
fd_alloc
(
void
)
fd_alloc
(
void
)
{
{
int
i
;
int
i
;
acquire
(
&
fd_table_lock
);
acquire
(
&
fd_table_lock
);
for
(
i
=
0
;
i
<
NF
D
;
i
++
){
for
(
i
=
0
;
i
<
NF
ILE
;
i
++
){
if
(
f
ds
[
i
].
type
==
FD_CLOSED
){
if
(
f
ile
[
i
].
type
==
FD_CLOSED
){
f
ds
[
i
].
type
=
FD_NONE
;
f
ile
[
i
].
type
=
FD_NONE
;
f
ds
[
i
].
ref
=
1
;
f
ile
[
i
].
ref
=
1
;
release
(
&
fd_table_lock
);
release
(
&
fd_table_lock
);
return
f
ds
+
i
;
return
f
ile
+
i
;
}
}
}
}
release
(
&
fd_table_lock
);
release
(
&
fd_table_lock
);
...
@@ -56,7 +56,7 @@ fd_alloc(void)
...
@@ -56,7 +56,7 @@ fd_alloc(void)
// Write to file descriptor;
// Write to file descriptor;
// addr is a kernel address, pointing into some process's p->mem.
// addr is a kernel address, pointing into some process's p->mem.
int
int
fd_write
(
struct
f
d
*
fd
,
char
*
addr
,
int
n
)
fd_write
(
struct
f
ile
*
fd
,
char
*
addr
,
int
n
)
{
{
if
(
fd
->
writable
==
0
)
if
(
fd
->
writable
==
0
)
return
-
1
;
return
-
1
;
...
@@ -78,7 +78,7 @@ fd_write(struct fd *fd, char *addr, int n)
...
@@ -78,7 +78,7 @@ fd_write(struct fd *fd, char *addr, int n)
// Read from file descriptor.
// Read from file descriptor.
int
int
fd_read
(
struct
f
d
*
fd
,
char
*
addr
,
int
n
)
fd_read
(
struct
f
ile
*
fd
,
char
*
addr
,
int
n
)
{
{
if
(
fd
->
readable
==
0
)
if
(
fd
->
readable
==
0
)
return
-
1
;
return
-
1
;
...
@@ -99,7 +99,7 @@ fd_read(struct fd *fd, char *addr, int n)
...
@@ -99,7 +99,7 @@ fd_read(struct fd *fd, char *addr, int n)
// Close file descriptor.
// Close file descriptor.
void
void
fd_close
(
struct
f
d
*
fd
)
fd_close
(
struct
f
ile
*
fd
)
{
{
acquire
(
&
fd_table_lock
);
acquire
(
&
fd_table_lock
);
...
@@ -107,7 +107,7 @@ fd_close(struct fd *fd)
...
@@ -107,7 +107,7 @@ fd_close(struct fd *fd)
panic
(
"fd_close"
);
panic
(
"fd_close"
);
if
(
--
fd
->
ref
==
0
){
if
(
--
fd
->
ref
==
0
){
struct
f
d
dummy
=
*
fd
;
struct
f
ile
dummy
=
*
fd
;
fd
->
ref
=
0
;
fd
->
ref
=
0
;
fd
->
type
=
FD_CLOSED
;
fd
->
type
=
FD_CLOSED
;
...
@@ -127,7 +127,7 @@ fd_close(struct fd *fd)
...
@@ -127,7 +127,7 @@ fd_close(struct fd *fd)
// Get metadata about file descriptor.
// Get metadata about file descriptor.
int
int
fd_stat
(
struct
f
d
*
fd
,
struct
stat
*
st
)
fd_stat
(
struct
f
ile
*
fd
,
struct
stat
*
st
)
{
{
if
(
fd
->
type
==
FD_FILE
){
if
(
fd
->
type
==
FD_FILE
){
ilock
(
fd
->
ip
);
ilock
(
fd
->
ip
);
...
@@ -140,7 +140,7 @@ fd_stat(struct fd *fd, struct stat *st)
...
@@ -140,7 +140,7 @@ fd_stat(struct fd *fd, struct stat *st)
// Increment file descriptor reference count.
// Increment file descriptor reference count.
void
void
fd_incref
(
struct
f
d
*
fd
)
fd_incref
(
struct
f
ile
*
fd
)
{
{
acquire
(
&
fd_table_lock
);
acquire
(
&
fd_table_lock
);
if
(
fd
->
ref
<
1
||
fd
->
type
==
FD_CLOSED
)
if
(
fd
->
ref
<
1
||
fd
->
type
==
FD_CLOSED
)
...
...
fd.h
浏览文件 @
39593d2f
struct
f
d
{
struct
f
ile
{
enum
{
FD_CLOSED
,
FD_NONE
,
FD_PIPE
,
FD_FILE
}
type
;
enum
{
FD_CLOSED
,
FD_NONE
,
FD_PIPE
,
FD_FILE
}
type
;
int
ref
;
// reference count
int
ref
;
// reference count
char
readable
;
char
readable
;
...
@@ -7,5 +7,3 @@ struct fd {
...
@@ -7,5 +7,3 @@ struct fd {
struct
inode
*
ip
;
struct
inode
*
ip
;
uint
off
;
uint
off
;
};
};
extern
struct
fd
fds
[
NFD
];
param.h
浏览文件 @
39593d2f
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
#define PAGE 4096 // granularity of user-space memory allocation
#define PAGE 4096 // granularity of user-space memory allocation
#define KSTACKSIZE PAGE // size of per-process kernel stack
#define KSTACKSIZE PAGE // size of per-process kernel stack
#define NCPU 8 // maximum number of CPUs
#define NCPU 8 // maximum number of CPUs
#define NOFILE 16 //
file descriptor
s per process
#define NOFILE 16 //
open file
s per process
#define NF
D 100 // file descriptor
s per system
#define NF
ILE 100 // open file
s per system
#define NREQUEST 100 // outstanding disk requests
#define NREQUEST 100 // outstanding disk requests
#define NBUF 10 // size of disk block cache
#define NBUF 10 // size of disk block cache
#define NINODE 100 // maximum number of active i-nodes
#define NINODE 100 // maximum number of active i-nodes
...
...
pipe.c
浏览文件 @
39593d2f
...
@@ -19,7 +19,7 @@ struct pipe {
...
@@ -19,7 +19,7 @@ struct pipe {
};
};
int
int
pipe_alloc
(
struct
f
d
**
fd1
,
struct
fd
**
fd2
)
pipe_alloc
(
struct
f
ile
**
fd1
,
struct
file
**
fd2
)
{
{
*
fd1
=
*
fd2
=
0
;
*
fd1
=
*
fd2
=
0
;
struct
pipe
*
p
=
0
;
struct
pipe
*
p
=
0
;
...
...
proc.c
浏览文件 @
39593d2f
...
@@ -125,9 +125,9 @@ copyproc(struct proc *p)
...
@@ -125,9 +125,9 @@ copyproc(struct proc *p)
// Copy file descriptors
// Copy file descriptors
for
(
i
=
0
;
i
<
NOFILE
;
i
++
){
for
(
i
=
0
;
i
<
NOFILE
;
i
++
){
np
->
fds
[
i
]
=
p
->
fds
[
i
];
np
->
ofile
[
i
]
=
p
->
ofile
[
i
];
if
(
np
->
fds
[
i
])
if
(
np
->
ofile
[
i
])
fd_incref
(
np
->
fds
[
i
]);
fd_incref
(
np
->
ofile
[
i
]);
}
}
np
->
cwd
=
p
->
cwd
;
np
->
cwd
=
p
->
cwd
;
...
@@ -328,9 +328,9 @@ proc_exit(void)
...
@@ -328,9 +328,9 @@ proc_exit(void)
// Close all open files.
// Close all open files.
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
for
(
fd
=
0
;
fd
<
NOFILE
;
fd
++
){
if
(
cp
->
fds
[
fd
]){
if
(
cp
->
ofile
[
fd
]){
fd_close
(
cp
->
fds
[
fd
]);
fd_close
(
cp
->
ofile
[
fd
]);
cp
->
fds
[
fd
]
=
0
;
cp
->
ofile
[
fd
]
=
0
;
}
}
}
}
...
...
proc.h
浏览文件 @
39593d2f
...
@@ -39,7 +39,7 @@ struct proc{
...
@@ -39,7 +39,7 @@ struct proc{
int
ppid
;
int
ppid
;
void
*
chan
;
// sleep
void
*
chan
;
// sleep
int
killed
;
int
killed
;
struct
f
d
*
fds
[
NOFILE
];
struct
f
ile
*
ofile
[
NOFILE
];
struct
inode
*
cwd
;
struct
inode
*
cwd
;
struct
jmpbuf
jmpbuf
;
struct
jmpbuf
jmpbuf
;
struct
trapframe
*
tf
;
// points into kstack, used to find user regs
struct
trapframe
*
tf
;
// points into kstack, used to find user regs
...
...
syscall.h
浏览文件 @
39593d2f
...
@@ -17,4 +17,3 @@
...
@@ -17,4 +17,3 @@
#define SYS_dup 17
#define SYS_dup 17
#define SYS_getpid 18
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_sbrk 19
sysfile.c
浏览文件 @
39593d2f
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
int
int
sys_pipe
(
void
)
sys_pipe
(
void
)
{
{
struct
f
d
*
rfd
=
0
,
*
wfd
=
0
;
struct
f
ile
*
rfd
=
0
,
*
wfd
=
0
;
int
f1
=
-
1
,
f2
=
-
1
;
int
f1
=
-
1
,
f2
=
-
1
;
struct
proc
*
p
=
curproc
[
cpu
()];
struct
proc
*
p
=
curproc
[
cpu
()];
uint
fdp
;
uint
fdp
;
...
@@ -27,10 +27,10 @@ sys_pipe(void)
...
@@ -27,10 +27,10 @@ sys_pipe(void)
goto
oops
;
goto
oops
;
if
((
f1
=
fd_ualloc
())
<
0
)
if
((
f1
=
fd_ualloc
())
<
0
)
goto
oops
;
goto
oops
;
p
->
fds
[
f1
]
=
rfd
;
p
->
ofile
[
f1
]
=
rfd
;
if
((
f2
=
fd_ualloc
())
<
0
)
if
((
f2
=
fd_ualloc
())
<
0
)
goto
oops
;
goto
oops
;
p
->
fds
[
f2
]
=
wfd
;
p
->
ofile
[
f2
]
=
wfd
;
if
(
fetcharg
(
0
,
&
fdp
)
<
0
)
if
(
fetcharg
(
0
,
&
fdp
)
<
0
)
goto
oops
;
goto
oops
;
if
(
putint
(
p
,
fdp
,
f1
)
<
0
)
if
(
putint
(
p
,
fdp
,
f1
)
<
0
)
...
@@ -45,9 +45,9 @@ sys_pipe(void)
...
@@ -45,9 +45,9 @@ sys_pipe(void)
if
(
wfd
)
if
(
wfd
)
fd_close
(
wfd
);
fd_close
(
wfd
);
if
(
f1
>=
0
)
if
(
f1
>=
0
)
p
->
fds
[
f1
]
=
0
;
p
->
ofile
[
f1
]
=
0
;
if
(
f2
>=
0
)
if
(
f2
>=
0
)
p
->
fds
[
f2
]
=
0
;
p
->
ofile
[
f2
]
=
0
;
return
-
1
;
return
-
1
;
}
}
...
@@ -62,12 +62,12 @@ sys_write(void)
...
@@ -62,12 +62,12 @@ sys_write(void)
return
-
1
;
return
-
1
;
if
(
fd
<
0
||
fd
>=
NOFILE
)
if
(
fd
<
0
||
fd
>=
NOFILE
)
return
-
1
;
return
-
1
;
if
(
p
->
fds
[
fd
]
==
0
)
if
(
p
->
ofile
[
fd
]
==
0
)
return
-
1
;
return
-
1
;
if
(
addr
+
n
>
p
->
sz
)
if
(
addr
+
n
>
p
->
sz
)
return
-
1
;
return
-
1
;
ret
=
fd_write
(
p
->
fds
[
fd
],
p
->
mem
+
addr
,
n
);
ret
=
fd_write
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
return
ret
;
return
ret
;
}
}
...
@@ -82,11 +82,11 @@ sys_read(void)
...
@@ -82,11 +82,11 @@ sys_read(void)
return
-
1
;
return
-
1
;
if
(
fd
<
0
||
fd
>=
NOFILE
)
if
(
fd
<
0
||
fd
>=
NOFILE
)
return
-
1
;
return
-
1
;
if
(
p
->
fds
[
fd
]
==
0
)
if
(
p
->
ofile
[
fd
]
==
0
)
return
-
1
;
return
-
1
;
if
(
addr
+
n
>
p
->
sz
)
if
(
addr
+
n
>
p
->
sz
)
return
-
1
;
return
-
1
;
ret
=
fd_read
(
p
->
fds
[
fd
],
p
->
mem
+
addr
,
n
);
ret
=
fd_read
(
p
->
ofile
[
fd
],
p
->
mem
+
addr
,
n
);
return
ret
;
return
ret
;
}
}
...
@@ -100,10 +100,10 @@ sys_close(void)
...
@@ -100,10 +100,10 @@ sys_close(void)
return
-
1
;
return
-
1
;
if
(
fd
<
0
||
fd
>=
NOFILE
)
if
(
fd
<
0
||
fd
>=
NOFILE
)
return
-
1
;
return
-
1
;
if
(
p
->
fds
[
fd
]
==
0
)
if
(
p
->
ofile
[
fd
]
==
0
)
return
-
1
;
return
-
1
;
fd_close
(
p
->
fds
[
fd
]);
fd_close
(
p
->
ofile
[
fd
]);
p
->
fds
[
fd
]
=
0
;
p
->
ofile
[
fd
]
=
0
;
return
0
;
return
0
;
}
}
...
@@ -114,7 +114,7 @@ sys_open(void)
...
@@ -114,7 +114,7 @@ sys_open(void)
struct
inode
*
ip
,
*
dp
;
struct
inode
*
ip
,
*
dp
;
uint
arg0
,
arg1
;
uint
arg0
,
arg1
;
int
ufd
;
int
ufd
;
struct
f
d
*
fd
;
struct
f
ile
*
fd
;
int
l
;
int
l
;
char
*
last
;
char
*
last
;
...
@@ -170,7 +170,7 @@ sys_open(void)
...
@@ -170,7 +170,7 @@ sys_open(void)
}
}
fd
->
ip
=
ip
;
fd
->
ip
=
ip
;
fd
->
off
=
0
;
fd
->
off
=
0
;
cp
->
fds
[
ufd
]
=
fd
;
cp
->
ofile
[
ufd
]
=
fd
;
return
ufd
;
return
ufd
;
}
}
...
@@ -306,11 +306,11 @@ sys_fstat(void)
...
@@ -306,11 +306,11 @@ sys_fstat(void)
return
-
1
;
return
-
1
;
if
(
fd
<
0
||
fd
>=
NOFILE
)
if
(
fd
<
0
||
fd
>=
NOFILE
)
return
-
1
;
return
-
1
;
if
(
cp
->
fds
[
fd
]
==
0
)
if
(
cp
->
ofile
[
fd
]
==
0
)
return
-
1
;
return
-
1
;
if
(
addr
+
sizeof
(
struct
stat
)
>
cp
->
sz
)
if
(
addr
+
sizeof
(
struct
stat
)
>
cp
->
sz
)
return
-
1
;
return
-
1
;
r
=
fd_stat
(
cp
->
fds
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
r
=
fd_stat
(
cp
->
ofile
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
return
r
;
return
r
;
}
}
...
@@ -324,12 +324,12 @@ sys_dup(void)
...
@@ -324,12 +324,12 @@ sys_dup(void)
return
-
1
;
return
-
1
;
if
(
fd
<
0
||
fd
>=
NOFILE
)
if
(
fd
<
0
||
fd
>=
NOFILE
)
return
-
1
;
return
-
1
;
if
(
cp
->
fds
[
fd
]
==
0
)
if
(
cp
->
ofile
[
fd
]
==
0
)
return
-
1
;
return
-
1
;
if
((
ufd1
=
fd_ualloc
())
<
0
)
if
((
ufd1
=
fd_ualloc
())
<
0
)
return
-
1
;
return
-
1
;
cp
->
fds
[
ufd1
]
=
cp
->
fds
[
fd
];
cp
->
ofile
[
ufd1
]
=
cp
->
ofile
[
fd
];
fd_incref
(
cp
->
fds
[
ufd1
]);
fd_incref
(
cp
->
ofile
[
ufd1
]);
return
ufd1
;
return
ufd1
;
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论