UNIX INTERNALS

Disk and Terminal Drivers

       A. Sarang
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.
Ui disk & terminal drivers
 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.
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.
Ui disk & terminal drivers
Accessing block 940 of dev/dsk3

 Section 3 starts at block
  336000
 336000+940
 336940
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
 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.
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.
 Block interface = read , write
 Raw interface = lseek
# include “fcntl.h”
Main()
{
Char buf1[4096],buf2[4096];
Int fd1,fd2,I;
If(((fd1=open(“/dev/dk5”,O_RDONLY))==-
    1)||((fd2=open(“/dev/rdsk5”,O_RDONLY))==-1))
{
Printf(“failure on openn”);
Exit();
}
Lseek(fd1,8192L,0);
Lseek(fd2,8192L,0);
If((read(fd1,buf1,sizeof(buf1))==-1)||
   (read(fd2,buf3,sizeof(buf1))==-1))
{
Printf(“failure on readn”);
Exit();
}
For(i=0;i<sizeof(buf1);i++)
   If(buf1[i]!=buf2[i])
   {
       Printf(“different at offset %dn”,i);
       Exit();
   }
Printf(“reads matchn”);
}
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.
 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.
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.
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.
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.
Example

 Hello data DEL DEL DEL DEL world


 RAW mode output :-
 Hello data DEL DEL DEL DEL world


 Canonical mode output :-
 Hello world
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
 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.
