LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author]
  From: Daryl Tester <dt@picknowl.com.au>
  To  : David Newall <davidn@rebel.net.au>
  Date: Thu, 27 Apr 2000 08:01:39 +0930

Re: Protecting files against power failure

David Newall wrote:

>> There is also chattr +S; while the man page says this applies to files,
>> I have seen documentation that says it works with directories as well.

> I doubt it.  That is, I doubt setting +S on a directory would have any
> affect on files "within" that directory.  Remember that files are uniquely
> identified by their inode number, not by any name, and files can (and
> regularly do) appear in multiple directories simultaneously.

The last time I devoted serious amounts of thought about this
(without resorting to the kernel sources), I concluded it was
the same effect as the setuid bits on a directory; upon creation
of the file the file inherits "some" attributes from the directory.
So this time, I actually checked it ...

[root@nipnyep /tmp]# mkdir /tmp/foo
[root@nipnyep /tmp]# chattr +S foo
[root@nipnyep /tmp]# lsattr -d foo
---S---- foo
[root@nipnyep /tmp]# touch foo/bar
[root@nipnyep /tmp]# lsattr foo/bar 
---S---- foo/bar

So that does appears to be the case.  My fault for being vague
originally (the original document that I refered to actually
recommended doing this to /var/spool/mqueue).

> Files can even appear in *no* directory.  (Try this: bash$ exec 5>foo
> 6<foo; ls -l / >&5; ls -l foo; rm foo; cat <&6)

Heh, File Systems 101 - it's one of the first things I try to teach
Unix Admin wannabees (usually after they've asked "why can't I free
up disk space when I've deleted this logfile?").  It would probably
make for a good job interview question for a Unix Admin position.

> I suppose when the kernel opens a file it could look back through the
> directory hierarchy, checking for +S in any of the outer directories, and
> associate that with the open file descriptor.  It doesn't seem likely,
> though.

You're right, it's not.


Regards,
  Daryl Tester

-- 
LinuxSA WWW: http://www.linuxsa.org.au/  IRC: #linuxsa on irc.linux.org.au
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author]
Return to the LinuxSA Mailing List Information Page