Pio*_*dyk 4 c inode file linux-kernel
我想从 Linux Kernel v3.0.8 中检查文件的内容,只知道struct inode *. 我只需要读取这个 inode 指向的文件的开头,然后关闭并返回。我不关心文件名/挂载点等附加信息。事实上,文件可能没有名称(如已删除但仍打开)。是否可以?
我终于这样做了:
struct path root;
struct file *filerd;
Run Code Online (Sandbox Code Playgroud)
task_lock(&init_task);
get_fs_root(init_task.fs, &root);
task_unlock(&init_task);
Run Code Online (Sandbox Code Playgroud)
root.dentry = d_find_alias(inode);
Run Code Online (Sandbox Code Playgroud)
filerd = file_open_root(root.dentry->d_parent, root.mnt,
root.dentry->d_name.name, O_RDONLY);
Run Code Online (Sandbox Code Playgroud)
它适用于我测试的每个进程和不同的挂载点,这让我感到惊讶。
| 归档时间: |
|
| 查看次数: |
828 次 |
| 最近记录: |