"linux& unix--document describing the character and authority of the narrative "

Source: Internet
Author: User

personal Learning and collation, if there are deficiencies, please do not hesitate to enlighten. Reprint Please specify:@CSU-max


Series Blog:

                      Linux&unix Study of the first play--the description and permission of file descriptor

          Linux&unix Learning The second play--the description of file descriptor and permission


descriptive descriptors for documents

Each UNIX process has a file Description descriptor range, with a size of 0 to n,n the maximum value of the descriptive descriptor for the symbol file. The size of n depends on the UNIX version number and system configuration.

As a matter of fact. It is an index value that points to the record table in which the kernel opens a file for each process maintained by the process. When a program opens an existing file or creates a new file. The kernel returns a file description descriptor to the process. In the program design of Linux and Unix operating systems. Some of the underlying programming tends to revolve around the file description descriptor unfolding.

standard file Descriptive descriptor

usually the first three file descriptors are opened when the process is executed.

File Description Descriptor 0: standard input

File Description Descriptor 1: Standard output

File Description Descriptor 2: standard error output

In addition to using numbers to denote. It is also possible to use symbolic constants, corresponding to: Stdin_fileno, Stdout_fileno. Stderr_fileno.

These standard file descriptive descriptors can open files, pipelines, FIFO, devices and even sockets, and can immediately use these three standard file descriptive descriptors when invoking read and write system calls. Other file descriptive descriptors for files, pipelines, etc. can be obtained through the process itself.

The file Description descriptor is simply an index to each process table .

Each record entry in the process table points to a system-wide open file descriptive narrative (that is, a file table record entry). The file description descriptor points to the file data.

The above procedure can be expressed as:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy3n1x21hea==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">




As you can see, multiple file descriptors and even file descriptors from different processes may point to the same file description .

each open or pipe system call creates a new open file descriptive narrative and a new descriptive descriptor for the file. As you can see, process a two times has opened the same file, got the file Description descriptor 5 and 6. and created an open file descriptive narrative 1 and 2. After the file description of the narrative copy mechanism, process A has been a copy of the file description of the Descriptor 5-The file description of the Descriptor 7. Of course, the file Description descriptor 7 points to the open file descriptive narrative and the file description of the descriptor 5 points to the same. That is, pointing to the same open file descriptive narrative, instead of creating a new one as previously said. Process B is a child process of process a. The file Description Descriptor 3 is allowed to be a copy of the description descriptor 5 of the file.

file permissions and representations

Each file information node has a full user ID (for short) and a full group ID (group), at the same time, the information node also includes three sets of permission bits, each group of three bits, each group includes a read permission bit, a write permission bit and a run permission bit.

A value of 1 indicates consent permission. 0 indicates deny permission.

Three sets of permissions. One group for all, one for groups, and one for other users (i.e. not in the first two categories).

The permission bit is usually expressed in the order of three groups of all people, groups and other users, often using octal numbers.

The detailed representation method is as seen in the following:



For example, octal number 755 means that all people have read, write, and run permissions, while groups and other users have only read and run permissions. The LS command shows the combination of its permissions as Rwxr-xr-x, which is represented as 111101101 in binary notation.

file permission bit symbol

Suppose you feel that file permissions must be used in the above method: 9 file permission bits should be put together and in a certain order (all, groups, other users). That's a mistake.

This is not really the case, just have to have these 9 permission bits.

the permission bit symbol is the second way to represent file permissions, which can be used instead of the traditional octal number representation.

These symbols are in the form s_ipwww, where p represents access permission (R. W or x), which www represents who operates (USR, GRP, or OTH). This shows all 9 symbols.

For example, the example mentioned earlier, without the octal 755, the use of permission bit symbols to perform samples such as the following:

s_irusr | S_IWUSR | S_ixsur | S_irgrp | S_ixgrp | S_iroth | S_ixoth

when USR, GRP, or oth has all three access rights, it is possible to use a separate symbol, such as: S_irwxw.

Here W represents the user type, which can be u, g, or O.

Therefore, the above file access permission can also perform samples such as the following:

S_irwxu | S_irgrp | S_ixgrp | S_iroth | S_ixoth

Although this descriptive narrative is less readable. Also very easy error. However, the operator can freely arrange the position of the permission bit, and it is more convenient to read programming, generally we will define the required macro at once, rather than in all the necessary places to use a long sequence of symbols such as S_IRUSR.

#Define Perm_directory S_irwxu

#define Perm_file (S_irsur | S_iwsur | S_irgrp | S_iroth)

This will only change the macro once. Can change the access rights policy for the entire application.

***************************************************************************

                                        & nbsp;            *   Reprint Please specify source:   @CSU-max    http ://blog.csdn.net/csu_max      *

***************************************************************************






Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

"linux& The unix--file describes the character and authority of the narrative "

Related Article

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.