i-nodes is the method in which the linux filesystem is implemented. i am refering to a book - modern operating systems by andrew s. tanenbaum for this blog.
files, directories etc are stored on the hard disk. a method has to be devised so as to know which file is stored in which block(s) of the hdd. additional info like permissions, file attributes etc might also be stored. in linux this is stored in the form of i-nodes. an i-node is basically a pointer.
|------------------------------------------------~ ~--------|
| boot0 | super1 | inodes.... | data blocks.. |
|------------------------------------------------~ ~--------|
this is an image of a hdd. block0 is the boot. block 1 contains critical info about the file system like no of i-nodes, no of disk blocks etc. then there is a section where i-node data-structures are stored and then the actual data blocks start till the end of the partition. each i-node entry can be identified by a unique number, like 1,34,671 etc. this number can be used to locate the actual stored i-node data structure on the hdd.
now each file/directory has one inode associated with it. you can $>ls -i to see inode numbers for individual files/directories.i'll cover file attributes later.firstly how to locate a file using absolute or relative paths.
consider an absolute path like /usr/home/blog.txt first the os will find the i-node for /. the listing for the / dir i-node number will contain an entry for the /usr dir. the os can transverse down one level. inside the i-node entry for /usr, the entry for the blog.txt i-node will be present. that i-node will contain the block on the hdd where the file is stored. thus th os can access the file.
for relative paths the dot(.) and two dots(..) operators come into play. the . stands for current dir and .. stands for parent dir. so if you want to access a file like ../home/blog.txt when you are currently in /usr/shop, the first i-node obtained is .., or parent of /usr/shop which is /usr. inside this i-node listing it is possible to find the home dir, and then move lower to the blog.txt file.
more on the i-node data structure. it contains the following info - mode, link count, uid, gid, file size, times, addr of first 10 disk blocks, single indirect block, double and triple indirect blocks.
mode is the file permissions which are read, write and execute,set for user, group and others.
link count is the number of links to a file. if 0 links exist and the file is deleted then the file is removed. can hrishi/dinesh explain on soft/hard links coz i am a bit confused on this.
uid, gid are user id and group id.
times are file creation times.
indirect blocks exist for large files which span many hdd blocks. so a single indirect block can point to more actual block addresses. a double indirect block will point to many single indirect block, hence larger files can be stored. and a triple indirect block references to nuber of double indirect block forming a tree structure. normally triple indirect blocks are sufficient for very large files. i do not know whats the maximum capacity though.
in ms-dos, a linked list allocation using indices is used for the file sys organisation. however the entire table must be in memory to work.
No comments:
Post a Comment