Patch for FreeBSD 6.2 fstat(1) to support unionfs

Stuttgart, 20070812

fstat(1) from FreeBSD 6.2 can not display information about files which reside in a unionfs, as can be seen in this example:

USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W
pi       less       31028 root -         -  ?(unionfs)    -
pi       less       31028   wd -         -  ?(unionfs)    -
pi       less       31028 jail -         -  ?(unionfs)    -
pi       less       31028 text -         -  ?(unionfs)    -
pi       less       31028    0 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5 rw
pi       less       31028    1 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5 rw
pi       less       31028    2 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5 rw
pi       less       31028    3 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5  r
pi       less       31028    4 -         -  ?(unionfs)    -
This patch fixes it, as can be seen in this other example:
USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W
pi       less       31028 root /vserv/vserv3.nepustil.net 4804764 drwxrwxr-x     512  r  unionupper /usr    
pi       less       31028   wd /vserv/vserv3.nepustil.net 5042109 drwx------    1536  r  unionupper /usr    
pi       less       31028 jail /vserv/vserv3.nepustil.net 4804764 drwxrwxr-x     512  r  unionupper /usr    
pi       less       31028 text /vserv/vserv3.nepustil.net 5159119 -r-xr-xr-x  109300  r  unionlower /usr    
pi       less       31028    0 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5 rw
pi       less       31028    1 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5 rw
pi       less       31028    2 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5 rw
pi       less       31028    3 /vserv/vserv3.nepustil.net/dev    109 crw--w----   ttyp5  r
pi       less       31028    4 /vserv/vserv3.nepustil.net 5042526 -rw-------     702  r  unionupper /usr    
The filesytems involved:
f6# df [...]
Filesystem                     1K-blocks     Used    Avail Capacity  Mounted on
/dev/ad0s1e                     43938150 20634736 19788362    51%    /usr
[...]
<below>:/vserv/template/stage2  87876300 64572886 19788362    77%    /vserv/vserv3.nepustil.net
devfs                                  1        1        0   100%    /vserv/vserv3.nepustil.net/dev
[...]
were mounted with the following command:
/sbin/mount -t unionfs -o noatime,below,copymode=transparent /vserv/template/stage2 /vserv/vserv3.nepustil.net
/sbin/mount_devfs devfs /vserv/vserv3.nepustil.net

How to apply:

  
cd /tmp/
fetch http://opsec.eu/src/fstat-unionfs-patch/patch-20070812
cd /usr
patch < /tmp/patch-20070812
cd /usr/src/usr.bin/fstat/
make install
  
TODO: support other filesystems besides UFS as lower filesystems