Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
1b789e1d
提交
1b789e1d
8月 24, 2007
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove puts in favor of printf.
Allow multiple arguments to ls.
上级
8e88f9e2
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
82 行增加
和
97 行删除
+82
-97
cat.c
cat.c
+15
-20
echo.c
echo.c
+2
-5
init.c
init.c
+4
-4
ls.c
ls.c
+60
-60
sh.c
sh.c
+1
-1
ulib.c
ulib.c
+0
-6
user.h
user.h
+0
-1
没有找到文件。
cat.c
浏览文件 @
1b789e1d
...
@@ -2,19 +2,17 @@
...
@@ -2,19 +2,17 @@
#include "stat.h"
#include "stat.h"
#include "user.h"
#include "user.h"
char
buf
[
51
3
];
char
buf
[
51
2
];
void
void
rfile
(
int
fd
)
rfile
(
int
fd
)
{
{
int
cc
;
int
n
;
while
((
cc
=
read
(
fd
,
buf
,
sizeof
(
buf
)
-
1
))
>
0
){
while
((
n
=
read
(
fd
,
buf
,
sizeof
(
buf
)))
>
0
)
buf
[
cc
]
=
'\0'
;
write
(
1
,
buf
,
n
);
puts
(
buf
);
if
(
n
<
0
){
}
printf
(
1
,
"cat: read error
\n
"
);
if
(
cc
<
0
){
puts
(
"cat: read error
\n
"
);
exit
();
exit
();
}
}
}
}
...
@@ -26,19 +24,16 @@ main(int argc, char *argv[])
...
@@ -26,19 +24,16 @@ main(int argc, char *argv[])
if
(
argc
<=
1
)
{
if
(
argc
<=
1
)
{
rfile
(
0
);
rfile
(
0
);
}
else
{
exit
();
for
(
i
=
1
;
i
<
argc
;
i
++
){
fd
=
open
(
argv
[
i
],
0
);
if
(
fd
<
0
){
puts
(
"cat: cannot open "
);
puts
(
argv
[
i
]);
puts
(
"
\n
"
);
exit
();
}
rfile
(
fd
);
close
(
fd
);
}
}
}
for
(
i
=
1
;
i
<
argc
;
i
++
){
if
((
fd
=
open
(
argv
[
i
],
0
))
<
0
){
printf
(
1
,
"cat: cannot open %s
\n
"
,
argv
[
i
]);
exit
();
}
rfile
(
fd
);
close
(
fd
);
}
exit
();
exit
();
}
}
echo.c
浏览文件 @
1b789e1d
...
@@ -7,10 +7,7 @@ main(int argc, char *argv[])
...
@@ -7,10 +7,7 @@ main(int argc, char *argv[])
{
{
int
i
;
int
i
;
for
(
i
=
1
;
i
<
argc
;
i
++
){
for
(
i
=
1
;
i
<
argc
;
i
++
)
puts
(
argv
[
i
]);
printf
(
1
,
"%s%s"
,
argv
[
i
],
i
+
1
<
argc
?
" "
:
"
\n
"
);
puts
(
" "
);
}
puts
(
"
\n
"
);
exit
();
exit
();
}
}
init.c
浏览文件 @
1b789e1d
...
@@ -21,18 +21,18 @@ main(void)
...
@@ -21,18 +21,18 @@ main(void)
dup
(
0
);
// stderr
dup
(
0
);
// stderr
for
(;;){
for
(;;){
p
uts
(
"init: starting sh
\n
"
);
p
rintf
(
1
,
"init: starting sh
\n
"
);
pid
=
fork
();
pid
=
fork
();
if
(
pid
<
0
){
if
(
pid
<
0
){
p
uts
(
"init: fork failed
\n
"
);
p
rintf
(
1
,
"init: fork failed
\n
"
);
exit
();
exit
();
}
}
if
(
pid
==
0
){
if
(
pid
==
0
){
exec
(
"sh"
,
sh_args
);
exec
(
"sh"
,
sh_args
);
p
uts
(
"init: exec sh failed
\n
"
);
p
rintf
(
1
,
"init: exec sh failed
\n
"
);
exit
();
exit
();
}
}
while
((
wpid
=
wait
())
>=
0
&&
wpid
!=
pid
)
while
((
wpid
=
wait
())
>=
0
&&
wpid
!=
pid
)
p
uts
(
"zombie!
\n
"
);
p
rintf
(
1
,
"zombie!
\n
"
);
}
}
}
}
ls.c
浏览文件 @
1b789e1d
...
@@ -3,83 +3,83 @@
...
@@ -3,83 +3,83 @@
#include "user.h"
#include "user.h"
#include "fs.h"
#include "fs.h"
void
char
*
pname
(
char
*
n
)
fmtname
(
char
*
path
)
{
{
int
i
;
static
char
buf
[
DIRSIZ
+
1
];
char
*
p
;
for
(
i
=
0
;
(
i
<
DIRSIZ
)
&&
(
n
[
i
]
!=
'\0'
)
;
i
++
)
{
printf
(
1
,
"%c"
,
n
[
i
]);
// Find first character after last slash.
}
for
(
p
=
path
+
strlen
(
path
);
p
>=
path
&&
*
p
!=
'/'
;
p
--
)
for
(;
i
<
DIRSIZ
;
i
++
)
;
printf
(
1
,
" "
);
p
++
;
// Return blank-padded name.
if
(
strlen
(
p
)
>=
DIRSIZ
)
return
p
;
memmove
(
buf
,
p
,
strlen
(
p
));
memset
(
buf
+
strlen
(
p
),
' '
,
DIRSIZ
-
strlen
(
p
));
return
buf
;
}
}
int
void
main
(
int
argc
,
char
*
argv
[]
)
ls
(
char
*
path
)
{
{
char
buf
[
512
],
*
p
;
char
buf
[
512
],
*
p
;
int
fd
;
int
fd
;
uint
off
,
sz
;
struct
dirent
de
;
struct
dirent
de
;
struct
stat
st
;
struct
stat
st
;
if
(
argc
>
2
){
if
(
(
fd
=
open
(
path
,
0
))
<
0
){
p
uts
(
"Usage: ls [dir]
\n
"
);
p
rintf
(
2
,
"ls: cannot open %s
\n
"
,
path
);
exit
()
;
return
;
}
}
if
(
argc
==
2
)
{
if
(
fstat
(
fd
,
&
st
)
<
0
){
fd
=
open
(
argv
[
1
],
0
);
printf
(
2
,
"ls: cannot stat %s
\n
"
,
path
);
if
(
fd
<
0
){
close
(
fd
);
printf
(
2
,
"ls: cannot open %s
\n
"
,
argv
[
1
]);
return
;
exit
();
}
}
else
{
fd
=
open
(
"."
,
0
);
if
(
fd
<
0
){
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
}
}
}
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
switch
(
st
.
type
){
printf
(
2
,
"ls: cannot stat dir
\n
"
);
exit
();
}
switch
(
st
.
type
)
{
case
T_FILE
:
case
T_FILE
:
pname
(
argv
[
1
]);
printf
(
1
,
"%s %d %d %d
\n
"
,
fmtname
(
path
),
st
.
type
,
st
.
ino
,
st
.
size
);
printf
(
1
,
"%d %d %d
\n
"
,
st
.
type
,
st
.
ino
,
st
.
size
);
break
;
break
;
case
T_DIR
:
case
T_DIR
:
sz
=
st
.
size
;
if
(
strlen
(
path
)
+
1
+
DIRSIZ
+
1
>
sizeof
buf
){
for
(
off
=
0
;
off
<
sz
;
off
+=
sizeof
(
de
))
{
printf
(
1
,
"ls: path too long
\n
"
);
if
(
read
(
fd
,
&
de
,
sizeof
(
de
))
!=
sizeof
(
de
))
{
break
;
printf
(
1
,
"ls: read error
\n
"
);
}
break
;
strcpy
(
buf
,
path
);
}
p
=
buf
+
strlen
(
buf
);
if
(
de
.
inum
!=
0
)
{
*
p
++
=
'/'
;
p
=
buf
;
while
(
read
(
fd
,
&
de
,
sizeof
(
de
))
==
sizeof
(
de
)){
if
(
argc
==
2
)
{
if
(
de
.
inum
==
0
)
strcpy
(
p
,
argv
[
1
]);
continue
;
p
+=
strlen
(
p
);
memmove
(
p
,
de
.
name
,
DIRSIZ
);
if
(
*
(
p
-
1
)
!=
'/'
)
p
[
DIRSIZ
]
=
0
;
*
p
++
=
'/'
;
if
(
stat
(
buf
,
&
st
)
<
0
){
}
printf
(
1
,
"ls: cannot stat %s
\n
"
,
buf
);
memmove
(
p
,
de
.
name
,
DIRSIZ
);
continue
;
p
[
DIRSIZ
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
)
{
printf
(
1
,
"stat: failed %s
\n
"
,
de
.
name
);
continue
;
}
pname
(
de
.
name
);
printf
(
1
,
"%d %d %d
\n
"
,
st
.
type
,
de
.
inum
,
st
.
size
);
}
}
printf
(
1
,
"%s %d %d %d
\n
"
,
fmtname
(
buf
),
st
.
type
,
st
.
ino
,
st
.
size
);
}
}
break
;
break
;
}
}
close
(
fd
);
close
(
fd
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
if
(
argc
<
2
){
ls
(
"."
);
exit
();
}
for
(
i
=
1
;
i
<
argc
;
i
++
)
ls
(
argv
[
i
]);
exit
();
exit
();
}
}
sh.c
浏览文件 @
1b789e1d
...
@@ -51,7 +51,7 @@ main(void)
...
@@ -51,7 +51,7 @@ main(void)
int
int
getcmd
(
char
*
buf
,
int
nbuf
)
getcmd
(
char
*
buf
,
int
nbuf
)
{
{
p
uts
(
"$ "
);
p
rintf
(
2
,
"$ "
);
memset
(
buf
,
0
,
nbuf
);
memset
(
buf
,
0
,
nbuf
);
gets
(
buf
,
nbuf
);
gets
(
buf
,
nbuf
);
if
(
buf
[
0
]
==
0
)
// EOF
if
(
buf
[
0
]
==
0
)
// EOF
...
...
ulib.c
浏览文件 @
1b789e1d
...
@@ -3,12 +3,6 @@
...
@@ -3,12 +3,6 @@
#include "fcntl.h"
#include "fcntl.h"
#include "user.h"
#include "user.h"
int
puts
(
char
*
s
)
{
return
write
(
1
,
s
,
strlen
(
s
));
}
char
*
char
*
strcpy
(
char
*
s
,
char
*
t
)
strcpy
(
char
*
s
,
char
*
t
)
{
{
...
...
user.h
浏览文件 @
1b789e1d
...
@@ -21,7 +21,6 @@ char* sbrk(int);
...
@@ -21,7 +21,6 @@ char* sbrk(int);
// ulib.c
// ulib.c
int
stat
(
char
*
,
struct
stat
*
);
int
stat
(
char
*
,
struct
stat
*
);
int
puts
(
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
void
*
memmove
(
void
*
,
void
*
,
int
);
void
*
memmove
(
void
*
,
void
*
,
int
);
char
*
strchr
(
const
char
*
,
char
c
);
char
*
strchr
(
const
char
*
,
char
c
);
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论