10 File Systems1
10 File Systems1
Kangjie Lu
February 20, 2024
Computer Science & Engineering, University of Minnesota
1
Review: Files
2
File systems overview
File Systems
3
File Systems
4
Unix File System Structure
5
Files
7
Unix File-Directory Organization
8
Directory Internals
9
Directory Structure
10
Directory Operations
• Different operations from the ones used for regular files. Why?
• Cannot use:
• open, read, write, close
• Instead use:
• opendir, readdir, closedir
11
Opening a Directory
12
DIR
13
Reading Directory Entries
14
Closing and Repositioning a Directory
15
Modifying Directory Entries
16
File System Traversal
17
Path Name Translation
18
File and Directory Permissions
File mode bits
19
File mode bits
19
File mode bits
19
Interpretation of mode bits
20
Directory mode bits
21
File Sharing
22
File system layout and Inodes
File systems
• File system design: how to allocate and keep track of files and directories
• Does it matter? What is the difference?
• Performance, reliability, limitations on files, overhead, . . .
• Many different file systems have been proposed and continue to be proposed
23
Disk Layout Strategies
25
File System Layout
26
Unix Inodes
struct inode {
umode_t i_mode;
unsigned short i_opflags;
kuid_t i_uid;
kgid_t i_gid;
unsigned int i_flags;
struct posix_acl *i_acl;
const struct inode_operations *i_op;
struct super_block *i_sb;
struct timespec64 i_atime;
...
27
Unix Inodes
• The inode pointer structure lists the addresses of a file’s data blocks
• Each inode contains 15 block pointers
• First 12 are direct blocks, then single, double, and triple indirect. Why?
28
Unix Inodes and Path Search
• Unix Inodes are “not” directories
• Inodes describe where on disk the blocks for a file are placed
• Directories are files, so inodes also describe where the blocks for directories
are placed on the disk
• Directory entries map file names to inodes
• To open “/file”, use Master Block to find inode for “/” on disk
• Open “/”, look for entry for “file”
• This entry gives the disk block number for the inode for “file”
• Read the inode for “file” into memory
• The inode says where first data block is on disk
• Read that block into memory to access the data in the file
• This is why
• we have open in addition to read and write
• we should check potential errors due to the complexity 29
Quiz 1
30
Quiz 1
30
Quiz 2
31
Quiz 2
31
Quiz 3
32
Quiz 3
32
Summary
• File systems
• Purposes
• Structure
• Directories
• Structure
• Traversal
• Permissions
• Mode bits
• Inodes
• Inode pointer structure
33
Next lecture
34
References
[1] http://www-users.cselabs.umn.edu/classes/Fall-
2018/csci4061/notes/w5_1_post.pdf
[2] http://www-users.cselabs.umn.edu/classes/Spring-
2018/csci4061/notes/file_sys.pdf
[3] https://www.cs.ucr.edu/~csong/cs153/l/fs1.pdf
[4] https://www.cs.ucr.edu/~csong/cs153/l/fs2.pdf
35