Subject: Re: df(1) on unmounted device works improperly
To: Johnny Billquist <bqt@update.uu.se>
From: Greywolf <greywolf@starwolf.com>
List: current-users
Date: 03/18/2003 10:21:28
Thus spake Johnny Billquist ("JB> ") sometime Today...

JB> > Hey, all,
JB> >
JB> > with -current kernel and userland as of a week ago (and, it seems, as
JB> > far back as 1.6M, if not farther), df(1) does The Wrong Thing.
JB>
JB> Hm.
JB> I'd say it does the right thing. I didn't know it ever could take a device
JB> as an argument and treat that specially, nor does the documentation
JB> support that. df takes a file or a file system as an argument. Device
JB> names are just special files. File systems are mount points as I read it.
JB>
JB> It behaves exactly as I would expect it to.

You haven't done this much, I take it. ;)

JB> I'd say you are looking at a change request. But I might be totally
JB> confused of course.

I'm going to go do this on a Solaris box now:

solaris8# df -kF ufs
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0    2056211   69564 1924961     4%    /
/dev/dsk/c0t0d0s3    1018191  781675  175425    82%    /usr
/dev/dsk/c0t0d0s4    4131866    9751 4080797     1%    /autohome
solaris8# prtvtoc /dev/dsk/c0t0d0s2
* /dev/dsk/c0t0d0s2 partition map
*
* Dimensions:
*     512 bytes/sector
*     248 sectors/track
*      19 tracks/cylinder
*    4712 sectors/cylinder
*    7508 cylinders
*    7506 accessible cylinders
*
* Flags:
*   1: unmountable
*  10: read-only
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      2    00          0   4198392   4198391   /
       1      3    01    4198392   1050776   5249167
       2      5    00          0  35368272  35368271
       3      4    00    5249168   2101552   7350719   /usr
       4      0    00    7350720   8392072  15742791   /autohome
       5      0    00   15742792   4198392  19941183
       6      0    00   19941184   4198392  24139575
       7      0    00   24139576  11228696  35368271
solaris8# truss -f -o /tmp/df.out df -k /dev/dsk/c0t0d0s5
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s5    2056211       9 1994505     0%
solaris8#

Looking at the way it behaves, it calls /usr/lib/fs/ufs/df on an unmounted
(but valid) fs, using ufs as the default, while it calls statvfs64
(equivalent to statfs for us) on a mounted one.

I would have guessed that the better way would have been to put it
into statfs(2) itself, but that might produce some "security problems"
(though, if what you're reading isn't a valid FS, and it rejects it,
I don't see what the problem is).

				--*greywolf;
--
NetBSD: The server is up!