C language foundation (11)

Files:
1. Static files (inode)
The files in the hard disk are static files. Files are made up of blocks and sectors. In general, a sector (512 bytes), 64 sectors constitute a block. In the hard disk, there is a specific rule for file management (file management table + real content): file management table, which provides all the information of each file in units of files (each file information table corresponds to a structure body, this structure is called inode, also called i-node, how many blocks and sectors this file contains), and we can find the content of the file we need by looking up this table.
We are looking for a file, and we find it by (file name). The first step: in the file management table, find the name of the file, the second, access the file. U disk format: 1. Quick format, clear your file management table, the file system can not find the file name you need, your real content is still in the hard disk, you can partially recover 2. Complete format, This means that the real content of the file is also cleared, and the U disk cannot be restored through software technology, and must be restored with the help of national security agencies (through physical mechanisms, through hardware memory recovery).
Contact: In life, a means of dealing with small files, file compression. Utilize the spare bytes of the sector to reduce the space occupied on the hard disk. Hard drives love large files.
2. Dynamic file (vnode), in memory.
The running of a program is a process, and the files we open belong to this process. The operating system has a structure to manage each process. This structure that manages all the information of the current process is called (process information table). There is a pointer in this table to our file management table, this file management table contains all the files opened by this process, by looking up the index of the file management table (file descriptor fd, equivalent to the subscript of this structure array) , we get the structure (Vnode, V node) of all the information of our file, and the pointer of this structure is the file pointer.
File attributes:
//refers to: the content of the file has changed
Last change: 2018-01-25 18:11:16.082959503 +0800
//Refers to: the file permissions have changed
Last change: 2018-01-25 18:11:16.082959503 +0800
3. File and stream
system -level file operations Function: file IO; operation file function provided by the standard library: standard IO. The difference is portability.
File IO can complete all operations on files, but the efficiency is not high, so standard IO appears. But you know, standard IO is ultimately implemented through file IO.
Stream: The meaning of character stream. When reading and writing files, it is operated one by one, continuously. The content of the file is not divided, and the lines are closely linked together.

File copy: 1. Continuously open the same file (inode) 2. API in C language (dup, dup2) 3. Multiple processes open the same file

Server:
1. Establish a socket communication, which is equivalent to (open) function.
2. Fill in the structure on the server side: struct sockaddr_in
3. Bind the network structure information and the network communication fd (file descriptor obtained from the first step)
4. Monitor this ip and port: listen
5. Wait for the connection from the client : accept. It is a blocking function that creates a fd for connection communication.
6. As for who sends data first, there is no regulation. Both (s/c) are fine. But be careful: once it is determined that one party is sending data, the other party must receive the data.

Client:
1. Establish a socket communication, which is equivalent to (open) function.
2. Fill in the structure of the client: struct addr_in, the port server of the client has nothing to do with it.
2.1. Fill in the structure on the server side: struct addr_in
3. Bind the network structure information and the network communication fd (file descriptor obtained from the first step) (optional)
4. The client connects to your server: connect(fd, the structure of the server)
perror:
Only the function whose error code is set to errno can use perror(printf 0f errno).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325918783&siteId=291194637