SYS V unlink() call

Andrew Koenig ark at alice.UucP
Sat Feb 15 10:48:49 AEST 1986


> Our system (a CRDS Universe/32 w/ Unos 6.1) is based
> on Unix V, or to be more precise, is SYS V compatible.
>
> My question is this: In SYSV do you have* to be SU
> to unlink directories? I wrote a program that 
> unlinks whatever file name is passed to it to 
> confirm my ideas, and sure enough, it would not
> remove (unlink) a file that is a directory even if
> I owned it, and it had write permission. The error 
> I get back is EPERM..Looking it up in the good olde
> System V Interface Definition Book (Spring 1985 - Issue 1)
> on page 143:
>
>	[EPERM]		The named file is a directory and
>			the effective user ID of the process
>			is not super-user.
> 
> Does that mean that to delete *any* directory the program
> must be set uid'ed to root? I can't believe that this is
> what is really meant here, and it must be some sort of typo.
> Could anyone from Bell please clarify this?

Correct: only the super-user can unlink a directory.  It has
always been thus (at least as far back as V6).  The reason is
that removing a directory is not simply a matter of breaking the
link to it from its parent.  One must also break the link FROM
the directory TO its parent (always named "..") and the link
from the directory to itself (always named ".").  Unless all three
of these things are done in the proper order, there is the possibility
of various kinds of file system damage.

In order to restrict unlinking of directories to programs that take
pains to do the right things, the system allows only the super-user
to break a link to a directory.

Why can't you believe this is what is really meant?



More information about the Comp.unix.wizards mailing list