Wei Dongshan Embedded Getting Started Notes-Application Development Fundamentals (3)

Four, file I/O

1. The top-level application layer can access ordinary files at the bottom through various functional interfaces (such as open, read, write), and can also access the driver, and then access the bottom-level hardware.
On the one hand, the application does not need to care about how the underlying hardware operates, but only needs to be responsible for the business on the application; on the other hand, the bottom-level developer writes the driver and provides the driver’s function interface to the top-level application developer; Each part performs its own duties and does what it is good at.

2. Where do the files come from?
(1) From hardware devices
. Files in hardware devices such as disks, Flash, SD cards, U disks, etc. are real files stored in the hardware devices. You must mount the device first if you want to access them.

Example: Access the files in the SD card
(a) Mount the device, it shows that there are three partitions: sda (total partition), sda1 (partition one), sda2 (partition two) to
see if it is automatically mounted:

cat  /proc/mounts

It shows that /dev/sda2 is mounted under the media/usb0 directory and /dev/sda1 is mounted under the media/usb1 directory, indicating that it has been automatically mounted.

If it is not automatically mounted, you can mount it manually, using the mount command:

mount  /dev/sda1  /mnt

In this way, the files in the sda1 partition can be read by reading the /mnt directory, just like ordinary files.

(2) From the virtual file system
provided by the Linux kernel. View the information in the Linux kernel through this virtual file system.
The files in this system can also be accessed by mounting. For details, see the relevant notes of [Knowledge Point: Root File System]

(3) Special files: For
example, the files in the /dev directory are called device nodes . When accessing the device node, the actual operation is the hardware (accessing the hardware through the driver).
Each device node has a corresponding major device number and minor device Number, and drive type.
Drivers are divided into character device drivers and block device drivers. They are distinguished by file type. C stands for char, which is a character device driver, and b stands for block, which is a block device driver. The
major device number indicates the corresponding driver; the
minor device number indicates the corresponding major device number. Which hardware is driven by the
application program? It is through standard interfaces such as open, read, and write that the application accesses these device nodes, and then accesses its driver, and then accesses the hardware.

3. Methods of accessing files:
(1) General I/O models: open, read, write, close, lssek
(2) Not general models: ioctl, mmap
(3) Understand the usage of these functions: man, help
such as :

man  2  open


4. How does the system call enter the kernel: Omitted

 

 

Guess you like

Origin blog.csdn.net/San_a_fish_of_dream/article/details/113459442