UWB CSS 430 Operating Systems: File System Interface

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, from
Operating Systems Concepts with Java, 8th Ed.
© 2009 Silberschatz, Galvin & Gagne
CSS 430: Operating Systems - File System Interface
2
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
[joemcc@uw1-320-18 ThreadOS]$ ls -l
-rw------- 1 css430 users 10193 Nov
-rw------- 1 css430 users 8603 Dec
-rw-r--r-- 1 css430 users 8395 Nov
-rw------- 1 css430 users 8817 Nov
Kernel*.java
11 2004 Kernel_fil.java
23 2010 Kernel_hw3part1.java
13 2004 Kernel.java
11 2004 Kernel_org.java
[joemcc@uw1-320-18 ThreadOS]$ stat Kernel.java
File: `Kernel.java'
Size: 8395
Blocks: 24
IO Block: 32768 regular file
Device: 17h/23d Inode: 130884
Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1803/ css430)
Gid: ( 100/
users)
Access: 2011-11-12 19:40:45.000000000 -0800
Modify: 2004-11-13 20:36:20.000000000 -0800
Change: 2011-10-17 14:00:43.000000000 -0700
CSS 430: Operating Systems - File System Interface
8
File Operations
CSS 430: Operating Systems - File System Interface
9
File Operations
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)
CSS 430: Operating Systems - File System Interface
10
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
lseek (logical seek)
lseek( int fd, int offset, int origin )
• origin == 0 (SEEK_SET)
EOF
offset (> 0)
new file pointer position
• origin == 1 (SEEK_CUR)
EOF
current file pointer position
offset (> 0)
new file pointer position
• origin == 2 (SEEK_END)
EOF
new file pointer position offset (< 0)
CSS430: Operating Systems - File System Interface
12
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)
http://cs.oberlin.edu/~jdonalds/3
41/lecture24.html
http://www.cis.temple.edu/~ingargio/cis
307/readings/unix1.html
CSS 430: Operating Systems - File System Interface
14
File Types
CSS 430: Operating Systems - File System Interface
15
File Types
CSS 430: Operating Systems - File System Interface
16
Access Methods
• Sequential Access
read next block
write next block
reset
no read after last write
(rewrite)
• Direct Access
read block n
write block n
position to block n
read next block
write next block
rewrite block n
n = relative block number
CSS 430: Operating Systems - File System Interface
17
Directory Structure
• A collection of nodes containing
information about all files
Directory
Files
F1
F2
F3
F4
Fn
* Both the directory structure and the files reside on disk
CSS 430: Operating Systems - File System Interface
18
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
Naming problem
Grouping problem
CSS 430: Operating Systems - File System Interface
22
Two-Level Directory
• Separate directory for each user
 Path names
 Can [re]use the same file name for different users
 Efficient searching
 No grouping capability
CSS 430: Operating Systems - File System Interface
23
Tree-Structured Directories
 Absolute & relative paths, current working directory
 Can [re]use the same file name in any directory
 Efficient searching
 Grouping capability
CSS 430: Operating Systems - File System Interface
24
Acyclic-Graph Directories
• For sharing subdirectories and files
CSS 430: Operating Systems - File System Interface
25
Acyclic-Graph Directories
• For sharing subdirectories and files
What if
/dict/w/list
is deleted?
CSS 430: Operating Systems - File System Interface
26
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
[css430@uw1-320-19 ~]$ df
Filesystem
1K-blocks
/dev/mapper/VG00-lv_root
2951952
/dev/sda1
101086
tmpfs
1036984
/dev/mapper/VG00-lv_home
1967952
/dev/mapper/VG00-lv_tmp
1967952
/dev/mapper/VG00-lv_usr
60216936
/dev/mapper/VG00-lv_var
2984720
metis.uwb.edu:/usr/apps
18385920
medusa.uwb.edu:/home/uwagent
35318528
medusa.uwb.edu:/home/condor
35318528
medusa.uwb.edu:/home/hadoop
35318528
69.91.206.17:/home2 108598240
metis:/home4
12095040
Used Available Use% Mounted on
900344
24835
0
1899240
71032
1036984
33% /
26% /boot
0% /dev/shm
35808
1830564
2% /home
36960
1829412
2% /tmp
14042456
43071736
25% /usr
1169764
1664236
42% /var
14719200
2736224
85% /usr/apps
21919264
11611904
66% /home/uwagent
21919264
11611904
66% /home/condor
21919264
77730208
1847840
11611904
26454816
9632800
66% /home/hadoop
75% /net/metis/home2
17% /net/metis/home4
CSS 430: Operating Systems - File System Interface
31
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
CSS 430: Operating Systems - File System Interface
32
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
• Only administrators can create users & groups
• 3 modes of access: read, write, execute
• 3 classes of users:
a) owner
7

b) group
6

c) universe
4

RWX
111
RWX
110
RWX
100
• Example settings (Linux):
– 755 (-rwxr-xr-x)
– 644 (-rw-r--r--)
– 700 (drwx------) [“d” = directory]
CSS 430: Operating Systems - File System Interface
35
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