The seventh week of CST 334 discussed persistent storage, I/O, and file systems.
The OS virtualizes devices similar to how it virtualizes the CPU and RAM. However, unlike CPU and RAM virtualization, device virtualization rarely uses specific hardware capabilities. Instead, every device that the OS wishes to control must provide a device driver, which gives the OS a high-level, abstract means of controlling said device. The advantage to this solution is that the OS can interface with devices without ever needing to know their internal implementation. For example, an OS can access an HDD and an SDD in the exact same way, without being concerned whether the data is stored and accessed via spinning magnetic platters, or solid-state memory chips.
File systems are another important abstraction that the OS provides. While implementations vary, an average filesystem might function as follows:
- C programs access a file using the open() function. This function returns a “file descriptor”, which is an index into the process’s file descriptor table (FDT). The FDT is an array of indexes into an OS-wide “open file table” (OFT) structure. Note that unless file descriptors are sharing an OFT entry via something like fork() or dup(), each file descriptor points to a unique OFT entry.
- An OFT entry keeps track of how many file descriptors are referencing the entry, the current read/write offset into the file, and the file’s “inode” index.
- The inode array is a special part of the file system that keeps track of file metadata. Depending on the file system the inode struct will contain different fields, though common ones include: data location, file size, protection information, last read / write times, reference count, and so on.
No comments:
Post a Comment