2. DEVICE DRIVERS :-
The I/O Subsystem allows the process to
communicate with the peripheral devices
such as :-
disks, terminal, tape drives, printers,
networks and kernel modules.
3.
4. A disk can be partitioned into a no. of file
systems.
An administrator can leave a partition
mounted or unmounted and can make it
read only / read write.
5. Disk driver
A disk driver translates the file system
address to the particular sector of the disk.
The file system address consists of a logical
device number and a block no.
Eg : /dev/dsk0 of a DEC RP07 disk
Which means accessing section 0 of the DEC
RP07 disk.
6.
7. Accessing block 940 of dev/dsk3
Section 3 starts at block
336000
336000+940
336940
8. Accessing disk data
Using raw or block interface
Eg : lseek , ls
Using commands like mkfs & fsck.
They access the file systems directly.
Lseek sets the file offset for the open file
9. Mkfs : formats disk section for UNIX file
system & creates the super block , inode , list
, linked list of free disk blocks and root
directory.
Fsck : checks the consistency of the file
system and corrects the errors.
10. Block and raw interface
Ls –l /dev/dsk15 /dev/rdsk15
Br ----- 2 root 0,21 Feb12 15:00 /dev/dsk15
0 = Major n0.
21= Minor no.
2= physical drive
1= section no.
14. From the program we infer :-
Using read & write to the disk directly is
dangerous .
Jeopardizes system security.
Administrators need to put appropriate
permissions for the disk device.
For eg : /dev/dsk15 should be owned by root
to read but should not allow other users to
read or write.
15. Read or write routine converts byte offset to
block offset .
Use of block interface needs an extra copy of
data between user address space & kernel
buffers
Use of raw interface on the other hand is
faster.
16. TERMINAL DRIVERS
Terminal Drivers are used to control
the transmission of data to & from
the terminals.
But terminals are also user interface
to the sytem unlike disks.
17. Line Disciplines
Set of manipulations that input editing does.
For eg : for moving one step backward , you
have BACKSPACE in some terminals and DEL
in some others.
18. Modes of a terminal
Raw mode
Canonical mode
Raw mode sends the entire sequence typed
sequence including the erase characters.
In Canonical mode , line disciple buffers the
data into lines and processes erase characters
before sending the revised sequence to the
reading process.
Canonical mode processes edit, delete.
19. Example
Hello data DEL DEL DEL DEL world
RAW mode output :-
Hello data DEL DEL DEL DEL world
Canonical mode output :-
Hello world
20. Functions of line discipline:-
Parse the input string into lines.
Process the erase characters.
Process “kill” character that invalidates all
characters typed so far on the current line.
To echo(write) received characters to the
terminal.
To expand o/p such as tab character to a
sequence of blank spaces
21. Generate signals to process terminal
hangups, line breaks or response to user
hitting the delete key.
To allow raw mode that does not interpret
special characters such as erase,kill or
carriage return.
22.
23. Data structures used
Cblocks
Clists
Buffer is made of several physical entities or
character blocks – Cblocks.
Clist is a variable length linked list of Cblocks.
Cblock has a pointer to the next Cblock on the
linked list.
24.
25. Data structures used :-
Three Clists :-
O/p Clist : Clist to store o/p of terminal
Raw i/p Clist : Clist to store raw i/p data
(provided by terminal interrupt handler as the
user types in).
Canonical i/p Clist : Clist to store “cooked” i/p
data(after line discipline converts spl
characters )
26.
27. Terminal driver in Canonical mode :-
Write :-
Terminal driver invokes the line discipline.
Line discipline loops reading o/p characters
from user address space & places them on o/p
clist.
If no. of characters in o/p clist is greater than
the “high-water mark” , it puts the writing
process to sleep.
28. If the amount of data is below the “low water
mark” , the interrupt handler awakens all
processes asleep.
Line discipline processes the spl characters .
Write operation is started with data on o/p
clist.
29. Algorithm for write
Algorithm terminal_write
{
while (more data to be copied from user
space)
{
if (tty flooded with o/p data)
{
start write operation on hardware
with data on o/p clist;
30. Sleep;
Continue;
}
copy cblock size of data from user space to o/p
clist ;
line discipline converts tab characters etc;
}
start write operation on h/w with data on output
clist;
}
31. Read :-
If no data is available in the i/p clist the
reading process sleeps until the arrival of a
line of data.
Whenever data is entered , terminal interrupt
handler places the data in raw clist for i/p &
o/p clist for echoing back to the terminal.
32. If terminal is in raw mode , copy all data from
raw clist to canonical clist.
If terminal is in canonical mode , copy one
character at a time from raw clist to canonical
clist , process the data.
Finally copy cblocks from canonical clist to
user address space.
33. Algorithm for read
Algorithm terminal_read
{
while (no data on raw clist )
{
if (tty opened with no delay option)
return;
if (tty in raw mode based on timer & timer not
active)
arrange for timer wakeup(callout table);
Sleep (event : data arrives from terminal)
}
34. /*there is data on raw clist*/
If(tty in raw mode)
copy all data from raw clist to canonical clist
Else /*tty in canonical mode*/
{
while(characters on raw clist)
{
copy one character at a time from raw clist to canonical clist;
do erase , kill processing ;
if (char is carriage return or e-o-f )
Break;
}}}
35. While (characters on canonical clist and read
count not satisfied)
Copy from cblocks on canonical list to user
address space;
}
36. Terminal driver in Raw mode
In raw mode , line disclipline transmits
characters exactly as the user types them: no
input processing is done.
Kernel must know when to satisfy user read
calls since carriage return is treated as
ordinary character
37. Satisfying read system calls
Read system calls are satisfied after minimum
no. of characters are input at the terminal.
After waiting a fixed time from the receipt of
any characters from the terminal.
The kernel times the entry of characters from
the terminal by placing entries in the callout
table.
Algorithm is same as canonical case.
38. Terminal Polling
Terminal polling can be done by opening a
terminal with “no delay” option & polling all
of the devices.
However this leads to wasting processing
power.
39. Terminal Polling in BSD
BSD system has a select system call for
device polling.
Select (nfds,rfds,wfds,efds,timeout)
Nfds = no.of file descriptors
Rfds,wfds & efds – bit masks
Timeout = how long select should sleep.
40. Control Terminal
It is the terminal on which a user logs into the
system .
It controls processes that the user initiates
from the terminal.
Plays an important role in handling signals.
When user presses delete , break or quit keys,
it sends appropriate signals to all the
processes.
41. Indirect Terminal Driver
Unix systems provide indirect terminal
access via the device file /dev/tty .
Kernel can define a special device no. for the
indirect terminal file with a special entry in
the character device switch table.
Allocating inode for the control terminal.
42. Logging in
First the get ty (get terminal process
executes) and the process is set.
Open terminal line.
If open successful , exec login program &
prompt for username and password.
If login successful , put the terminal in
canonical mode else try again.