Disk I/O * A disk or secondary storage device is used to persistently store user data. The abstractions of files and directories are commonly used. A filesystem organizes storage on the disk. A disk is divided into blocks or sectors. Some disk blocks store file data and some store file metadata. * The disk blocks that store metadata about a file/directory are called index nodes or inodes. An inode stores, among other things, the location of the disk blocks of the file. * When a file is opened, a copy of the inode is made in memory, and the file descriptor points to it. Read and write operations on a file are translated into read and write requests on disk blocks using the information about location of disk blocks of the file that is present in the inode. * The operating system also maintains a cache is recently read/written blocks, called the disk buffer cache, because disk access is typically much slower than memory access. A disk read returns immediately if the block is present in the disk buffer cache, and blocks if it has to be fetched from disk. When a disk read is initiated, the disk raises an interrupt when the block is available. * Writes to a disk block can be blocking or non-blocking, depending on whether the disk buffer cache is a write through cache or write back cache. A write through cache blocks the process until the dirty block is written to disk. A write back cache returns immediately and flushes the dirty block to the disk at a later time. * Disks are block devices, where multiple blocks can be accessed independently. On the other hand, keyboards and other I/O devices are character devices where a stream of data keeps flowing in. * Besides read and write from file descriptors, files can also be accessed via memory mapping. A memory mapped file is read into a kernel page, and this page is mapped into the virtual address space of a process. With memory mapping, files can be read and written like memory locations. Memory mapping avoids copying of file data from kernel pages to user memory and is hence beneficial for certain workloads. * There are libraries to perform asynchronous I/O on disks, though they are not very widely used.