Subject: kern/32413: stat on a special file doesn't reveal size until it was opened
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <mlelstv@serpens.de>
List: netbsd-bugs
Date: 12/29/2005 16:35:00
>Number:         32413
>Category:       kern
>Synopsis:       stat on a special file doesn't reveal size until it was opened
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 29 16:35:00 +0000 2005
>Originator:     Michael van Elst
>Release:        NetBSD 3.0
>Organization:
	
>Environment:
	
	
System: NetBSD henery 3.0 NetBSD 3.0 (HENERY) #17: Wed Dec 28 12:13:19 CET 2005 src@henery:/usr/obj/home/src/sys/arch/i386/compile/HENERY i386
Architecture: i386
Machine: i386
>Description:
When you stat() a character or block special file of a disk device
the returned size should reflect the disk or partition size.

This seems to work for some partitions but not for all.

The reason is that the v_size field of the vnode is only filled
when opening the device. Devices that are mounted and thus have
been opened and return a valid size. Using a device for swapping
is not sufficient though.

Opening a partition (say by reading with 'dd') fills the data for
the 'd' partition as well. The 'c' partition on the other hand cannot
be accessed.

Even when the device is closed again the data is kept (probably
because the vnode is cached).

The relevant code is in sys/miscfs/specfs/spec_vnops.c.

>How-To-Repeat:

stat -f "%N %z" /dev/wd0*
stat -f "%N %z" /dev/sd0*
...

>Fix:
	

>Unformatted: