Modul 6 - Filsystem Flashcards
Benefits of interrupts over polling? (I/0)
- Interrupts allow for overlap of computation and I/O, which improves utilization.
- Instead of polling the device repeatedly the os can issue a request, put the process to sleep and do a context switch.
- When the device is finished with the I/O a interrupt is raised by the hardware and handled by the interrupt handler. Then wakes the process that issued the I/O.
When can interrupts be bad?
- If the I/O is performed quickly, interrupts can slow the process because of context switch and interrupt handling.
- In networks, when a huge stream of incoming packets each generate an interrupt, it is possible for the OS to livelock, that is, find itself only processing interrupts and never allowing a user-level process to run and actually service the requests.
- Solution: Wait a little bit before delivering an interrupt to the CPU.
How to interact with a device?
- A register to read the status of the device.
- A register to instruct the device to read or
write. - A register that holds the data.
- I/O-bus could be separate from memory bus (or the same).
- The driver will use either special I/O instructions or regular load/store instructions.
Access time for a HDD? (Seek, rotation, read)
- seek time: time to move arm to the right cylinder
- rotation time: time to rotate the disk
- read time: read one or more sectors
What is a file system?
A file system is the user space implementation of persistent storage.
- A file is persistent i.e. it survives the termination of a process
- A file can be access by several processes i.e. a shared resource
- A file can be located given a path name
What is a file?
- A sequence of bytes
Attributes, associated meta-data:
- Size and type
- Owner and permissions
- Author
- Created, last written
- Icons, fonts, presentation….
What role does the directory have in a file system?
- It maps from name to identifier.
- Contains a list of (user-readable name, low-level name) pairs.
- Each entry in a directory is either a file or other directories.
- Directories also has an inode number (low-level name)
What role does the file module have in a file system?
Locates file
What role does access control have in a file system?
Interacts with authentication system
What role does file operations have in a file system?
Read and write operations
What role does block operations have in a file system?
Which blocks on which devices
What role does device operations have in a file system?
Operations on physical drive
What is an inode number?
It’s a low level name for a file, the user is not aware of the name.
How is a file created and what happens?
- By passing the O_CREAT flag to the system call open().
- When a file is created an inode structure is created that will track all relevant information about the file (size, blocks on disk etc.)
- Then link a human-readable name to that file and putting that link into a directory.
Ex:
int fd = open(“foo”, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
The routine open() takes a number of different flags. In this example, the second parameter creates the file (O CREAT) if it does not exist, ensures that the file can only be written to (O WRONLY), and, if the file already exists, truncates it to a size of zero bytes thus removing any existing content (O TRUNC). The third parameter specifies permissions, in this case making the file readable and writable by the owner.
What is a file descriptor?
- A file descriptor is just an integer, private per process, and is used in UNIX systems to access files.
- Once a file is opened, the file descriptor is used to read or write the file.
- The system call open() returns a file descriptor.
What does lseek() system call do?
- Used to read or write to a specific offset within a file. (specific location)
off_t lseek(int fildes, off_t offset, int whence); First argument is the file descriptor, second is the offset and the third determines how the seek is performed.
What is a open file table?
- Open file table contains entries of the file descriptors that each process has (processes maintains these in an array).
. Table is global, one entry per open operation
- Also contains the current offset and information such as whether the file is readable or writable.
When does processes share file tables entries?
- When a parent process creates a child process with fork().
What happens if different processes reads the same file at the same time?
If the open file table isn’t shared, then each logical reading or writing of a file is independent.
What happens when a file table is shared?
- When a file table entry is shared, its reference count is incremented; only when both processes close the file (or exit) will the entry be removed.
- Sharing open file table entries across parent and child is occasionally useful. For example, if you create a number of processes that are cooperatively working on a task, they can write to the same output file without any extra coordination.
What does dup() system call do?
- The dup() call allows a process to create a new file descriptor that refers to the same underlying open file as an existing descriptor.
- The dup() call (and, in particular, dup2()) are useful when writing a UNIX shell and performing operations like output redirection;
What does fsync() system call do?
- When a process calls fsync() for a particular file descriptor, the file system responds by forcing all dirty
(i. e., not yet written) data to disk, for the file referred to by the specified file descriptor. The fsync() routine returns once all of these writes are complete.
What is a hard link?
- A hard link is a way to create a link between a new file name to an old one. Basically you create another way to refer to the same file.
What does the system call link() do?
- Creates a hard link between two file names.
- link() takes two arguments, an old pathname and a new one.
- Command-line program ln is used to do this.
- The way link works is that it simply creates another name in the directory you are creating the link to, and refers it to the same inode number (i.e., low-level name) of the original file. The file is not copied in any way