Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
b6be3a2f
提交
b6be3a2f
3月 05, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ulib fstatat
上级
3d00ccd2
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
12 行删除
+20
-12
xls.cc
bin/xls.cc
+5
-12
user.h
include/user.h
+1
-0
ulib.c
lib/ulib.c
+14
-0
没有找到文件。
bin/xls.cc
浏览文件 @
b6be3a2f
...
...
@@ -12,6 +12,7 @@
#define ST_ISDIR(st) S_ISDIR((st).st_mode)
#define ST_ISREG(st) S_ISREG((st).st_mode)
#define BSIZ 256
#define xfstatat(fd, n, st) fstatat(fd, n, st, 0)
#else // assume xv6
#include "types.h"
#include "stat.h"
...
...
@@ -26,12 +27,12 @@
#define ST_ISREG(st) ((st).type == T_FILE)
#define BSIZ (DIRSIZ + 1)
#define stderr 2
#define xfstatat fstatat
#endif
void
ls
(
const
char
*
path
)
{
char
buf
[
512
],
*
p
;
int
fd
;
struct
stat
st
;
...
...
@@ -49,21 +50,13 @@ ls(const char *path)
if
(
ST_ISREG
(
st
))
{
printf
(
"%u %10lu %10lu %s
\n
"
,
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
),
path
);
}
else
if
(
ST_ISDIR
(
st
))
{
if
(
strlen
(
path
)
+
1
+
BSIZ
>
sizeof
buf
)
{
printf
(
"ls: path too long
\n
"
);
}
strcpy
(
buf
,
path
);
p
=
buf
+
strlen
(
buf
);
*
p
++
=
'/'
;
dirit
di
(
fd
);
for
(;
!
di
.
end
();
++
di
)
{
const
char
*
name
=
*
di
;
size_t
len
=
strlen
(
name
);
memmove
(
p
,
name
,
len
);
p
[
len
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
){
if
(
xfstatat
(
fd
,
name
,
&
st
)
<
0
){
printf
(
"ls: cannot stat %s
\n
"
,
name
);
free
((
void
*
)
name
);
printf
(
"ls: cannot stat %s
\n
"
,
buf
);
continue
;
}
...
...
include/user.h
浏览文件 @
b6be3a2f
...
...
@@ -34,6 +34,7 @@ int setfs(u64 base);
// ulib.c
int
stat
(
char
*
,
struct
stat
*
);
int
fstatat
(
int
dirfd
,
const
char
*
,
struct
stat
*
);
char
*
strcpy
(
char
*
,
const
char
*
);
void
*
memmove
(
void
*
,
const
void
*
,
int
);
char
*
strchr
(
const
char
*
,
char
c
);
...
...
lib/ulib.c
浏览文件 @
b6be3a2f
...
...
@@ -102,6 +102,20 @@ stat(char *n, struct stat *st)
}
int
fstatat
(
int
dirfd
,
const
char
*
n
,
struct
stat
*
st
)
{
int
fd
;
int
r
;
fd
=
openat
(
dirfd
,
n
,
O_RDONLY
);
if
(
fd
<
0
)
return
-
1
;
r
=
fstat
(
fd
,
st
);
close
(
fd
);
return
r
;
}
int
atoi
(
const
char
*
s
)
{
int
n
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论