SYS V unlink() call

Kenneth Almquist ka at hropus.UUCP
Sat Feb 15 08:33:46 AEST 1986


> Does that mean that to delete [meaning unlink - ka] *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?

Yes, the manual means what it says.

This is true for all versions of UN*X.  The reason is that if normal users
were permitted to unlink directories, they might forget to unlink all the
entries in the directory first.  If they forgot to unlink the entry for ".",
the directory would become inaccessible when the entry for it in the parent
directory was unlinked, but the directory would not be deleted because there
would still be an entry pointing to it, namely the entry "." in the directory
itself.  If they remembered to unlink the entry for ".", but forgot to unlink
other entries in the directory, then when the directory disappeared the link
counts on the files or directories that these entries pointed to would be
incorrect.

4.2 BSD has a separate set of system calls called "mkdir" and "rmdir" which
allow non-superusers to create and delete directories and which check that
"." and ".." are handled correctly.  (Actually, the documentation claims
that you have to be superuser to invoke the mkdir system call, but this is
never checked for in the code.)  Under System V, all you have to do to create
and delete directories is to run the mkdir and rmdir programs.
				Kenneth Almquist
				ihnp4!houxm!hropus!ka	(official name)
				ihnp4!opus!ka		(shorter path)



More information about the Comp.unix.wizards mailing list