vault backup: 2022-09-22 12:37:27

This commit is contained in:
Jet Hughes 2022-09-22 12:37:27 +12:00
parent 58d82b6d6a
commit f0c3f895eb
2 changed files with 61 additions and 4 deletions

View File

@ -4,6 +4,9 @@ aliases:
tags: tags:
- lecture - lecture
- cosc204 - cosc204
sr-due: 2022-09-25
sr-interval: 3
sr-ease: 250
--- ---
# Device controller and driver # Device controller and driver
@ -36,12 +39,65 @@ the sequence of read/write requests can (should) be optimized
also support buffering (accepting keyboard input line by line) and editing of buffers (e.g., spcial treatement of backspace character) also support buffering (accepting keyboard input line by line) and editing of buffers (e.g., spcial treatement of backspace character)
# IO models # IO models
IO system calls use different IO models IO system calls use different IO models
- blocking - when a proccess needs IO input it waits to recieve it before c - blocking - when a proccess needs IO input it waits to recieve it before continuing
- non blocking - non blocking - waits a fixed (small) amount of time, and returns (possibly with some data still untransferred)
- async - async - does not wait, is informed with a signal when io is completed
# IO scheduling and buffering # IO scheduling and buffering
for when there are several requests for IO waiting to be serviced
- first come firs served is not efficient
IO buffers are used in main memroy to optimise file systems
when a data block is used often, it is kept is memory and only written to secondary storage once all its accesses are finished
# example ramdisk driver
![](https://i.imgur.com/NIqCAzy.png)
## open
``` c
int temp_open (struct inode *inode, struct file *filp){
// check if the process has the permission to access;
// suspend the calling process if the device is busy
// or used by another process;
// otherwise record the id of the calling process
// so that the device is owned by the process;
// initialise or reset the device.
}
```
## read
```c
ssize_t temp_read(struct file *filp, char __user *buf,size_t count,loff_t *f_pos){
// find the location of data;
// ask the controller to copy data to kernel kbuf
// copy data to user space kbuf -> buf
copy_to_user (buf, kbuf, count);
*f_pos += count; // update pointer
return count; // return the number of bytes read
}
```
## write
```c
ssize_t temp_write(struct file *filp, char __user *bufsize_t count, loff_t *f_pos){
// copy data from user space buf -> kbuf
copy_from_user (kbuf, buf, count);
// find the location of data;
// ask the controller to copy data from kernel kbuf
*f_pos += count; // update pointer
return count; // return the number of bytes written
}
```
## close
```c
int temp_release (struct inode *inode, struct file *filp){
// release the device by removing the id of the process;
// check if there is any waiting process to wake up;
// undo anything done at open(), e.g. free memory.
}
```
# UI for IO devices # UI for IO devices

View File

@ -45,6 +45,7 @@ tags:
- [14-processes-and-system-calls](notes/14-processes-and-system-calls.md) - [14-processes-and-system-calls](notes/14-processes-and-system-calls.md)
- [15-file-systems](notes/15-file-systems.md) - [15-file-systems](notes/15-file-systems.md)
- [16-device-drivers](notes/16-device-drivers.md) - [16-device-drivers](notes/16-device-drivers.md)
# Archive # Archive
# Info # Info