Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
71fbc8bc
提交
71fbc8bc
10月 25, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Build file.c and pipe.c.
上级
2d5c99ba
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
34 行增加
和
8 行删除
+34
-8
Makefile
Makefile
+4
-2
file.c
file.c
+1
-1
kernel.h
kernel.h
+23
-0
pipe.c
pipe.c
+6
-5
没有找到文件。
Makefile
浏览文件 @
71fbc8bc
...
@@ -4,6 +4,7 @@ OBJS = \
...
@@ -4,6 +4,7 @@ OBJS = \
cga.o
\
cga.o
\
condvar.o
\
condvar.o
\
console.o
\
console.o
\
file.o
\
fs.o
\
fs.o
\
lapic.o
\
lapic.o
\
kalloc.o
\
kalloc.o
\
...
@@ -11,6 +12,7 @@ OBJS = \
...
@@ -11,6 +12,7 @@ OBJS = \
memide.o
\
memide.o
\
mp.o
\
mp.o
\
ns.o
\
ns.o
\
pipe.o
\
proc.o
\
proc.o
\
rcu.o
\
rcu.o
\
spinlock.o
\
spinlock.o
\
...
@@ -76,9 +78,9 @@ clean:
...
@@ -76,9 +78,9 @@ clean:
QEMUOPTS
=
-smp
$(CPUS)
-m
512
-nographic
QEMUOPTS
=
-smp
$(CPUS)
-m
512
-nographic
qemu
:
kernel
qemu
:
kernel
$(QEMU)
$(QEMUOPTS)
-kernel
kernel
-d
int
$(QEMU)
$(QEMUOPTS)
-kernel
kernel
gdb
:
kernel
gdb
:
kernel
$(QEMU)
$(QEMUOPTS)
-kernel
kernel
-
d
int
-
S
-s
$(QEMU)
$(QEMUOPTS)
-kernel
kernel
-S
-s
ud0
:
kernel
ud0
:
kernel
rsync
-avP
kernel amsterdam.csail.mit.edu:/tftpboot/ud0/kernel.xv6
rsync
-avP
kernel amsterdam.csail.mit.edu:/tftpboot/ud0/kernel.xv6
file.c
浏览文件 @
71fbc8bc
#include "types.h"
#include "types.h"
#include "defs.h"
#include "param.h"
#include "param.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h"
#include "condvar.h"
#include "kernel.h"
#include "fs.h"
#include "fs.h"
#include "file.h"
#include "file.h"
#include "stat.h"
#include "stat.h"
...
...
kernel.h
浏览文件 @
71fbc8bc
...
@@ -18,8 +18,11 @@ struct condvar;
...
@@ -18,8 +18,11 @@ struct condvar;
struct
context
;
struct
context
;
struct
vmnode
;
struct
vmnode
;
struct
inode
;
struct
inode
;
struct
file
;
struct
stat
;
struct
proc
;
struct
proc
;
struct
vmap
;
struct
vmap
;
struct
pipe
;
// bio.c
// bio.c
void
binit
(
void
);
void
binit
(
void
);
...
@@ -40,6 +43,15 @@ void cprintf(const char*, ...);
...
@@ -40,6 +43,15 @@ void cprintf(const char*, ...);
void
panic
(
const
char
*
)
__attribute__
((
noreturn
));
void
panic
(
const
char
*
)
__attribute__
((
noreturn
));
void
snprintf
(
char
*
buf
,
u32
n
,
char
*
fmt
,
...);
void
snprintf
(
char
*
buf
,
u32
n
,
char
*
fmt
,
...);
// 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
*
namei
(
char
*
);
struct
inode
*
namei
(
char
*
);
...
@@ -49,6 +61,9 @@ void ilock(struct inode*, int writer);
...
@@ -49,6 +61,9 @@ void ilock(struct inode*, int writer);
void
iunlockput
(
struct
inode
*
);
void
iunlockput
(
struct
inode
*
);
void
iupdate
(
struct
inode
*
);
void
iupdate
(
struct
inode
*
);
void
iunlock
(
struct
inode
*
);
void
iunlock
(
struct
inode
*
);
int
readi
(
struct
inode
*
,
char
*
,
u32
,
u32
);
void
stati
(
struct
inode
*
,
struct
stat
*
);
int
writei
(
struct
inode
*
,
char
*
,
u32
,
u32
);
// ide.c
// ide.c
void
ideinit
(
void
);
void
ideinit
(
void
);
...
@@ -65,6 +80,7 @@ void kmfree(void*);
...
@@ -65,6 +80,7 @@ void kmfree(void*);
// lapic.c
// lapic.c
int
cpunum
(
void
);
int
cpunum
(
void
);
void
lapicstartap
(
u8
,
u32
addr
);
void
lapicstartap
(
u8
,
u32
addr
);
void
lapiceoi
(
void
);
// mp.c
// mp.c
extern
int
ncpu
;
extern
int
ncpu
;
...
@@ -114,6 +130,12 @@ void* ns_remove(struct ns *ns, struct nskey key, void *val); // remove
...
@@ -114,6 +130,12 @@ void* ns_remove(struct ns *ns, struct nskey key, void *val); // remove
void
*
ns_enumerate
(
struct
ns
*
ns
,
void
*
(
*
f
)(
void
*
,
void
*
,
void
*
),
void
*
arg
);
void
*
ns_enumerate
(
struct
ns
*
ns
,
void
*
(
*
f
)(
void
*
,
void
*
,
void
*
),
void
*
arg
);
void
*
ns_enumerate_key
(
struct
ns
*
ns
,
struct
nskey
key
,
void
*
(
*
f
)(
void
*
,
void
*
),
void
*
arg
);
void
*
ns_enumerate_key
(
struct
ns
*
ns
,
struct
nskey
key
,
void
*
(
*
f
)(
void
*
,
void
*
),
void
*
arg
);
// pipe.c
int
pipealloc
(
struct
file
**
,
struct
file
**
);
void
pipeclose
(
struct
pipe
*
,
int
);
int
piperead
(
struct
pipe
*
,
char
*
,
int
);
int
pipewrite
(
struct
pipe
*
,
char
*
,
int
);
// proc.c
// proc.c
void
addrun
(
struct
proc
*
);
void
addrun
(
struct
proc
*
);
struct
proc
*
copyproc
(
struct
proc
*
);
struct
proc
*
copyproc
(
struct
proc
*
);
...
@@ -180,3 +202,4 @@ int copyout(struct vmap *, uptr, void*, u64);
...
@@ -180,3 +202,4 @@ int copyout(struct vmap *, uptr, void*, u64);
void
vmn_free
(
struct
vmnode
*
);
void
vmn_free
(
struct
vmnode
*
);
void
switchuvm
(
struct
proc
*
);
void
switchuvm
(
struct
proc
*
);
void
switchkvm
(
void
);
void
switchkvm
(
void
);
int
pagefault
(
struct
vmap
*
,
uptr
,
u32
);
pipe.c
浏览文件 @
71fbc8bc
#include "types.h"
#include "types.h"
#include "defs.h"
#include "param.h"
#include "param.h"
#include "mmu.h"
#include "mmu.h"
#include "kernel.h"
#include "spinlock.h"
#include "spinlock.h"
#include "condvar.h"
#include "condvar.h"
#include "queue.h"
#include "queue.h"
#include "proc.h"
#include "proc.h"
#include "fs.h"
#include "fs.h"
#include "file.h"
#include "file.h"
#include "cpu.h"
#define PIPESIZE 512
#define PIPESIZE 512
...
@@ -15,8 +16,8 @@ struct pipe {
...
@@ -15,8 +16,8 @@ struct pipe {
struct
spinlock
lock
;
struct
spinlock
lock
;
struct
condvar
cv
;
struct
condvar
cv
;
char
data
[
PIPESIZE
];
char
data
[
PIPESIZE
];
u
int
nread
;
// number of bytes read
u
32
nread
;
// number of bytes read
u
int
nwrite
;
// number of bytes written
u
32
nwrite
;
// number of bytes written
int
readopen
;
// read fd is still open
int
readopen
;
// read fd is still open
int
writeopen
;
// write fd is still open
int
writeopen
;
// write fd is still open
};
};
...
@@ -85,7 +86,7 @@ pipewrite(struct pipe *p, char *addr, int n)
...
@@ -85,7 +86,7 @@ pipewrite(struct pipe *p, char *addr, int n)
acquire
(
&
p
->
lock
);
acquire
(
&
p
->
lock
);
for
(
i
=
0
;
i
<
n
;
i
++
){
for
(
i
=
0
;
i
<
n
;
i
++
){
while
(
p
->
nwrite
==
p
->
nread
+
PIPESIZE
){
//DOC: pipewrite-full
while
(
p
->
nwrite
==
p
->
nread
+
PIPESIZE
){
//DOC: pipewrite-full
if
(
p
->
readopen
==
0
||
proc
->
killed
){
if
(
p
->
readopen
==
0
||
myproc
()
->
killed
){
release
(
&
p
->
lock
);
release
(
&
p
->
lock
);
return
-
1
;
return
-
1
;
}
}
...
@@ -106,7 +107,7 @@ piperead(struct pipe *p, char *addr, int n)
...
@@ -106,7 +107,7 @@ piperead(struct pipe *p, char *addr, int n)
acquire
(
&
p
->
lock
);
acquire
(
&
p
->
lock
);
while
(
p
->
nread
==
p
->
nwrite
&&
p
->
writeopen
){
//DOC: pipe-empty
while
(
p
->
nread
==
p
->
nwrite
&&
p
->
writeopen
){
//DOC: pipe-empty
if
(
proc
->
killed
){
if
(
myproc
()
->
killed
){
release
(
&
p
->
lock
);
release
(
&
p
->
lock
);
return
-
1
;
return
-
1
;
}
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论