10.1 (conspect) FileIO

A file represents a data stream that has a beginning and an end. Some input and output devices work the same way. For example, a typewriter or keyboard: you press, the Button loads bytes and you cannot step skipping part. Therefore, the OS must provide unification for input and output-the keyboard starts working as a file. Files in the OS are not much different from C. In fact, input and output are an abstraction of files and they are quite weighty.

When you want to create a file, an a stdio will appear and there will be a file, which will be a structure with pointers and a buffer. The file identifier is a number starting with 0, thus it already opens files ( 0, 1 and 2): stdin, stdout stderr- and all programs that run in C are implemented this way.

Read

You can use the read function to read a file with an array of numbers. Very often the type of object depends on the OS on which the architecture is running. If the end of the file occurs the reader returns 0 and the loop ends.

Open

Open - function to open a file and they must be closed using cloexeec O_direct helps to avoid overcaching. Direct recording is a very slow. O_tmpfile you can delete an open file immediately

Seek_set

Use it To read the middle of a file we need to know the file size It is impossible to read what you enter from the keyboard after 100bytes

Holes in the file

When creating a File, it consists of 0. Open it and Write and there is Record chunk and 0 and you Go to the end and Start after 0 and then continue And the OS still understands that these are zeros and doesn't store them. Readlink can read text from links, the cat can not

HSE/ProgrammingOS/10_FileIO/Cospect_en (последним исправлял пользователь VasilyKireenko 2020-03-05 23:03:32)