Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
1f544842
提交
1f544842
8月 12, 2006
创建
作者:
kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fstat
primitive ls
上级
0633b971
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
115 行增加
和
5 行删除
+115
-5
Makefile
Makefile
+6
-2
defs.h
defs.h
+3
-0
fd.c
fd.c
+13
-0
fs.c
fs.c
+11
-0
ls.c
ls.c
+43
-0
stat.h
stat.h
+7
-0
syscall.c
syscall.c
+26
-0
syscall.h
syscall.h
+1
-0
user.h
user.h
+1
-1
userfs.c
userfs.c
+2
-1
usys.S
usys.S
+2
-1
没有找到文件。
Makefile
浏览文件 @
1f544842
...
...
@@ -87,11 +87,15 @@ sh : sh.o $(ULIB)
$(LD)
-N
-e
main
-Ttext
0
-o
sh sh.o
$(ULIB)
$(OBJDUMP)
-S
sh
>
sh.asm
ls
:
ls.o $(ULIB)
$(LD)
-N
-e
main
-Ttext
0
-o
ls
ls.o
$(ULIB)
$(OBJDUMP)
-S
ls
>
ls.asm
mkfs
:
mkfs.c fs.h
cc
-o
mkfs mkfs.c
fs.img
:
mkfs userfs usertests echo cat README init sh
./mkfs fs.img userfs usertests
echo cat
README init sh
fs.img
:
mkfs userfs usertests echo cat README init sh
ls
./mkfs fs.img userfs usertests
echo cat
README init sh
ls
-include
*.d
...
...
defs.h
浏览文件 @
1f544842
...
...
@@ -85,12 +85,14 @@ int pipe_write(struct pipe *p, char *addr, int n);
int
pipe_read
(
struct
pipe
*
p
,
char
*
addr
,
int
n
);
// fd.c
struct
stat
;
void
fd_init
(
void
);
int
fd_ualloc
(
void
);
struct
fd
*
fd_alloc
(
void
);
void
fd_close
(
struct
fd
*
);
int
fd_read
(
struct
fd
*
fd
,
char
*
addr
,
int
n
);
int
fd_write
(
struct
fd
*
fd
,
char
*
addr
,
int
n
);
int
fd_stat
(
struct
fd
*
fd
,
struct
stat
*
);
void
fd_incref
(
struct
fd
*
fd
);
// ide.c
...
...
@@ -115,6 +117,7 @@ void iunlock(struct inode *ip);
void
idecref
(
struct
inode
*
ip
);
void
iput
(
struct
inode
*
ip
);
struct
inode
*
namei
(
char
*
path
,
uint
*
);
void
stati
(
struct
inode
*
ip
,
struct
stat
*
st
);
int
readi
(
struct
inode
*
ip
,
char
*
xdst
,
uint
off
,
uint
n
);
int
writei
(
struct
inode
*
ip
,
char
*
addr
,
uint
off
,
uint
n
);
struct
inode
*
mknod
(
char
*
,
short
,
short
,
short
);
...
...
fd.c
浏览文件 @
1f544842
#include "types.h"
#include "stat.h"
#include "param.h"
#include "x86.h"
#include "mmu.h"
...
...
@@ -121,6 +122,18 @@ fd_close(struct fd *fd)
release
(
&
fd_table_lock
);
}
int
fd_stat
(
struct
fd
*
fd
,
struct
stat
*
st
)
{
if
(
fd
->
type
==
FD_FILE
){
ilock
(
fd
->
ip
);
stati
(
fd
->
ip
,
st
);
iunlock
(
fd
->
ip
);
return
0
;
}
else
return
-
1
;
}
void
fd_incref
(
struct
fd
*
fd
)
{
...
...
fs.c
浏览文件 @
1f544842
#include "types.h"
#include "stat.h"
#include "param.h"
#include "x86.h"
#include "mmu.h"
...
...
@@ -270,6 +271,16 @@ bmap(struct inode *ip, uint bn)
#define min(a, b) ((a) < (b) ? (a) : (b))
void
stati
(
struct
inode
*
ip
,
struct
stat
*
st
)
{
st
->
st_dev
=
ip
->
dev
;
st
->
st_ino
=
ip
->
inum
;
st
->
st_type
=
ip
->
type
;
st
->
st_nlink
=
ip
->
nlink
;
st
->
st_size
=
ip
->
size
;
}
int
readi
(
struct
inode
*
ip
,
char
*
dst
,
uint
off
,
uint
n
)
{
...
...
ls.c
0 → 100644
浏览文件 @
1f544842
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
char
buf
[
512
];
struct
stat
stat
;
struct
dirent
dirent
;
int
main
(
int
argc
,
char
*
argv
[])
{
int
fd
;
uint
off
;
if
(
argc
>
1
){
puts
(
"Usage: ls
\n
"
);
exit
();
}
fd
=
open
(
"."
,
0
);
if
(
fd
<
0
){
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
}
if
(
fstat
(
fd
,
&
stat
)
<
0
)
{
printf
(
2
,
"ls: cannot open .
\n
"
);
exit
();
}
if
(
stat
.
st_type
!=
T_DIR
)
{
printf
(
2
,
"ls: . is not a dir
\n
"
);
}
for
(
off
=
0
;
off
<
stat
.
st_size
;
off
+=
sizeof
(
struct
dirent
))
{
if
(
read
(
fd
,
&
dirent
,
sizeof
(
struct
dirent
))
!=
sizeof
(
struct
dirent
))
{
printf
(
2
,
"ls: read error
\n
"
);
exit
();
}
printf
(
1
,
"%s
\n
"
,
dirent
.
name
);
}
close
(
fd
);
exit
();
}
stat.h
0 → 100644
浏览文件 @
1f544842
struct
stat
{
int
st_dev
;
uint
st_ino
;
short
st_type
;
short
st_nlink
;
uint
st_size
;
};
syscall.c
浏览文件 @
1f544842
#include "types.h"
#include "stat.h"
#include "param.h"
#include "mmu.h"
#include "proc.h"
...
...
@@ -334,6 +335,28 @@ sys_unlink(void)
return
r
;
}
int
sys_fstat
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
uint
fd
,
addr
;
int
r
;
if
(
fetcharg
(
0
,
&
fd
)
<
0
)
return
-
1
;
if
(
fetcharg
(
1
,
&
addr
)
<
0
)
return
-
1
;
if
(
fd
<
0
||
fd
>=
NOFILE
)
return
-
1
;
if
(
cp
->
fds
[
fd
]
==
0
)
return
-
1
;
if
(
addr
+
sizeof
(
struct
stat
)
>
cp
->
sz
)
return
-
1
;
r
=
fd_stat
(
cp
->
fds
[
fd
],
(
struct
stat
*
)(
cp
->
mem
+
addr
));
return
r
;
}
int
sys_exec
(
void
)
{
...
...
@@ -570,6 +593,9 @@ syscall(void)
case
SYS_unlink
:
ret
=
sys_unlink
();
break
;
case
SYS_fstat
:
ret
=
sys_fstat
();
break
;
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
...
...
syscall.h
浏览文件 @
1f544842
...
...
@@ -14,4 +14,5 @@
#define SYS_open 14
#define SYS_mknod 15
#define SYS_unlink 16
#define SYS_fstat 17
user.h
浏览文件 @
1f544842
...
...
@@ -14,7 +14,7 @@ int exec(char *, char **);
int
open
(
char
*
,
int
);
int
mknod
(
char
*
,
short
,
short
,
short
);
int
unlink
(
char
*
);
int
fstat
(
int
fd
,
struct
stat
*
stat
);
int
puts
(
char
*
);
char
*
strcpy
(
char
*
,
char
*
);
void
printf
(
int
fd
,
char
*
fmt
,
...);
...
...
userfs.c
浏览文件 @
1f544842
#include "user.h"
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"
...
...
usys.S
浏览文件 @
1f544842
...
...
@@ -23,4 +23,5 @@ STUB(cons_puts)
STUB(exec)
STUB(open)
STUB(mknod)
STUB(unlink)
STUB(unlink)
STUB(fstat)
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论