2017-04-05 30 views
1

我正在開發一個模塊來讀取文件xattributes。我迷上了sys_open,由於這個原因,我需要在不打開文件的情況下獲取文件的dentry。簡而言之,我有inode和絕對路徑,但無法弄清楚;如何從這些獲得dentry。所有意見都非常感謝。如何從inode/pathname找到一個dentry?

+0

http://stackoverflow.com/questions/8556461/how-to-obtain-a-pathname-or-dentry-or-struct-file-from-a-given-inode – ilansch

回答

2

按我低估了你正在嘗試開放的回調函數期間從您的驅動器模塊的目錄項路徑。如果是這樣;然後在放下之前添加訪問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); 
    } 
+0

我們實際上試圖獲得來自文件路徑的dentry結構。我們需要它來訪問屬於該文件的dentry中的xattributes。我們不需要dentry路徑本身 –

+0

@BenAtkinson我不明白。 ***你的意思是通過獲得dentry結構***。你是否正在尋找像'custom_structure-> mydent = file-> f_path.dentry;'或者其他更類似於你自定義函數的dentry結構? –

0

問題是錯誤的。擴展屬性存儲在inode中,因此只要有inode,您就可以訪問它們。

我掛鉤了sys_open,因此我需要在不打開文件的情況下得到 文件的dentry。

這是錯誤的2個帳戶。

  1. SYS_OPEN不是能打開一個文件的唯一地方。
  2. 就算你勾搭成所有的地方,你執行額外的查找可以找到一個不同文件比得到了打開了一個(考慮一個小丑做CP文件1 toopen; CP FIL2在一個循環toopen)

你想要的是使用LSM框架(Linux安全模塊)。具體見security_file_open。

但是,鑑於問題的質量,我不得不問這是什麼。這是一個大學項目嗎?我認爲你沒有準備好開發它,並且建議儘可能轉換爲非內核版本。