Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
64f096c7
提交
64f096c7
3月 03, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
In progress userspace wq and du stuff
上级
9ba75050
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
117 行增加
和
54 行删除
+117
-54
xdu.cc
bin/xdu.cc
+15
-54
dirit.hh
include/dirit.hh
+38
-0
wq.hh
include/wq.hh
+9
-0
Makefrag.wq
user/Makefrag.wq
+17
-0
dirit.hh
user/dirit.hh
+38
-0
没有找到文件。
bin/xdu.cc
浏览文件 @
64f096c7
...
...
@@ -6,71 +6,28 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <stdint.h>
#include <stddef.h>
#include <errno.h>
#include "include/wq.hh"
#include "user/dirit.hh"
#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 "lib.h"
#include "fs.h"
#include "wq.hh"
#include "dirit.hh"
#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
...
...
@@ -85,17 +42,21 @@ du(int fd)
int
size
=
ST_SIZE
(
st
);
if
(
ST_ISDIR
(
st
))
{
char
buf
[
BSIZ
];
dir_t
d
=
fdopendir
(
fd
);
while
(
getdent
(
d
,
buf
,
BSIZ
)
==
0
)
{
dirit
di
(
fd
);
wq_for
<
dirit
>
(
di
,
[](
dirit
&
i
)
->
bool
{
return
!
i
.
end
();
},
[
&
](
dirit
&
i
)
->
void
{
char
buf
[
BSIZ
];
i
.
name
(
buf
,
BSIZ
);
if
(
!
strcmp
(
buf
,
"."
)
||
!
strcmp
(
buf
,
".."
))
continue
;
return
;
int
nfd
=
openat
(
fd
,
buf
,
0
);
if
(
nfd
>=
0
)
size
+=
du
(
nfd
);
// should go into work queue
}
closedir
(
d
);
});
}
close
(
fd
);
...
...
include/dirit.hh
0 → 100644
浏览文件 @
64f096c7
class
dirit
{
public
:
dirit
(
int
fd
)
:
fd_
(
fd
),
end_
(
false
)
{
refill
();
}
dirit
&
operator
++
()
{
refill
();
return
*
this
;
}
bool
end
()
const
{
return
end_
;
}
char
*
name
(
char
*
buf
,
size_t
n
)
const
{
n
=
MIN
(
DIRSIZ
+
1
,
n
);
memmove
(
buf
,
de_
.
name
,
n
-
1
);
buf
[
n
-
1
]
=
0
;
return
buf
;
}
private
:
void
refill
(
void
)
{
int
r
;
again
:
r
=
read
(
fd_
,
&
de_
,
sizeof
(
de_
));
if
(
r
==
sizeof
(
de_
))
{
if
(
de_
.
inum
==
0
)
goto
again
;
}
else
{
end_
=
true
;
}
}
int
fd_
;
bool
end_
;
struct
dirent
de_
;
};
include/wq.hh
浏览文件 @
64f096c7
...
...
@@ -7,3 +7,12 @@ struct work {
void
*
arg4
;
char
data
[];
};
template
<
typename
IT
,
typename
BODY
>
static
inline
void
wq_for
(
IT
&
init
,
bool
(
*
cond
)(
IT
&
it
),
BODY
body
)
{
for
(
IT
&
it
=
init
;
cond
(
it
);
++
it
)
{
body
(
it
);
}
}
user/Makefrag.wq
0 → 100644
浏览文件 @
64f096c7
NCXXFLAGS = -static -g -MD -m64 -O3 -Wall -Werror -DHW_$(HW) -DXV6 \
-fno-builtin -fno-strict-aliasing -fno-omit-frame-pointer \
-fms-extensions -mno-sse -mcx16 -mno-red-zone -std=c++0x \
-Wno-sign-compare -fno-exceptions -fno-rtti -fcheck-new -I.
$(O)/user/%.o: bin/%.cc
@echo " CXX $@"
$(Q)mkdir -p $(@D)
$(Q)$(CXX) -DLINUX $(NCXXFLAGS) -c -o $@ $<
$(O)/xdu: $(O)/user/xdu.o
@echo " LD $@"
$(Q)mkdir -p $(@D)
$(Q)$(CXX) -o $@ $^ -lpthread
.PRECIOUS: $(O)/user/%.o
-include $(O)/user/*.d
user/dirit.hh
0 → 100644
浏览文件 @
64f096c7
#include <sys/types.h>
#include <dirent.h>
class
dirit
{
public
:
dirit
(
int
fd
)
:
fd_
(
fd
),
end_
(
false
)
{
d_
=
fdopendir
(
fd
);
ent_
=
(
struct
dirent
*
)
ebuf_
;
refill
();
}
dirit
&
operator
++
()
{
refill
();
return
*
this
;
}
bool
end
()
const
{
return
end_
;
}
char
*
name
(
char
*
buf
,
size_t
n
)
const
{
strncpy
(
buf
,
ent_
->
d_name
,
n
-
1
);
buf
[
n
-
1
]
=
0
;
return
buf
;
}
private
:
void
refill
(
void
)
{
struct
dirent
*
result
;
int
r
=
readdir_r
(
d_
,
ent_
,
&
result
);
if
(
r
!=
0
||
result
==
NULL
)
end_
=
true
;
}
int
fd_
;
bool
end_
;
char
*
ebuf_
[
512
];
struct
dirent
*
ent_
;
DIR
*
d_
;
};
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论