[OT] RE: Being denied my own files!

Miles Goodhew mgoodhew at gmail.com
Fri Mar 11 13:23:23 UTC 2005


Hi,
  The magic of Unix inodes:

    No user can _actually_ delete a file (Not even root)!

  However, If a user can write to a directory (and root can write to
any local directory not on a read-only filesystem), then that user can
delete the link to the file (i.e. delete the file's name from the
directory). If a file's link count (= number of directories the file
has a name in) and the number of references (= number of open file
descriptors for the file) both go to zero, then the system deallocates
the files data blocks and makes the file's inode (which is the unique
head of a file) reusable for new files.

Exercise:

% echo "This is the first file" >file1
% ln file1 file2 # Do _not_ put a "-s" here!
% ls -li file?

  The inode number is the first column - file1 and file2 have the same
inode -> they're the same file (just two different names for it - the
inode and all data blocks on disk ate the same thing). The link count
is the column after the mode bits - it's has the value 2 indicating
that the file has two names.

% rm file1
% cat file2

  Hmm, look familiar?

Bonus brainteasers:
* How many links does "/" have? Why? What are ".." and "."?
* What's a symbolic link.
* What do "chmod g+s" and "chmod u+s" do to files/directories (This
can be fun on Sunos!)

Moles.

-- 
Miles Goodhew, Senior Hacker
TransACT communications




More information about the desktop mailing list