Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On behalf of this particular question I would like to know how directories are managed in the file system. What does the author of the above question mean by telling

each directory has n+2 pointers to itself

I would like to get more clarity and info on this.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

As far as I can tell, any directory that contains n sub-directories has n+2 links to itself.

Every directory has a '.' entry that's a link to itself. Every directory's parent has a link to it.

That's 2 links.

Every sub-directory has a '..' in it, which is a link to the directory in question. If your directory has n directories in it, that's n links.

So a total of n+2 links to any given directory.

share|improve this answer
    
Thanks, but can you give me a detail explanation on how are directories maintained by the file system? At least some pointers to it. –  Sen Jan 12 '11 at 5:45
1  
The problem with that question is that no two filesystems do directories the same way. In some (SysV, FFS) directories are just files, albeit with a specified organization. In ResierFS, they're part of a database, almost: en.wikipedia.org/wiki/ReiserFS#Design . That question has as many answers as there are filesystems. –  Bruce Ediger Jan 12 '11 at 14:06

Linux filesystems are all POSIX compliant and rely on an inode pointer structure to represent directory relations. Apart from the above Wikipedia link, you can have a look at the POSIX inode description, or the IBM article on 'The anatomy of the Linux filesystem'.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.