Why Can't Files Be Manipulated by Inode

Why can't files be manipulated by inode?

Some Operating Systems do have that facility. For example, OS X needs it to support the Carbon File Manager, and on Linux you can use debugfs. Of course, you can do it on any UNIX from the command-line via find -inum, but the real reason you can't access files by inode is that it isn't particularly useful. It does kindof circumvent file permissions, because if there's a file you can read in a folder you can't read or execute, then opening the inode lets you discover it.

The reason it isn't very useful is that you need to find an inode number via a *stat() call, at which point you already have the filename (or an open fd)...or you need to guess the inum.

Why is root directory always stored in inode two?

The first inode number is 1. 0 is used as a NULL value, to indicate that there is no inode. Inode 1 is used to keep track of any bad blocks on the disk; it is essentially a hidden file containing the bad blocks, so that they will not be used by another file. The bad blocks can be recorded using e2fsck -c. The filesystem root directory is inode 2.

The meaning of particular inode numbers differs by filesystem. For ext4 you can find more information on the Ext4 Wiki Ext4 Disk Layout page; in particular see the "Special inodes" table.

Is there a way to open file by known inode

Short of a brute-force search of the filesystem for the inode (ex, find / -inum $X), you can't.

See the discussion here: http://coding.derkeiler.com/Archive/Perl/comp.lang.perl.misc/2006-05/msg02223.html

Can you directly modify the indirect blocks of an inode in user space?

Some filesystems(ext*fs, not sure about minix) optimize and write data(<60 bytes) into the block pointer array of the inode.

In that case you can just modify last 12 bytes which are corresponding to indirect block pointers.

You cannot access the block pointer array in user space; however, you can do the hack of just create a file of 60bytes and then try to read its content.

how to get directory name by inode value in c?

List the directory and get the inode of .. then list that and find the name of the file there that has the inode you are looking for.

Why the inode value of shadow file changes?

VI saves the data in a new file, and then either unlinks or renames the old diretory entry. The hard link is linked to the old one.

This is one of two ways for ensuring data consistency for the case saving fails.

The other way would be to copy the old file and then overwrite it. The old copy would then have a diffferent inum, and the newly saved file would have the same as before.

Link to a specific inode

Copy from /proc/pid/fd/file descriptor

Use lsof to find the pid and the file descriptor.



Related Topics



Leave a reply



Submit