FS System Calls
Create a new name for an existing inode
The functions sys_link
and sys_unlink
edit directories, creating or removing references to inodes.
Sys_link creates a new name for an existing inode
Flow
Begins by fetching its arguments, two strings
old
andnew
.Assuming old exists and is not a directory.
sys_link
increments old path’s inode’sip->nlink
count.Then
sys_link
callsnameiparent
to find the parent directory and final path element of new.Creates a new directory entry pointing at old ’s inode.
Create a new name for a new inode
The function create
creates a new name for a new inode.
open
is used in sys_open
, sys_mkdir
, and sys_mknod
.
Flow
Find parent inode from path.
Lock parent inode and fetch content from disk.
Call directory lookup to check if the about-to-create inode already exists.
If yes, returns.
Otherwise, continue to allocate a new on-disk inode.
Allocation of on-disk inode returns a copy of inode in cache.
Update inode metadata.
Save back to disk using txn.
If the node type is directory, add links for
.
, and..
.Otherwise, install link in the parent inode, with name, and inode index.
The famous open
system call
open
system callIf CREATE mode, call above
create
to get a new locked inode.Else, call
namei
to get an unlocked inode from the path. Lock it after.Allocate file and fd, update metadata. Includes set the inode, and other type, offset, etc.
Unlock the inode at the end.
Last updated