[GRLUG] Solution: Subfs+ disk free issue

Raymond McLaughlin driveray at ameritech.net
Mon Jan 23 06:15:09 EST 2006


Fellow LUGnuts,

I just want to share with you all a solution I have come up with for a problem 
that has irked me for over a year. I'm sure I'm not the only one who has run 
into this problem.

On SuSE, since 9.2, and other modern distributions, I'm sure, removable media 
like CDs and USB drives are automounted subfs. And subfs mounted drives are not 
reported by disk usage tools like df. This makes it difficult to tell how much 
free space you have left on such devices, which can be a rather important thing 
to know.

It's really aggravating that the auto mount feature is supposed to be a 
convenience, but it really diminishes the usefulness of thumb drives and such if 
you don't know how much space you have left.

I found a suggestion to this solution in this archived thread on the opensuse 
mailing list: <http://www.mail-archive.com/opensuse@opensuse.org/msg05808.html>

My solution is to place the following shell script, called df, in /usr/local/bin.

#!/bin/bash
/bin/df
for i in $(mount | grep subfs | cut -d ' ' -f 3 )
  do ls $i >/dev/null
  /bin/df $i|grep / # "|grep /" avoids extra headers in output
done

(Don't forget to chmod +x /usr/local/bin/df.)
On distro's other than SuSE you might want to check th path to your df binary.
Because /usr/local/bin comes before /bin/ on your $PATH (at least on SuSE it 
does) this version will run when you 'df' on a command line, and it will also be 
the executable called by other programs, like kdf. This is the best part. KDE's 
KDiskFree (KMenu->System->File System->View Disk Usage) and KDE Control Module 
(Kmenu->System->Monitor->Storage Devices) are graphical front ends that use df, 
and so will show your subfs mounted devices, and display their used and free 
space. I don't know if gnome has any comparable tools.

One draw back is that if you have a CD in your drive it will spin up every 
refresh interval (default= 60 sec) for as long as you leave the KDF window open 
and the disk in the drive.

If I can do this in a shell script I'm sure that gnu coders could easily build 
this functionality into the regular df. (I can't my 'C' isn't nearly good 
enough.) I realize that core utilities need to be very conservative about adding 
new features, but I think this could be a good candidate for such a change. How 
many config scripts, etc, rely on subfs file system *not* being reported? And 
couldn't any of these be accommodated with a flag? The df man page already says 
that its output is not "POSIXLY_CORRECT" (in regard to block size) unless a 
special flag for such is set.

Reading the mailing list thread I referenced above suggests that making any 
fat32 partitions you have mount type subfs rather than vfat could solve the 
problem of making such partitions read-write accessable to more than one user at 
a time. While literally simultanious writes would still not be possible, the 
fact that it is only really mounted (and thus owned and locked to other user 
writes) when it is actually being accessed. In fact modern distros may be doing 
this now, I don't have any dual boot machins any more, so I don't know. At any 
rate it should work. And my improved df should make it better, provided no one 
points out any fatal flaws in it. ;-o

I hope some of you find this useful.
Raymond McLaughlin


More information about the grlug mailing list