LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2013, 05:30 AM   #1
IMAX
LQ Newbie
 
Registered: Mar 2013
Posts: 6

Rep: Reputation: Disabled
Question Question about the root dir`s inode


$ls / -1ia
2 .
2 ..

Why Unix/Linux assigned same inode number on the root dir?
What`s advantage of that design?
How about set NULL with its ".." inode number 2?
 
Old 03-14-2013, 06:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
The first inode number is 1. 0 is used as a NULL value, to indicate that there is no inode. Inode 1 is used to keep track of any bad blocks on the disk; it is essentially a hidden file containing the bad blocks, so that they will not be used by another file. The meaning of particular inode numbers differs by file-system.

Also have a look here: Ext4 Disk Layout (especially the Special Inodes / Block and Inode Allocation Policy section).

This might also be worth while a read: Anatomy of the Linux file system
 
1 members found this post helpful.
Old 03-14-2013, 08:28 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by IMAX View Post
$ls / -1ia
2 .
2 ..

Why Unix/Linux assigned same inode number on the root dir?
What`s advantage of that design?
How about set NULL with its ".." inode number 2?
A directory structure is implemented as a tree. Each directory has an entry that points to the data that describes the files listed - basically, the data is a list of pairs: inode number and file name.
The pointer to the directory file is the "." entry.

For management handling, each directory also has a pointer to its parent. This entry is named ".."

Since the root directory (commonly referred to as "/") must have both entries the easiest way to know if you are at the root entry is to have both ".", and ".." point to the same inode.

This also makes the relative file naming specification "../directory", work even if you are in the root directory, and without any special handling that would be necessary if the parent directory were listed as NULL.

Last edited by jpollard; 03-14-2013 at 08:30 AM.
 
1 members found this post helpful.
Old 03-14-2013, 09:30 AM   #4
IMAX
LQ Newbie
 
Registered: Mar 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
The first inode number is 1. 0 is used as a NULL value, to indicate that there is no inode. Inode 1 is used to keep track of any bad blocks on the disk; it is essentially a hidden file containing the bad blocks, so that they will not be used by another file. The meaning of particular inode numbers differs by file-system.

Also have a look here: Ext4 Disk Layout (especially the Special Inodes / Block and Inode Allocation Policy section).

This might also be worth while a read: Anatomy of the Linux file system
Thank you very much for your explaning,I am now have a goog understanding why it start at 2,
And thank you for providing these links.
 
Old 03-14-2013, 09:35 AM   #5
IMAX
LQ Newbie
 
Registered: Mar 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
A directory structure is implemented as a tree. Each directory has an entry that points to the data that describes the files listed - basically, the data is a list of pairs: inode number and file name.
The pointer to the directory file is the "." entry.

For management handling, each directory also has a pointer to its parent. This entry is named ".."

Since the root directory (commonly referred to as "/") must have both entries the easiest way to know if you are at the root entry is to have both ".", and ".." point to the same inode.

This also makes the relative file naming specification "../directory", work even if you are in the root directory, and without any special handling that would be necessary if the parent directory were listed as NULL.
Wow,what a excellent design on that!Even in the root directory ,the "../**" works well!
Thanks a lot!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
EXT-fs error (device dm-0) ext3_lookup: unlinked inode 4587763 in dir # 458752 linux5nasser Linux - Server 6 05-03-2011 09:08 PM
loop through a DIR to delete files by inode j-me Linux - General 5 02-09-2010 05:05 PM
Web Root Dir Change and New Dir Added issue in CentOS 5 Ginnyz Linux - Server 2 06-01-2009 09:29 PM


All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration