Learning Linux part 6/15: Linux filesystem
This part is a short flight through the filesystem of linux.
In short, the filesystem controls the way how files are organised on the disk.
To describe how this works, I will try to explain some of the process when a file gets accessed.
In order to access a file, the operating system needs the full path of the file.
Then the operating system needs to take care that the file is loaded in the memory. To load the file into the memory, two things are needed:
- Inode table
- Directory ( in which directory is the file placed )
INODES
In the inode of a file is described on which datablocks of the harddisk the data of the file is saved. All these inodes are saved into the inodes table. The inodes table is stored in the beginning of the storage device. Do notice that every device has it's very own inodes table.
So what's inside an inode? Well, some things that are stored are:
- file owner
- permissions
- creation- and modification time
- filesize
- number of links
- etc.
The inode of a file is important when a process needs to use a certain file. When this happens, the system first searches in the inodes table for the filename and it's corresponding directory. Therefore the inode number of the file is used. After that, the kernel is used to check if all permissions are valid and to see on which blocks the data resides.
Curious how can you see the inodes number in a certain folder?
Simply do a "ls -i" on the directory of your choice.
root@proteus:~# ls -i
1962 bin 373 Downloads
22 Desktop 2 MediaLibrary
26 Documents
Want to read out the inode information? For that purpose you can use "debugfs". So how does this work?
First find the inode number of the file:
root@proteus:~# ls -i /etc/ | grep localtime
104 localtime
As you can see, 104 is the inode number of the localtime file. Because the file exists on the /dev/sda5 partition we execute the command "debugfs /dev/sda5". After this you enter "stat" with the inode number between the greather then and less then signs.
root@proteus:~# debugfs /dev/sda5
debugfs 1.41.4 (27-Jan-2009)
debugfs: stat <104>
The system will then display the statistics of the file
Inode: 104 Type: regular Mode: 0644 Flags: 0x80000
Generation: 118761872 Version: 0x00000000:00000001
User: 0 Group: 0 Size: 2917
File ACL: 0 Directory ACL: 0
Links: 1 Blockcount: 8
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x4ab50b7f:96735238 -- Sat Sep 19 18:49:03 2009
atime: 0x4ab50b7f:97677498 -- Sat Sep 19 18:49:03 2009
mtime: 0x4ab50b7f:96735238 -- Sat Sep 19 18:49:03 2009
crtime: 0x4ab50b7f:96735238 -- Sat Sep 19 18:49:03 2009
Size of extra inode fields: 28
BLOCKS:
(0):104463
TOTAL: 1