Operating Systems - File Systems

20
UNIVERSITY OF MASSACHUSETTS AMHERST Department of Computer Science Operating Systems CMPSCI 377 File Systems Emery Berger University of Massachusetts Amherst

description

From the Operating Systems course (CMPSCI 377) at UMass Amherst, Fall 2007.

Transcript of Operating Systems - File Systems

Page 1: Operating Systems - File Systems

UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science

Operating SystemsCMPSCI 377File Systems

Emery Berger

University of Massachusetts Amherst

Page 2: Operating Systems - File Systems

UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science

Files

Associate names with data

Usuallystored on persistent media (disks)

2

Page 3: Operating Systems - File Systems

UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science

File Names

Hierarchicaldirectory structure

Absolute, relativeto current

Windows names = location + dir

3

Page 4: Operating Systems - File Systems

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

Page 5: Operating Systems - File Systems

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>

Page 6: Operating Systems - File Systems

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

Page 7: Operating Systems - File Systems

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

Page 8: Operating Systems - File Systems

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

Page 9: Operating Systems - File Systems

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>

Page 10: Operating Systems - File Systems

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>

Page 11: Operating Systems - File Systems

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>

Page 12: Operating Systems - File Systems

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>

Page 13: Operating Systems - File Systems

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

Page 14: Operating Systems - File Systems

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

Page 15: Operating Systems - File Systems

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

Page 16: Operating Systems - File Systems

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

Page 17: Operating Systems - File Systems

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

Page 18: Operating Systems - File Systems

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

Page 19: Operating Systems - File Systems

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

Page 20: Operating Systems - File Systems

UNIVERSITY OF MASSACHUSETTS AMHERST • Department of Computer Science 20

The End