The UNIX kernel is used for all I/O data structures

Source: Internet
Author: User

The kernel uses three data structures to represent open files, namely the File descriptor table, the file table, and the V-node tables. The relationship between them determines the possible impact a process might have on another process in terms of file sharing.

    1. Each process has a record entry in the process table, and the record entry contains an open file descriptor table, with each descriptor occupying one item. associated with each file description typeface:

      (a) The file descriptor flag.

      (b) A pointer to a file table entry.


    2. The kernel maintains a single file table for all open files. Each file Table entry contains:

      (a) file status flags (read, write, add-write, synchronous, non-blocking, etc.).

      (b) The current file offset.

      (c) A pointer to the V-node table entry for the file.

    3. Each open file (or device) has a V-node (V-NODE) structure. The V node contains pointers to the file types and functions that perform various operations on this file. The V node also contains information about the I node (i-node) read from disk, which contains the owner of the file, the length of the file, the device on which the file resides, a pointer to the location of the actual data block on the disk, and so on.


Figure 1 shows the relationship between the three tables of a process. The process has two different open files, one file opens as standard input (file descriptor is 0) and the other opens as standard output (file descriptor 1).

Figure 1: Kernel data structure for a process to open two files


Figure 2 shows the kernel data structure for two processes that open the same file. Assume that the first process opens the file on file descriptor 3, and another process opens the file on file descriptor 4. Each process that opens the file gets a file table entry, but only one v node table entry for a given file.

Figure 2: Two processes open the kernel data structure for the same file


With these data structures, some concepts and operations are described below:

    1. Each process obtains its own file table entry, so each process has its own current offset to the file.

    2. After each write is completed, the current file offset in the file table entry increases the number of bytes written. If this causes the current file offset to exceed the current file length, the current file length in the I node table entry is set to the current file offset (that is, the file is extended).

    3. If you open a file with the O_append flag, the corresponding flag is also set to the file status flag of the file table entry. Each time a write is performed on this file with an append write flag, the current file offset in the file table entry is first set to the length of the file in the I node table entry. This allows the data to be written each time it is appended to the current end of the file.

    4. If a file is anchored to the current end of the file with Lseek, the current file offset in the file table entry is set to the current file length in the I node table entry. this is different from the way the above file is opened with the O_append flag.

    5. The Lseek function modifies only the current file offset in the file table entry, without any I/O operations.

The UNIX kernel is used for all I/O data structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.