關於檔案結構
轉:https://blog.csdn.net/yuzhihui_no1/article/details/51272563
file結構在include\linux\fs.h中定義如下:
struct files_struct {
atomic_t count; /* 共享該表的程序數 */
rwlock_t file_lock; /* 保護以下的所有域,以免在tsk->alloc_lock中的巢狀*/
int max_fds; /*當前檔案物件的最大數*/
int max_fdset; /*當前檔案描述符的最大數*/
int next_fd; /*已分配的檔案描述符加1*/
struct file ** fd; /* 指向檔案物件指標陣列的指標 */
fd_set *close_on_exec; /*指向執行exec( )時需要關閉的檔案描述符*/
fd_set *open_fds; /*指向開啟檔案描述符的指標*/
fd_set close_on_exec_init;/* 執行exec( )時需要關閉的檔案描述符的初 值集合*/
fd_set open_fds_init; /*檔案描述符的初值集合*/
struct file * fd_array[32];/* 檔案物件指標的初始化陣列*/
};
2.使用者開啟檔案表
每個程序用一個files_struct結構來記錄檔案描述符的使用情況,這個files_struct結構稱為使用者開啟檔案表,它是程序的私有資料。files_struct結構在include/linux/sched.h中定義如下:
struct files_struct {
atomic_t count; /* 共享該表的程序數 */
rwlock_t file_lock; /* 保護以下的所有域,以免在tsk->alloc_lock中的巢狀*/
int max_fds; /*當前檔案物件的最大數*/
int max_fdset; /*當前檔案描述符的最大數*/
int next_fd; /*已分配的檔案描述符加1*/
struct file ** fd; /* 指向檔案物件指標陣列的指標 */
fd_set *close_on_exec; /*指向執行exec( )時需要關閉的檔案描述符*/
fd_set *open_fds; /*指向開啟檔案描述符的指標*/
fd_set close_on_exec_init;/* 執行exec( )時需要關閉的檔案描述符的初 值集合*/
fd_set open_fds_init; /*檔案描述符的初值集合*/
struct file * fd_array[32];/* 檔案物件指標的初始化陣列*/
};
3.關於檔案系統資訊的fs_struct結構
第三個結構是fs_struct,在2.4以前的版本中在include/linux/sched.h 中定義為:
struct fs_struct {
atomic_t count;
int umask;
struct dentry * root, * pwd;
};