File Systems
2026-09-29
How might you make this faster when xs is large?
unsafe extern "C" {
fn memmove(dst: *mut c_void, src: *const c_void,
len: size_t) -> *mut c_void;
}
fn my_memmove(dst: &mut [u8], src: &[u8]) -> *const u8 {
if src.len() > dst.len() { panic!(); }
unsafe {
memmove(dst.as_mut_ptr() as *mut c_void,
src.as_ptr() as *const c_void, src.len()) as *const u8
}
}This code compiles; should I still worry? (5 min, then poll)
This code compiles; should I still worry? (5 min, then poll)
Respond at: https://PollEv.com/davidbindel252
or send davidbindel252 to 22333
This module: Unix abstractions
(Yes, some overlap with 3410/4410.)
(base) dbindel@dhcp-vl2041-13487 lec % ls /
Applications etc private Users
bin home sbin usr
cores Library System var
dev opt tmp Volumes
ls know what to show?dev mean?I’ll take operating systems for 100!
A: Unix
Q: What if everything was a file?
Two key pieces of OS functionality:
Plus programmatic interfaces to this functionality
Abstraction from HW interfaces (e.g. SCSI)
(Partial picture; orange boxes represent their own structures)
Components include:
AKA inodes, they contain metadata:
Ordinary files are files!
Data blocks list (name, inode) pairs
., current dir inode id).., parent dir inode id).. maps to current dir inodeDoes not directly include directory path.
Everything is a file! With different inode types
Unifies naming and interfaces, but no data blocks.
chmod 700 foo means owner (but not group or world) can read (4), write(2), execute (1)Link a file for access via a different path
ln foo bar)
ln -s foo bar)
Use rm to unlink a file
Which of the following do you think is true? (5 min, then poll)
Respond at: https://PollEv.com/davidbindel252
or send davidbindel252 to 22333
Often virtualize file systems (VFS)
Involve in-memory (vs persistent) structure.
A.txtB.txtWhat does the kernel make of this?
Kernel maintains three-level structure
Let’s consider each
Table of file descriptor pointers
and others via system open
Contains file descriptor structs with
This is a system-wide data structure
Contains vnodes (virtual nodes)
This is again a system-wide data structure
Matters for sharing! Consider
stdout to foo.txtecho is a built-in, advances output positioncat is a new subprocess!
stderr and stdout the samestdout with parentBufReader and BufWriterflush buffered writers!
drop are ignoredCan set standard input, output, error
Unix filesystem gives
Plus three-layer structure to manage shared access
On Ed: What was the muddiest point today?