LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can someone explain the detail of the 'inode count' when using command 'll' (https://www.linuxquestions.org/questions/linux-newbie-8/can-someone-explain-the-detail-of-the-inode-count-when-using-command-ll-4175465069/)

hizzana 06-07-2013 12:30 AM

Can someone explain the detail of the 'inode count' when using command 'll'
 
i can understand why hard links can change that number,but still confused with the number of a directory.

in fact, create a sub dir will change the number of his parent, regular files will not.

hard link:

file1
|
|——> inode -> data block
|
file2

the 2 files above have a common inode with the count value 2

directoy:

assume ./a/b, b is the only sub dir of a

inode(a) ——> data block(a) ——> contains {inode:[10, 11, 12], filename:[., .., b]} // this editor will ignore the extra blank, so here i use json instead

above show the struct of storage of a dir
if a's inode is 9, b's is 12, they are not the same
means only 2 filenames are linked to inode 9(a and .)

someone can help me understand why?

shm0 06-07-2013 03:35 AM

Quote:

Originally Posted by hizzana (Post 4967005)
i can understand why hard links can change that number,but still confused with the number of a directory.

Do you mean the "Total <number>" part of the command output? if yes, then check this from the GNU page on the ls command :

Quote:

For each directory that is listed, preface the files with a line ‘total blocks’, where blocks is the total disk allocation for all files in that directory. The block size currently defaults to 1024 bytes, but this can be overridden (see Block size). The blocks computed counts each hard link separately; this is arguably a deficiency.

rknichols 06-07-2013 09:00 AM

Quote:

Originally Posted by hizzana (Post 4967005)
assume ./a/b, b is the only sub dir of a

inode(a) ——> data block(a) ——> contains {inode:[10, 11, 12], filename:[., .., b]} // this editor will ignore the extra blank, so here i use json instead

above show the struct of storage of a dir
if a's inode is 9, b's is 12, they are not the same
means only 2 filenames are linked to inode 9(a and .)

Directory b contains a ".." link, which is to the inode of directory a. The link count for a directory is always ( 2 + number_of_immediate_subdirs ) due to these ".." links.

hizzana 06-07-2013 09:10 AM

Quote:

Originally Posted by rknichols (Post 4967223)
Directory b contains a ".." link, which is to the inode of directory a. The link count for a directory is always ( 2 + number_of_immediate_subdirs ) due to these ".." links.

hmm, i see, except the root, . and .. are same.

rknichols 06-07-2013 09:28 AM

Quote:

Originally Posted by hizzana (Post 4967232)
hmm, i see, except the root, . and .. are same.

The formula (2 + number_of_subdirs) is correct for the root directory too. It's just that in the root directory, one of those "2" links is different. In a non-root directory, there is one link from the parent directory plus the directory's own "." link. In the root directory, there is no parent directory, but both "." and ".." point to the root directory, so there are still 2 links.

BTW, when you want to post something with spacing preserved, just wrap it in [CODE] ... [/CODE] tags. The "#" icon in the toolbar will do that for you.


All times are GMT -5. The time now is 01:14 PM.