Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
d15f0d10
提交
d15f0d10
8月 14, 2006
创建
作者:
kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
start on mkdir
stat
上级
e4bcd2a3
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
73 行增加
和
7 行删除
+73
-7
ls.c
ls.c
+12
-6
syscall.c
syscall.c
+28
-0
syscall.h
syscall.h
+1
-0
ulib.c
ulib.c
+16
-0
user.h
user.h
+2
-1
userfs.c
userfs.c
+13
-0
usys.S
usys.S
+1
-0
没有找到文件。
ls.c
浏览文件 @
d15f0d10
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include "fs.h"
#include "fs.h"
char
buf
[
512
];
char
buf
[
512
];
struct
stat
st
at
;
struct
stat
st
;
struct
dirent
dirent
;
struct
dirent
dirent
;
int
int
...
@@ -23,20 +23,26 @@ main(int argc, char *argv[])
...
@@ -23,20 +23,26 @@ main(int argc, char *argv[])
printf
(
2
,
"ls: cannot open .
\n
"
);
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
exit
();
}
}
if
(
fstat
(
fd
,
&
st
at
)
<
0
)
{
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
printf
(
2
,
"ls: cannot open .
\n
"
);
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
exit
();
}
}
if
(
st
at
.
st_type
!=
T_DIR
)
{
if
(
st
.
st_type
!=
T_DIR
)
{
printf
(
2
,
"ls: . is not a dir
\n
"
);
printf
(
2
,
"ls: . is not a dir
\n
"
);
}
}
for
(
off
=
0
;
off
<
stat
.
st_size
;
off
+=
sizeof
(
struct
dirent
))
{
cprintf
(
"size %d
\n
"
,
st
.
st_size
);
for
(
off
=
0
;
off
<
st
.
st_size
;
off
+=
sizeof
(
struct
dirent
))
{
if
(
read
(
fd
,
&
dirent
,
sizeof
(
struct
dirent
))
!=
sizeof
(
struct
dirent
))
{
if
(
read
(
fd
,
&
dirent
,
sizeof
(
struct
dirent
))
!=
sizeof
(
struct
dirent
))
{
printf
(
2
,
"ls: read error
\n
"
);
printf
(
2
,
"ls: read error
\n
"
);
exit
();
exit
();
}
}
if
(
dirent
.
inum
!=
0
)
if
(
dirent
.
inum
!=
0
)
{
printf
(
1
,
"%s
\n
"
,
dirent
.
name
);
if
(
stat
(
dirent
.
name
,
&
st
)
<
0
)
printf
(
2
,
"stat: failed
\n
"
);
printf
(
1
,
"%s t %d
\n
"
,
dirent
.
name
,
st
.
st_type
);
}
}
}
close
(
fd
);
close
(
fd
);
...
...
syscall.c
浏览文件 @
d15f0d10
...
@@ -290,6 +290,31 @@ sys_mknod(void)
...
@@ -290,6 +290,31 @@ sys_mknod(void)
}
}
int
int
sys_mkdir
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
inode
*
nip
;
uint
arg0
;
int
l
;
if
(
fetcharg
(
0
,
&
arg0
)
<
0
)
return
-
1
;
if
((
l
=
checkstring
(
arg0
))
<
0
)
return
-
1
;
if
(
l
>=
DIRSIZ
)
return
-
1
;
nip
=
mknod
(
cp
->
mem
+
arg0
,
T_DIR
,
0
,
0
);
// XXX put . and .. in
iput
(
nip
);
return
(
nip
==
0
)
?
-
1
:
0
;
}
int
sys_unlink
(
void
)
sys_unlink
(
void
)
{
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
proc
*
cp
=
curproc
[
cpu
()];
...
@@ -561,6 +586,9 @@ syscall(void)
...
@@ -561,6 +586,9 @@ syscall(void)
case
SYS_link
:
case
SYS_link
:
ret
=
sys_link
();
ret
=
sys_link
();
break
;
break
;
case
SYS_mkdir
:
ret
=
sys_mkdir
();
break
;
default:
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
// XXX fault
...
...
syscall.h
浏览文件 @
d15f0d10
...
@@ -13,4 +13,5 @@
...
@@ -13,4 +13,5 @@
#define SYS_unlink 16
#define SYS_unlink 16
#define SYS_fstat 17
#define SYS_fstat 17
#define SYS_link 18
#define SYS_link 18
#define SYS_mkdir 19
ulib.c
浏览文件 @
d15f0d10
#include "types.h"
#include "stat.h"
#include "fcntl.h"
#include "user.h"
#include "user.h"
int
int
...
@@ -54,3 +57,16 @@ gets(char *buf, int max)
...
@@ -54,3 +57,16 @@ gets(char *buf, int max)
buf
[
i
]
=
'\0'
;
buf
[
i
]
=
'\0'
;
return
buf
;
return
buf
;
}
}
int
stat
(
char
*
n
,
struct
stat
*
st
)
{
int
fd
=
open
(
n
,
O_RDONLY
);
int
r
;
if
(
fd
<
0
)
return
-
1
;
r
=
fstat
(
fd
,
st
);
close
(
fd
);
return
r
;
}
user.h
浏览文件 @
d15f0d10
...
@@ -14,9 +14,10 @@ int exec(char *, char **);
...
@@ -14,9 +14,10 @@ int exec(char *, char **);
int
open
(
char
*
,
int
);
int
open
(
char
*
,
int
);
int
mknod
(
char
*
,
short
,
short
,
short
);
int
mknod
(
char
*
,
short
,
short
,
short
);
int
unlink
(
char
*
);
int
unlink
(
char
*
);
struct
stat
;
int
fstat
(
int
fd
,
struct
stat
*
stat
);
int
fstat
(
int
fd
,
struct
stat
*
stat
);
int
link
(
char
*
,
char
*
);
int
link
(
char
*
,
char
*
);
int
mkdir
(
char
*
);
int
stat
(
char
*
,
struct
stat
*
stat
);
int
puts
(
char
*
);
int
puts
(
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
...
...
userfs.c
浏览文件 @
d15f0d10
...
@@ -65,7 +65,13 @@ main(void)
...
@@ -65,7 +65,13 @@ main(void)
printf
(
stdout
,
"read failed
\n
"
);
printf
(
stdout
,
"read failed
\n
"
);
}
}
close
(
fd
);
close
(
fd
);
printf
(
stdout
,
"unlink doesnotexist
\n
"
);
unlink
(
"doesnotexist"
);
unlink
(
"doesnotexist"
);
printf
(
stdout
,
"many creates, followed by unlink
\n
"
);
name
[
0
]
=
'a'
;
name
[
0
]
=
'a'
;
name
[
2
]
=
'\0'
;
name
[
2
]
=
'\0'
;
for
(
i
=
0
;
i
<
52
;
i
++
)
{
for
(
i
=
0
;
i
<
52
;
i
++
)
{
...
@@ -80,6 +86,13 @@ main(void)
...
@@ -80,6 +86,13 @@ main(void)
unlink
(
name
);
unlink
(
name
);
}
}
printf
(
stdout
,
"mkdir
\n
"
);
if
(
mkdir
(
"dir0"
)
<
0
)
printf
(
stdout
,
"mkdir failed
\n
"
);
// unlink("dir0");
//exec("echo", echo_args);
//exec("echo", echo_args);
printf
(
stdout
,
"about to do exec
\n
"
);
printf
(
stdout
,
"about to do exec
\n
"
);
exec
(
"cat"
,
cat_args
);
exec
(
"cat"
,
cat_args
);
...
...
usys.S
浏览文件 @
d15f0d10
...
@@ -23,3 +23,4 @@ STUB(mknod)
...
@@ -23,3 +23,4 @@ STUB(mknod)
STUB(unlink)
STUB(unlink)
STUB(fstat)
STUB(fstat)
STUB(link)
STUB(link)
STUB(mkdir)
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论