Subject: kern/29679: st_blksize is 0 for write side of pipe
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <Gunnar.Ritter@pluto.uni-freiburg.de>
List: netbsd-bugs
Date: 03/12/2005 16:46:01
>Number:         29679
>Category:       kern
>Synopsis:       st_blksize is 0 for write side of pipe
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 12 16:46:00 +0000 2005
>Originator:     Gunnar Ritter
>Release:        2.0
>Organization:
n/a
>Environment:
NetBSD jadzia.ritter 2.0 NetBSD 2.0 (GENERIC) #0: Wed Dec  1 10:58:25 UTC 2004  builds@build:/big/builds/ab/netbsd-2-0-RELEASE/i386/200411300000Z-obj/big/builds/ab/netbsd-2-0-RELEASE/src/sys/arch/i386/compile/GENERIC i386
>Description:
When running fstat() on the write side file descriptor obtained from pipe(), st_blksize is zero (see the test program below). This causes problems with applications that rely on the sanity of this value as obtained from the kernel.
>How-To-Repeat:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

main()
{
        struct stat st;
        int p[2];

        pipe(p);
        if (fstat(p[0], &st) < 0)
                abort();
        fprintf(stderr, "%ld\n", (long)st.st_blksize); /* prints 16384 */
        if (fstat(p[1], &st) < 0)
                abort();
        fprintf(stderr, "%ld\n", (long)st.st_blksize); /* prints 0 */
}
>Fix: