Have you ever thought or imagined on how does a linux system manages all your files in ur hard disk? Lets have a look, it uses a very simple concept of nodes. When a file is created, a data structure is created which contains information about the files. Each file is associated with an inode that is identified by an inode number. On many types of file systems the number of inodes available is fixed at file system creation. A typical fraction of space allocated for inodes in a file system is 1% of total size. From the inode number, the kernel can access the contents of the inode, including the data pointers, and so the contents of the file.
ls -i (list the inode number of all the files and folder in the current directory)
ls -l (this retrieve the inode information/file information)
File names and directory implications :-
1. Inodes do not contain file names, only metadata.
2. Unix directories are list of “link” structures, each of which contains one file name and one inode number.
3. The kernel must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number if the name is found
Some more implications :
1. If multiple names link to the same inode then all of them are equivalent. The first one to have beed has no special status. This is unlike the sometimes more familiar symbolic links, where all the links depend on the original name.
2. An inode can even have no links at all. Normally such a file would be removed from the disk and its resources freed for reallocation (normal process of delete), but if any process are holding the file open, they may continue to access it, and file will be finnaly deleted
when the last reference to it is closed.
3. It is not possible to map from an open file to the file name that was used to open it. The operating system would convert the filename to an inode number at the first possible chance, then forget the file name. This means that the getcwd() and getwd() library functions
would need to search the parent directory to find a file with an inode matching the working directory, then search that directory’s parent, and so on until reaching the root.
4. It is also possible to hard link the directories which leads to a directory structure into an arbitrary directed graph and this will have n-1 nodes edges for n nodes.
5. A file’s inode number will stay the same when it is moved to another directory on the same device, or when the disk is de-fragmented. Therefore, moving either a file’s directory entry or its data(or both) is not enough to prevent a running process from accessing it, if the
process ever had a chance of finding out the inode number.
6.Installation of new libraries is simple with inode file systems. A running process can have a library mapped whilst another process replaces the file, creating a new inode, and an all new mapping of the library will exst for the new file. This facilities eliminates the need
to reboot tp replace currently mapped libraries.
I hope it helps you understand the concept behind the file management..!
Recent Comments