What is a inode, Why we need them ?
Have you ever wondered where is your access permissions located? How does your system know that you are the owner of your home folder? Is it written on the file itself ?
Answer to your questions is the Inodes also known as Index nodes.
Inode is a data structure, inodes stores all data about the file objects, except data content and file name. Unix doesn’t use the file name to refer to the file, it uses the inodes and inodes are pointing to actual block addresses where the data is located. inodes reside in Inode table (see Ext4 Disk Layout)
Windows (NTFS) equivalent is Master file table
Max OSX (HFS) equivalent is Catalog File
POSIX standard description for inode is:
Unix or Linux systems doesn't usually store creation date, but ext4 has an attribute for creation date.
crtime (Create time) and also a dtime (Delete time)
inodes allows us to do linking and gives us significant performance increase, because inodes points us to the right data block when we are querying for files.
You can run out of inodes, what happens then ?
inode limit is decided at file system creation time. Its not a fixed value. You can check your current inodes usage with df -i
If you happen to run out of Inodes before you run out of disk space, you simply cannot create any more files or directories that consume Inodes, your things start to get very messy and unstable :)
stat command
stat displays file or file system status.
You can query file or file system with stat, for example for file:
and for file system (use -f flag)
Inode data pointers, direct blocks and indirect blocks
One inode can point only to 12 blocks of data.
So if your block size is 4096, that would mean 12x4096 = 49152 bytes (48kb). This limitation would suck so that's why inode also has 3 indirect block pointers.
Indirect block pointer points to a block of block pointers, which.. again can point to indirect blocks that will point to new set of block pointers! This allows us to have very large files in our file system.
I tried to illustrate this with a picture but i ended up with a big messy pile of lines. Please check the wikipedia page for more info.
Have you ever wondered where is your access permissions located? How does your system know that you are the owner of your home folder? Is it written on the file itself ?
Answer to your questions is the Inodes also known as Index nodes.
Inode is a data structure, inodes stores all data about the file objects, except data content and file name. Unix doesn’t use the file name to refer to the file, it uses the inodes and inodes are pointing to actual block addresses where the data is located. inodes reside in Inode table (see Ext4 Disk Layout)
Windows (NTFS) equivalent is Master file table
Max OSX (HFS) equivalent is Catalog File
POSIX standard description for inode is:
- File size in bytes
- Owner and Group of the file
- Device ID (device where file is contained)
- file mode (access permissions)
- Timestamps (Content last modified (mtime), Inode last modified(ctime) and Last accessed (atime))
- Link count (how many hard links point to the inode)
- Pointers to actual disk blocks that are containing the data
- Additional system and user flags (limit its use and modification)
Unix or Linux systems doesn't usually store creation date, but ext4 has an attribute for creation date.
crtime (Create time) and also a dtime (Delete time)
inodes allows us to do linking and gives us significant performance increase, because inodes points us to the right data block when we are querying for files.
You can run out of inodes, what happens then ?
inode limit is decided at file system creation time. Its not a fixed value. You can check your current inodes usage with df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 14983168 95016 14888152 1% /
If you happen to run out of Inodes before you run out of disk space, you simply cannot create any more files or directories that consume Inodes, your things start to get very messy and unstable :)
stat command
stat displays file or file system status.
You can query file or file system with stat, for example for file:
m@srv:~/symlink_test$ stat file1
File: `file1'
Size: 65 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 5506851 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ m) Gid: ( 1000/ m)
Access: 2012-12-30 14:38:23.983590932 +0200
Modify: 2012-12-30 14:38:49.112092037 +0200
Change: 2012-12-30 14:38:49.112092037 +0200
and for file system (use -f flag)
m@srv:~/symlink_test$ stat -f /dev/sda1
File: "/dev/sda1"
ID: 0 Namelen: 255 Type: tmpfs
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 191863 Free: 191821 Available: 191821
Inodes: Total: 191863 Free: 191262
Inode data pointers, direct blocks and indirect blocks
One inode can point only to 12 blocks of data.
So if your block size is 4096, that would mean 12x4096 = 49152 bytes (48kb). This limitation would suck so that's why inode also has 3 indirect block pointers.
Indirect block pointer points to a block of block pointers, which.. again can point to indirect blocks that will point to new set of block pointers! This allows us to have very large files in our file system.
I tried to illustrate this with a picture but i ended up with a big messy pile of lines. Please check the wikipedia page for more info.
No comments:
Post a Comment