本文介绍了通过inode打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ls -i /tmp/test/test.txt $是否可以打开一个知道它的inode的文件? b $ b 529965 /tmp/test/test.txt 

我可以提供路径,inode(大于529965 ),我期待得到一个文件描述符。

解决方案

这是不可能的,因为它会打开一个漏洞访问控制规则。您是否可以打开文件不仅取决于自己的访问权限位,而且取决于每个包含目录的权限位。 (例如,在你的例子中,如果 test.txt 是模式644,但是包含目录 test 是模式700,那么只有 root test 的所有者可以打开 test.txt 。)inode数字只能识别文件,而不能识别包含的目录(文件可能位于多个目录中,读到硬链接),因此内核无法执行一组完整的访问控制检查只有一个inode号。
$ b (一些Unix实现已经提供了非标准的纯根APIs来通过inode编号打开一个文件,绕过一些访问控制规则,但是如果目前的Linux有这样一个API,我不知道。)


Is it possible to open a file knowing its inode?

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

I can provide path, inode (above 529965) and I am looking to get in return a file descriptor.

解决方案

This is not possible because it would open a loophole in the access control rules. Whether you can open a file depends not only on its own access permission bits, but on the permission bits of every containing directory. (For instance, in your example, if test.txt were mode 644 but the containing directory test were mode 700, then only root and the owner of test could open test.txt.) Inode numbers only identify the file, not the containing directories (it's possible for a file to be in more than one directory; read up on "hard links") so the kernel cannot perform a complete set of access control checks with only an inode number.

(Some Unix implementations have offered nonstandard root-only APIs to open a file by inode number, bypassing some of the access-control rules, but if current Linux has such an API, I don't know about it.)

这篇关于通过inode打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 15:36