Ui disk & terminal drivers
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.
Ui disk & terminal drivers
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 )
Ui disk & terminal drivers
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.
 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.
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;
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;
}
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.
 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.
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)
}
/*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;
}}}
While (characters on canonical clist and read
 count not satisfied)

Copy from cblocks on canonical list to user
  address space;

}
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
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.
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.
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.
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.
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.
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.

More Related Content

PDF
Centralized shared memory architectures
PPTX
Direct Memory Access(DMA)
PDF
Computer organization memory
PPTX
Direct memory access
PPT
Understanding operating systems 5th ed ch01
PPTX
Flow Control and Error Control
PPTX
Memory organization (Computer architecture)
PPTX
HDLC(High level Data Link Control)
Centralized shared memory architectures
Direct Memory Access(DMA)
Computer organization memory
Direct memory access
Understanding operating systems 5th ed ch01
Flow Control and Error Control
Memory organization (Computer architecture)
HDLC(High level Data Link Control)

What's hot (20)

PPTX
Computer architecture addressing modes and formats
PPTX
Operating system 18 process creation and termination
PPT
Chapter 13 - I/O Systems
PPT
I/O System
PPTX
What Is User Datagram Protocol?
PPTX
Swapping | Computer Science
PPTX
RISC - Reduced Instruction Set Computing
PPTX
ch 2 - DISTRIBUTED DEADLOCK DETECTION.pptx
PPTX
System protection in Operating System
PPT
31 address binding, dynamic loading
PPTX
Direct memory access
PPTX
Basic Computer Organization and Design
PPT
Registers
PPTX
RAID LEVELS
PDF
Monitors
PPTX
Interrupts and types of interrupts
PPT
15. Transactions in DBMS
PPTX
Three main Architectures For Parallel Database.pptx
PPT
pipelining
Computer architecture addressing modes and formats
Operating system 18 process creation and termination
Chapter 13 - I/O Systems
I/O System
What Is User Datagram Protocol?
Swapping | Computer Science
RISC - Reduced Instruction Set Computing
ch 2 - DISTRIBUTED DEADLOCK DETECTION.pptx
System protection in Operating System
31 address binding, dynamic loading
Direct memory access
Basic Computer Organization and Design
Registers
RAID LEVELS
Monitors
Interrupts and types of interrupts
15. Transactions in DBMS
Three main Architectures For Parallel Database.pptx
pipelining
Ad

Viewers also liked (20)

PPT
Input output systems ppt - cs2411
PPTX
Unix Operating System
PPTX
Unix operating system
PPT
Device drivers tsp
PPT
Linux io
PPT
Chap2 hdd1
PPT
Input output in linux
PPTX
Kernel I/O subsystem
PPTX
Ch 6 development plan and quality plan
PPT
CASE tools and their effects on software quality
PPTX
Device Drivers
PDF
Operating system concepts (notes)
PPTX
Pert cpm
PPTX
Pert & cpm project management
PPTX
Personal swot analysis
PPT
Personal Swot Analysis
PDF
SQA Components
Input output systems ppt - cs2411
Unix Operating System
Unix operating system
Device drivers tsp
Linux io
Chap2 hdd1
Input output in linux
Kernel I/O subsystem
Ch 6 development plan and quality plan
CASE tools and their effects on software quality
Device Drivers
Operating system concepts (notes)
Pert cpm
Pert & cpm project management
Personal swot analysis
Personal Swot Analysis
SQA Components
Ad

Similar to Ui disk & terminal drivers (20)

DOCX
LINUX RS232程式設計
PDF
Summarized of UNIX Time Sharing System
PPT
Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture)
PDF
Prog ii
PPT
2ab. UNIX files.ppt JSS science and technology university
PPTX
MODULE 3.1 updated-18cs56.pptx
DOCX
Linux 系統程式--第一章 i/o 函式
PPTX
Unix operating system architecture with file structure
PDF
Operating System
PDF
Operating System
PDF
Systems Programming - File IO
PPTX
System calls operating system ppt by rohit malav
PPT
Unix fundamentals
PPTX
operating system calls input and output by (rohit malav)
PDF
Ch12 io systems
PPTX
DEVICE FILE AND INPUT OUTPUT SUBSYSTEMS MANAGEMENT
PPT
Unit 7
PDF
Mc7404 np final
PPTX
Chapter -2 Operating-System and its Structures
PPT
LINUX RS232程式設計
Summarized of UNIX Time Sharing System
Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture)
Prog ii
2ab. UNIX files.ppt JSS science and technology university
MODULE 3.1 updated-18cs56.pptx
Linux 系統程式--第一章 i/o 函式
Unix operating system architecture with file structure
Operating System
Operating System
Systems Programming - File IO
System calls operating system ppt by rohit malav
Unix fundamentals
operating system calls input and output by (rohit malav)
Ch12 io systems
DEVICE FILE AND INPUT OUTPUT SUBSYSTEMS MANAGEMENT
Unit 7
Mc7404 np final
Chapter -2 Operating-System and its Structures

More from Sarang Ananda Rao (10)

PDF
Reducing Inefficiencies in Financial Markets
PDF
Partners Healthcare Case Analysis
PDF
Auction analysis from Kaggle
PDF
Personal Finance: Portfolio Optimization using Jensen's Performance Measure
PDF
ACG Case Competition 2016 - Sierra Securities
PPT
Ticketing platform for cinemalls
PPTX
Redundancy schemes for deduplicated cloud storage systems
PPTX
Musicperk - Developro 2012
PPTX
CMS & Chrome Extension Development
PPTX
Introduction to SSH & PGP
Reducing Inefficiencies in Financial Markets
Partners Healthcare Case Analysis
Auction analysis from Kaggle
Personal Finance: Portfolio Optimization using Jensen's Performance Measure
ACG Case Competition 2016 - Sierra Securities
Ticketing platform for cinemalls
Redundancy schemes for deduplicated cloud storage systems
Musicperk - Developro 2012
CMS & Chrome Extension Development
Introduction to SSH & PGP

Ui disk & terminal drivers

  • 1. UNIX INTERNALS Disk and Terminal Drivers A. Sarang
  • 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.
  • 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.
  • 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.
  • 11.  Block interface = read , write  Raw interface = lseek
  • 12. # include “fcntl.h” Main() { Char buf1[4096],buf2[4096]; Int fd1,fd2,I; If(((fd1=open(“/dev/dk5”,O_RDONLY))==- 1)||((fd2=open(“/dev/rdsk5”,O_RDONLY))==-1)) { Printf(“failure on openn”); Exit(); } Lseek(fd1,8192L,0); Lseek(fd2,8192L,0);
  • 13. If((read(fd1,buf1,sizeof(buf1))==-1)|| (read(fd2,buf3,sizeof(buf1))==-1)) { Printf(“failure on readn”); Exit(); } For(i=0;i<sizeof(buf1);i++) If(buf1[i]!=buf2[i]) { Printf(“different at offset %dn”,i); Exit(); } Printf(“reads matchn”); }
  • 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.
  • 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.
  • 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 )
  • 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.