Unit 6


Published on

Input output and files system

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

  • Be the first to like this

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

No notes for slide

Unit 6

  1. 1. Review of computer hardwarePrinciples of i/o hardwarePrinciples of i/o softwarei/o software layersDisks, clocksGraphical user interfaceGraphical user interfaceNetwork terminalPower managementFiles,directories,file system implementationFile system layout, implementing filesImplementing directories, shared files,Disc space management ,examples of file systemCDROM,MSDODS,Win98,UNIX.
  2. 2. The control of devices connected to the computer is amajor aspect of operating system.There is a wide variety I/O devicesThese devices are vary in their function and speed.It is difficult for any operating system to develop aIt is difficult for any operating system to develop ageneral ,consistent solution for these I/O devices.
  3. 3. There is no single method to control these i/o devices.Every operating system separates methods of dealingwith i/o devices from the rest of OSDevices drives are becoming popularDevices drivers provide standard interface between i/oDevices drivers provide standard interface between i/odevices and OS.
  4. 4. A computer uses many kind of devices .These devicescan be put in three categories1.Storage devices such as Disks ,tapes.2.Transmission devices, such as modem ,network cards.2.Transmission devices, such as modem ,network cards.3. Human interface devices such as screen, mouse,keyboard, etc
  5. 5. I/o devices communicate with a computer systemthrough a port.Devices are connected through a bus . A bus is set ofwires. Interaction through a bus is through a set ofmessages.messages.A controller is a collection of electronics circuitThat can operate a port ,a bus or a device.
  6. 6. I/o devices can be put in two categories1.Block Devices2.Character devicesBlock devices:-Blocks device stores information in fixed size blocks.Each blocks has unique address .each blocks can beaccessed independently.eg disks ,tape ,CD
  7. 7. Character devices:-A character devices accepts or delivers a stream ofcharacter. There is no concept of blocking in a characterdevices. Terminals ,printers, network interface, keyboardsetc,are character devices.etc,are character devices.Some devices like clocks do not fit into any of the abovetwo categories .Clocks simply generate interrupts at well defined intervals .
  8. 8. A device controller consists of electronic components.It interact both with the device and the system bus.Disk PrinterDiskDisk PrinterOthercontrollerCPUDiskcontrollerPrintercontrollercontrollerMemorybus
  9. 9. An OS interact with the controller and it does notinteract with the devices.A controller has several registers for data and controlsignals. The processor communicate with the controllerby reading and writing data in these registers.by reading and writing data in these registers.Device control registers can be memory mapped or I/omapped.Controller has four registers
  10. 10. 1.Data in register2. Data out register3.Status Register Busy and Ready4.Error condition.The OS perform I/O by writing commands into theThe OS perform I/O by writing commands into thecontrol register
  11. 11. In most of the data processing activities, a program hasto accept input from the keyboards or from asecondary storage device.i/o operation refers to a data transfer between an i/odevice and main memory or between an i/o device anddevice and main memory or between an i/o device andCPU.User program never interact directly with i/o devices.
  12. 12. All i/o operations are performed with the help ofsystem calls.Whenever a system call is made, CPU executes a smallmemory resident program known as device driver orinterrupt service routine. These specialized routinesinterrupt service routine. These specialized routinesinteract with an i/o device with the help of i/ocommands .There are four types of i/o commands1.control 2.Test status 3.Read 4.Write
  13. 13. A CPU is general purpose processor. it is capable ofaddressing all needs of an i/o device. CPU executes aprogram that intiates,directs,and terminates the i/ooperation ,the computer is said to be using programmedi/o.i/o.i/o device is very slow,CPU will be wasting a lot of itstime in trivial i/o operations.
  14. 14. Another technique, that can considerably improve CPUperformance is known as Interrupt driven Input/output.In both programmed and interrupt driven i/o CPU isresponsible for either sending and receiving of data .A slight increase in hardware enables an i/o device toA slight increase in hardware enables an i/o device totransfer a block of data to and from memory withoutintervention of CPU . This mode of interaction isknown as DMA(Direct Memory Access)
  15. 15. Thus there are three commonly used I/o techniques (datatransfer mode).1.Programmed Input/output1.Programmed Input/output2.Interrupt Driven input/output3. Direct Memory Access.
  16. 16. Programmed i/o is useful method for computers wherehardware costs need to be minimized.Entire i/o is handled by CPU with the help of smallsoftware without any additional hardware.CPU perform the following steps.CPU perform the following steps.
  17. 17. 1. Read the i/o device’s status bit.2.Test the status bit to determine if the device is readyto begin data transfer operation.3.If the device is not ready, return to step1,;otherwiseproceed with the data transfer. During the interval,device is not ready ,CPU simply wastes its time untilthe devices become ready.
  18. 18. When the processor, main memory, i/o share a common bus, twomodes of addressing are possiblememory –mapped i/oi/o mapped i/o
  19. 19. Data busAddress busWrite lineRead lineMainmemoryCPUI/omodule-1i/o modules-2Write linei/o device i/o device•Read command is for input of data•Write command is for output of data•I/o modules is used for interfacing of a Device with the system bus
  20. 20. With memory mapped i/o, there is a single addressspace for memory location and i/o devices.Processor treats status and data registers as separatesmemory location.Processor uses same memory instruction to access bothProcessor uses same memory instruction to access bothmemory and i/o deviceWith memory mapped i/o single read line and singlewrite line are needed on the bus
  21. 21. READ: line is activated during transfer of data frommemory to CPU.e.g.: MOV Ax [AX x] in 8086 transfer a word of data frommemory location x into CPU Register AX.Write : line is activated during transfer of data from CPU tomemory .memory .e.g: MOV x ,AX[x AX]With memory mapped i/o, no special commands (likeIN,OUT )are needed for i/o operations.A large set of instruction can be used for i/oInterfacing circuit for memory mapped i/o is complex.
  22. 22. Data busAddress busi/o ReadMemoryreadMemory writeMainmemoryCPUI/omodule-1i/omodules-2i/o Writei/o device i/o device
  23. 23. There are separate control lines for memory and i/o devices.A memory reference instruction does not effect an i/o device.A memory reference instruction for memory read will causegeneration of ‘memory read’ control signal.MOV AX,x [Ax x]A memory reference instruction for memory write will causegeneration of ‘memory write’ control signal.generation of ‘memory write’ control signal.MOV x ,AX [x AX ]A i/o reference instruction for i/o read will cause generation of‘i/o read’ control signal.IN AL ,300H [AL 300H ]A i/o reference instruction for i/o write will cause generation of‘i/o write’ control signal.OUT 300H,AL
  24. 24. Major drawback of programmed i/o is busy waiting .CPU Switches to some other program without waitingfor the i/o device to complete or to become free. whendevice become ,it inform back the CPU through adevice become ,it inform back the CPU through amechanism known as interrupt.
  25. 25. Types of interruptsProgram Interrupt(s/w interrupt )Timer interruptsi/o interruptsHardware failureHardware failure
  26. 26. Program interrupt: are generated by some condition thatoccurs as a result of an instruction execution,Arithmetic overflowDivision by zeroExecution of an illegal machine instructionSegment limit violationSegment limit violationExecution of privileged instructionTimer interrupt: are generated within processori/o interrupt are generated due to initiation or completion ofoperation.Hardware failure interrupt are generated by a failure,such aspower failure or memory parity error.
  27. 27. Both interrupt driven and programmed i/o required involvement of CPU fordata transfer.CPU can be better utilized for program execution.i/o activities are slow and involvement of CPU will not have a desired effect onsystem performance .When CPU was involved in data transfer, it uses the system bus twice.During memory to CPU transfer & CPU to i/o transfer.DMA increase the speed of i/o transfer by eliminating the role played by CPUin such operation.When i/o is requested , the CPU instruct the DMA module about the operation.
  28. 28. Operation of a DMA transfer29
  29. 29. DAMDMA Data transfermode1.DMA BlockDatacountData lines1.DMA BlockTransfer2. Cycle Stealingmode3.TransparentsDMADataregisterAddressregisterControlunitAddress linesReadWrite
  30. 30. How interrupts happens. Connections between devices andinterrupt controller actually use interrupt lines on the busrather than dedicated wires31
  31. 31. Device independence◦ Programs can access any I/O device◦ without specifying device in advance· (floppy, hard drive, or CD-ROM)· For examples :-A program that reads a file as input should be able to read a file ona floppy, disk, on a hard disk or on a CD-ROM, without having to modify theprogram for each different device.Uniform namingUniform naming◦ name of a file or device a string or an integer◦ not depending on which machine◦ The name of file or device should simply be a string or an integer and notdepend on the device in any way.◦ In UNIX ,all disks can be integrated in the file system hierarchy in arbitraryways so the user need not be aware of which name corresponds to whichdevice.32
  32. 32. Error handlingErrors should be handled as close to the hardware as possible .If controller discovers a read error , it should try to correct the error itself if it can. If it cannot ,then the device driver handled it, perhaps byjust trying to reads the block again.Synchronous vs. asynchronous transfersSynchronous vs. asynchronous transfers◦ blocked transfers vs. interrupt-driven◦ Most physical i/o is asynchronous the CPU starts the transferand goes off to do something else until the interrupt arrives .◦ User program are much easier to write if the i/o operations areblocking –after a read system call the program is automaticallysuspended until the data are available in the buffer.33
  33. 33. Buffering◦ data coming off a device cannot be stored in final destination◦ For E.g when a packet comes in off the networks the operatingsystem does not know where to put it until it has stored the packetsomewhere and examined it.◦ Also some devices have severe() real time constraints ,(e,g digital◦ Also some devices have severe() real time constraints ,(e,g digitalaudio devices)so the data must be put into an output buffer inadvance to decoupled the rate at which the buffer is filled from therate at which it is emptied ,in order to avoid buffer under runs.Sharable vs. dedicated devices◦ disks are sharable◦ tape drives would not be
  34. 34. Steps in printing a string35
  35. 35. Writing a string to the printer usingprogrammed I/O36
  36. 36. Writing a string to the printer using interrupt-driven I/O◦ Code executed when print system call is made◦ Interrupt service procedure37
  37. 37. Printing a string using DMA◦ code executed when the print system call is made◦ interrupt service procedure38
  38. 38. Layers of the I/O Software System39
  39. 39. i/o software is typically organized in four layers .Each layer has a well defined function to perform andwell defined interface to the adjacent layers.Lowermost layer interacts with the hardware .Uppermost layer provides a nice and friendly interfaceto users
  40. 40. Interrupt handlers are best hidden◦ have driver starting an I/O operation block until interruptnotifies of completionInterrupt procedure does its taskInterrupt procedure does its task◦ then unblocks driver that started it41
  41. 41. Steps must be performed in software after interrupt completedSave regs not already saved by interrupt hardwareSet up context for interrupt service procedure. Doing this may involve setting up theTLB,MMU and Page table .Set up stack for interrupt service procedureAck interrupt controller, reenable interruptsCopy registers from where saved Run service procedureSet up MMU context for process to run nextLoad new process registersStart running the new process42
  42. 42. Logical position of device drivers is shown hereCommunications between drivers and device controllers goes over the bus43
  43. 43. A device driver is piece of i/o software that handles alldevice independent tasks.A device driver accepts abstract request from thedevice-independent software above it, and converts itdevice-independent software above it, and converts itinto device dependent commands.A device drivers essentially converts the generalscommands from the device-independent software tomessages that the device type can understand.
  44. 44. Each controller has some device register used to give it commandor some device register used to readout its status or both.e.gMouse driver accept the information from the mouse tellinghow far it has moved and which button are currently depressed.In contrast, a disk driver has to know about sector, tracks,cylinders, heads, arm motion, motor drives ,head setting time andall other mechanism of making the disks work properly.Each i/o device attached to a computer needs some device-specific code for controlling it. This is called the device Driver
  45. 45. Device independent i/o software refers to that set ofprogram which provide a device independent interfaceto the user.The basic function of the device independent softwareis to perform functions common to all devices. Itprovides a uniform interface to the user level software.The basic function of the device inedpendent softwareare as follows:
  46. 46. Uniform interfacing for device driversBufferingError reportingFunctions of the device-independent I/O software47Error reportingAllocating and releasing dedicate devicesProviding a device-independent blocksize
  47. 47. (a) Without a standard driver interface(b) With a standard driver interface48
  48. 48. (a) Unbuffered input(b) Buffering in user space(c) Buffering in the kernel followed by copying to user space(d) Double buffering in the kernel49
  49. 49. Consider a process that wants to read data from a modem.One possible strategy for dealing with the incoming characteris to have arriving character cause an interrupt .The interruptservice procedure hands the character to the user process andservice procedure hands the character to the user process andunblocks it. After putting the character somewhere ,the processreads another character and blocks again.The trouble with this way of doing business is that the userprocess has to be started up for every incoming character.Allowing a process to run many times for short run isinefficient , so this design is not a good one
  50. 50. Networking may involve many copies51
  51. 51. Layers of the I/O system and the main functions of each layer52
  52. 52. Spooling is way of dealing with dedicated i/o device ina multiprogramming system.
  53. 53. Disks come in variety of types1.Magnetic disks (hard disks and floppy disks)2. Arrays of disks3.Optical disks (CD-ROMs ,CD-recordables, CD-Rewritables, DVD)A magnetic disk is a circular platter of plastic that is coated with magnetized material.A magnetic disk is a circular platter of plastic that is coated with magnetized material.The disks are mounted on a rotary drive so that the magnetized surface move in closeproximity to read/write head. The disks rotate at uniform speed.Sides : The magnetic coating if applied to both sides of the platter is called as double sideddisks.A disks has multiple platter that are stacked vertically . This is known as disk pack. A cylinderis defined which is the ring of all Co-centric tracks.
  54. 54. Data is stored in co-centric rings know as a tracks. The width of the tracksis equal to the width of the head. These track are separated by inter tracksgaps. Tracks are divided into sector.Two adjacent sector are separated by intra tracks gaps. In a typical harddisk, a sector of 600 bytes can contain, only 512 bytes of data anddisk, a sector of 600 bytes can contain, only 512 bytes of data andremaining is control information.Both data and identification field start with synchronization byte and have2 byte of error-detecting code.The identification field contains the basic information such as the tracksnumber ,sector number and head number which are needed to identify asector.
  55. 55. Gap17IdentificationfieldsGapGapGapGap41414141Data field512Gap2017fields07 41414141 512 20Length in byte 600
  56. 56. The most common ones are the magnetic disks(hard disks andfloppy disks) .They are characterized by the fact that reads andwrite are equally fast, which makes them ideal as secondarymemory..Magnetics Disks are organized into cylinders, each onecontaining as many tracks as there are heads stacked vertically.The tracks are divided into sectors ,with the number of sectoraround the circumference typically being 8 to 32 on floppydisks, and up to several hundred in hard disks.
  57. 57. CPU performance has been increasing exponentially over the past decade.In the 1970s, average seek times on minicomputers disks were 50 to100msec.Now seek times are slightly under 10msec.In 1988 paper ,Patterson suggested six specific disk organizations that could beused to improve disks performance, reliability or both.These ideas were quickly adopted by industry and have led to a new class of i/odevice called a RAID.RAID as Redundant array of Inexpensive Disks ,but industry redefined the I tobe independent rather than InexpensiveRAID: Redundant array of Independent Disks.
  58. 58. In a RAID system, a single large file is stored in severalseparate disks units by breaking the file up into a number ofsmall pieces and storing these pieces on different disks.When a file is accessed for a read, all disks deliver their dataWhen a file is accessed for a read, all disks deliver their datain parallel.RAID may be implemented in hardware or in the operatingsystem.
  59. 59. RAID Level 0It creates one large virtual disks from a number of smaller disks.Storage is grouped into logical unit called strips.The strips are mapped round –robin to consecutive array member.RAID level 0 architecture achieves the parallism but it does notinclude redundancy to improve reliability.include redundancy to improve reliability.Benefit:- Create a large disks.Limitation:- Files tend to get scattered over number of disks, evenafter a disks failure , some file data may be retrievable.In n disk array , the first n logical strips are physically stored as thefirst strip on each of the n disks, the second n strips are disturbedas second strips on each disks and so on.
  60. 60. RAID Level-1Redundancy is achieved by Just duplicating all the data.The data stripping is used, same as RAID Level 0.RAID level 1 stores duplicates copies of each strip, with eachcopy on a different disk.
  61. 61. RAID Level-2Single copies of each strip are maintained.Error correcting code such as hamming code is calculated forthe corresponding bits on each data disks.The bits of code are stored in the corresponding bit position onmultiple parity disks.The strips are very small, so when a block is read, all disks areaccessed in parallel
  62. 62. RAID Level-3In RAID level 3,single parity bit is used instead of an errorcorrecting code.It required just one extra disks.It required just one extra disks.The data stripping is used , similar to the other RAID Levels.If any disk in the array fails ,its data can be determined fromthe data on the remaining disks.
  63. 63. RAID Level-4RAID level 4 is similar to RAID level 3 , Except strips are larger.Operations to read a block involves only s single disk.Parity bit are stored in the Corresponding strips on the parity disk.A bit by bit parity strip is calculated across corresponding data blocks oneach data disk.Write operation requires parity information to be calculated.Write must be performed on both the data and parity disks.For each read and write operation parity bits are checked for datareliability.
  64. 64. RAID level-5It eliminates the potential bottleneck found in RAID-4.RAID-5 distributes the parity strips across all disks.
  65. 65. Disk parameters for the original IBM PC floppy diskand a Western Digital WD 18300 hard disk
  66. 66. Physical geometry of a disk with two zonesA possible virtual geometry for this disk67
  67. 67. Raid levels 0 through 2Backup and parity drives are shaded68
  68. 68. Raid levels 3 through 5Backup and parity drives are shaded69
  69. 69. Optical disks have much higher recording densities than conventional Magnetic disks.Optical disks were originally developed for the recording television Program.First – generation optical disks were invented by the Dutch electronics conglomeratePhilips for holding movies .In 1980,Philips , together with Sony developed the CD( Compact Disc)In 1980,Philips , together with Sony developed the CD( Compact Disc)A CD-ROM (Compact Disk read only memory) disk is an optical Laser disk whichstores digital data by using laser beams.This laser technology provides very large storagescapacities, and a CD-ROM disk is able to store up to 600 MB of dataAll technical details given in RED book.
  70. 70. A CD is prepared by using a high power infrared laser toburn 0.8 micron diameter holes in a coated glass masterdisk. From this master, a mold is made, with bumpswhere the laser holes were.Into this mold, molten Polycarbonate resin is injected toInto this mold, molten Polycarbonate resin is injected toform a CD with the same pattern of holes as the glassmaster. Then very thin layer of reflective aluminum isdeposited on the polycarbonate, topped by a protectivelacquer and finally a label. The depressions in thepolycarbonate substrate are called Pits. The unburnedareas between the pits are called lands.
  71. 71. Recording structure of a CD or CD-ROM72
  72. 72. In 1984 Philips and Sony launched new version of CD. Alldetails in Yellow book.The basic format of a CD-ROM consist of encoding everybyte in a 14 Bit symbol.byte in a 14 Bit symbol.A group of 42 consecutive symbol forms a 588 bit frame.Each frame holds 192 data bits (24 bytes) remaining 396 bitbits are used for error correction and control.
  73. 73. Logical data layout on a CD-ROM74Mode1: 2048 data+16 bytes Preamble+ 288 ECCMode1: 2048 data+16 bytes Preamble+ 288 ECCMode1: 2048 data+16 bytes Preamble+ 288 ECCMode1: 2048 data+16 bytes Preamble+ 288 ECCMode2: 2336 data+ Mode2 combine data &ECCMode2: 2336 data+ Mode2 combine data &ECCMode2: 2336 data+ Mode2 combine data &ECCMode2: 2336 data+ Mode2 combine data &ECC
  74. 74. Cross section of a CD-R disk and laser◦ not to scaleSilver CD-ROM has similar structure◦ without dye layer◦ with pitted aluminum layer instead of gold75
  75. 75. Although people are used to other write once mediasuch as paper and photographic film , there is a demandfor a rewritable CD-ROM.CD-RW uses an alloy of silver , indium ,antimony andtellurium for the recording layer.tellurium for the recording layer.CD-RW drives use laser with three different powers.At high powerAt medium powerAt low power
  76. 76. DVD(Digitally Video Disk) but now(Digital versatile Disk)Hollywood would like to put multiple movies on the same disk sofour format have been defined1. Single sided, single layer(4.7 GB).1. Single sided, single layer(4.7 GB).2. Single sided, dual layer(8.5 GB).3. Double sided, single layer(9.4 GB).4. Double sided ,double layer(17 GB).
  77. 77. A double sided, dual layer DVD disk78
  78. 78. A disk sector79
  79. 79. 80An illustration of cylinder skew
  80. 80. A hard disks consists of a stack of aluminum ,alloy orglass platters 5.25 inch or 3.5 inch in diameter. On eachPlatter is deposited a thin magnetizable metal oxide.After manufacturing there is no information whatsoeveron disk.on disk.Before the disk can be used, each platter must receive alow level format done by software .
  81. 81. Preamble:- it start with a certain bit pattern that allows the hardware torecognize the start of sector. It also contains the cylinder and sector numberand some other information.Data:-The size of the data portion is determined by the low level formattingprogram. Most disks use 512 byte sector.ECC:- This field contains redundant information that can be used toECC:- This field contains redundant information that can be used torecover from read errors. The size and content of this field varies frommanufacturer to manufacturer.Disks formatting is of two types1. Physical formatting or Low level formatting .2. Logical Formatting .
  82. 82. Physical Formatting :-Disk must be formatted before storing a data.Disk must be divided into sector that the disk controller can read/write.Low level formatting fills the disk with a special data structure for each sector.Data structure consist of three fields: Header, data area and trailer.Sector number and error correcting codes (ECC) contained in the header and trailer.Sector number and error correcting codes (ECC) contained in the header and trailer.For writing data to the sector – ECC is updated.For reading data from the sector- ECC is recalculated.If there is mismatch in stored and calculated value then data area is corrupted.Low level formatting is done at factory.
  83. 83. Logical Formatting:-After disk is partitioned , logical formatting used.Operating system stored the initial file system datastructures onto the disk.structures onto the disk.
  84. 84. No interleavingSingle interleavingDouble interleaving85
  85. 85. Time required to read or write a disk block determined by 3factorsSeek timeRotational delayActual transfer timeSeek time : Seek time is the time required to move the diskarm to the required track . It consist of two key components: initial startup time and rate at which read/write head canarm to the required track . It consist of two key components: initial startup time and rate at which read/write head canbe moved.Ts= m x n + sWhere Ts= seek time,m = constants that depends on the disk drive,n = Number of track traversed.s = startup time.86
  86. 86. Rotational delay:- Disks , other than floppy disks, typicallyrotate at 3600 rpm, which is one revolution per 16.7 msec.Rotational Latency:-it is the time spent waiting for thetarget sector to appear under the read and write heads.Transfer time:- The transfer time to or form the disk fromthe disk depends on the rotation speed of the disk in thefollowing fashion.By reducing the mean seek time,the system performancecan be improved substantially.
  87. 87. There are several scheduling algorithms.1. First-Come First served (FCFS).2. Shortest –seek –time-first (SSTF).2. Shortest –seek –time-first (SSTF).3. Scan Scheduling4. Circular Scan.
  88. 88. ◦ In this scheduling, request are serviced in the sequence they arrive.◦ FCFS is easy to program.◦ Consider the examples of disk queue with requests involving tracks toread◦ Consider an examples◦ Consider an examples◦ 98,183,37,122,14,124,65,67
  89. 89. ◦ The SSTF Scheduling select the disk i/o request that requiredthe least movement of disk head from its current position.◦ Consider an examples◦◦ 98,183,37,122,14,124,65,67
  90. 90. ◦ Scan scheduling algorithm is also called as the elevatoralgorithm. This algorithm developed for the two reasons1.To preserve advantages of bothFCFS & SSTF.2. To eliminate shortcoming of2. To eliminate shortcoming ofboth FCFS & SSTF.
  91. 91. In c-scan algorithm .Scanning and servicing is restricted to one direction only. Thuswhen the last track is serviced in one direction , the disk head isreturned to the opposite end of the disk and the scan begin again.
  92. 92. InitialpositionPendingrequestsWhich algorithm is this?93
  93. 93. Which algorithm is this? e94
  94. 94. A disk track with a bad sectorSubstituting a spare for the bad sectorShifting all the sectors to bypass the bad one95
  95. 95. As we have seen,disks sometimes make errors.Good sector can suddenly become bad sectors. Whole drives can die unexpectedly.RAIDs Protect against a few sector going bad or even a drive falling out.For some applications, it is essential that never be lost or corrupted, even in the faceof disk and CPU errors. Ideally, a disk should simply work all the time with noerrors. Unfortunately , that is not achievable .errors. Unfortunately , that is not achievable .What is achievable that has following propertyWhen a write is issued to it, the disk either correctly writes the data or it doesnothing, leaving the existing data intact .Such as system is called Stable storage.Stable devices never lost the information .
  96. 96. Analysis of the influence of crashes on stable writes971.Stable write 2. Stable reads 3.Crash Recovery
  97. 97. Hardware clocks (also called timers)• give the current time• give the elapsed time• set a timer to trigger operation X at time T• Programmable interval timer - hardware to measureelapsed time and trigger operations• This mechanism is used by the scheduler, disk I/Osubsystem, network subsystem
  98. 98. • Older/simpler clocks• Tied to the 110 or 220 volt power line and cause interrupt on everyvoltage cycle at 50-60 Hz.• Current clocks consist of three components:• a crystal oscillator• a counter• a counter• a holding register.• Feature:• Quartz crystal generates very accurate periodic signal• This signal is fed into the counter which counts downto zero.• When the counter is zero, it causes CPU interrupt.The holding register is used to load the counter
  99. 99. Modes of programmable clocks:• one-shot mode:• Software starts the clock• Copies the register value into the counter• Decrements the counter (interrupt when 0)• Stops• square-wave mode:• square-wave mode:• Clock starts• Copies the register value into the counter• Decrements the counter (interrupt when 0)• Holding register value is copied into the counter• Whole process repeats (i.e., there is no explicit start of the clock by thesoftware)The periodic interrupts are called clock ticks.Programmable clock chips usually contain two or three independently programmable clocks.
  100. 100. A programmable clock101
  101. 101. Clock hardware generates interrupts at known intervals.The clock hardware is served by the clock driver software.Functions of the clock driver:– Maintaining the time of day– Maintaining the time of day– Preventing processes from running longer than they are allowedto– Accounting for CPU usage– Handling alarm system call made by the user process– Providing watchdog timers for parts of the system itself– Doing profiling, monitoring and statistics gathering
  102. 102. Three ways to maintain the time of day103
  103. 103. Simulating multiple timers with a single clock104
  104. 104. • Software-based timer, called soft timer, is a timer which• sets to the requested frequency as needed• is checked by the kernel when entries are made for other reasonssuch as system calls, TLB misses, page faults, I/O interrupts,CPU going idle.• If the soft timer has expired, the scheduled event is performed• If the soft timer has expired, the scheduled event is performed(e.g., packet transmission) with no need to switch to kernel mode.• The kernel resets the soft timer again to go off. The kernel copiesthe current clock value to the timer and adds the timeout intervalto it.• Soft timer can avoid interrupts• the frequency of kernel entries is so high that the kernel cancheck on the soft timer and schedule the events without sendingan interrupt.
  105. 105. Network terminalsare used to connect a remote user to computer over a network eitherlocal area network or wide area networkThe X Window system:◦ The x windows system is a windowing graphical user interface.◦ The program inside the x terminals that collects input from the keyboardor mouse and accepts commands from a remote computer is called the Xserver.server.◦ One layer is Xlib , which is a set of library procedure for accessing the Xfunctionality.◦ To make programming with X easier, a toolkit consisting of the intrinsicis supplied as part of X. This layer manages buttons ,scroll bars andother GUI elements called widgets.
  106. 106. The x window server◦ Managing the i/oThe x window Client◦ runs the programs that use the x window server.After connection is establish , the client and serverAfter connection is establish , the client and serverexchange four different types of packet over channel.◦ Request◦ Reply◦ Event◦ Error
  107. 107. Clients and servers in the M.I.T. X Window System108
  108. 108. Stateless Low-level interface Machine◦ The idea is based on traditional centralized timesharingThe architecture of the SLIM terminal system
  109. 109. Messages used in the SLIM protocol from the server to the terminals110
  110. 110. ◦ The first general purpose electronics computer, the ENIAC,had 18000 vacuum tubes and consumed 140,000 watts ofpower.◦ After invention of the transistor ,power usage droppeddramatically .◦ A desktop PC often has 200 watt power supply.
  111. 111. ◦ There are two general approach to reducing energyconsumptionThe first one is for the OS to turn off parts of the computer(mostlyi/o devices). When they are not in use.The second one is for the application program to use less energy .
  112. 112. Hardware issues:Batteries come in two general typeDisposableRechargeableDisposableDisposable◦ batteries can be used to run handheld devices, but do not haveenough energy to power notebook computer with large brightscreens.Rechargeable◦ batteries can store enough energy to power a notebook for afew hours.
  113. 113. Operating system:◦ operating system plays a key role in energy management. it controlall the devices, so it must decide what to shut down and when to shutit down◦ Power management bring up a number of question that operating◦ Power management bring up a number of question that operatingsystem must deal with.◦ Which devices can be controller ?Are they on/off or they haveintermediate state?How much power is saved in the lower power states? Is energy expended torestart the devices?
  114. 114. Power consumption of various parts of a laptop computer115
  115. 115. The use of zones for backlighting thedisplay116
  116. 116. Running at full clock speedCutting voltage by twocuts clock speed by two,cuts power by four117
  117. 117. A GUI is type of computer human interface on acomputer.◦ GUI usually have common characteristic such aswindows,iocns,menus,and push buttonswindows,iocns,menus,and push buttonsGUI usually has three major components.A windowing system.An imaging model.An application program interface(API)
  118. 118. The windowing system◦ builds the windows,menus,and dialog boxes that appear on thescreen.The imaging modelThe imaging model◦ defines the fonts and graphics that appear on the screen.The API◦ is the mean in which the user specifies how and what windowsand graphics appear on the screen.
  119. 119. PURPOSE◦ Hard drives can be very small, they still contain millions of bits and thereforeneed to be organized so that information can be located. This is the purpose ofthe file system◦ The file system is based on management of clusters (the smallest disk unit thatthe operating system is able to manage).◦ An operating system only knows how to manage whole allocation units, themore sectors per cluster, the more wasted space there will be. This is why thechoice of file system is important
  120. 120. All computer applications need to store and retrieve information.E.g. banking ,corporate record keepingA second problem with keeping information within the processor‘address space’ is that when the process terminates the informationis lost.is lost.For many application (e.g. databases) ,the information must beretained for weeks, months ,or even forever.A third problem is that it is frequently necessary for multipleprocess to access (part of )the information at the same time.
  121. 121. ◦ The way to solve this problem is to make the information it selfindependent of any one process.◦ Three essential requirement for long term information storageIt must be possible to store a very large amount of informationIt must be possible to store a very large amount of informationThe information must survive the termination of the process using it.Multiple process must be able to access the information concurrently.
  122. 122. ◦ The usual solution to all these problems is to store informationon disks and other external media in units called files.
  123. 123. Some typical file extensions
  124. 124. 1.Byte sequenceThe file is an unstructured sequence of bytes. In effect, theoperating system does not know or care what is in the file.2.Record sequenceIn this model, a file is sequence of fixed length records, each withsome internal structure.some internal structure.3.TreeIn this organization ,a file consist of tree of records, not necessaryall the same length ,each containing the a key field in a fixedposition in the record. The tree is sorted on the key field, to allowrapid searching for a particular key.
  125. 125. a) Byte sequence b) Record sequence c)Tree126
  126. 126. 1. Regular files2. Directories3. Character Special files4. Block special files
  127. 127. Regular filesare either ASCII files or binary files.e.g a file contains c program, file containing letter, file containing textDirectoriesDirectories are system file for maintaining the structure of theDirectories are system file for maintaining the structure of thefile system.Character special filesThese are system files. They are related to i/o and used tomodel serial i/o devices such as terminals, printers.Block special filesused to model disks.
  128. 128. (a) An executable file (b) An archive 129
  129. 129. Sequential access◦ read all bytes/records from the beginning◦ cannot jump around, could rewind or back up◦ convenient when medium was mag tapeRandom access◦ bytes/records read in any order◦ bytes/records read in any order◦ essential for data base systems◦ read can be …move file marker (seek), then read or …read and then move file marker130
  130. 130. Every file has a name and its data. In addition , alloperating systems associate other information witheach.E.g the date time the file was created and the file’ssize. We will call these extra items the file’s attributes.
  131. 131. Possible file attributes 132
  132. 132. Files exist to store information and allow it to beretrieved later. Different system provide differentoperation to allow storage and retrieval. Below is adiscussion of the most common system calls relating tofiles.files.
  133. 133. 1. Create2. Delete3. Open4. Close7. Append8. Seek9. Get attributes4. Close5. Read6. Write9. Get attributes10.Set Attributes11.Rename
  134. 134. (a) Segmented process before mapping files into its address space(b) Process after mapping existing file abc into one segment creating new segment for xyz135
  135. 135. Directories◦ Directories is the data structure for storing details about files. Adirectories typically contains a number of records , one per file.Each records contains1 File name1 File name2 File attributes3 Addresses of the disk block where the data are stored
  136. 136. ◦ Single-Level Directory Systems◦ Two-level Directory Systems◦ Hierarchical Directory Systems◦ Path Names
  137. 137. The simplest from of directory system is having one directorycontaining all the files. Sometimes it is called the root directory .This scheme is not used multiuser system any more but could be usedon a small embedded system.Advantage :Advantage :The advantage of this scheme are its simplicity and the ability to locatefiles quickly.Disadvantage:1. Not suitable for the a large number of files and more than one user.2. Because of single directories , files require unique file name.3. it is difficult to remember the names of all the files as the number offiles increase .
  138. 138. A single level directory system◦ contains 4 files◦ owned by 3 different people, A, B, and C139
  139. 139. In two level directory ,each user has his own directory .It is called user file directory(UFD).Each UFD hassimilar structureWhen a user refer to a particular file, only his ownUFD is searched.UFD is searched.Operating system can not accidently delete another userfile that has the same name.
  140. 140. Letters indicate owners of the directories and files141
  141. 141. The two level hierarchy eliminate conflicts among userbut is not satisfactory for the user with a large numberof files.It is quite common for the user to want to group theirfiles together in logical way.files together in logical way.
  142. 142. A hierarchical directory system143
  143. 143. When the files system is organized as directory tree, some way is needed for thespecifying file names.Two different methods are commonly used .◦ Absolute path name◦ Relative path name
  144. 144. In the first method, each file is given an absolute pathname consisting of the path from the root directory tothe file.E.g The path usr/ast/mailbox means that the rootdirectory contains a subdirectory usr, which in turndirectory contains a subdirectory usr, which in turncontain a subdirectory ast which contains the filemailbox.Absolute path names always start at the root directory .
  145. 145. The second method is the Relative path name. This isused in conjunction with the concept of the workingDirectory.A user can designate one directory as the currentworking directory ,in which case all path names notworking directory ,in which case all path names notbeginning at root directory are taken relative to theworking directory.For examples , if the current working directory isusr/ast, the file whose absolute path is usr/ast/mailboxcan be referenced simply as mailbox.
  146. 146. A UNIX directory tree 147
  147. 147. 1. Create2. Delete3. Open dir5. Read dir6. Rename7. Link3. Open dir4. Close dir7. Link8. Unlink148
  148. 148. Files system are stored on disks. Most disks can be divided upto into one or more partitions, with independent file systemson each patitions.Sector 0 of the disks is called the MBR(Master Boot Record )and is used to boot the computer.The end of the MBR contains the partition table. This givesthe starting and ending address of each partition. One of thepartition in the table is marked as the Active.
  149. 149. The first one is the Superblock . It contain all the keyparameters about the files system and is read intomemory when the computer is booted or the file systemfirst touchedI nodes ,an array of data structure, one per file ,tellingI nodes ,an array of data structure, one per file ,tellingall about the file.Root directory, which contain the top of the file systemtree. Finally , the remainder of the disk typicallycontain all the other directories and files.
  150. 150. A possible file system layout151
  151. 151. ◦ An important function of the file system is to manage space onthe secondary storage, which includes keeping track of bothdisk blocks allocated to files and the free blocks available forallocation.The main problem in allocating space to files are◦◦ Effective utilization of disks space◦ Fast accessing of files
  152. 152. Management of disk block is similar to memorymanagement. But secondary storage introduces twoadditional problems.slow disk access timeLarge number of blocks to deal withLarge number of blocks to deal withThere are three widely used techniques for allocationof disks block to a file.1. Contiguous Allocation2. Linked Allocation3. Indexed Allocation
  153. 153. While discussing these allocation strategies, we willconsider that a file is a sequence of blocks. Theconversion from logical records to physical blocks isdone by the software.In contiguous allocation , files are assigned toIn contiguous allocation , files are assigned tocontiguous area of secondary storage.In this scheme , user specifies in advance the size of thearea needed to hold a file before creation .if desiredamount of contiguous space is not available , the filecannot be created.
  154. 154. Advantages : Successive records of a file are normallyadjacent to each other. This increase the accessingspeed of records.This allocation supports both sequential and directaccessing of file. It is necessary merely to retain theaccessing of file. It is necessary merely to retain thestarting address of the file and file’s size.Disadvantages:External fragmentation
  155. 155. ◦ Allocation list of blocks to a file is linked list of blocks. Theseblocks may be scattered through the disk. These blocks neednot be contiguous . Each block contain the address of the nextblock .Advantages :◦◦ Simple to implement .◦ Disk compaction is not required .◦ There is no problem of external fragmentation.◦ The file size can grow or shrink dynamically.
  156. 156. Disadvantages :Slow accessing of a records – to find out a records , wemust start at the beginning of the file and follow thepointer until we get block containing the records.There is wastage of space for storing block pointers.There is wastage of space for storing block pointers.There is problem of reliability – A single damagedpointer can make thousands of disk block inaccessible.
  157. 157. (a) Contiguous allocation of disk space for 7 files(b) State of the disk after files D and F have beenremoved159
  158. 158. Storing a file as a linked list of disk blocks160
  159. 159. Linked list allocation using a file allocation table in RAM161
  160. 160. Our last method for keeping track of whichblocks belong to which file is to associatewith each file a data structure called Inode(index node) which lists the attributesand disk address of the file’s blocks.and disk address of the file’s blocks.Advantages : The big advantages of thisscheme over linked files using an in memorytable is that the I node need only be inmemory when the corresponding file is open.
  161. 161. An example i-node163
  162. 162. Directory is data structure for the storing detailsabout files. Directory typically contains a numberof records, one per file. Each records contains filename, file attributesTo perform any operation on a file, the file mustbe opened . To open a file, the operating systemmust look into the directory entries to locate themust look into the directory entries to locate thenecessary file. Operating system requirespathname to locate the directory entry.The directory entry provides the informationneeded to find the disk blocks containing thedata. File attributes are normally stored indirectory entry itself.
  163. 163. (a) A simple directoryfixed size entriesdisk addresses and attributes in directory entry(b) Directory in which each entry just refers toan i-node165
  164. 164. So far we have assumed that files have short,fixed length names.All modern operating system support longer,variable length files names, how can these beimplemented ?1.In line: wastes a great deal of directory spaceWhen file is removed, variable sized gap isintroduced into the directory into which the nextfile to be entered may not fit.Pages fault may occur while reading a file name.2. In a heap: Hash table uses
  165. 165. Two ways of handling long file names indirectory◦ (a) In-line◦ (b) In a heap 167
  166. 166. When several users are working together on aproject, they often need to share files , it isoften convenient for a shared file to appearsimultaneously in different directoriesbelonging to different users.belonging to different users.The following system are called as DirectedAcyclic Graph or DAG
  167. 167. File system containing a shared file169
  168. 168. (a) Situation prior to linking(b) After the link is created(c)After the original owner removes the file170
  169. 169. Operating system maintain a list of free diskblocks. Free disk blocks are those blocks in adisk which are not being used by any file.Whenever a file is created , the list of freedisk blocks is searched for and then allocatedto the list of free blocks. When a file isto the list of free blocks. When a file isdeleted, its disk space is added to the list offree block. Two method to manage free diskblock are popularLinked listBit map
  170. 170. Linked list:In this method , all free disk block are linkedtogether by each free block pointing to the nextfree block.This scheme required additional memory formaintaining linked list of all free disk blocks.This space could be quite large when the disk ismaintaining linked list of all free disk blocks.This space could be quite large when the disk isalmost empty. But if the disk is nearly full (veryfew free blocks) then the linked list could be thedesired method.This scheme is not very efficient since totraverse the list, we must read each block isrepresented by a single bit.
  171. 171. Bit map:In this scheme, the list of free disk blocks isimplemented as bit map or bit vector. Each block isrepresented by a single bit0 for a free block1 for allocated blockAdvantagesAdvantagesIt is very simple methodIt is easy to find n consecutive free block on the diskCompared to linked list the bit map requires lessspace since it uses 1 bit per block.Disadvantages;If the disk is nearly full then finding a free block mayrequired many comparison
  172. 172. Dark line (left hand scale) gives data rate of a diskDotted line (right hand scale) gives disk space efficiencyAll files 2KB174Block size
  173. 173. (a) Storing the free list on a linked list(b) A bit map175
  174. 174. (a) Almost-full block of pointers to free disk blocksin RAM- three blocks of pointers on disk(b) Result of freeing a 3-block file(c) Alternative strategy for handling 3 free blocks- shaded entries are pointers to free disk blocks176
  175. 175. Quotas for keeping track of each user’s disk use177
  176. 176. A file system to be dumped◦ squares are directories, circles are files◦ shaded items, modified since last dump◦ each directory & file labeled by i-node number178File that hasnot changed
  177. 177. Bit maps used by the logical dumping algorithm179
  178. 178. File system states(a) consistent(b) missing block(c) duplicate block in free list(d) duplicate data block180
  179. 179. The block cache data structures181
  180. 180. I-nodes placed at the start of the diskDisk divided into cylinder groups◦ each with its own blocks and i-nodes182
  181. 181. With CPUs faster, memory larger◦ disk caches can also be larger◦ increasing number of read requests can come from cache◦ thus, most disk accesses will be writesLFS Strategy structures entire disk as a logLFS Strategy structures entire disk as a log◦ have all writes initially buffered in memory◦ periodically write these to the end of the disk log◦ when file opened, locate i-node, then find blocks183
  182. 182. The ISO 9660 directory entry184• Every CD ROM begins with 16 blocks whose function is not defined bythe ISO (9660Standards•Next block containing the primary volume descriptor, which containssome generalinformation about CD ROM. System Identifier 32 bytes, Volumeidentifier 32 bytes
  183. 183. In CP/M ,there is only one directory . Each file residesin this directory . So the work of the file system isvery simple, to look up a filename it search the oneand only directory.Disk block number are stored in the directory entryitself. It can store addresses of 16 blocks.itself. It can store addresses of 16 blocks.The filed EXTENT is needed because a file larger than16 blocks occupies multiple entries. This field tellswhich entry comes first, second and so on.BLOCK COUNT :This field tells how many of the 16blocks entries are in use.The user code field keeps track of the owner of thefield.
  184. 184. Memory layout of CP/M 186
  185. 185. The CP/M directory entry format187
  186. 186. The MS-DOS directory entry188
  187. 187. Maximum partition for different block sizesThe empty boxes represent forbiddencombinations 189
  188. 188. BytesThe extended MOS-DOS directory entry used in Windows 98190
  189. 189. BytesAn entry for (part of) a long file name in Windows 98191Checksum
  190. 190. An example of how a long name is stored in Windows98192
  191. 191. A UNIX V7 directory entry193
  192. 192. A UNIX i-node194
  193. 193. The steps in looking up /usr/ast/mbox195