为什么不能通过inode操作文件? [英] Why can't files be manipulated by inode?

查看:182
本文介绍了为什么不能通过inode操作文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当你只知道它的inode时,你不能访问一个文件,而不搜索链接到这个inode的文件?一个到文件的硬链接只包含一个名字和一个数字,告诉你在哪里可以找到包含关于该文件的所有真实信息的索引节点。我很惊讶,当我被告知没有用户模式的方式来直接使用inode号码来打开文件。

这似乎是这样一个无害和有用的功能系统提供。为什么没有提供?

解决方案

一些操作系统 do 有这个功能。例如,OS X需要它支持碳文件管理器,在Linux上可以使用 debugfs 。当然,你可以通过命令行通过 find -inum 在任何UNIX上执行,但是无法通过inode访问文件的真正原因是它不是'特别有用。它不会阻止文件权限,因为如果有一个文件,你可以在一个文件夹中读取你不能读取或执行,然后打开inode让你发现它。



它不是非常有用的原因是你需要通过 * stat()调用找到一个inode号码, 文件名(或打开的fd)...或者你需要猜测inum。


Why is it that you cannot access a file when you only know its inode, without searching for a file that links to that inode? A hard link to the file contains nothing but a name and a number telling you where to find the inode with all the real information about the file. I was surprised when I was told that there was no usermode way to use the inode number directly to open a file.

This seems like such a harmless and useful capability for the system to provide. Why is it not provided?

解决方案

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.

这篇关于为什么不能通过inode操作文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