Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
8787cd01
提交
8787cd01
8月 19, 2006
创建
作者:
kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chdir
cd in shell nits in mkdir, ls, etc.
上级
ceb0e427
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
90 行增加
和
20 行删除
+90
-20
fs.c
fs.c
+7
-1
fstests.c
fstests.c
+2
-0
ls.c
ls.c
+20
-10
proc.c
proc.c
+2
-2
sh.c
sh.c
+10
-4
syscall.c
syscall.c
+42
-1
syscall.h
syscall.h
+1
-0
trap.c
trap.c
+1
-1
user.h
user.h
+2
-1
usertests.c
usertests.c
+2
-0
usys.S
usys.S
+1
-0
没有找到文件。
fs.c
浏览文件 @
8787cd01
...
...
@@ -385,6 +385,7 @@ struct inode *
namei
(
char
*
path
,
int
mode
,
uint
*
ret_off
)
{
struct
inode
*
dp
;
struct
proc
*
p
=
curproc
[
cpu
()];
char
*
cp
=
path
,
*
cp1
;
uint
off
,
dev
;
struct
buf
*
bp
;
...
...
@@ -392,7 +393,12 @@ namei(char *path, int mode, uint *ret_off)
int
i
,
atend
;
unsigned
ninum
;
dp
=
iget
(
rootdev
,
1
);
if
(
*
cp
==
'/'
)
dp
=
iget
(
rootdev
,
1
);
else
{
dp
=
p
->
cwd
;
iincref
(
dp
);
ilock
(
dp
);
}
while
(
*
cp
==
'/'
)
cp
++
;
...
...
fstests.c
浏览文件 @
8787cd01
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
...
...
ls.c
浏览文件 @
8787cd01
...
...
@@ -15,22 +15,31 @@ main(int argc, char *argv[])
uint
sz
;
int
i
;
if
(
argc
>
1
){
puts
(
"Usage: ls
\n
"
);
if
(
argc
>
2
){
puts
(
"Usage: ls
[dir]
\n
"
);
exit
();
}
fd
=
open
(
"."
,
0
);
if
(
fd
<
0
){
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
if
(
argc
==
2
)
{
fd
=
open
(
argv
[
1
],
0
);
if
(
fd
<
0
){
printf
(
2
,
"ls: cannot open dir %s
\n
"
,
argv
[
1
]);
exit
();
}
}
else
{
fd
=
open
(
"."
,
0
);
if
(
fd
<
0
){
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
}
}
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
printf
(
2
,
"ls: cannot
open .
\n
"
);
printf
(
2
,
"ls: cannot
stat dir
\n
"
);
exit
();
}
if
(
st
.
st_type
!=
T_DIR
)
{
printf
(
2
,
"ls:
. is not a dir
\n
"
);
printf
(
2
,
"ls:
dir is not a directory
\n
"
);
}
sz
=
st
.
st_size
;
for
(
off
=
0
;
off
<
sz
;
off
+=
sizeof
(
struct
dirent
))
{
...
...
@@ -39,9 +48,10 @@ main(int argc, char *argv[])
break
;
}
if
(
dirent
.
inum
!=
0
)
{
// xxx prepend to name the pathname supplied to ls (e.g. .. in ls ..)
if
(
stat
(
dirent
.
name
,
&
st
)
<
0
)
{
printf
(
1
,
"stat: failed
\n
"
);
break
;
printf
(
1
,
"stat: failed
%s
\n
"
,
dirent
.
name
);
continue
;
}
for
(
i
=
0
;
i
<
DIRSIZ
;
i
++
)
{
if
(
dirent
.
name
[
i
]
!=
'\0'
)
...
...
proc.c
浏览文件 @
8787cd01
...
...
@@ -132,8 +132,8 @@ copyproc(struct proc* p)
fd_incref
(
np
->
fds
[
i
]);
}
//
np->cwd = p->cwd;
//
iincref(p->cwd);
np
->
cwd
=
p
->
cwd
;
iincref
(
p
->
cwd
);
return
np
;
}
...
...
sh.c
浏览文件 @
8787cd01
...
...
@@ -15,15 +15,20 @@ main(void)
while
(
1
){
puts
(
"$ "
);
memset
(
buf
,
'\0'
,
sizeof
(
buf
));
gets
(
buf
,
sizeof
(
buf
));
if
(
buf
[
0
]
==
'\0'
)
continue
;
pid
=
fork
();
if
(
pid
==
0
){
parse
(
buf
);
exec
(
buf
,
args
);
printf
(
1
,
"%s: not found
\n
"
,
buf
);
exit
();
if
(
buf
[
0
]
==
'c'
&&
buf
[
1
]
==
'd'
&&
buf
[
2
]
==
'\0'
)
{
// cd
chdir
(
&
buf
[
3
]);
}
else
{
exec
(
buf
,
args
);
printf
(
1
,
"%s: not found
\n
"
,
buf
);
exit
();
}
}
if
(
pid
>
0
)
wait
();
...
...
@@ -39,11 +44,12 @@ parse(char buf[])
for
(
i
=
0
;
buf
[
i
]
!=
'\0'
;
i
++
)
{
if
(
buf
[
i
]
==
' '
)
{
buf
[
i
]
=
'\0'
;
args
[
j
++
]
=
buf
+
i
+
1
;
args
[
j
++
]
=
buf
+
i
+
1
;
if
(
j
>=
100
)
{
printf
(
2
,
"too many args
\n
"
);
exit
();
}
}
}
args
[
j
]
=
'\0'
;
}
syscall.c
浏览文件 @
8787cd01
...
...
@@ -309,7 +309,8 @@ sys_mkdir(void)
return
-
1
;
nip
=
mknod
(
cp
->
mem
+
arg0
,
T_DIR
,
0
,
0
);
memset
(
de
.
name
,
'\0'
,
DIRSIZ
);
de
.
name
[
0
]
=
'.'
;
de
.
inum
=
nip
->
inum
;
writei
(
nip
,
(
char
*
)
&
de
,
0
,
sizeof
(
de
));
...
...
@@ -324,6 +325,43 @@ sys_mkdir(void)
return
(
nip
==
0
)
?
-
1
:
0
;
}
int
sys_chdir
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
inode
*
ip
;
uint
arg0
;
int
l
;
if
(
fetcharg
(
0
,
&
arg0
)
<
0
)
return
-
1
;
if
((
l
=
checkstring
(
arg0
))
<
0
)
return
-
1
;
if
(
l
>=
DIRSIZ
)
return
-
1
;
if
((
ip
=
namei
(
cp
->
mem
+
arg0
,
NAMEI_LOOKUP
,
0
))
==
0
)
return
-
1
;
if
(
ip
==
cp
->
cwd
)
{
iput
(
ip
);
return
0
;
}
if
(
ip
->
type
!=
T_DIR
)
{
iput
(
ip
);
return
0
;
}
idecref
(
cp
->
cwd
);
cp
->
cwd
=
ip
;
iunlock
(
cp
->
cwd
);
return
0
;
}
int
sys_unlink
(
void
)
{
...
...
@@ -599,6 +637,9 @@ syscall(void)
case
SYS_mkdir
:
ret
=
sys_mkdir
();
break
;
case
SYS_chdir
:
ret
=
sys_chdir
();
break
;
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
...
...
syscall.h
浏览文件 @
8787cd01
...
...
@@ -14,4 +14,5 @@
#define SYS_fstat 17
#define SYS_link 18
#define SYS_mkdir 19
#define SYS_chdir 20
trap.c
浏览文件 @
8787cd01
...
...
@@ -128,7 +128,7 @@ trap(struct trapframe *tf)
cprintf
(
"trap %d from cpu %d eip %x
\n
"
,
v
,
cpu
(),
tf
->
eip
);
if
(
curproc
[
cpu
()])
cprintf
(
"pid %d
\n
"
,
curproc
[
cpu
()]
->
pid
);
panic
(
"trap"
);
//
panic("trap");
return
;
}
user.h
浏览文件 @
8787cd01
...
...
@@ -17,8 +17,9 @@ int unlink (char*);
int
fstat
(
int
fd
,
struct
stat
*
stat
);
int
link
(
char
*
,
char
*
);
int
mkdir
(
char
*
);
int
stat
(
char
*
,
struct
stat
*
stat
);
int
chdir
(
char
*
);
int
stat
(
char
*
,
struct
stat
*
stat
);
int
puts
(
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
void
printf
(
int
fd
,
char
*
fmt
,
...);
...
...
usertests.c
浏览文件 @
8787cd01
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
...
...
usys.S
浏览文件 @
8787cd01
...
...
@@ -24,3 +24,4 @@ STUB(unlink)
STUB(fstat)
STUB(link)
STUB(mkdir)
STUB(chdir)
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论