Open inode file

Is it possible to open a file knowing its inode?

ls -i /tmp/test/test.txt 529965 /tmp/test/test.txt 

I can specify the path, inode (above 529965), and I want to get a file descriptor in return.

+5
source share
1 answer

This is not possible because it will open a loophole in access control rules. Whether a file can be opened depends not only on its own access bits, but also on the resolution bits of each containing directory. (For example, in your example, if test.txt was in 644 mode, but the containing test directory was in 700 mode, then only root and the owner of test could open test.txt .) The inode numbers only identify the file, not the directories (possibly the file is located in several directories, read "hard links"), so the kernel cannot perform a full set of access control checks with only the inode number.

(Some Unix implementations suggested non-standard root-only APIs to open the file by inode number, bypassing some access control rules, but if current Linux has such an API, I don’t know about that.)

+8
source

Source: https://habr.com/ru/post/1245342/


All Articles