Subject: Re: -W flag in rm, undelete, "whiteout"'d files ?
To: Curt Sampson <curt@portal.ca>
From: Brian C. Grayson <bgrayson@ece.utexas.edu>
List: netbsd-users
Date: 04/23/1997 21:18:41
Curt Sampson wrote:
> 
> > the man page for "rm" talks about the "-W" flag, which is supposed to
> > recover files covered by whiteouts. what are they? it also references
> > "undelete(2)", for which there does not appear to be a man page.
> > is this a real method of undeleting files? if so, is there a way to
> > make sure a file cannot be undeleted?
> 
> I noticed a reference to `whiteout' file types when I was poking
> through the filesystem source code the other day. I didn't look
> too closely, but I get the impression that it's intended to be part
> of a way to `delete' a file without really deleting it, though
> creating opaque `whiteout' directories that the files get moved
> to.

  Since no one else has done a public answer (at least no
messages have reached me yet), I'll try my hand at it...

  Unless I'm mistaken, 'whiteouts' are used in the union
filesystem (see mount_union for a bit of information on
whiteouts).  I can't seem to find the docs where I originally
discovered this, but I believe they are used when deleting files
in using union filesystems, in order to hide a lower-layer
version of a file.  

  Perhaps one situation would be, modify a lower-layer file so
that the modified file now exists in the upper layer, with the
original still in the lower layer.  Then try to delete the file.
The upper-layer version will be deleted, but we don't want the
lower-layer version to now start showing up, because we
'delete'd it.  We also don't want to delete the lower-layer
version, because it's a union filesystem, and that's one of the
features of a union mount -- the lower layer is not allowed to
change (much).  So, cover up the lower-layer version with
'whiteout' in the upper layer so that it becomes not visible to
the union-mount, but still exists via non-union-mount access.

  Thus, rm -W doesn't allow one to recover arbitrary files --
only whiteout'd files, which were never really rm'd in the
first place -- they were just 'covered up'.

  A quick grep of 'hiteout' in /usr/src/sys/miscfs showed up
stuff only in the union directory.

  By the way, (semi-related topic) if you want to make certain files
undeletable (to protect yourself from yourself), look at the
man pages for chflags(1), in particular the schg or uchg option.
Successful deletion of such flagged files requires a 'chflags
no?chg foo' before the usual 'rm foo', which is usually
sufficient protection for me.

  Hope this helps!  Anyone want to correct me?  :)  I know there
are people out there who have used a union filesystem for more
than my 5-minute gee-whiz tinkerings...  I thought at least one
person had mentioned using union-mounts to keep a 'clean'
/usr/src tree in a lower layer, with local modifications in an
upper-layer.

  Brian
-- 
Brian Grayson (bgrayson@ece.utexas.edu)
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office:  ENS 406       (512) 471-8011
Finger bgrayson@orac.ece.utexas.edu for PGP key.