L10 - File Management Introduction
L10 - File Management Introduction
Lecture 10
1
Overview
File System
Definition
Vs Memory Management
Motivation
File
Metadata
Operations
Directory
Directory Structure
I/O Scheduling
[ CS2106 L10 - AY2021 S1 ]
2
File System: Motivation
Physical memory is volatile
Use external storage to store persistent information
File Metadata
File Data
File structure
Access Methods
File Operations
Contains:
Data: Information structured in some ways
Protection: Access permissions, can be classified as reading, writing and execution rights
Table of content: Information for the FS to determine how to access the file
Binary files:
Example: executable, Java class file, pdf file, mp3/4, png/jpeg/bmp
etc
Type of access:
Read: Retrieve information from file
Write: Write/Rewrite the file
Execute: Load file into memory and execute it
Append: Add new information to the end of file
Delete: Remove the file from FS
List: Read metadata of a file
rwxr--r-- somefile.eg
Owner Universe
Group
[ CS2106 L10 - AY2021 S1 ]
18
File Protection: Access Control List
In Unix, Access Control List (ACL) can be:
Minimal ACL (the same as the permission bits)
Extended ACL (added named users / group )
"getfacl" is the command
$ getfacl exampleDir to get ACL information
# file: exampleDir
# owner: ccris Permission for
# group: compsc Specific User
user::rwx
user:sooyj:rwx
group::r-x Permission for
group:cohort20:rwx Specific Group
mask::rwx
other::---
Permission
"upperbound"
[ CS2106 L10 - AY2021 S1 ]
19
Operations on File Metadata
Rename:
Change filename
Change attributes:
File access permissions
Dates
Ownership
etc
Read attribute:
Get file creation time
Random Access:
Data can be read in any order
Can be provided in two ways:
1. Read( Offset ): Every read operation explicitly state the position to be
accessed
2. Seek( Offset ): A special operation is provided to move to a new location
in file
E.g. Unix and Windows uses (2)
Read:
Read data from file, usually starting from current position
Write:
Write data to file, usually starting from current position
fd
… …
File Descriptor
Table
System-wide "Actual File“
Per-process
Open File Table (i-node table)
[ CS2106 L10 - AY2021 S1 ] FD Table
27
Tables in the Kernel Space: Unix Illustration
DIRECTORY
directory
dir2
file 1 file 2
dir3
file 3
file 3
dir2
dir3
alias
dir2
cycle
dir3
In Unix:
Symbolic link is allowed to link to directory
General Graph can be created
I/O SCHEDULING
Seek
(Change Track)
Track
Disk
Head
Sector
Very intuitive: Imagine the tracks are floors in a building, and the disk head is
the elevator servicing the floors (Figure out the algorithm before lecture )
[ CS2106 L10 - AY2021 S1 ]
45
SCAN: Disk Head Movement
disk I/O requests indicated by only the track number :
[13, 14, 2, 10, 17, 31, 21, 7]
35
30
25
20
Track
15
10
0
0 2 4 6 8 10 12 14 16
Simulated Time
[ CS2106 L10 - AY2021 S1 ]
46
I/O Scheduling: Newer Algorithms
Deadline - 3 queues for I/O requests:
Sorted
Read FIFO - read requests stored chronologically
Write FIFO - write requests stored chronologically
noop (No-operation) - no sorting
cfq (Completely Fair Queueing) - time slice and per-
process sorted queues
bfq (Budget Fair Queuing) (Multiqueue) - fair sharing
based on the number of sectors requested
By convention:
Default file descriptors:
STDIN (0), STDOUT (1), STDERR (2)
Parameters:
fd: file descriptor (must be opened for read)
buf: An array large enough to store n bytes
read() is sequential read:
starts at current offset and increments offset by bytes read
[ CS2106 L10 - AY2021 S1 ]
53
Write Operation: write()
Function Call:
int write(int fd, void *buf, int n)
Purpose:
writes up to n bytes from current offset from buffer buf
Return:
-1: Error
Parameters:
fd: file descriptor (must be opened for write)
Possible errors:
exceeds file size limit, quota, disk space, etc.
Return:
-1: Error
Parameters:
fd: file descriptor (must be opened)