2013-07-26 :-(
_ 午後
1300 ガジェット
_ [du][NetBSD]/usr/bin/du
du を眺めるなど。
fts を利用してディレクトリ構造をたどりながらファイルの stat をかき集めて ブロックサイズを印字する。という流れらしい。
The fts functions are provided for traversing UNIX file hierarchies.
du.c はこちら
http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/usr.bin/du/du.c
fts_open してひたすら fts_read してく
if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL) err(1, "fts_open `%s'", *argv);
for (rval = 0; (p = fts_read(fts)) != NULL;) { if (nflag) {
かき集めながら印字か
/* * If listing each file, or a non-directory file was * the root of a traversal, display the total. */ if (listfiles || !p->fts_level) prstat(p->fts_path, COUNT);
COUNT は冒頭に定義されている。
/* Count inodes or file size */ #define COUNT (iflag ? 1 : p->fts_statp->st_blocks)
st_blocks は stat(2) のメンバー変数。ブロック数を表す。
st_blocks The actual number of blocks allocated for the file in 512-byte units. As short symbolic links are stored in the inode, this number may be zero.
fts.c はつまり木構造をたどっていくry
http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/lib/libc/gen/fts.c
[ツッコミを入れる]