我正在開發一個模塊來讀取文件xattributes
。我迷上了sys_open
,由於這個原因,我需要在不打開文件的情況下獲取文件的dentry
。簡而言之,我有inode
和絕對路徑,但無法弄清楚;如何從這些獲得dentry
。所有意見都非常感謝。如何從inode/pathname找到一個dentry?
回答
按我低估了你正在嘗試開放的回調函數期間從您的驅動器模塊的目錄項路徑。如果是這樣;然後在放下之前添加訪問dentry信息所需的結構列表。
include/linux/fs.h
Struct file{
struct path f_path;
};
include/linux/path.h
struct path {
struct vfsmount *mnt;
struct dentry *dentry;
};
include/linux/dcache.h
struct dentry {
};
所以你可以這樣做。
static int sample_open(struct inode *inode, struct file *file)
{
char *path, *dentry,*par_dentry;
char buff[256];
dentry = file->f_path.dentry->d_iname;
pr_info("dentry :%s\n",dentry);
par_dentry = file->f_path.dentry->d_parent->d_iname;
pr_info("parent dentry :%s\n",par_dentry);
path=dentry_path_raw(file->f_path.dentry,buff,256);
pr_info("Dentry path %s\n",path);
}
我們實際上試圖獲得來自文件路徑的dentry結構。我們需要它來訪問屬於該文件的dentry中的xattributes。我們不需要dentry路徑本身 –
@BenAtkinson我不明白。 ***你的意思是通過獲得dentry結構***。你是否正在尋找像'custom_structure-> mydent = file-> f_path.dentry;'或者其他更類似於你自定義函數的dentry結構? –
問題是錯誤的。擴展屬性存儲在inode中,因此只要有inode,您就可以訪問它們。
我掛鉤了sys_open,因此我需要在不打開文件的情況下得到 文件的dentry。
這是錯誤的2個帳戶。
- SYS_OPEN不是能打開一個文件的唯一地方。
- 就算你勾搭成所有的地方,你執行額外的查找可以找到一個不同文件比得到了打開了一個(考慮一個小丑做CP文件1 toopen; CP FIL2在一個循環toopen)
你想要的是使用LSM框架(Linux安全模塊)。具體見security_file_open。
但是,鑑於問題的質量,我不得不問這是什麼。這是一個大學項目嗎?我認爲你沒有準備好開發它,並且建議儘可能轉換爲非內核版本。
- 1. 文件查找和dentry緩存
- 2. 如何找到一個從我的iPhone
- 3. Linux Kernel dentry和inode
- 4. 如何找到一個TreeViewItem
- 5. 如何找到一個ndarray
- 6. 如何從一個下拉標籤找到一個下拉值
- 7. 從另一個類找到一個object.member
- 8. PHP如何找到一條直線從一個文本文件
- 9. 如何找到從
- 10. 如何從一個絕對到另一個找到相對的文件路徑?
- 11. 如何找到一個元素
- 12. 如何找到一個LPCSTR的長度
- 13. 如何找到一個select查詢
- 14. 如何找到一個__m128(F32vec4)
- 15. 如何找到一個字符串
- 16. 如何找到一個HTML元素
- 17. 如何找到一個數據庫表
- 18. Flash Professional如何找到一個類
- 19. 樹java如何找到一個詞
- 20. cmake如何找到一個包?
- 21. 如何得到一個查找()/查詢
- 22. 如何找到一個列表元素
- 23. C++ find_if - 如何找到一個ID(INT(
- 24. 如何找到在一個列表
- 25. 如何找到一個向無環圖
- 26. 如何找到一個Java類
- 27. 如何找到在一個數組
- 28. wxpython如何找到一個wx.ListCtrl範圍
- 29. 如何找到一個mac地址?
- 30. 我如何找到一個字符
http://stackoverflow.com/questions/8556461/how-to-obtain-a-pathname-or-dentry-or-struct-file-from-a-given-inode – ilansch