NetBSD Problem Report #32413

From mlelstv@henery.1st.de  Thu Dec 29 16:33:55 2005
Return-Path: <mlelstv@henery.1st.de>
Received: from serpens.de (serpens.de [62.208.181.200])
	by narn.netbsd.org (Postfix) with ESMTP id 6D1AC63B869
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 29 Dec 2005 16:33:54 +0000 (UTC)
Message-Id: <200512291633.jBTGXWBX025803@henery.1st.de>
Date: Thu, 29 Dec 2005 17:33:32 +0100 (CET)
From: mlelstv@serpens.de
Reply-To: mlelstv@serpens.de
To: gnats-bugs@netbsd.org
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
>Closed-Date:    
>Last-Modified:  Sun Jan 20 15:13:40 +0000 2008
>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:


>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->analyzed
State-Changed-By: pooka@narn.netbsd.org
State-Changed-When: Sun, 20 Jan 2008 17:13:40 +0200
State-Changed-Why:
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!)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

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