Документ взят из кэша поисковой машины. Адрес оригинального документа : http://star.arm.ac.uk/sag-0.4/node95.html
Дата изменения: Sun May 4 15:24:42 1997
Дата индексирования: Mon Oct 1 22:52:03 2012
Кодировка:

Поисковые слова: molecules
Measuring Holes next up previous contents index
Next: Glossary (DRAFT) Up: Linux System Administrators' Guide Previous: When the clock is

Measuring Holes

 

This appendix contains the interesting part of the program used to measure the potential for holes in a filesystem. 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 May 4 14:08:43 EEST 1997