📄 1425-1431.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Complete Command Reference:Kernel Reference Guide:EarthWeb Inc.-</TITLE>
</HEAD>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311046 //-->
<!-- TITLE=Linux Complete Command Reference//-->
<!-- AUTHOR=Red Hat//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=09 //-->
<!-- PAGES=1423-1432 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="1423-1424.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="1432-1432.html">Next</A></CENTER></P>
<A NAME="PAGENUM-1425"><P>Page 1425</P></A>
<P><B>
AUTHOR
</B></P>
<P>Theodore T'so (tytso@mit.edu)
</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>settimeofday(2)
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 0.99.10, 7 July 1993
</P>
<H3><A NAME="ch09_ 4">
ctrl_alt_del
</A></H3>
<P>ctrl_alt_del—Routes the keyboard interrupt Ctrl+Alt+Del key sequence.
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
linux/kernel/sys.c
void ctrl_alt_del(void);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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.
</P>
<P><B>
WARNINGS
</B></P>
<P>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.
</P>
<P><B>
NOTE
</B></P>
<P>The default of this function is to do hard resets immediately.
</P>
<P><B>
AUTHOR
</B></P>
<P>Linus Torvalds
</P>
<P><B>
SEE ALSO
</B></P>
<P>reboot(2), reset_hard_now(9), sync(2)
</P>
<P>Linux 0.99.10, 6 July 1993
</P>
<H3><A NAME="ch09_ 5">
file_table
</A></H3>
<P>file_table—Detailed description of the table and table entry.
</P>
<P><B>
SYNOPSIS
</B></P>
<P>From #include <linux/fs.h>
</P>
<!-- CODE //-->
<PRE>
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;
</PRE>
<!-- END CODE //-->
<A NAME="PAGENUM-1426"><P>Page 1426</P></A>
<!-- CODE SNIP //-->
<PRE>
struct inode *f_inode;
struct file_operations *f_op;
};
</PRE>
<!-- END CODE SNIP //-->
<P>From linux/fs/file_table.c
</P>
<!-- CODE SNIP //-->
<PRE>
struct file *first_file;
int nr_files = 0;
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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.
</P>
<P>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.
</P>
<P><B>
UNDERSTANDING THE STRUCTURE OF THE FILE TABLE
</B></P>
<P>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).
</P>
<P><B>
THE FILE STRUCTURE, A FILE TABLE ENTRY
</B></P>
<P>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.
</P>
<TABLE>
<TR><TD>
f_mode
</TD><TD>
After ANDing with O ACCMODE, this is what bits 0 and 1 mean:
</TD></TR><TR><TD>
00
</TD><TD>
No permissions needed
</TD></TR><TR><TD>
01
</TD><TD>
Read-permission
</TD></TR><TR><TD>
10
</TD><TD>
Write-permission
</TD></TR><TR><TD>
11
</TD><TD>
Read-write
</TD></TR><TR><TD>
f_rdev
</TD><TD>
It is used only with tty lines. It contains the major and minor numbers of the
tty device.
</TD></TR><TR><TD>
f_pos
</TD><TD>
The current position in a file, if meaningful.
</TD></TR><TR><TD>
f_flags
</TD><TD>
Storage for the flags from open() and
fcntl()
</TD></TR><TR><TD>
f_count
</TD><TD>
Reference counter
</TD></TR><TR><TD>
f_reada
</TD><TD>
This is a Boolean variable where
True means that an actual read is needed.
</TD></TR><TR><TD>
f_next, f_prev
</TD><TD>
Pointers to other entries
</TD></TR><TR><TD>
f_inode
</TD><TD>
Pointer to v-node and filesystem-specific i-node information
</TD></TR><TR><TD>
f_op
</TD><TD>
Pointer to a file's operations
</TD></TR></TABLE>
<P><B>
AUTHOR
</B></P>
<P>Linus Torvalds
</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>
insert_file_free(9), remove_file_free(9),
put_last_free(9) grow_files(9), file_table_init(9),
get_empty_filp(9)
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 0.99.10, 11 July 1993
</P>
<A NAME="PAGENUM-1427"><P>Page 1427</P></A>
<H3><A NAME="ch09_ 6">
file_table_init
</A></H3>
<P>file_table_init—Initializes the file table in the kernel.
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
linux/fs/file_table.c unsigned long file_table_init(
unsigned long start, unsigned long end);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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.
</P>
<P><B>
RETURN VALUE
</B></P>
<P>Returns start.
</P>
<P><B>
NOTE
</B></P>
<P>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.
</P>
<P><B>
AUTHOR
</B></P>
<P>Linus Torvalds
</P>
<P>Linux 0.99.10, 9 July 1993
</P>
<H3><A NAME="ch09_ 7">
filesystems
</A></H3>
<P>filesystems—Details the table of configured filesystems.
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
linux/fs/filesystems.c
</PRE>
<!-- END CODE SNIP //-->
<P>From #include <linux/fs.h>
</P>
<!-- CODE SNIP //-->
<PRE>
struct file system type {
struct super_block *(*read_super) (struct super_block *, void *, int);
char *name;
int requires dev;
};
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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.
</P>
<P><B>
THE MEANINGS
</B></P>
<P>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.
</P>
<P>The name is just the string representation of the name of a specific filesystem, such as
ext2 or minix.
</P>
<P>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.
</P>
<A NAME="PAGENUM-1428"><P>Page 1428</P></A>
<P><B>
AUTHOR
</B></P>
<P>Linus Torvalds
</P>
<P>Linux 0.99.10, 12 July 1993
</P>
<H3><A NAME="ch09_ 8">
get_empty_filp
</A></H3>
<P>get_empty_filp—Fetches an unreferenced entry from the file table.
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
linux/fs/file table.c
struct file *get_empty_filp(void);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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.
</P>
<P><B>
NOTE
</B></P>
<P>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.
</P>
<P><B>
RETURN VALUE
</B></P>
<P>NULL—No entries were found and the file table is full.
</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -