Linux认证辅导之Linux中常见文件结构体(3)
: Y0 C) g) S% o6 o1.3 struct files_struct7 r# o! `+ `$ J( `* E
对于每个进程,包含一个files_struct结构,用来记录文件描述符的使用情况,定义在include/linux/file.h中/ v( s6 v! T- l- q1 P9 u$ {0 h: Z
struct files_struct
7 P* s: m0 W8 Z& k8 y5 d{
9 q) i) _) U1 h/ C0 M, j# Catomic_t count; 使用该表的进程数7 a7 ^ y! t6 e+ p
struct fdtable *fdt;
) B x0 g5 S A! r _: D- [struct fdtable fdtab;
7 m8 @1 \) _- _spinlock_t file_lock ____cacheline_aligned_in_smp;4 r% v D- u9 V
int next_fd; 数值最小的最近关闭文件的文件描述符,下一个可用的文件描述符
; D/ n' z0 r& W! L1 D/ O- Z& x$ j7 wstruct embedded_fd_set close_on_exec_init; 执行exec时需要关闭的文件描述符初值集合7 S3 A2 E- T! O+ i# Y" M2 v( n
struct embedded_fd_set open_fds_init; 文件描述符的屏蔽字初值集合: w, y; L! y1 D4 E. ~$ _! r% Z
struct file * fd_array[NR_OPEN_DEFAULT]; 默认打开的fd队列8 y6 ^3 ~- g) \3 b3 M
};: w5 G' E' C: ~' [
struct fdtable {
) a# O# M: `, J# }, lunsigned int max_fds;
- f t: @8 g7 Z( astruct file ** fd; 指向打开的文件描述符列表的指针,开始的时候指向fd_array,
' {7 v3 v; f) \2 |当超过max_fds时,重新分配地址$ C* j$ m. e5 b
fd_set *close_on_exec; 执行exec需要关闭的文件描述符位图(fork,exec即不被子进程继承的文件3 {$ Q# `' x% @ x3 H
描述符)& j0 o, E7 t0 r+ {8 K) {2 k; g( a
fd_set *open_fds; 打开的文件描述符位图# I& o" N2 |( z8 I0 ~
struct rcu_head rcu;
: h5 [( ?- Z+ s# C! ~6 n, Wstruct fdtable *next;
0 Z! }0 D& m0 Z}; |