Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ukma!rutgers!rochester!cornell!uw-beaver!blake!ogccse!littlei!uunet!mcvax!ukc!etive!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.unix.questions Subject: Re: File Write Permission Rules Message-ID: <173@skye.ed.ac.uk> Date: 13 Feb 89 20:28:29 GMT References: <306@wubios.wustl.edu> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 62 In article <306@wubios.wustl.edu> david@wubios.wustl.edu (David J. Camp) writes: >We have a strange situation where a program can write to a file even >though it does not have write permission. What it does is remove the >file and write a new one in its place. It can do this because it has >write permission to the directory in which the file is contained. > >My question is: What is the (historical or otherwise) justification for >this rule? It seems wrong. I would have required write permission to >the file itself in order that it be removed. In Unix, a file has an existence separate from a directory entry that refers to it. Changing the file, and changing a reference to it in a directory, are logically distinct. So it's not surprising that there are separate permissions for the two operations. Of course, the kernel could prevent you from removing a reference to a file you can't write. Why doesn't it? Because it would remove a useful feature. This feature is most apparent when there are multiple references (or "links" as they're usually known) to a single file. Then writing the file has a quite different effect from removing it and creating a new file. Try it: % echo hello > fred % ln fred jane % ls -li fred janeb 571 -rw-r--r-- 2 richard 6 Feb 13 20:20 fred 571 -rw-r--r-- 2 richard 6 Feb 13 20:20 jane ^ ^ | this says there are two links to the file this is the "inode number" of the file, which identifies it uniquely (more or less) % echo xyzzy >fred % cat fred xyzzy % cat jane xyzzy skye% ls -li fred jane 571 -rw-r--r-- 2 richard 6 Feb 13 20:23 fred 571 -rw-r--r-- 2 richard 6 Feb 13 20:23 jane ^ still the same file % rm jane % echo plugh >jane % cat fred xyzzy % cat jane plugh % ls -li fred jane 571 -rw-r--r-- 1 richard 6 Feb 13 20:23 fred 586 -rw-r--r-- 1 richard 6 Feb 13 20:25 jane ^ now they're different files -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nss.cs.ucl.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin