Upload
emery-berger
View
2.483
Download
5
Embed Size (px)
DESCRIPTION
From the Operating Systems course (CMPSCI 377) at UMass Amherst, Fall 2007.
Citation preview
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Operating SystemsCMPSCI 377File Systems
Emery Berger
University of Massachusetts Amherst
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Files
Associate names with data
Usuallystored on persistent media (disks)
2
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
File Names
Hierarchicaldirectory structure
Absolute, relativeto current
Windows names = location + dir
3
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
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
4
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
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
5
C:\Documents and Settings\Emery\Local Settings\Temporary Internet Files\Content.IE5>ls -ltratotal 1873-rwx------+ 1 Emery None 67 Jan 10 17:31 desktop.inidrwx------+ 2 Emery None 0 Jan 17 22:42 0NDWKTYTdrwx------+ 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 8HZD6WS6drwx------+ 2 Emery None 0 May 1 21:54 I4F15DOKdrwx------+ 2 Emery None 0 May 1 22:03 XM0N4Q4W-rwx------+ 1 Emery None 1916928 May 3 12:21 index.datdrwx------+ 2 Emery None 0 May 3 12:21 S0RKZRFZ
C:\Documents and Settings\Emery\Local Settings\Temporary Internet Files\Content.IE5>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
File Systems Abstraction
File system manages files
Traditionally: file system maps files to disk
But: files convenient abstractionuse 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)
6
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Device files
Unix devices live in /dev,act like ordinary files
7
elnux14> echo "foo" > /dev/ttyfoo
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
/proc filesystem
Normal file access to kernel internals
8
elnux14> ls -l /proc/30917/total 0dr-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 cmdlinelrwxrwxrwx 1 emery fac 0 May 3 13:18 cwd -> /nfs/elsrv4/users5/fac/emery-r-------- 1 emery fac 0 May 3 13:18 environlrwxrwxrwx 1 emery fac 0 May 3 13:18 exe -> /bin/tcshdr-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 mountslrwxrwxrwx 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 statusdr-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
Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc -l
9
elnux14> mkfifo thePipeelnux14> ls -ld thePipeprw-r----- 1 emery fac 0 May 3 14:00 thePipeelnux14> cat simplesocket.h > thePipe &[1] 32242elnux14> wc -l < thePipe155[1] Done cat simplesocket.h> thePipeelnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc -l
10
elnux14> mkfifo thePipeelnux14> ls -ld thePipeprw-r----- 1 emery fac 0 May 3 14:00 thePipeelnux14> cat simplesocket.h > thePipe &[1] 32242elnux14> wc -l < thePipe155[1] Done cat simplesocket.h> thePipeelnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc -l
11
elnux14> mkfifo thePipeelnux14> ls -ld thePipeprw-r----- 1 emery fac 0 May 3 14:00 thePipeelnux14> cat simplesocket.h > thePipe &[1] 32242elnux14> wc -l < thePipe155[1] Done cat simplesocket.h> thePipeelnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Named Pipes (FIFO)
Special file: acts like unnamed pipe
E.g., cat file | wc –l
Useful when cannot do redirection
Especially for compression12
elnux14> mkfifo thePipeelnux14> ls -ld thePipeprw-r----- 1 emery fac 0 May 3 14:00 thePipeelnux14> cat simplesocket.h > thePipe &[1] 32242elnux14> wc -l < thePipe155[1] Done cat simplesocket.h> thePipeelnux14>
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
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”
13
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
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”
14
elnux14> mkfifo joe.outelnux14> gzip –c < joe.out > joe.out.gz &[1]elnux14> joe
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
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
15
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Untyped Files
Unix, Windows – file contents untyped
Stream of bytes
Type implied by convention (extensions)
.ppt, .pdf, …
Mac: file types stored in metadata
16
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
File Types
Unix, Windows – file contents untyped
Stream of bytes
Type implied by convention (extensions)
.ppt, .pdf, …
Mac: file types stored in metadata
17
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
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)
18
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science
Access Control - chmod
Can read bits via ls, set bits via chmod
19
elnux14> ls -l ack.scm-rw-r----- 1 emery fac 197 Feb 25 15:19 ack.scmelnux14> chmod -r ack.scmelnux14> ls -l ack.scm--w------- 1 emery fac 197 Feb 25 15:19 ack.scmelnux14> cat ack.scmcat: ack.scm: Permission denied
UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 20
The End