Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface1.

37
Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface 1

Transcript of Chapter 10: File System Interface Joe McCarthy CSS 430: Operating Systems - File System Interface1.

Chapter 10:File System Interface

Joe McCarthy

CSS 430: Operating Systems - File System Interface 1

Chapter 10: File System Interface

• File Concept• Access Methods• Directory Structure• File-System Mounting• File Sharing• Protection

Material derived, in part, fromOperating Systems Concepts with Java, 8th Ed.

© 2009 Silberschatz, Galvin & Gagne

2CSS 430: Operating Systems - File System Interface

File Concept

• What is a file?

CSS430: Operating Systems - File System Interface 3

File Concept

• Named collection of related information on secondary storage (nonvolatile)

• Smallest unit of logical secondary storage– May be composed of multiple physical secondary

storage units– Logically contiguous space– May be physically distributed

CSS430: Operating Systems - File System Interface 4

File Structure• Levels of structure

– None - sequence of words, bytes– Simple record structure

• Lines • Fixed length records• Variable length records

– Complex structures• Formatted document• Relocatable load file

– Can simulate last two with first method by inserting appropriate control characters

• Structure imposed by:– Operating system– Program

CSS 430: Operating Systems - File System Interface 5

File Attributes

CSS 430: Operating Systems - File System Interface 6

File Attributes• Name: only information kept in human-readable form• Identifier: unique tag (number) identifies file within file

system• Type: needed for systems that support different types• Location: pointer to file location on device• Size: current file size• Protection: specifies who can read, write, execute• Time, date, and owner identification: data for

protection, security, and usage monitoring• Information about files are kept in the directory

structure, which is maintained on the disk

CSS 430: Operating Systems - File System Interface 7

Linux ls –l, stat

CSS 430: Operating Systems - File System Interface 8

[joemcc@uw1-320-18 ThreadOS]$ ls -l Kernel*.java-rw------- 1 css430 users 10193 Nov 11 2004 Kernel_fil.java-rw------- 1 css430 users 8603 Dec 23 2010 Kernel_hw3part1.java-rw-r--r-- 1 css430 users 8395 Nov 13 2004 Kernel.java-rw------- 1 css430 users 8817 Nov 11 2004 Kernel_org.java

