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
How to Close a Netcat Connection After a Certain Character Is Returned in the Response
How to Save Output of "Watch" to File
Changing Permissions of Files in a Directory Recursively
Differencebetween .So and .A Files
Fast Concatenate Multiple Files on Linux
Anyway Change the Cursor "Vertical Line" Instead of a Box
Search for a Cronjob with Crontab -L
What Happens to Other Processes When a Docker Container's Pid1 Exits
Why Is My Bash Script Adding <Feff> to the Beginning of Files
How to Tell What a Linux Process Is Waiting For
Is It Possible That Linux File Descriptor 0 1 2 Not for Stdin, Stdout and Stderr
How to Get Started Developing on *Nix
Awk One Liner Select Only Rows Based on Value of a Column
Can You Prevent a Command from Going into the Bash Shell Command History