Design Inode Layer
// On-disk inode structure
struct dinode {
short type; // File type
short major; // Major device number (T_DEVICE only)
short minor; // Minor device number (T_DEVICE only)
short nlink; // Number of links to inode in file system
uint size; // Size of file (bytes)
uint addrs[NDIRECT+1]; // Data block addresses
};// in-memory copy of an inode
struct inode {
uint dev; // Device number
uint inum; // Inode number
int ref; // Reference count
struct sleeplock lock; // protects everything below here
int valid; // inode has been read from disk?
short type; // copy of disk inode
short major;
short minor;
short nlink;
uint size;
uint addrs[NDIRECT+1];
};On-disk inode
inodeIn-memory inode
inodeLocking in inode (4 kinds)
inode (4 kinds)Big lock on in-memory inodes array
Lock on each in-memory inode
Inode reference count
Number of links
Separate reference count and locking
Why we have in-memory cache of inode?
Implement Inodes
Allocate a new inode
Get inode from cache
Release a reference count on in-memory inode
Locking when freeing inode
Every FS system calls can write to disk
Handle orphan inodes
How to clean those un-linked inode?
Last updated