Subject: bin/9643: Unexpected behavior from rm -rf
To: None <firstname.lastname@example.org>
From: William O Ferry <email@example.com>
Date: 03/20/2000 02:09:44
>Synopsis: Unexpected behavior from rm -rf
>Responsible: bin-bug-people (Utility Bug People)
>Arrival-Date: Mon Mar 20 02:09:01 2000
>Originator: William O Ferry
>Release: <NetBSD-current source date> sup'ed 2000/03/16
System: NetBSD slipstream 1.4U NetBSD 1.4U (kernel) #22: Fri Mar 17 00:03:32 PST 2000 firstname.lastname@example.org:/usr/obj.i386/kernel i386
Attempting to remove a nonexistant file from a read-only directory
with "rm -rf" causes the "Read-only file system" error to be displayed, rather
than no error at all. "man rm" says that with the -f flag "If the file does
not exist, do not display a diagnostic message or modify the exist status to
reflect an error.", yet rm returns an error if the file does not exist but is
in a read-only filesystem.
Mount a filesystem as read-only.
Attempt to "rm -rf" a non-existant file in that mountpoint.
Ran across this one doing a "make clean" in an already cleaned, read-only
(using obj dirs) /usr/src.
Not sure exactly which piece of code should be corrected here. In rm
the "problem" begins with line 194. If the -r and -f flags were set we end
up at this clause, and needstat is false. So we fall out of the switch
statement and enter the second one, which ends up in the default case.
unlink() sets errno to EROFS, which does not count as true for the
NONEXISTENT() macro, so we end up at the warn() and print the error message
for EROFS. I suspect this code path could be adjusted to prevent this from
happening, I'm not sure where the best place to modify things would be.
The other possible problem is that unlink() returns EROFS in this
case. Should unlink() return ENOENT if the file doesn't exist whether the
directory is writable or not, or is EROFS the right error response?