KEMBAR78
Input output in linux | PPT
INPUT AND OUTPUT IN LINUX
OVERVIEW Linux follows the philosophy that every thing is a file. For ex. A keyboard, Monitor, Mouse, Printer.  The I/O system in Linux is like that in any Unix system. Here all device drivers appear as normal files. A user can access a device in the same way as he open any other file. The administrator can set access permission for each device.
CATEGORIES   Linux splits all devices into three classes :- Block Devices Character Devices Network Devices
BLOCK DEVICES It includes all devices such as Hard Disks, Floppy Disks, CD-ROMs and Flash Memory. These devices can be accessed randomly. They read only blocks of data.
CHARACTER DEVICES It include devices such as mice and keyboards. These devices are access only serially or sequentially. They read the data character by character.
NETWORK DEVICES These are dealt differently from Block and Character Devices. Users cannot directly transfer data to Network Devices; instead, they must communicate indirectly by opening a connection to the kernel’s networking sub-system.
DEVICE-DRIVER BLOCK STRUCTURE File system Block device File I/O  Scheduler Block Device  Driver SCSI manager SCSI Device Driver Character device File Character Device  Driver TTY Driver  Line Discipline Network Socket Network Device  Driver Protocol Driver
Block devices provide the main interface to all disk devices in a system, or block devices allow random access and fixed sized blocks of data, including hard disk, floppy disk, CD ROMs etc. in the context of block devices, block represents the unit with which the kernel perform I/O. when a block read in to memory, it stored in a buffer. The work of request manager in block devices. BLOCK DEVICES
Block devices (contd….) A separate list of requests is kept for each block device. These request have been scheduled according to a unidirectional elevator algorithm. The request are maintain in sorted order of increasing starting sector number. When a request is accept for processing by a block device driver, it’s not removed form the list .It is removed after only the input output is complete.
Block device (contd….) In the block device there are two problems that may occur :- STARVATION DEADLINE
Block device (contd…) The deadline for read requests is  0.5 sec. & for writing request is 5 sec. block device also maintains three  queue  Sorted queue Read queue Write queue These queues are ordered  according to deadline.
All Character devices deal with data one character at a time and process them seqentially. Eg. The keyboard  strokes,mouse clicks, etc. Any character-device drivers registered to the Linux kernel must also register a set of functions that implement the file I\O operations that the driver can handle. CHARACTER DEVICES
The kernel performs almost no preprocessing of a file read or write request to the device in question and lets the device deal with request. Printers  are character devices and after the kernel sends data to the printer,the responsibility for that data passes to the printer,the kernel cannot back up and  reexamine the data.
The exception to this rule is the special subset of character device drivers that implement terminal devices. The kernel maintains a standard interface to these drivers by means of a set of  tty_struct  structures. Each of these structures provide buffering and flow control on the data stream from the terminal device and feeds those data to a line discipline.
A line discipline is an interpreter for the information from the terminal device. The most common line discipline is the  tty discipline. tty discipline  decides which process’s data should be attached or detached from the terminal device.
Users can’t directly transfer data to network devices. They communicate indirectly by opening a connection to the kernel’s networking subsystem. Networking in LINUX kernel is implemented by three layers of software:- 1.  The socket interface 2. Protocol drivers 3. Network device drivers. NETWORK STRUCTURE
1.The socket interface : User applications perform all networking  requests through the socket interface. It  looks like BSD socket layer, so  that the program designed for BSD socket can easily run on LINUX without any source code changes. BSD socket is sufficient to represent network addresses for networking protocols.
2.Protocol drivers: It is the second layer of software. When data arrives to this layer ,it is expected to have been tagged with an identifier specifying which network protocol they contain. Functions of protocol layer: 1.Rewrite packets, 2.Create new packets, 3.Split or reassembling packets into fragments, 4.Discard incoming data.
3.Network–device drivers: Communication between the layers of networking stack is performed by passing single  skbuff  structures An  skbuff  is a set of   pointers into a single   continuous area of memory, representing a buffer inside which network packets can be constructed. The networking code either add or trim data from the end of packet.
The most important set of protocol used in LINUX is TCP\IP suite. IP protocol implements routing between different hosts, anywhere on the network. UDP protocol carries arbitrary individual datagrams between hosts TCP protocol implements reliable connection between hosts . ICMP protocol is used to carry various errors & status messages between hosts.
Incoming IP packets are delivered to the IP driver. This layer performs routing. After deciding the destination of a packet is forwarded to appropriate internal protocol driver to delivered locally or injects it back into a selected network –device driver queue to be forwarded to another host.
The routing can be done by two  tables: 1.FIB(forwarding information base) 2.Cache of recent routing decisions. 1. FIB is a set of hash tables indexed by destination address. 2. It caches routes only by specific destination. An entry in route cache expires after a fixed period with no hits.
IP software passes its packets to a separate section code for firewall management. It manages separate firewall chains 1.For forwarded packets 2.For packets being input to host 3.For data generated at the host. IP driver performs disassembly and reassembly of large packets.
Large outgoing packets are split up into smaller fragments At the receiving host these fragments are reassembled . Incoming fragments are matched against each known ipq; If a match is found fragment is added to it otherwise , new ipq is created  Once the final fragment has arrived new skbuff is created ,to hold anew packet. This is passed back to IP driver.

