[TUHS] question about mkfs(8) and stdio

Kenneth Stailey kstailey at yahoo.com
Mon Dec 15 05:11:20 AEST 2003

Did stdio buffering change over time?

If you look at an old BSD mkfs for cylinder-group style file systems (not 7th
Ed filesystems) you will see the super block backup loop does not fflush(stdio)
between printf()s

        printf("super-block backups (for fsck -b#) at:");
        for (cylno = 0; cylno < sblock.fs_ncg; cylno++) {
                if (cylno % 10 == 0)
                printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno)));

but I have memories that the superblocks were printed out one at a time as if
fflush(stdout) was called between them rather than one line at a time with
line-buffered stdio.

At some point I thought "SysV must have broke this" since newfs would print out
a complete row of superblock numbers at once with a big delay between the rows
rather than each superblock number with a short delay between each number.

But when I go searching the oldest BSD code has no fflush(stdout) the way
modern FreeBSD does:

        for (cylno = 0; cylno < sblock.fs_ncg; cylno++) {
                initcg(cylno, utime);
                if (mfs)
                j = snprintf(tmpbuf, sizeof(tmpbuf), " %ld%s",
                    fsbtodb(&sblock, cgsblock(&sblock, cylno)),
                    cylno < (sblock.fs_ncg-1) ? "," : "" );
                if (i + j >= width) {
                        i = 0;
                i += j;
                printf("%s", tmpbuf);

Did stdio buffering change over time so that line buffering became the default?


Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

More information about the TUHS mailing list