Practical System Programming for Rust Developers by Prabhu Eshwarla

Practical System Programming for Rust Developers by Prabhu Eshwarla

Author:Prabhu Eshwarla
Language: eng
Format: epub
Publisher: PACKT Publishing Pvt. Ltd.
Published: 2020-12-23T00:00:00+00:00


Understanding Linux system calls for file operations

In this section, we will look at the terminology and basic mechanisms associated with managing file system resources at the operating system level. We will use Linux/Unix as an example, but similar concepts apply to other operating systems.

So, what do you think a file is?

A file is just a set of bytes. A byte represents a unit of information—it can be a number, text, video, audio, image, or any other such digital content. The bytes are organized in a linear array called a byte stream. There is no other expectation in terms of the structure or contents of a file, as far as the operating system is concerned. It is the user application that does the interpretation of the file and its contents.

A user application is a program that is not a part of the operating system kernel. An example of a user application is an image viewer that interprets the bytes of data as an image. Since files are resources that are managed by the operating system, any user programs that we write must know how to interact with the operating system through system calls. A file can be read from, written to, or executed. An example of a file that can be executed is the binary executable (object) file, generated by software build systems such as Make or Cargo.

Another aspect that is unique to Linux/Unix is the philosophy that everything is a file. Here, everything refers to system resources. There can be many types of files on Linux/Unix:

Regular files, which we use to store text or binary data

Directories, which contain listings of names and references to other files

Block device files, for example, a hard disk, a tape drive, USB cameras

Character device files, for example, a terminal, a keyboard, a printer, a sound card

Named pipes, an in-memory inter-process communication mechanism

Unix domain sockets, also a form of inter-process communication

Links, such as hard links and symbolic links



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.