🐧 Unix Filesystem (341 recap)

Filesystems provide an abstraction from dealing with disk and memory blocks ➡️ ➡️ ➡️

Header contains metadata like:

// read man pages for filesystem API spec

fd1 = open(filepath, mode) // access file in mode r, w, x 
fd2 = creat(filename, mode)
close(fd2) 

error = read(fd1, buffer, num_bytes) 
error = write(fd1, buffer, num_bytes) 
pos = lseek(fd1, offest, whence) // whence -> absolute or relative offset from current fd pointer 
status = link(old_link, new_link) // this is a hard link
status = unlink(old_link) // decrements ref count
status = stat(filename, buffer) // get file header

image.png

💡 Hard Link vs. Soft link

| • A hard link is like creating another "name" for the same file. • Both the original file and the hard link point to the same data on the disk. • If you delete the original file, the hard link still works because the actual data isn't deleted until all hard links to it are removed. • Hard links can only exist on the same file system as the original file. | • A soft link is like a shortcut or pointer to the original file. • It is a separate file that points to the path of the original file. • If you delete the original file, the soft link breaks because it has no data of its own. • Soft links can cross file systems and point to directories. | | --- | --- |


🔠 Distributed File System Terminology

DFS should be transparent (conceal server details from client), handle concurrent clients, and replicate for fault-tolerance

One-copy Update When a file is replicated, its contents when fetched by a client are no different than when fetched if only one replica existed
At-most Once Operations that should not be repeated - like link() and create()
At-least Once Operations that need to be executed at least once (usually idempotent) - like stat() read() with abs offset lseek() with abs offset
Idempotent Operations that have no side effects if run multiple times
Authentication “Is the user who they claim they are?”
Authorization “After authentication, is this user allowed to access the file they’re requesting?”
Access Control Lists (ACLs) is a per-file list of allowed users
Capability Lists is a per-user list of files they can access and the type of access (r w x )

DFS Implemenations

🍦 Vanilla DFS [not a real DFS]

Flat File Service API

Directory Service API

Interact with Client using Unix API

image.png


📶 NFS (Network File System)

NFS client is integrated into kernel and makes RPCs to server

image.png

NFS server plays the role of dir + flat file service

Virtual File System Module


👱🏽‍♂️ AFS (Andrew File System)