[英]How to open and read file from `struct inode *` in Linux kernel
我想從Linux Kernel v3.0.8檢查文件的內容,只知道struct inode *
。 我只需要讀取此inode指向的文件的開頭,然后關閉並返回。 我不關心文件名/ mountpoint等附加信息。事實上,該文件可能沒有名稱(如刪除但仍然打開)。 可能嗎?
我終於做到了這樣:
struct path root;
struct file *filerd;
task_lock(&init_task);
get_fs_root(init_task.fs, &root);
task_unlock(&init_task);
root.dentry = d_find_alias(inode);
filerd = file_open_root(root.dentry->d_parent, root.mnt,
root.dentry->d_name.name, O_RDONLY);
它適用於我測試的每個過程以及不同的安裝點,這讓我感到驚訝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.