1. Operating Systems
CMPSCI 377
File Systems
Emery Berger
University of Massachusetts Amherst
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
2. Files
Associate
names with
data
Usually
stored on
persistent
media
(disks)
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 2
3. File Names
Hierarchical
directory
structure
Absolute,
relative
to current
Windows
names =
location +
dir
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 3
4. Directories
Directory – just special file
Contains metadata, filenames, inodes
inode = unique number for file
May contain other directory, etc.
Beware: fixed max filename length
File systems use directory structure to
improve locality
E.g., ext2 – all files in same directory
clustered in same region of disk
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 4
5. Poor Man’s Database
Because files & directories are easy to use,
they get used as de facto databases
e.g., Internet Explorer web cache
~ 1000 files in each hash subdirectory
C:Documents and SettingsEmeryLocal SettingsTemporary Internet FilesContent.IE5>
ls -ltra
total 1873
-rwx------+ 1 Emery None 67 Jan 10 17:31 desktop.ini
drwx------+ 2 Emery None 0 Jan 17 22:42 0NDWKTYT
drwx------+ 7 Emery None 0 Feb 19 19:53 .
drwx------+ 7 Emery None 0 Apr 20 14:45 ..
drwx------+ 2 Emery None 0 May 1 21:41 8HZD6WS6
drwx------+ 2 Emery None 0 May 1 21:54 I4F15DOK
drwx------+ 2 Emery None 0 May 1 22:03 XM0N4Q4W
-rwx------+ 1 Emery None 1916928 May 3 12:21 index.dat
drwx------+ 2 Emery None 0 May 3 12:21 S0RKZRFZ
C:Documents and SettingsEmeryLocal SettingsTemporary Internet FilesContent.IE5>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 5
6. File Systems Abstraction
File system manages files
Traditionally: file system maps files to disk
But: files convenient abstraction
use same, easy interface (read, write)
Block devices (/dev/scsi0)
Disk drives – transfer in blocks
Character devices (/dev/tty)
Console, printer
Proc filesystem (/proc/mem)
FIFO (named pipes)
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 6
7. Device files
Unix devices live in /dev,
act like ordinary files
elnux14> echo quot;fooquot; > /dev/tty
foo
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 7
8. /proc filesystem
Normal file access to kernel internals
elnux14> ls -l /proc/30917/
total 0
dr-xr-xr-x 2 emery fac 0 May 3 13:18 attr
-r-------- 1 emery fac 0 May 3 13:18 auxv
-r--r--r-- 1 emery fac 0 May 3 13:01 cmdline
lrwxrwxrwx 1 emery fac 0 May 3 13:18 cwd -> /nfs/elsrv4/users5/fac/em
-r-------- 1 emery fac 0 May 3 13:18 environ
lrwxrwxrwx 1 emery fac 0 May 3 13:18 exe -> /bin/tcsh
dr-x------ 2 emery fac 0 May 3 12:06 fd
-rw-r--r-- 1 emery fac 0 May 3 13:18 loginuid
-r-------- 1 emery fac 0 May 3 13:18 maps
-rw------- 1 emery fac 0 May 3 13:18 mem
-r--r--r-- 1 emery fac 0 May 3 13:18 mounts
lrwxrwxrwx 1 emery fac 0 May 3 13:18 root -> /
-r--r--r-- 1 emery fac 0 May 3 13:01 stat
-r--r--r-- 1 emery fac 0 May 3 13:18 statm
-r--r--r-- 1 emery fac 0 May 3 13:01 status
dr-xr-xr-x 3 emery fac 0 May 3 13:18 task
-r--r--r-- 1 emery fac 0 May 3 13:10 wchan
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 8
9. Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc -l
elnux14> mkfifo thePipe
elnux14> ls -ld thePipe
prw-r----- 1 emery fac 0 May 3 14:00 thePipe
elnux14> cat simplesocket.h > thePipe &
[1] 32242
elnux14> wc -l < thePipe
155
[1] Done cat simplesocket.h
> thePipe
elnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 9
10. Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc -l
elnux14> mkfifo thePipe
elnux14> ls -ld thePipe
prw-r----- 1 emery fac 0 May 3 14:00 thePipe
elnux14> cat simplesocket.h > thePipe &
[1] 32242
elnux14> wc -l < thePipe
155
[1] Done cat simplesocket.h
> thePipe
elnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 10
11. Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc -l
elnux14> mkfifo thePipe
elnux14> ls -ld thePipe
prw-r----- 1 emery fac 0 May 3 14:00 thePipe
elnux14> cat simplesocket.h > thePipe &
[1] 32242
elnux14> wc -l < thePipe
155
[1] Done cat simplesocket.h
> thePipe
elnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 11
12. Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc –l
elnux14> mkfifo thePipe
elnux14> ls -ld thePipe
prw-r----- 1 emery fac 0 May 3 14:00 thePipe
elnux14> cat simplesocket.h > thePipe &
[1] 32242
elnux14> wc -l < thePipe
155
[1] Done cat simplesocket.h
> thePipe
elnux14>
Useful when cannot do redirection
Especially for compression
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 12
13. Named Pipes (FIFO)
Exercise:
Program named “joe” outputs file “joe.out”
Huge (~ 3 GB)
Compress it automagically using gzip -c &
named FIFO to “joe.out.gz”
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 13
14. Named Pipes (FIFO)
Exercise:
Program named “joe” outputs file “joe.out”
Huge (~ 3 GB)
Compress it automagically using gzip -c &
named FIFO to “joe.out.gz”
elnux14> mkfifo joe.out
elnux14> gzip –c < joe.out > joe.out.gz &
[1]
elnux14> joe
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 14
15. File Metadata
Files have a lot of associated “metadata”;
ex.: Unix (from stat)
Date created, last modified, last accessed
Size (bytes)
User & group ID of file’s owner
File type (not content type)
Directory
Regular file
Block / character device (disk drive, screen)
FIFO
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 15
16. Untyped Files
Unix, Windows – file contents untyped
Stream of bytes
Type implied by convention (extensions)
.ppt, .pdf, …
Mac: file types stored in metadata
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 16
17. File Types
Unix, Windows – file contents untyped
Stream of bytes
Type implied by convention (extensions)
.ppt, .pdf, …
Mac: file types stored in metadata
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 17
18. Access Control
Unix: each file has associated bits that
control access (& other stuff)
Read
Write
Execute
Can specify for three “users”
User (file owner)
Group (set of users)
Other (everyone else)
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 18
19. Access Control - chmod
Can read bits via ls, set bits via chmod
elnux14> ls -l ack.scm
-rw-r----- 1 emery fac 197 Feb 25 15:19 ack.scm
elnux14> chmod -r ack.scm
elnux14> ls -l ack.scm
--w------- 1 emery fac 197 Feb 25 15:19 ack.scm
elnux14> cat ack.scm
cat: ack.scm: Permission denied
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 19
20. The End
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 20