Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
7239ca33
提交
7239ca33
2月 29, 2012
创建
作者:
Frans Kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sketch of parallel ls, but should probably use Silas's wq
上级
ff1eef00
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
107 行增加
和
0 行删除
+107
-0
pls.cc
bin/pls.cc
+107
-0
没有找到文件。
bin/pls.cc
0 → 100644
浏览文件 @
7239ca33
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
const
char
*
fmtname
(
const
char
*
path
)
{
static
char
buf
[
DIRSIZ
+
1
];
const
char
*
p
;
// Find first character after last slash.
for
(
p
=
path
+
strlen
(
path
);
p
>=
path
&&
*
p
!=
'/'
;
p
--
)
;
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
;
}
void
ls
(
const
char
*
path
)
{
char
buf
[
512
],
*
p
;
int
fd
;
struct
dirent
de
;
struct
stat
st
;
if
((
fd
=
open
(
path
,
0
))
<
0
){
fprintf
(
2
,
"ls: cannot open %s
\n
"
,
path
);
return
;
}
if
(
fstat
(
fd
,
&
st
)
<
0
){
fprintf
(
2
,
"ls: cannot stat %s
\n
"
,
path
);
close
(
fd
);
return
;
}
switch
(
st
.
type
){
case
T_FILE
:
fprintf
(
1
,
"%s %d %d %d
\n
"
,
fmtname
(
path
),
st
.
type
,
st
.
ino
,
st
.
size
);
break
;
case
T_DIR
:
if
(
strlen
(
path
)
+
1
+
DIRSIZ
+
1
>
sizeof
buf
){
fprintf
(
1
,
"ls: path too long
\n
"
);
break
;
}
strcpy
(
buf
,
path
);
p
=
buf
+
strlen
(
buf
);
*
p
++
=
'/'
;
while
(
read
(
fd
,
&
de
,
sizeof
(
de
))
==
sizeof
(
de
)){
if
(
de
.
inum
==
0
)
continue
;
memmove
(
p
,
de
.
name
,
DIRSIZ
);
p
[
DIRSIZ
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
){
fprintf
(
1
,
"ls: cannot stat %s
\n
"
,
buf
);
continue
;
}
fprintf
(
1
,
"%s %d %d %d
\n
"
,
fmtname
(
buf
),
st
.
type
,
st
.
ino
,
st
.
size
);
}
break
;
}
close
(
fd
);
}
void
work
(
void
*
arg
)
{
u64
tid
=
(
u64
)
arg
;
// grab and push work (may divide into blocks? and call ls on a block)?
// maybe implement getdirent sys call that gives you some unread dir entry
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
int
nthread
=
4
;
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
{
sbrk
(
8192
);
void
*
tstack
=
sbrk
(
0
);
// fprintf(1, "tstack %lx\n", tstack);
int
tid
=
forkt
(
tstack
,
(
void
*
)
thr
,
(
void
*
)(
u64
)
i
);
if
(
0
)
fprintf
(
1
,
"pls[%d]: child %d
\n
"
,
getpid
(),
tid
);
}
// push work wq.cc
if
(
argc
<
2
){
ls
(
"."
);
exit
();
}
for
(
i
=
1
;
i
<
argc
;
i
++
)
ls
(
argv
[
i
]);
for
(
int
i
=
0
;
i
<
nthread
;
i
++
)
wait
();
exit
();
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论