Filesystems
CS-446/646
C. Papachristos
Robotic Workers (RoboWork) Lab
University of Nevada, Reno
Filesystems
Filesystem
“ Block”
Main Filesystem tasks:
CS446/646 C. Papachristos
Filesystems
File
Associated Blocks on Disk, with a name
How a File’s data is managed by the Filesystem (more later)
CS446/646 C. Papachristos
Filesystems
Filetypes
A File can also have a Type
A File’s Type can be encoded in its Filename or Contents
CS446/646 C. Papachristos
Filesystems
Basic File Operations
Unix
creat(name)
rename(oldname, newname)
open(name, how)
read(fd, buf, len)
write(fd, buf, len)
truncate(fd, len)
sync(fd)
lseek(fd, pos)
close(fd)
unlink(name)
CS446/646 C. Papachristos
Windows
CreateFile(name, CREATE)
CreateFile(name, OPEN)
ReadFile(handle, …)
WriteFile(handle, …)
FlushFileBuffers(handle, …)
SetFilePointer(handle, …)
CloseHandle(handle, …)
DeleteFile(name)
CopyFile(name)
MoveFile(name)
Filesystems
CS446/646 C. Papachristos
For our Lectures
Filesystems
Directories
Should users remember where on Disk their Files are located (i.e. Disk Sector Number) ?
�Directories serve two purposes
CS446/646 C. Papachristos
Filesystems
Hierarchical Directories
CS446/646 C. Papachristos
/ (FileSystem Root Directory)
afs
bin
cdrom
dev
sbin
tmp
awk
chmod
chown
Filesystems
Directory Internals
A Directory is a list of Directory Entries
Directory Entry:
CS446/646 C. Papachristos
/
afs
bin
cdrom
dev
sbin
tmp
awk
chmod
chown
<afs,1021>
<tmp,1020>
<bin,1022>
<cdrom,4123>
<dev,1001>
<sbin,1011>
…
File contents for /
Filesystems
Pathname Translation (simple & high-level overview)
CS446/646 C. Papachristos
Filesystems
Unix Example
CS446/646 C. Papachristos
Filesystems
Unix inodes and Path Search (more detailed overview)
For a not-so-elaborate Filesystem structure, to open File "/one":
CS446/646 C. Papachristos
Filesystems
Naming
CS446/646 C. Papachristos
Note:
Filesystems
Basic Directory Operations
Unix
Directories implemented in Files
opendir(name)
readdir(DIR*)
seekdir(DIR*)
closedir(DIR*)
CS446/646 C. Papachristos
Windows
Explicit Directory operations
CreateDirectory(name)
RemoveDirectory(name)
Very different method for reading Directory Entries
FindFirstFile(pattern)
FindNextFile()
Filesystems
Default Context: Working Directory
CS446/646 C. Papachristos
Filesystems
Hardlinks
More than one Directory Entries can refer to a given File
CS446/646 C. Papachristos
foo
inode #31279
links_count=1
ln foo bar
Existing File
Hardlink to create
foo
bar
inode #31279
links_count=2
Filesystems
Softlinks / Symlinks
Softlinks / Sym(bolic)links : Synonyms for Filenames
CS446/646 C. Papachristos
foo
bar
ln –s bar barz
barz
Existing File
Symlink to create
inode #31279
links_count=2
File Data
"bar"
inode #35382
links_count=1
Filesystems
File Sharing
CS446/646 C. Papachristos
Filesystems
Protection
CS446/646 C. Papachristos
Filesystems
Protection – Conceptual Representation
1) Access Control Lists (ACL)
CS446/646 C. Papachristos
2) Capabilities
| /one | /two | /three |
root | rw | rw | rw |
alice | rw | - | r |
bob | w | r | rw |
Objects
Subjects
ACL
Capability
Filesystems
ACLs and Capabilities
CS446/646 C. Papachristos
Filesystems
Unix File Protection
Unix uses both Protection approaches in its Filesystem
CS446/646 C. Papachristos
int fd = open("file.txt", O_WRONLY);
if (fd == -1)
exit(-1);
for (int i = 0; i < 100; i++)
write(fd, buf + i * 4, 4);
ACL check, expensive
Capability
Use Capability from now on
Filesystems
Filesystem Implementation
Note: A File Descriptor in the Process’ filp Table is a Capability that allows the Process to access the File in a specific way, even after a change in the ACL of the File
CS446/646 C. Papachristos
Filesystems
Filesystems vs Virtual Memory
CS446/646 C. Papachristos
Filesystems
CS446/646 C. Papachristos
Filesystems
Filesystems vs Virtual Memory
CS446/646 C. Papachristos
Filesystems
Filesystems vs Virtual Memory
CS446/646 C. Papachristos
Filesystems
Filesystems vs Virtual Memory
CS446/646 C. Papachristos
Filesystems
Filesystems vs Virtual Memory
CS446/646 C. Papachristos
Filesystems
Problem: How to Track a File’s Data
The “Index Node” –or– “inode”
CS446/646 C. Papachristos
Filesystems
Idea 1: Contiguous Allocation
Example: IBM OS/360
Advantages
Disadvantages (think of corresponding Virtual Memory Segmentation scheme)
CS446/646 C. Papachristos
Fragmentation:�What if File c needs 2 Sectors
Filesystems
Idea 2: Linked Files
Advantages
Disadvantages
CS446/646 C. Papachristos
A single File’s Clusters are “Fragmented” throughout the Disk
Filesystems
Idea 2 (fixed): File Allocation Table (FAT) – Example : DOS Filesystem
Linked Files with key optimization:
CS446/646 C. Papachristos
Filesystems
CS446/646 C. Papachristos
Filesystems
Idea 3: Indexed Files
Advantages
Disadvantages
CS446/646 C. Papachristos
Filesystems
CS446/646 C. Papachristos
File Index Array
Disk Blocks
(Determined by desired Max File Size)
Filesystems
Idea 3 (fixed): Multi-Level Indexed Files – Example : Unix inodes
Unix inode:
�
CS446/646 C. Papachristos
inode
Metadata
Note: �Indirect Blocks: Contain BLKSIZE/PTRSIZE amount of Block Entries
Filesystems
More about inodes
Note: Information about Type (File/Directory/Symlink/Character Device/etc.) could be stored in corresponding � Directory Entry that points to this inode, e.g.: <inode, file_type, name_len, name>
� �
�
CS446/646 C. Papachristos
struct inode
Data Block
Data Block
Data Block
Indirect
Data Block
type_perm (Type & Permissions)
uid (Owner)
gid (Group)
size (of File in Bytes)
blocks (# Blocks of this File – whether
atime (Access Time)
mtime (Modification Time)
ctime (Creation Time)
dtime (Deletion Time)
links_count (Hardlinks – # of Paths)
block[15] (12+1+1+1 Data Blocks)
used or not)
Filesystems
More about inodes
The “inode Table” : Array that stores inodes (one inode for every File)
CS446/646 C. Papachristos
Filesystems
More about inodes
Locality Problem: inode Table located at start of Disk
CS446/646 C. Papachristos
Filesystems
Remember: Unix inodes and Path Search
CS446/646 C. Papachristos
Note: 4 Disk Accesses required
Filesystems
Unix Example: /a/b/c.c
CS446/646 C. Papachristos
Filesystems
Write Caching
CS446/646 C. Papachristos
Filesystems
Read Caching
CS446/646 C. Papachristos
Filesystems
Read Caching at Higher-Level: File Buffering
CS446/646 C. Papachristos
Time for Questions !
CS-446/646
CS446/646 C. Papachristos