next up previous
Next: Device Allocation Up: No Title Previous: Implementation of Interface Procedures

Synchronous vs. Asynchronous I/O

Synchronous I/O

Asynchronous I/O

write(fd, buffer, length)
 {continue processing}
status = waitio(fd)
 {blocked waiting for I/O to complete}
 {continue processing}

How is waitio implemented ? Using semaphores :

PROCEDURE waitio(fd)
 P(complete(fd))
 return status
END

File Manager Process

PROCESS  fileman
  initialise data structures
 REPEAT
  receiveany(source, msg)
  case msg.mode

  open : get device descriptor
    	 check access permissions and mode
	 if device free - allocate file descriptor
	 {what if device already open ?}
	 insert info. into descriptor
 	 send(source,fd)

   close : ...

   read : use fd to find the file descriptor
	  save source in descriptor
	  check if request is valid
	  set up devicemsg 
	  send(device, devicemsg)

   write : ...

   I/O complete: If error - notify
		 find descriptor for device
		 send(user_process, status)
 FOREVER
END

  figure105
Figure 5: File manager data structures

open(device_name, mode)
 find device in device descriptor table
 IF (allocated) or (out of service) or
    (mode incompatible with operations supported)
    or (no access permissions)
 THEN 
    send(source, error)
 ELSE
    find free file descriptor
    set mode and device descriptor pointer
    set device status busy
    send(source, fd)

close(fd)
  IF (allocated to process)
  THEN
     set device status free
     deallocate file descriptor
     send(source,ok)

The Device Descriptor (held by the filemanager) contains :

Device Name
Access Control Information
Permitted Operations
Current Status : allocated, free, out of service etc
Current User : process id if allocated
Device Handler process id
Error Handling procedures - who to send what messages



Omer F Rana
Fri Feb 14 18:33:29 GMT 1997