-->

Previous | Table of Contents | Next

Page 1425

AUTHOR

Theodore T'so (tytso@mit.edu)

SEE ALSO

settimeofday(2)

Linux 0.99.10, 7 July 1993

ctrl_alt_del

ctrl_alt_del—Routes the keyboard interrupt Ctrl+Alt+Del key sequence.

SYNOPSIS


linux/kernel/sys.c

void ctrl_alt_del(void);

DESCRIPTION

This simple routine tests the variable C_A_D for a true/false condition. If it is true, a hard reset is done by the system. Otherwise, a signal SIGINT is sent to the process with the process ID 1, usually a program called init.

WARNINGS

This routine is in interrupt mode. It cannot sync() your system. Data loss may occur. It is recommended that you configure your system to send a signal to init, where you can control the shutdown.

NOTE

The default of this function is to do hard resets immediately.

AUTHOR

Linus Torvalds

SEE ALSO

reboot(2), reset_hard_now(9), sync(2)

Linux 0.99.10, 6 July 1993

file_table

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;



Page 1426


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 as 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. An entry contains how a file was opened, what tty device, a reference count, pointers to other entries, pointer to v-node (the vfs i-node) filesystem-specific i-node information, and so on.

f_mode After ANDing 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 used only 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 filesystem-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)

Linux 0.99.10, 11 July 1993

Page 1427

file_table_init

file_table_init—Initializes the file table in the kernel.

SYNOPSIS


linux/fs/file_table.c unsigned long file_table_init(

unsigned long start, unsigned long end);

DESCRIPTION

This routine is called from kernel_start() in linux/init/main.c. It sets first_file, a struct file pointer, to NULL. This is the head of the linked list of open files maintained in the kernel, the infamous file table in all UNIXs.

RETURN VALUE

Returns start.

NOTE

Because this is part of the kernel's startup routine, it has the option to allocate memory, in kernel space, for itself. It does not need to do this and returns the new start of memory for the next initializing section. In this case, start is returned unmodified.

AUTHOR

Linus Torvalds

Linux 0.99.10, 9 July 1993

filesystems

filesystems—Details the table of configured filesystems.

SYNOPSIS


linux/fs/filesystems.c

From #include <linux/fs.h>


struct file system type {

struct super_block *(*read_super) (struct super_block *, void *, int);

char *name;

int requires dev;

};

DESCRIPTION

This source code makes a data structure call file_systems[], which contains all the configured filesystems for the kernel. It is used primarily in linux/fs/super.c for many of the mounting of filesystems functions.

THE MEANINGS

This first member, in struct file_system_type, is a function pointer to a routine that will read in the super_block. A super_block generically means an i-node or special place on the device where information about the overall filesystem is stored.

The name is just the string representation of the name of a specific filesystem, such as ext2 or minix.

The final member, int_requires_dev, is a Boolean value. If it is True, then the filesystem requires a block device. For False, it is unclear what happens, but an unnamed device is used, such as proc and nfs.

Page 1428

AUTHOR

Linus Torvalds

Linux 0.99.10, 12 July 1993

get_empty_filp

get_empty_filp—Fetches an unreferenced entry from the file table.

SYNOPSIS


linux/fs/file table.c

struct file *get_empty_filp(void);

DESCRIPTION

This routine will seek out an entry that is not being referenced by any processes. If none are found, then it will add new entries to the file table, minimum of NR_FILE entries.

NOTE

Due to grow_files(), a whole page of entries is created at one time. This may make more than NR_FILE entries. Also when an unreferenced entry is found, it is moved to the "end" of the file table. This heuristic is used to speed up finding unreferenced entries.

RETURN VALUE

NULL—No entries were found and the file table is full.

Returns a pointer to the entry in the file table.

AUTHOR

Linus Torvalds

SEE ALSO


grow_files(9)

Linux 0.99.10, 12 July 1993

grow_files

grow_files—Adds entries to the file table.

SYNOPSIS


linux/fs/file table.c

void grow_files(void);

DESCRIPTION

This function adds entries to the file table. First, it allocates a page of memory. It fills the entire page with entries, adding each to the file table.

