Please enable JavaScript.
Coggle requires JavaScript to display documents.
File Systems (Files and Directories (File (File Interface (Creating a file…
File Systems
Files and Directories
File
-
-
File Interface
Creating a file
Files are created using the open() system call and passing the O_CREAT flag
int fd = open("foo", O_CREAT, S_IRUSR | S_IWUSR)
param1 -> filename
param2 -> creates the file
param3 -> permissions
returns -> file descriptor - an int used to read or write the file
Reading a file
Files are read using the read() system call
int bytes = read(3, vaddr, 4096)
param1 -> the file descriptor
param2 -> the buffer where the result is stored
param3 -> the size of the buffer
return -> returns the number of bytes it read
Writing a file
Files are written using the write() system call
int size = write(1, vaddr, 4096)
param1 -> location to write to
param2 -> location of the buffer to write from
param3 -> the amount to write
return -> the number of bytes written
-
Directory
List of (user-readable names, low-level name) pairs (files)
Can also contain other directories
Hard Links
Definition
A link between a name and an inode. If I add a hardlink between a file then both the link and the original filename refer to the same file. Changes made to one are seen by both
Unlinking
Unlinking removes one pair of (pathname, inode). If the unlink removes the last pair of pathname associated with an inode then it also deletes the file.
-
-
File Inconsistency, FSCK and Journaling
Since file systems deal with persistent data a problem arises where suppose while writing to the disk a power outage occurs. How do we implement safeguards for these kind of scenario's?
-
Journaling
Creates a log of every I/O operation so in the case of a outage we can refer to the journal and attempt to run the same operations again
Disadvantages
Before every write we have to write to the log first. This will increase the time of every write INS
-