[joemcc@uw1-320-18 ThreadOS]$ stat Kernel.java File: `Kernel.java' Size: 8395 Blocks: 24 IO Block: 32768 regular fileDevice: 17h/23d Inode: 130884 Links: 1Access: (0644/-rw-r--r--) Uid: ( 1803/ css430) Gid: ( 100/ users)Access: 2011-11-12 19:40:45.000000000 -0800Modify: 2004-11-13 20:36:20.000000000 -0800Change: 2011-10-17 14:00:43.000000000 -0700

File Operations

CSS 430: Operating Systems - File System Interface 9

File Operations

CSS 430: Operating Systems - File System Interface 10

Operations

Descriptions Unix ThreadOS

Create Create a file with its attribute

creat(filename,mode) N/A

Open Open the specified file. (Create it if mode specified and necessary)

open(filename,flag,mode)

SysLib.open(filename,mode)

Read Read from a file read(fd, buf, size) SysLib.read(fd, buffer)

Write Write a file write(fd, buf, size) SysLib.write(fd, buffer)

Seek Reposition a file access point

lseek(fd, offset, origin) SysLib.seek(fd, offset, whence)

Close Close the file specified with fd

close(fd) SysLib.close(fd)

Delete Destroy the specified file remove(filename) SysLib.delete(filename)

Truncate Resize the file to a specified length

truncate(filename, length)

N/A

Status Returns the specified file status

stat(fd, statbuf) SysLib.fsize(fd)

Format Format the disk N/A SysLib.format(files)

lseek (logical seek)• lseek( int fd, int offset, int origin )

– Reposition logical file pointer (fp) within an open file– fd: file descriptor

• 0 (STDIN_FILENO) • 1 (STDOUT_FILENO)• 2 (STDERR_FILENO)• …

– offset can be + or – (down/right or up/left)– origin (whence in SysLib.seek())

• 0 (SEEK_SET), offset from start of file (offset must be +)• 1 (SEEK_CUR), offset from current fp position• 2 (SEEK_END), offset from end of file (offset must be -)

CSS430: Operating Systems - File System Interface 11

CSS430: Operating Systems - File System Interface 12

lseek (logical seek)lseek( int fd, int offset, int origin )• origin == 0 (SEEK_SET)

• origin == 1 (SEEK_CUR)

• origin == 2 (SEEK_END)

offset (> 0) new file pointer position

EOF

offset (> 0) new file pointer position

EOF

offset (< 0)

EOF

current file pointer position

new file pointer position

Open Files

• Several pieces of data are needed to manage open files:– File pointer: pointer to next read/write location, per

process that has the file open– File open count: counter of # processes that have

opened file - # of processes that have closed it • when 0, can remove entry from system-wide open file table

– Disk location of the file: cache of data access information

– Access rights: per-process access mode information

CSS 430: Operating Systems - File System Interface 13

Recall: File Descriptors (Ch. 3)

CSS 430: Operating Systems - File System Interface 14

http://www.cis.temple.edu/~ingargio/cis307/readings/unix1.html

http://cs.oberlin.edu/~jdonalds/341/lecture24.html

File Types

15CSS 430: Operating Systems - File System Interface

File Types

16CSS 430: Operating Systems - File System Interface

Access Methods• Sequential Access

read next blockwrite next block resetno read after last write (rewrite)

• Direct Accessread block nwrite block nposition to block n read next block write next block rewrite block n

n = relative block number

17CSS 430: Operating Systems - File System Interface

Directory Structure• A collection of nodes containing information about all files

F 1 F 2F 3

F 4

F n

Directory

Files

* Both the directory structure and the files reside on disk

18CSS 430: Operating Systems - File System Interface

A Typical File-System Organization

CSS 430: Operating Systems - File System Interface 19

Operations Performed on Directory

CSS 430: Operating Systems - File System Interface 20

Operations Performed on Directory

• Search for a file• Create a file• Delete a file• List a directory• Rename a file• Change working directory

– Navigate / traverse the file system

CSS 430: Operating Systems - File System Interface 21

Single-Level Directory

• A single directory for all users

CSS 430: Operating Systems - File System Interface 22

Naming problem

Grouping problem

Two-Level Directory

• Separate directory for each user

CSS 430: Operating Systems - File System Interface 23

Path names

Can [re]use the same file name for different users

Efficient searching

No grouping capability

Tree-Structured Directories

CSS 430: Operating Systems - File System Interface 24

Absolute & relative paths, current working directory

Can [re]use the same file name in any directory

Efficient searching

Grouping capability

Acyclic-Graph Directories

• For sharing subdirectories and files

CSS 430: Operating Systems - File System Interface 25

Acyclic-Graph Directories

• For sharing subdirectories and files

CSS 430: Operating Systems - File System Interface 26

What if /dict/w/listis deleted?

General Graph Directory

CSS 430: Operating Systems - File System Interface 27

General Graph Directory

• How do we guarantee no cycles?

CSS 430: Operating Systems - File System Interface 28

General Graph Directory

• How do we guarantee no cycles?– Allow only links to files (not subdirectories)– Garbage collection– Every time a new link is added use a cycle

detection algorithm to determine whether it is OK

CSS 430: Operating Systems - File System Interface 29

File System Mounting

• A file system must be mounted before it can be accessed

• A unmounted file system is mounted at a mount point

CSS 430: Operating Systems - File System Interface 30

Linux df

CSS 430: Operating Systems - File System Interface 31

[css430@uw1-320-19 ~]$ dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/VG00-lv_root 2951952 900344 1899240 33% //dev/sda1 101086 24835 71032 26% /boottmpfs 1036984 0 1036984 0% /dev/shm/dev/mapper/VG00-lv_home 1967952 35808 1830564 2% /home/dev/mapper/VG00-lv_tmp 1967952 36960 1829412 2% /tmp/dev/mapper/VG00-lv_usr 60216936 14042456 43071736 25% /usr/dev/mapper/VG00-lv_var 2984720 1169764 1664236 42% /varmetis.uwb.edu:/usr/apps 18385920 14719200 2736224 85% /usr/appsmedusa.uwb.edu:/home/uwagent 35318528 21919264 11611904 66% /home/uwagentmedusa.uwb.edu:/home/condor 35318528 21919264 11611904 66% /home/condormedusa.uwb.edu:/home/hadoop 35318528 21919264 11611904 66% /home/hadoop69.91.206.17:/home2 108598240 77730208 26454816 75% /net/metis/home2metis:/home4 12095040 1847840 9632800 17% /net/metis/home4

File Sharing• Sharing of files on multi-user systems is desirable

• Sharing may be done through a protection scheme

• On distributed systems, files may be shared across a network

• Network File System (NFS) is a common distributed file-sharing method

32CSS 430: Operating Systems - File System Interface

File Sharing – Multiple Users

• User IDs identify users, allowing permissions and protections to be per-user

• Group IDs allow users to be in groups, permitting group access rights

CSS 430: Operating Systems - File System Interface 33

Protection

• File owner/creator should be able to control:– what can be done– by whom

• Types of access– Read– Write– Execute– Append– Delete– List

CSS 430: Operating Systems - File System Interface 34

Access Lists & Groups

CSS 430: Operating Systems - File System Interface 35

• Only administrators can create users & groups• 3 modes of access: read, write, execute• 3 classes of users:

RWXa) owner 7 1 1 1

RWXb) group 6 1 1 0

RWXc) universe 4 1 0 0

• Example settings (Linux):– 755 (-rwxr-xr-x)– 644 (-rw-r--r--)– 700 (drwx------) [“d” = directory]

Windows XP Access-control List Management

CSS 430: Operating Systems - File System Interface 36

A Sample UNIX Directory Listing

CSS 430: Operating Systems - File System Interface 37