alp-ch06-mastering-linux

alp-ch06-mastering-linux - II Mastering Linux 6 7 8 9 10 11...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Mastering Linux II 6 Devices 7 The /proc File System 8 Linux System Calls 9 Inline Assembly Code 10 Security 11 A Sample GNU/Linux Application
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Devices 6 L INUX , LIKE MOST OPERATING SYSTEMS , INTERACTS WITH HARDWARE devices via modularized software components called device drivers .A device driver hides the pecu- liarities of a hardware device’s communication protocols from the operating system and allows the system to interact with the device through a standardized interface. Under Linux, device drivers are part of the kernel and may be either linked stati- cally into the kernel or loaded on demand as kernel modules. Device drivers run as part of the kernel and aren’t directly accessible to user processes. However, Linux pro- vides a mechanism by which processes can communicate with a device driver—and through it with a hardware device—via file-like objects.These objects appear in the file system, and programs can open them, read from them, and write to them practi- cally as if they were normal files. Using either Linux’s low-level I/O operations (see Appendix B,“Low-Level I/O”) or the standard C library’s I/O operations, your pro- grams can communicate with hardware devices through these file-like objects. Linux also provides several file-like objects that communicate directly with the kernel rather than with device drivers.These aren’t linked to hardware devices; instead, they provide various kinds of specialized behavior that can be of use to application and system programs.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
130 Chapter 6 Devices Exercise Caution When Accessing Devices! The techniques in this chapter provide direct access to device drivers running in the Linux kernel, and through them to hardware devices connected to the system. Use these techniques with care because mis- use can cause impair or damage the GNU/Linux system. See especially the sidebar “Dangers of Block Devices.” 6.1 Device Types Device files aren’t ordinary files—they do not represent regions of data on a disk- based file system. Instead, data read from or written to a device file is communicated to the corresponding device driver, and from there to the underlying device. Device files come in two flavors: n A character device represents a hardware device that reads or writes a serial stream of data bytes. Serial and parallel ports, tape drives, terminal devices, and sound cards are examples of character devices. n A block device represents a hardware device that reads or writes data in fixed-size blocks. Unlike a character device, a block device provides random access to data stored on the device.A disk drive is an example of a block device. Typical application programs will never use block devices.While a disk drive is repre- sented as block devices, the contents of each disk partition typically contain a file sys- tem, and that file system is mounted into GNU/Linux’s root file system tree. Only the kernel code that implements the file system needs to access the block device directly; application programs access the disk’s contents through normal files and directories.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

alp-ch06-mastering-linux - II Mastering Linux 6 7 8 9 10 11...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online