20145331 "Information Security system Design Fundamentals" 9th Week Study Summary

Source: Internet
Author: User
Tags types of functions hosting

20145331 "The basis of information security system Design" 9th Week Study Summary Textbook learning Contents 10.1 Unix I/O

All I/O devices in Unix are modeled as files, and all inputs and outputs are executed as read and write to the corresponding file.

10.2 Open Close File

1. Open File:

int open(char *filename, int flags,mode_t mode);

Where the first parameter in parentheses is a file name, the second parameter is the way to access the file (3 kinds), and the third parameter is the access permission bit (mode&~umask).

2. Close the file:

int close(int fd);   
10.3 Read and write files
读:ssize_t read(int fd, void *buf, size_t n);写:ssize_t write(int fd, const void *buf, size_t n);

Note that there are differences between ssize_t and size_t.

10.3RIO Packet Read/write

1, the Rio package will automatically handle the insufficient value.

2, divided into two types of functions: unbuffered input and output functions (binary), buffered input functions (binary + text lines).

3, the first class read and write:

读:ssize_t rio_readn(int fd,void *usrbuf,size_t n);写:ssize_t rio_writen(int fd,void *usrbuf,size_t n);

4. Second class reading (three functions):

带缓冲顾名思义就先联系缓冲区:void rio_readinitb(rio_t *rp,int fd);接着读:ssize_t rio_readlineb(rio_t *rp,void *usrbuf,size_t maxlen);ssize_t rio_writen(rio_t *rp,void *usrbuf,size_t n);
10.5 Read File meta data

1, the file element is the file information, call Stat and Fstat function to retrieve information about the file

int stat(const char *filename,struct stat *buf);int fstat(int fd,struct stat *buf);

2, where the St_size member contains the file's byte size. St_mode is the file access License bit.

10.6 Sharing files

1, three structure:
Descriptor table: Stand-alone file tables: Multi-part, process-sharing. V-node table: Process sharing. 2, the key: Each descriptor has its own file location, different operators can read from different locations to obtain data.

10.7I/O redirection

1. Use dup2 function redirection.

int dup2(int oidfd,int newfd);

2, this section looked for a long time, from the example to understand: the previous two descriptors to a, b two files, now call the above function, all point to a file (if it is B), a is closed, its file table and the V-node table is deleted, the reference count of B is increased; later data is redirected to File B.

10.8 Standard I/O

1.

标准I/O库(libc):高级输入输出函数fopen/fclose:打开和关闭文件fread/fwrite:读和写字节fgets/fputs:读和写字符串scanf/printf:复杂格式化的I/O函数

2. There are three open streams at the beginning of each program:

stdin:标准输入stdout:标准输出stderr:标准错误
Problems encountered in textbook learning:

10.1:

The return value of the Open function: The descriptor of the new file if successful, or 1 if an error occurs

Each process starts with three files open: standard input, standard output, standard error. They have descriptors of 0, 1, and 2, respectively. Therefore, FD1 returns a descriptor of 3. The close function is then called, releasing the descriptor 3. So the return value of FD2 is the descriptor 3.

10.2:

10-12. FD1 and FD2 correspond to different descriptor tables, but they also correspond to different file table entries, but they correspond to the V-note table, which is open foobar.txt. So read the first byte of foobar, output F

10.3:

10-13. First you know that the DAO Zi process is equivalent to copying the parent process, OK so the parent process is the same as the Descriptor table, file table, V-note tables correspondence and child processes. Descriptor FD points to the same file table entry in the parent-child process. So when the child process has finished reading, the parent process reads O, and the output O

10.4:

Dup2 (A, A, b) refers to the redirection of a to a, and a copy to the B standard input descriptor is 0

10.5:

Dup2 (FD2,FD1) fd2 Copy to Fd1,fd1 is redirected to FD2. So after performing the read again, the output is O

Problems encountered in the code:

The p598 code found at the start of compiling the book does not have "csapp.h":

Workaround: See the book p597 code above the header file, try it, compile and run it successfully:

These three header files are equivalent to "csapp.h".

Code hosting:

Refer to the teacher's comments this week code hosting made a link form:

Dot me to order me!

And the relevant instructions are used to statistic:

Experience:

Content seems to be very small, but more difficult to understand than before, also spent a lot of time to read, my experience is to see this chapter must learn to find different, this is the key; from next week to learn the C language, it feels like reading some basic code is very laborious.

Learning progress Bar /Cumulative) new/cumulative)
lines of code (newBlog volume (Learning time (new/cumulative) Important growth
Goal 5000 rows 30 Articles 400 hours
7th Week 67/472 1/10 20/151

20145331 "Information Security system Design Fundamentals" 9th Week Study Summary

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.