NetBSD Problem Report #32413

From  Thu Dec 29 16:33:55 2005
Return-Path: <>
Received: from ( [])
	by (Postfix) with ESMTP id 6D1AC63B869
	for <>; Thu, 29 Dec 2005 16:33:54 +0000 (UTC)
Message-Id: <>
Date: Thu, 29 Dec 2005 17:33:32 +0100 (CET)
Subject: stat on a special file doesn't reveal size until it was opened
X-Send-Pr-Version: 3.95

>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:          analyzed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 29 16:35:00 +0000 2005
>Last-Modified:  Sun Jan 20 15:13:40 +0000 2008
>Originator:     Michael van Elst
>Release:        NetBSD 3.0


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
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.


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




State-Changed-From-To: open->analyzed
State-Changed-When: Sun, 20 Jan 2008 17:13:40 +0200
stat should always report 0:
1) you can't know the size of a disk device without opening it and
   you don't want to open every device when you ls -l /dev
2) the size can change behind the vnode's back, so the cached value can
   become stale (already a problem!)


NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD:,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.