Input output in linux


Published on

Published in: Design, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Input output in linux

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