47ebedfe7af0a854558475b0cfc586e5c2d13260
[cascardo/kernel/old_slides/.git] / _ldd.xml
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">
3
4 <slides>
5
6 <slidesinfo>
7 <title>Linux Device Drivers</title>
8 <author><firstname>Thadeu</firstname><surname>Cascardo</surname></author>
9 </slidesinfo>
10
11 <foil>
12 <title>Introduction</title>
13 <para>
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,
16 ioctl'd, and others.
17 </para>
18
19 <para>
20 Examples of device files:
21 </para>
22
23 <itemizedlist>
24 <listitem>
25 <para>
26 /dev/sda - A SCSI block device
27 </para>
28 </listitem>
29 <listitem>
30 <para>
31 /dev/ttyS0 - A Serial terminal device
32 </para>
33 </listitem>
34 </itemizedlist>
35
36 </foil>
37
38 <foil>
39 <title>POSIX I/O calls</title>
40 <para>
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:
44 </para>
45 <itemizedlist>
46 <listitem><para>
47 open
48 </para></listitem>
49 <listitem><para>
50 read
51 </para></listitem>
52 <listitem><para>
53 write
54 </para></listitem>
55 <listitem><para>
56 close
57 </para></listitem>
58 <listitem><para>
59 seek
60 </para></listitem>
61 <listitem><para>
62 ioctl
63 </para></listitem>
64 </itemizedlist>
65 </foil>
66
67 <foil>
68 <title>open</title>
69 <para>
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
72 once at a time.
73 </para>
74 <para>
75 int open (char * filename, int flags);
76 </para>
77 <para>
78 flags may be O\_RDONLY, O\_WRONLY, O\_RDWR and many others, some not
79 important for devices.
80 </para>
81 <para>
82 Example:
83 </para>
84 <para>
85 fd = open ("/dev/ttyS0", O\_RDWR);
86 </para>
87 </foil>
88
89 <foil>
90 <title>close</title>
91 <para>
92 The close system call closes an open file.
93 </para>
94 <para>
95 int close (int fd);
96 </para>
97 <para>
98 Example:
99 </para>
100 <para>
101 close (fd);
102 </para>
103 </foil>
104
105 <foil>
106 <title>read</title>
107 <para>
108 The read system call reads data from an open file into a buffer. For
109 devices, it reads from the device.
110 </para>
111 <para>
112 int read (int fd, char *buffer, int bsz);
113 </para>
114 <para>
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.
117 </para>
118 <para>
119 Example:
120 </para>
121 <para>
122 c = read (fd, buffer, sizeof (buffer));
123 </para>
124 </foil>
125
126 <foil>
127 <title>write</title>
128 <para>
129 The write system call writes data to an open file from a buffer. For
130 devices, it writes to the device.
131 </para>
132 <para>
133 int write (int fd, char *buffer, int bsz);
134 </para>
135 <para>
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.
138 </para>
139 <para>
140 Example:
141 </para>
142 <para>
143 c = write (fd, buffer, strlen (buffer));
144 </para>
145 </foil>
146
147 </slides>