2015-09-07 41 views
1

下面是從Linux內核中摘錄:爲什麼Linux內核函數filp_close中的posix線程id可能爲NULL?

/* 
* "id" is the POSIX thread ID. We use the 
* files pointer for this.. 
*/ 
int filp_close(struct file *filp, fl_owner_t id) 

文檔說id是POSIX線程ID,它應該是current->files

但是,我在Linux內核中發現了很多用法,例如acct_on,用它作爲filp_close(filp, NULL)

我的問題是:

爲什麼叫filp_close時爲NULL可以接受的?

參數id的意圖是什麼?

回答

1

根據該discussion,的fl_owner_t正式描述將是

A generic "file lock owner" value. This is set differently for different 
types of locks. 

The POSIX file lock owner is determined by the "struct files_struct" in the 
thread group. 

Flock (BSD) locks, OFD locks and leases set the fl_owner to the 
file description pointer. 

,但實際上這是不透明的指針

legacy typedef, should eventually go away 

其是指處理文件描述符表(struct files_struct)。

至於filp_close函數,只有fs/file.c源使用非NULL id參數。所有其他用戶手動創建filp(使用filp_openfile_open_name),並將id作爲NULL。

相關問題