Subject: Re: Request For Comments!! POSIX atomic mv
To: None <zeurkous@nichten.info>
From: Johnny Billquist <bqt@softjar.se>
List: netbsd-users
Date: 12/14/2007 01:15:51
De Zeurkous skrev:
> Haai,
> 
> On Thu, December 13, 2007 22:26, George Georgalis wrote:
>> On Thu, Dec 13, 2007 at 07:41:57AM -0500, Izaac wrote:
>> [snip]
>>
>> I think I got it, but where is the content of /. stored?
> 
> If you mean the root directory (/), it's stored in an inode with itself as
> a parent. Try cd'ing to '/..' and seeing what happens. The '.' entry in /
> is simply a hard link to the same inode as /.

Or just do an "ls -lid /. /.." and notice that they both give the same inode number.

> If you mean the '.' entry in any directory, it's about the same: another
> hard link to the directory inode, like the one listed in it's parent
> directory (technically, for any inode multiple parent directories are
> allowed, but for some reason UNIX FS code maintainers don't like it with
> directories). An inode without a parent is considered deleted, but remains
> unreclaimed by the FS code until all fd's referring to it are closed.

The "some reason" is file structure consistency.
The ".." of a directory is expected to have a file name entry with the same 
inode number and vice versa. If a directory would have several parents, for all 
but one of the parents, subdir/.. would not point back to themself.
rmdir would become an interesting excercise...

And fsck is not happy as well.
It's basically a requirement for a sane file system that a directory only have 
one parent. fcsk will make sure of it.
(I remember creating a hard link to a directory in SunOS 4 once, a long time ago 
(had to be root to pull that off). Managed to get a directory that couldn't be 
deleted, and had to run fsck to clean the mess up.)

>> (no that's not a joke)
> 
> I didn't interpet it as such. It's a bit of a hard matter to explain using
> words. As is the case with many other concepts, understanding it requires
> a somewhat vivid imagination (however, a weird sense of humor is optional
> on this one :^).

I don't think it's that weird or difficult. It's just a matter of understanding 
the basic concepts of files and directories, and after that, everything else 
follows pretty logically.

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt@softjar.se             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol