FILE_TABLE(9)

NAME
file_table - detailed description of the table and table entry

SYNOPSIS
From #include <linux/fs.h>
struct file {
	mode_t f_mode;
	dev_t f_rdev;                /* needed for /dev/tty */
	off_t f_pos;
	unsigned short f_flags;
	unsigned short f_count;
	unsigned short f_reada;
	struct file *f_next, *f_prev;
	struct inode *f_inode;
	struct file_operations *f_op;
};
From linux/fs/file_table.c
struct file *first_file;
int nr_files = 0;

DESCRIPTION
The file table is fundamentally important to any UNIX system. It is where all open files (Linux includes closed files as well) are stored and managed by the kernel. For Linux, you can hardly do anything without referencing it in some way.

Linux stores its file table as a double circular linked list. The root pointer to the ``head'' of this list is first_file. Also, a count of how many entries are in the file table is maintained, called nr_files. Under this scheme, the file table for Linux could be as large memory could hold. Unfortunately, this would be unmanageable in most cases. Your computer would be in the kernel most of the time when processes are more important. To keep this from happening, nr_files is tested against NR_FILE to limit the number of file table entries.

  Understanding the Structure of the File Table
The file table is organized as a double circular linked list. Imagine, a circle of people with everyone facing the same direction. Each person is facing so that one arm is in the circle and the other arm is outside the circle. Now, if each person put his or her right hand on the shoulder of the person in front of him or her and if each person touched the person behind him or her with his or her left hand. You have formed two circles of arms, one inside and the other outside. The right arms represent pointers to the next entry (or person). The left arms represent pointers to the previous entry (or person).

  The file structure, a file table entry
At first glance, a table entry looks quite simple. A entry contains how a file was opened, what tty device, a reference count, pointers to another entries, pointer to v-node (the vfs i-node) and filesystem specific i-node information, etc.

f_mode
    After and'ing with O_ACCMODE, this is what bits 0 and 1 mean.
    00 = no permissions needed
    01 = read-permission
    10 = write-permission
    11 = read-write

f_rdev
    It is only used with tty lines. It contains the major and minor numbers of the tty device.

f_pos
    The current position in a file, if meaningful.

f_flags
    Storage for the flags from open() and fcntl()

f_count
    Reference counter

f_reada
    This is a boolean variable where true means that an actual read is needed.

f_next, f_prev
    Pointers to other entries

f_inode
    Pointer to v-node and fs specific i-node information

f_op
    Pointer to a file's operations

AUTHOR
Linus Torvalds

SEE ALSO
insert_file_free(9), remove_file_free(9), put_last_free(9) grow_files(9), file_table_init(9), get_empty_filp(9)