next up previous contents index
Next: Glossary (DRAFT) Up: Linux System Administrators' Guide Previous: When the clock is

测量孔(Measuring Holes)

 

本附录包括用于测量文件系统中潜在的孔的程序的有趣的部分。 The source distribution of the book contains the full source code(sag/measure-holes/measure-holes.c).

int process(FILE *f, char *filename) {
        static char *buf = NULL;
        static long prev_block_size = -1;
        long zeroes;
        char *p;

        if (buf == NULL || prev_block_size != block_size) {
                free(buf);
                buf = xmalloc(block_size + 1);
                buf[block_size] = 1;
                prev_block_size = block_size;
        }
        zeroes = 0;
        while (fread(buf, block_size, 1, f) == 1) {
                for (p = buf; *p == '\0'; )
                        ++p;
                if (p == buf+block_size)
                        zeroes += block_size;
        }
        if (zeroes > 0)
                printf("%ld %s\n", zeroes, filename);
        if (ferror(f)) {
                errormsg(0, -1, "read failed for `%s'", filename);
                return -1;
        }
        return 0;
}


Lars Wirzenius
Sun Jun 29 13:31:22 EEST 1997