1

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.

2 Answers2

3

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.

  • Thanks, but can you give me a detail explanation on how are directories maintained by the file system? At least some pointers to it. – Navaneeth Sen Jan 12 '11 at 05:45
  • 2
    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: http://en.wikipedia.org/wiki/ReiserFS#Design . That question has as many answers as there are filesystems. –  Jan 12 '11 at 14:06
2

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'.

Janus
  • 1,533