Subject: Re: stat(2), st_size on devices
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@tac.gw.com>
List: tech-kern
Date: 02/16/2005 18:36:05
In article <20050216230852.GB3918@antioche.eu.org>,
Manuel Bouyer <bouyer@antioche.eu.org> wrote:
>-=-=-=-=-=-
>
>Hi,
>with the attached test program, I stat some disk device. Sometimes I
>get the real size of the parition, sometimes I get 0:
>rochebonne# disklabel wd2
>[...]
>8 partitions:
># size offset fstype [fsize bsize cpg/sgs]
> d: 156301488 0 unused 0 0 # (Cyl. 0 - 155060)
> e: 59999184 0 4.4LFS 0 0 0 # (Cyl. 0 - 59522)
> f: 59999184 59999184 4.2BSD 2048 16384 28808 # (Cyl. 59523 - 119045)
> g: 36303120 119998368 4.2BSD 0 0 0 # (Cyl. 119046 - 155060)
>rochebonne# /tmp/tstat /dev/rwd2d
>dev 0x0 rdev 0x313 size 80026361856 blocks 65536
>rochebonne# /tmp/tstat /dev/rwd2e
>dev 0x0 rdev 0x314 size 30719582208 blocks 65536
>rochebonne# /tmp/tstat /dev/rwd2f
>dev 0x0 rdev 0x315 size 0 blocks 65536
>rochebonne# /tmp/tstat /dev/rwd2g
>dev 0x0 rdev 0x316 size 0 blocks 65536
>rochebonne# /tmp/tstat /dev/wd2g
>dev 0x0 rdev 0x16 size 0 blocks 2048
>rochebonne# /tmp/tstat /dev/wd2f
>dev 0x0 rdev 0x15 size 30719582208 blocks 2048
>rochebonne# /tmp/tstat /dev/wd2e
>dev 0x0 rdev 0x14 size 30719582208 blocks 2048
>rochebonne# /tmp/tstat /dev/wd2d
>dev 0x0 rdev 0x13 size 0 blocks 2048
>
>Any reason for such a behavior ?
>
>--
>Manuel Bouyer <bouyer@antioche.eu.org>
> NetBSD: 26 ans d'experience feront toujours la difference
>--
>
>-=-=-=-=-=-
>
>#include <sys/stat.h>
>
>main(int argc, char **argv)
>{
> struct stat sb;
>
> if (stat(argv[1], &sb) < 0) {
> perror("stat");
> exit(1);
> }
> printf("dev 0x%x rdev 0x%x size %lld blocks %d\n",
> (int)sb.st_dev, (int)sb.st_rdev, (long long)sb.st_size,
> (int)sb.st_blksize);
>}
Looks like a bug to me. It gets the right size if the vnode is cached.
so doing:
dd if=/dev/foo of=/dev/null count=1
fixes it.
christos