linux内核中的文件描述符(五)–fd的分配–locate

linux内核中的文件描述符(五)–fd的分配–locate_fd

Kernel version:2.6.14

CPU architecture:ARM920T

Author:ce123(http://blog.csdn.net/ce123)

(http://blog.csdn.net/ce123/article/details/8444482),在这里我们深入分析locate_fd函数,其定义如下:


max_fdset值的分析和rlim_cur差不多,最初的值时从父进程继承过来的。

linux/arch/arm/kernel/init_task.cstruct task_struct init_task = INIT_TASK(init_task);#define INIT_TASK(tsk)\{\....files= &init_files,\...}

init_files的定义如下:

static struct files_struct init_files = INIT_FILES;linux/init_task.h#define INIT_FDTABLE \{\.max_fds= NR_OPEN_DEFAULT, \.max_fdset= __FD_SETSIZE, \.next_fd= 0, \.fd= &init_files.fd_array[0], \.close_on_exec= &init_files.close_on_exec_init, \.open_fds= &init_files.open_fds_init, \.rcu= RCU_HEAD_INIT, \.free_files= NULL, \.next= NULL, \}#define NR_OPEN_DEFAULT BITS_PER_LONG#define __FD_SETSIZE1024#define INIT_FILES \{ \.count= ATOMIC_INIT(1), \.file_lock= SPIN_LOCK_UNLOCKED, \.fdt= &init_files.fdtab, \.fdtab= INIT_FDTABLE,\.close_on_exec_init = { { 0, } }, \.open_fds_init= { { 0, } }, \.fd_array= { NULL, } \}

BITS_PER_LONG是long型数据的字节数,即4*8=3,也就是说max_fds = 32。max_fdset为1024。max_fdset是进程打开文件描述符位图open_fds的大小。open_fds是fd_set的指针。

typedef __kernel_fd_setfd_set;#undef __NFDBITS#define __NFDBITS(8 * sizeof(unsigned long))#undef __FD_SETSIZE#define __FD_SETSIZE1024#undef __FDSET_LONGS#define __FDSET_LONGS(__FD_SETSIZE/__NFDBITS)#undef __FDELT#define__FDELT(d)((d) / __NFDBITS)#undef __FDMASK#define__FDMASK(d)(1UL << ((d) % __NFDBITS))typedef struct {unsigned long fds_bits [__FDSET_LONGS];} __kernel_fd_set;

fds_bits是一个long型数组,共有32个元素,共有1024bit。人生伟业的建立,不在能知,乃在能行。

linux内核中的文件描述符(五)–fd的分配–locate

相关文章:

你感兴趣的文章:

标签云: