Re: [SLUG] confused about file permissions

From: Eben King (eben1@tampabay.rr.com)
Date: Sat Oct 29 2005 - 08:43:17 EDT


On Sat, 29 Oct 2005, Paul M Foster wrote:

> On Sat, Oct 29, 2005 at 12:38:34AM -0400, Eben King wrote:
>
> > On Fri, 28 Oct 2005, Sick Twist wrote:
> >
> > > Having used Linux for some time, I thought I had a clear understanding of
> > > how file permissions work. However, I have no idea why I am able to
> > delete a
> > > file owned by someone else for which I do not have write permission:
> >
> > Whether you can delete a file depends on having write permission in its
> > directory, not on the permissions of the file itself. If you want to
> > truncate it and keep everything else -- inode, permissions, etc. -- the same
> > (e.g. "cat /dev/null > file"), you need to have write permission on the
> > file.
>
> Oh now you've gone and messed everything up. I had this all worked out,
> too, and now you've wrecked my understanding. ;-}
>
> If the permissions on the file itself don't have anything to do with
> whether one can write to or delete the file in a given directory,

They do affect whether you can write to it (that'd be modifying the file
data), but not whether you can delete it.

* What follows is my understanding. I welcome corrections. *

A directory is just another file, really. It's at something like

<file name>\0<file type>\0<inode>\0<other metadata>\0

so to delete a file involves deleting that line, thus modifying the
directory, not the file itself. Separators are not needed after fixed-width
fields, so some of that is wrong. Some extra stuff is done for files with
hard links, but I'm not sure what. I think there must be a list of hard
link locations and a link count, and when one reference to a file is
deleted, all link counts are decremented. But that sounds Byzantine; there
must be a simplification.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
CANCER:  The position of Jupiter says that you should spend the
rest of the week face down in the mud.  Try not to shove a roll of
duct tape up your nose when taking your driver's test.  -- Weird Al

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:55:36 EDT