Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
12e70a36
提交
12e70a36
3月 02, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Yet another du
上级
3820b87f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
114 行增加
和
3 行删除
+114
-3
Makefrag
bin/Makefrag
+4
-3
xdu.cc
bin/xdu.cc
+110
-0
没有找到文件。
bin/Makefrag
浏览文件 @
12e70a36
...
...
@@ -20,9 +20,10 @@ UPROGS= \
preadtest \
scripttest \
ftest \
perf
# pdu
# pls
perf \
xdu
# pdu
# pls
ifeq ($(HAVE_LWIP),y)
UPROGS += \
...
...
bin/xdu.cc
0 → 100644
浏览文件 @
12e70a36
#if defined(LINUX)
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
#define ST_SIZE(st) (st).st_size
#define ST_ISDIR(st) S_ISDIR((st).st_mode)
#define BSIZ 256
typedef
DIR
*
dir_t
;
static
inline
int
getdent
(
dir_t
d
,
char
*
buf
,
size_t
n
)
{
struct
dirent
*
entryp
,
*
result
;
char
*
dbuf
[
512
];
int
r
;
entryp
=
(
struct
dirent
*
)
dbuf
;
r
=
readdir_r
(
d
,
entryp
,
&
result
);
if
(
r
==
0
&&
result
!=
NULL
)
{
strcpy
(
buf
,
entryp
->
d_name
);
return
0
;
}
return
-
1
;
}
#else // assume xv6
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#define ST_SIZE(st) (st).size
#define ST_ISDIR(st) ((st).type == T_DIR)
#define stderr 2
#define BSIZ (DIRSIZ+1)
typedef
int
dir_t
;
static
inline
dir_t
fdopendir
(
int
fd
)
{
return
fd
;
}
static
inline
void
closedir
(
dir_t
d
)
{
}
static
inline
int
getdent
(
dir_t
fd
,
char
*
buf
,
size_t
n
)
{
struct
dirent
de
;
int
r
;
again:
r
=
read
(
fd
,
&
de
,
sizeof
(
de
));
if
(
r
==
sizeof
(
de
))
{
if
(
de
.
inum
==
0
)
goto
again
;
memmove
(
buf
,
de
.
name
,
n
-
1
);
buf
[
n
-
1
]
=
0
;
return
0
;
}
return
-
1
;
}
#endif
static
int
du
(
int
fd
)
{
struct
stat
st
;
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
fprintf
(
stderr
,
"du: cannot stat
\n
"
);
close
(
fd
);
return
0
;
}
int
size
=
ST_SIZE
(
st
);
if
(
ST_ISDIR
(
st
))
{
char
buf
[
BSIZ
];
dir_t
d
=
fdopendir
(
fd
);
while
(
getdent
(
d
,
buf
,
BSIZ
)
==
0
)
{
if
(
!
strcmp
(
buf
,
"."
)
||
!
strcmp
(
buf
,
".."
))
continue
;
int
nfd
=
openat
(
fd
,
buf
,
0
);
if
(
nfd
>=
0
)
size
+=
du
(
nfd
);
// should go into work queue
}
closedir
(
d
);
}
close
(
fd
);
return
size
;
}
int
main
(
int
ac
,
char
**
av
)
{
printf
(
"%d
\n
"
,
du
(
open
(
"."
,
0
)));
return
0
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论