Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
6fa5ffb5
提交
6fa5ffb5
8月 09, 2006
创建
作者:
kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
devsw
checkpoint: write(fd,"hello\n",6) where fd is a console dev almost works
上级
6c0e444f
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
66 行增加
和
0 行删除
+66
-0
console.c
console.c
+22
-0
defs.h
defs.h
+1
-0
dev.h
dev.h
+10
-0
fd.c
fd.c
+4
-0
fs.c
fs.c
+11
-0
main.c
main.c
+1
-0
param.h
param.h
+1
-0
syscall.c
syscall.c
+5
-0
userfs.c
userfs.c
+11
-0
没有找到文件。
console.c
浏览文件 @
6fa5ffb5
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include "x86.h"
#include "x86.h"
#include "defs.h"
#include "defs.h"
#include "spinlock.h"
#include "spinlock.h"
#include "dev.h"
struct
spinlock
console_lock
=
{
"console"
};
struct
spinlock
console_lock
=
{
"console"
};
int
panicked
=
0
;
int
panicked
=
0
;
...
@@ -155,3 +156,24 @@ panic(char *s)
...
@@ -155,3 +156,24 @@ panic(char *s)
for
(;;)
for
(;;)
;
;
}
}
int
console_write
(
int
minor
,
void
*
buf
,
int
n
)
{
int
i
;
uchar
*
b
=
buf
;
cprintf
(
"print character to console
\n
"
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
cons_putc
((
int
)
b
[
i
]);
}
return
n
;
}
void
console_init
()
{
devsw
[
CONSOLE
].
d_write
=
console_write
;
}
defs.h
浏览文件 @
6fa5ffb5
...
@@ -109,4 +109,5 @@ void idecref(struct inode *ip);
...
@@ -109,4 +109,5 @@ void idecref(struct inode *ip);
void
iput
(
struct
inode
*
ip
);
void
iput
(
struct
inode
*
ip
);
struct
inode
*
namei
(
char
*
path
);
struct
inode
*
namei
(
char
*
path
);
int
readi
(
struct
inode
*
ip
,
void
*
xdst
,
uint
off
,
uint
n
);
int
readi
(
struct
inode
*
ip
,
void
*
xdst
,
uint
off
,
uint
n
);
int
writei
(
struct
inode
*
ip
,
void
*
addr
,
uint
n
);
struct
inode
*
mknod
(
struct
inode
*
,
char
*
,
short
,
short
,
short
);
struct
inode
*
mknod
(
struct
inode
*
,
char
*
,
short
,
short
,
short
);
dev.h
0 → 100644
浏览文件 @
6fa5ffb5
struct
devsw
{
int
(
*
d_open
)(
char
*
,
int
);
int
(
*
d_read
)(
int
,
void
*
,
int
);
int
(
*
d_write
)(
int
,
void
*
,
int
);
int
(
*
d_close
)(
int
);
};
extern
struct
devsw
devsw
[];
#define CONSOLE 1
fd.c
浏览文件 @
6fa5ffb5
...
@@ -6,8 +6,10 @@
...
@@ -6,8 +6,10 @@
#include "defs.h"
#include "defs.h"
#include "fd.h"
#include "fd.h"
#include "spinlock.h"
#include "spinlock.h"
#include "dev.h"
struct
spinlock
fd_table_lock
;
struct
spinlock
fd_table_lock
;
struct
devsw
devsw
[
NDEV
];
struct
fd
fds
[
NFD
];
struct
fd
fds
[
NFD
];
...
@@ -56,6 +58,8 @@ fd_write(struct fd *fd, char *addr, int n)
...
@@ -56,6 +58,8 @@ fd_write(struct fd *fd, char *addr, int n)
return
-
1
;
return
-
1
;
if
(
fd
->
type
==
FD_PIPE
){
if
(
fd
->
type
==
FD_PIPE
){
return
pipe_write
(
fd
->
pipe
,
addr
,
n
);
return
pipe_write
(
fd
->
pipe
,
addr
,
n
);
}
else
if
(
fd
->
type
==
FD_FILE
)
{
return
writei
(
fd
->
ip
,
addr
,
n
);
}
else
{
}
else
{
panic
(
"fd_write"
);
panic
(
"fd_write"
);
return
-
1
;
return
-
1
;
...
...
fs.c
浏览文件 @
6fa5ffb5
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include "buf.h"
#include "buf.h"
#include "fs.h"
#include "fs.h"
#include "fsvar.h"
#include "fsvar.h"
#include "dev.h"
// these are inodes currently in use
// these are inodes currently in use
// an entry is free if count == 0
// an entry is free if count == 0
...
@@ -252,6 +253,16 @@ readi(struct inode *ip, void *xdst, uint off, uint n)
...
@@ -252,6 +253,16 @@ readi(struct inode *ip, void *xdst, uint off, uint n)
return
target
-
n
;
return
target
-
n
;
}
}
int
writei
(
struct
inode
*
ip
,
void
*
addr
,
uint
n
)
{
if
(
ip
->
type
==
T_DEV
)
{
return
devsw
[
ip
->
major
].
d_write
(
ip
->
minor
,
addr
,
n
);
}
else
{
panic
(
"writei: unknown type
\n
"
);
}
}
struct
inode
*
struct
inode
*
namei
(
char
*
path
)
namei
(
char
*
path
)
{
{
...
...
main.c
浏览文件 @
6fa5ffb5
...
@@ -72,6 +72,7 @@ main0(void)
...
@@ -72,6 +72,7 @@ main0(void)
setupsegs
(
p
);
setupsegs
(
p
);
// init disk device
// init disk device
console_init
();
ide_init
();
ide_init
();
mp_startthem
();
mp_startthem
();
...
...
param.h
浏览文件 @
6fa5ffb5
...
@@ -7,3 +7,4 @@
...
@@ -7,3 +7,4 @@
#define NREQUEST 100 // outstanding disk requests
#define NREQUEST 100 // outstanding disk requests
#define NBUF 10
#define NBUF 10
#define NINODE 100
#define NINODE 100
#define NDEV 10
syscall.c
浏览文件 @
6fa5ffb5
...
@@ -271,8 +271,13 @@ sys_open(void)
...
@@ -271,8 +271,13 @@ sys_open(void)
iunlock
(
ip
);
iunlock
(
ip
);
fd
->
type
=
FD_FILE
;
fd
->
type
=
FD_FILE
;
if
(
arg1
)
{
fd
->
readable
=
1
;
fd
->
writeable
=
1
;
}
else
{
fd
->
readable
=
1
;
fd
->
readable
=
1
;
fd
->
writeable
=
0
;
fd
->
writeable
=
0
;
}
fd
->
ip
=
ip
;
fd
->
ip
=
ip
;
fd
->
off
=
0
;
fd
->
off
=
0
;
cp
->
fds
[
ufd
]
=
fd
;
cp
->
fds
[
ufd
]
=
fd
;
...
...
userfs.c
浏览文件 @
6fa5ffb5
...
@@ -20,6 +20,17 @@ main(void)
...
@@ -20,6 +20,17 @@ main(void)
puts
(
"mknod failed
\n
"
);
puts
(
"mknod failed
\n
"
);
else
else
puts
(
"made a node
\n
"
);
puts
(
"made a node
\n
"
);
fd
=
open
(
"console"
,
1
);
if
(
fd
>=
0
){
puts
(
"open console ok
\n
"
);
close
(
fd
);
}
else
{
puts
(
"open console failed!
\n
"
);
}
if
(
write
(
fd
,
"hello
\n
"
,
6
)
!=
6
)
{
puts
(
"write to console failed
\n
"
);
}
close
(
fd
);
fd
=
open
(
"echo"
,
0
);
fd
=
open
(
"echo"
,
0
);
if
(
fd
>=
0
){
if
(
fd
>=
0
){
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论