Add a wq_for to xls, and print wq_stats in xls and xdu

上级 9a9ea644
...@@ -73,5 +73,6 @@ main(int ac, char **av) ...@@ -73,5 +73,6 @@ main(int ac, char **av)
{ {
initwq(); initwq();
printf("%ld\n", du(open(".", 0))); printf("%ld\n", du(open(".", 0)));
wq_dump();
return 0; return 0;
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include "user/dirit.hh" #include "user/dirit.hh"
#include "wq.hh"
#define ST_SIZE(st) (st).st_size #define ST_SIZE(st) (st).st_size
#define ST_TYPE(st) (ST_ISDIR(st) ? 1 : ST_ISREG(st) ? 2 : 3) #define ST_TYPE(st) (ST_ISDIR(st) ? 1 : ST_ISREG(st) ? 2 : 3)
#define ST_INO(st) (st).st_ino #define ST_INO(st) (st).st_ino
...@@ -46,25 +47,29 @@ ls(const char *path) ...@@ -46,25 +47,29 @@ ls(const char *path)
close(fd); close(fd);
return; return;
} }
if (ST_ISREG(st)) { if (ST_ISREG(st)) {
printf("%u %10lu %10lu %s\n", ST_TYPE(st), ST_INO(st), ST_SIZE(st), path); printf("%u %10lu %10lu %s\n", ST_TYPE(st), ST_INO(st), ST_SIZE(st), path);
close(fd);
} else if (ST_ISDIR(st)) { } else if (ST_ISDIR(st)) {
dirit di(fd); dirit di(fd);
for (; !di.end(); ++di) { wq_for<dirit>(di,
const char *name = di.copy_value(); [](dirit &i)->bool { return !i.end(); },
[&fd](const char *name)->void
{
struct stat st;
if (xfstatat(fd, name, &st) < 0){ if (xfstatat(fd, name, &st) < 0){
printf("ls: cannot stat %s\n", name); printf("ls: cannot stat %s\n", name);
free((void*)name); free((void*)name);
continue; return;
} }
printf("%u %10lu %10lu %s\n", ST_TYPE(st), ST_INO(st), ST_SIZE(st), name); printf("%u %10lu %10lu %s\n", ST_TYPE(st), ST_INO(st), ST_SIZE(st), name);
free((void*)name); free((void*)name);
} });
} else {
close(fd);
} }
close(fd);
} }
int int
...@@ -72,11 +77,16 @@ main(int argc, char *argv[]) ...@@ -72,11 +77,16 @@ main(int argc, char *argv[])
{ {
int i; int i;
if(argc < 2){ initwq();
if(argc < 2) {
ls("."); ls(".");
return 0; } else {
// XXX(sbw) wq_for
for (i=1; i<argc; i++)
ls(argv[i]);
} }
for(i=1; i<argc; i++)
ls(argv[i]); wq_dump();
return 0; return 0;
} }
...@@ -7,6 +7,7 @@ class work; ...@@ -7,6 +7,7 @@ class work;
int wq_trywork(void); int wq_trywork(void);
int wq_push(work *w); int wq_push(work *w);
void initwq(void); void initwq(void);
void wq_dump(void);
struct work { struct work {
virtual void run() = 0; virtual void run() = 0;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论