Fall 2017 :: CSE 306
File Systems Basics
Nima Honarmand
File Systems Basics Nima Honarmand Fall 2017 :: CSE 306 File and - - PowerPoint PPT Presentation
Fall 2017 :: CSE 306 File Systems Basics Nima Honarmand Fall 2017 :: CSE 306 File and inode File : user-level abstraction of storage (and other) devices Sequence of bytes inode : internal OS data structure representing a file
Fall 2017 :: CSE 306
Nima Honarmand
Fall 2017 :: CSE 306
devices
Fall 2017 :: CSE 306
file
blocks containing file data
Fall 2017 :: CSE 306
hierarchical structure
inode
characters we use to refer to the file
Fall 2017 :: CSE 306
normal file or a another directory.
like) organization of files in a file system.
are directories and leaves are
Fall 2017 :: CSE 306
string of characters we use to refer to a node in directory tree
→ Multiple paths might map to the same file
Fall 2017 :: CSE 306
that file
can be garbage collected
Demo: link count in output of ls -l
Fall 2017 :: CSE 306
int open(char *path, int flags, int mode);
corresponding to path
created
Fall 2017 :: CSE 306
Descriptor Table
into it
Object
through dentry)
Fall 2017 :: CSE 306
Process 1
fd File Object 1 File Descriptor Table inode 10 User Kernel
Fall 2017 :: CSE 306
Process 1
fd File Object 1 File Descriptor Table User Kernel inode 10
Fall 2017 :: CSE 306
Process 1
fd File Object 1 File Descriptor Table File Object 2 inode 10 User Kernel
Fall 2017 :: CSE 306
Process 2 Process 1
different processes
fd File Object 1 File Descriptor Table File Object 2 inode 10 File Descriptor Table User Kernel
Fall 2017 :: CSE 306
Process 2 Process 1
fd File Object 1 File Descriptor Table File Object 2 inode 10 File Descriptor Table User Kernel File Object 3 inode 20
Fall 2017 :: CSE 306
different flags
file at different offsets
problem!
Fall 2017 :: CSE 306
from root dentry (/) or current process’s working directory dentry
/lib/libc.so)
Fall 2017 :: CSE 306
permissions to see if user has been granted access
Fall 2017 :: CSE 306
entry in FDT, and put the file object pointer there
the file
Fall 2017 :: CSE 306
ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count);
cursor) for each open file
the cursor by number of bytes read/written
Fall 2017 :: CSE 306
Two solutions: 1) Change the cursor before read/write
2) Use random-access versions of read/write:
count, off_t offset);
Demo: Using strace to see syscalls made by cat
Fall 2017 :: CSE 306
int link(const char *oldpath, const char *newpath);
represented by oldpath
Fall 2017 :: CSE 306
[myself@newcastle ~/tmp]% ln -s "silly example" mydata [myself@newcastle ~/tmp]% ls -l lrwxrwxrwx 1 myself mygroup 23 Oct 24 02:42 mydata -> silly example
Fall 2017 :: CSE 306
int unlink(const char *pathname);
Otherwise, leaves it be because there are other dentries pointing to it.
Fall 2017 :: CSE 306
inodes that may be used by some process
an on-disk copy or free an in-memory copy
Fall 2017 :: CSE 306
memory objects
copy, increment ref count by 1
ref count
Fall 2017 :: CSE 306
(1 link, 1 ref)
(0 link, 1 ref)
Fall 2017 :: CSE 306
int rename(const char *oldpath, const char *newpath);
directories
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
int close(int fd);
corresponding file object’s ref count
which in turn, decrements inode’s ref count
memory copy
Fall 2017 :: CSE 306
the inode
exec()
Fall 2017 :: CSE 306
mode);
Fall 2017 :: CSE 306
linux_dirent *dirp, unsigned int count);
Fall 2017 :: CSE 306
(typically) implemented by the kernel
(library) structures
have a “f” prefixed to their names
Fall 2017 :: CSE 306
Drive (C, D, etc.)
Fall 2017 :: CSE 306
file system!
~$ mount /dev/sda1 on / type ext4 (rw) /dev/sdb1 on /backups type ext4 (rw) server:/honar on /homes/honar type nfs
Fall 2017 :: CSE 306
/ backups homes bak1 bak2 bak3 etc bin honar 306 lab1 lab2 .bashrc
Fall 2017 :: CSE 306
points to the root inode of the mounted file system
inode corresponding to the root of the file system od /dev/sdb1.
complicated but this is the gist of it.
Fall 2017 :: CSE 306
file offset
Fall 2017 :: CSE 306