AUTHOR

Linus Torvalds

Page 1429

insert_file_free

SEE ALSO

insert_file_free(9), remove_file_free(9),

put_last_free(9)

Linux 0.99.10, 12 July 1993

in_group_p

in_group_p—Searches group IDs for a match.

SYNOPSIS


linux/kernel/sys.c

int in_group_p(gid_t grp);

DESCRIPTION

Searches supplementary group IDs and the effective group ID for a match with grp.

RETURN VALUE

Returns True (1) if found; otherwise, false (0).

AUTHOR

Linus Torvalds

SEE ALSO

getgroups(2), getgid(2), getregid(2), setgid(2),

setregid(2), setgroups(2)

Linux 0.99.10, 7 July 1993

insert_file_free

insert_file_free—Adds a file entry into the file table.

SYNOPSIS


linux/fs/file_table.c

static void insert_file_free(struct file *file);

DESCRIPTION

This nightmare of pointers adds file into the file table with the root pointer at file. This is a building block of the file table management.

AUTHOR

Linus Torvalds

SEE ALSO

file_table_init(9), remove_file_free(9),

put_last_free(9)

See file_table(9) for details on the file table structure.

Linux 0.99.10

Page 1430

kernel_mktime

kernel_mktime—Convert startup struct mktime into the number of seconds since 00:00:00 January 1, 1970.

SYNOPSIS


linux/kernel/mktime.c

long kernel_mktime(struct mktime * time);

DESCRIPTION

This routine is called from time_init(void), linux/init/main.c. kernel_mktime() converts struct mktime (initialized from CMOS) into an encoded long.

CONVERSION METHOD

First an array, month[12], is created, holding how many seconds have passed to reach a peculiar month for a leap year. Next, it subtracts 70 from the current year, making 1970 the beginning year. It is math magic after this point; please look yourself. If you know why it does this, then send e-mail (see nroff source).

RETURN VALUE

Returns the encoded time in a long.

FILES

linux/kernel/mktime.c home of routine

NOTE

This routine is called only during startup of the kernel.

Historically, the value (encoded long) counts the number of seconds since the Epoch, which occurred at 00:00:00 January 1, 1970, and is called Coordinated Universal Time (UTC). In older manuals, this event is called Greenwich Mean Time (GMT).

WARNINGS

kernel_mktime() doesn't check to see if the year is greater than 1969. Be sure your CMOS is set correctly. It is customary to set on-board clocks to GMT and let processes who ask for the time to convert it to local time, if necessary.

RESTRICTIONS

For kernel use only.

AUTHOR

Linus Torvalds

Linux 0.99.10, 5 July 1993

proc_sel

proc_sel—Select a process by a criterion.

SYNOPSIS


linux/kernel/sys.c

#include <linux/resource.h>

static int proc_sel(struct task_struct *p, int which, int who);

Page 1431

DESCRIPTION

Compares a task p to supplied information or the current task in some aspect of priority. If who is zero, the comparison is task p and the current task. Otherwise, who and *p are the supplied information for the comparison.

OPTIONS

Valid values of which:

PRIO_PROCESS Compares process ID numbers. There is an exception here. If who is not zero and task p is the current task, then True is always returned.
PRIO_PGRP Compares process group leader numbers.
PRIO_USER Compares user ID numbers.

RETURN VALUE

Returns truth values (0, 1).

AUTHOR

Linus Torvalds

SEE ALSO


sys_setpriority(2), sys_getpriority(2)

Linux 0.99.10, 7 July 1993

put_file_last

put_file_last—Moves a file to the "end" of the file table.

SYNOPSIS


linux/fs/file table.c

static void put_last_free(struct file *file);

DESCRIPTION

This function will remove file from the file table and insert it again at the end. You can access by

first_file->prev

AUTHOR

Linus Torvalds

SEE ALSO


insert_file_free(9), remove_file_free(9)

Linux 0.99.10, 11 July 1993

remove_file_free

remove_file_free—Remove a file table entry from the linked list.

SYNOPSIS


linux/fs/file table.c

static void remove_file_free(struct file *file);

Previous | Table of Contents | Next