20145336 Zhang Ziyang "The foundation of Information Security system Design" 9th Week Study Summary Learning goal
- Mastering the concepts of system programming and system invocation
- Mastering the way of system programming error handling
- Mastering Unix/linux System level I/o:open Close Read Write seek stat
- Mastering Rio
- Mastering the method of I/O redirection
Summary of learning contents of textbook
- System-Level I/O: the input/output is the process of copying data between main memory and external devices, where the input is copying data from the I/O device to main memory, and the output is copying data from main memory to I/O devices.
Unix I/O
Unix I/O is a simple low-level application interface that performs all input and output as a read and write to a file
Descriptor: When opening a file, the kernel returns a small non-negative integer. Each process created by the Unix shell starts with three open files: a standard input (descriptor 0), a standard output (descriptor 1), and a standard error (descriptor 2). Change the current file location: The file location is K and the initial is 0. Seek action: explicitly sets the current location of the file to K.
EOF: is a condition, not a symbol.
Open File
If successful, the return value is a new file descriptor; If an error occurs, the return value is-1
The Open function converts the filename to a file descriptor and returns a descriptor number. The returned descriptor is always the smallest descriptor that is not currently open in the process. FD = Open ("filename", flag parameter, mode parameter)
Close File
Returns 0 if successful, or 1 if unsuccessful.
Closing an already closed descriptor program will cause an error.
Read and write files
Read function: Copies up to n bytes from the current file position of the descriptor to FD to the memory location BUF. return value:-1: an error; 0:eof; otherwise, the return value: The number of bytes actually transferred.
Write function: Copies the current file position of up to n bytes to the descriptor FD from the memory location BUF.
Write function: Copies the current file position of up to n bytes to the descriptor FD from the memory location BUF.
Ssize and size have the difference of return value
Insufficient values: Read and write transmit fewer bytes than the application requires.
Causes of insufficient values: 1. EOF 2 is encountered while reading. Read Text line 3 from terminal. Read and write network sockets
Rio Package
The Rio package handles the low value automatically
The Rio package provides two types of functions:
unbuffered input and OUTPUT functions
Applications can transfer data directly between memory and files by calling the Rioreadn and Riowritten functions.
The Rio_ Readn function can only return an insufficient value when it encounters EOF
Rio_ writen function will never return an insufficient value
Input function with buffering
RIOREADINITB: This function is called every time a descriptor is opened, which links the descriptor FD to a buffer of type rio_t at the address RP
RIOREADNB: Reads a maximum of n bytes from the file RP to the memory location USRBUF. Calls to the same descriptor, RIOREADNB and Rioreadlineb, can be interleaved
Ssizet Readlineb: Reads a line of text from the RP of the file (including the end of the newline character), copies it to the memory location usrbuf, and ends it with null characters
Applications can retrieve information about a file (metadata) by invoking the stat and FSTAT functions
The stat function takes the file name as input
St_size member contains the size of the number of bytes in the file
St_mode members encode file access License bits and file types
The kernel uses three related data structures to represent open files: 1. Descriptor tables: Each Open Descriptor table entry points to a list entry in the File table 2. File table: All processes share this table, and each table entry includes the file location, reference count, and a pointer to the table entry for the V-node table 3. V-node table: All processes share this table, which contains most of the letters in the stat structure
Problems in teaching materials learning and the solving process
Csapp can't find
Download in http://csapp.cs.cmu.edu/public/code.html
You can also use the <stdio.h><fcntl.h><unistd.h> three header file equivalent instead of
This week's code hosting
Code Managed Links: http://git.oschina.net/Zziyang/CS10
Learning progress Bar
|
lines of code (new | /Cumulative)
Blog volume ( | new/cumulative)
Learning time (new/cumulative) |
Important growth |
Goal |
5000 rows |
30 Articles |
400 hours |
|
Second week |
0/0 |
1/2 |
19/20 |
|
Third week |
80/80 |
1/3 |
25/44 |
|
Week Four |
110/190 |
1/4 |
23/67 |
|
Week Five |
60/250 |
2/6 |
26/93 |
|
Week Six |
80/330 |
2/8 |
25/118 |
|
Seventh Week |
60/390 |
1/9 |
25/133 |
|
Eighth Week |
0/390 |
2/11 |
22/155 |
|
Nineth Week |
70/460 |
2/13 |
23/178 |
|
The 7th Week Study summary of the basic design of information security system