1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE slides SYSTEM "/usr/share/xml/docbook/custom/slides/3.3.1/schema/dtd/slides-full.dtd">
7 <title>Linux Device Drivers</title>
8 <author><firstname>Thadeu</firstname><surname>Cascardo</surname></author>
12 <title>Introduction</title>
14 Devices in POSIX Systems are files in /dev directory. As with any files
15 in POSIX, they may be opened, closed, read from, written to, seeked,
20 Examples of device files:
26 /dev/sda - A SCSI block device
31 /dev/ttyS0 - A Serial terminal device
39 <title>POSIX I/O calls</title>
41 POSIX systems have some standard calls for I/O. Since devices are files,
42 these same system calls are used to work with devices. We are gonna work
43 with the following calls:
70 The open system call opens a file. When working with devices, that's
71 when some initialization should be done. Some devices may be opened only
75 int open (char * filename, int flags);
78 flags may be O\_RDONLY, O\_WRONLY, O\_RDWR and many others, some not
79 important for devices.
85 fd = open ("/dev/ttyS0", O\_RDWR);
92 The close system call closes an open file.
108 The read system call reads data from an open file into a buffer. For
109 devices, it reads from the device.
112 int read (int fd, char *buffer, int bsz);
115 Read returns the number of bytes written into the buffer, which may be
116 less than the number of bytes requested for any number of reasons.
122 c = read (fd, buffer, sizeof (buffer));
129 The write system call writes data to an open file from a buffer. For
130 devices, it writes to the device.
133 int write (int fd, char *buffer, int bsz);
136 Write returns the number of bytes written to the file, which may be
137 less than the number of bytes requested for any number of reasons.
143 c = write (fd, buffer, strlen (buffer));