Input output in linux

  • 1.
  • 2.
    OVERVIEW Linux followsthe philosophy that every thing is a file. For ex. A keyboard, Monitor, Mouse, Printer. The I/O system in Linux is like that in any Unix system. Here all device drivers appear as normal files. A user can access a device in the same way as he open any other file. The administrator can set access permission for each device.
  • 3.
    CATEGORIES Linux splits all devices into three classes :- Block Devices Character Devices Network Devices
  • 4.
    BLOCK DEVICES Itincludes all devices such as Hard Disks, Floppy Disks, CD-ROMs and Flash Memory. These devices can be accessed randomly. They read only blocks of data.
  • 5.
    CHARACTER DEVICES Itinclude devices such as mice and keyboards. These devices are access only serially or sequentially. They read the data character by character.
  • 6.
    NETWORK DEVICES Theseare dealt differently from Block and Character Devices. Users cannot directly transfer data to Network Devices; instead, they must communicate indirectly by opening a connection to the kernel’s networking sub-system.
  • 7.
    DEVICE-DRIVER BLOCK STRUCTUREFile system Block device File I/O Scheduler Block Device Driver SCSI manager SCSI Device Driver Character device File Character Device Driver TTY Driver Line Discipline Network Socket Network Device Driver Protocol Driver
  • 8.
    Block devices providethe main interface to all disk devices in a system, or block devices allow random access and fixed sized blocks of data, including hard disk, floppy disk, CD ROMs etc. in the context of block devices, block represents the unit with which the kernel perform I/O. when a block read in to memory, it stored in a buffer. The work of request manager in block devices. BLOCK DEVICES
  • 9.
    Block devices (contd….)A separate list of requests is kept for each block device. These request have been scheduled according to a unidirectional elevator algorithm. The request are maintain in sorted order of increasing starting sector number. When a request is accept for processing by a block device driver, it’s not removed form the list .It is removed after only the input output is complete.
  • 10.
    Block device (contd….)In the block device there are two problems that may occur :- STARVATION DEADLINE
  • 11.
    Block device (contd…)The deadline for read requests is 0.5 sec. & for writing request is 5 sec. block device also maintains three queue Sorted queue Read queue Write queue These queues are ordered according to deadline.
  • 12.
    All Character devicesdeal with data one character at a time and process them seqentially. Eg. The keyboard strokes,mouse clicks, etc. Any character-device drivers registered to the Linux kernel must also register a set of functions that implement the file I\O operations that the driver can handle. CHARACTER DEVICES
  • 13.
    The kernel performsalmost no preprocessing of a file read or write request to the device in question and lets the device deal with request. Printers are character devices and after the kernel sends data to the printer,the responsibility for that data passes to the printer,the kernel cannot back up and reexamine the data.
  • 14.
    The exception tothis rule is the special subset of character device drivers that implement terminal devices. The kernel maintains a standard interface to these drivers by means of a set of tty_struct structures. Each of these structures provide buffering and flow control on the data stream from the terminal device and feeds those data to a line discipline.
  • 15.
    A line disciplineis an interpreter for the information from the terminal device. The most common line discipline is the tty discipline. tty discipline decides which process’s data should be attached or detached from the terminal device.
  • 16.
    Users can’t directlytransfer data to network devices. They communicate indirectly by opening a connection to the kernel’s networking subsystem. Networking in LINUX kernel is implemented by three layers of software:- 1. The socket interface 2. Protocol drivers 3. Network device drivers. NETWORK STRUCTURE
  • 17.
    1.The socket interface: User applications perform all networking requests through the socket interface. It looks like BSD socket layer, so that the program designed for BSD socket can easily run on LINUX without any source code changes. BSD socket is sufficient to represent network addresses for networking protocols.
  • 18.
    2.Protocol drivers: Itis the second layer of software. When data arrives to this layer ,it is expected to have been tagged with an identifier specifying which network protocol they contain. Functions of protocol layer: 1.Rewrite packets, 2.Create new packets, 3.Split or reassembling packets into fragments, 4.Discard incoming data.
  • 19.
    3.Network–device drivers: Communicationbetween the layers of networking stack is performed by passing single skbuff structures An skbuff is a set of pointers into a single continuous area of memory, representing a buffer inside which network packets can be constructed. The networking code either add or trim data from the end of packet.
  • 20.
    The most importantset of protocol used in LINUX is TCP\IP suite. IP protocol implements routing between different hosts, anywhere on the network. UDP protocol carries arbitrary individual datagrams between hosts TCP protocol implements reliable connection between hosts . ICMP protocol is used to carry various errors & status messages between hosts.
  • 21.
    Incoming IP packetsare delivered to the IP driver. This layer performs routing. After deciding the destination of a packet is forwarded to appropriate internal protocol driver to delivered locally or injects it back into a selected network –device driver queue to be forwarded to another host.
  • 22.
    The routing canbe done by two tables: 1.FIB(forwarding information base) 2.Cache of recent routing decisions. 1. FIB is a set of hash tables indexed by destination address. 2. It caches routes only by specific destination. An entry in route cache expires after a fixed period with no hits.
  • 23.
    IP software passesits packets to a separate section code for firewall management. It manages separate firewall chains 1.For forwarded packets 2.For packets being input to host 3.For data generated at the host. IP driver performs disassembly and reassembly of large packets.
  • 24.
    Large outgoing packetsare split up into smaller fragments At the receiving host these fragments are reassembled . Incoming fragments are matched against each known ipq; If a match is found fragment is added to it otherwise , new ipq is created Once the final fragment has arrived new skbuff is created ,to hold anew packet. This is passed back to IP driver.