Download File Systems: Organization, Abstractions, and Operations by Maria Hybinette and more Study notes Operating Systems in PDF only on Docsity!
Maria Hybinette, UGA
CSCI 4730
Operating Systems
File System
Maria Hybinette, UGA^2
Chapter 10-11: File System
! What are files? What is file meta-data?
! How are directories organized?
! What operations can be performed on files?
! How are directories organized?
! What is the difference between hard & soft
links?
! How are files protected?
Maria Hybinette, UGA^3
Motivation: I/O is Important
! Applications have two essential components:
» Processing
» Input/Output (I/O)
! I/O performance predicts application
performance
Maria Hybinette, UGA^4
I/O performance predicts
application performance
! Amdahl’s Law: If continually improve only part of application
(e.g., processing), then achieve diminishing returns in speedup
» Example: infinite speedup and affect only 15% of the overall task roughly: 1/(1-0.15) = 1.18 times faster is max!
! f: portion of application that is improved (e.g., processing)
! speedupf: speedup of portion of application
! SpeedupApplication = 1/ ((1-f) + (f/speedupf))
» Examples:
- f = .15, speedupf = 2, speedupapp = 1.
- f = 1/3, speedupf = 2, speedupapp = 1.
- f = 1/2, speedupf = 2, speedupapp = 1. Example: sequential When the only maximum 10% ofspeedup the application using is infinite number of processors is 10. Maria Hybinette, UGA^5 Maria Hybinette, UGA^6
Role of OS for I/O
! Standard library » Provide abstractions, consistent interface » Simplify access to hardware devices ! Resource coordination » Provide protection across users/processes » Provide fair and efficient performance
- Requires understanding of underlying device characteristics ! User processes do not have direct access to devices » Could crash entire system » Could read/write data without appropriate permissions » Could hog device unfairly ! OS exports higher-level functions » File system: Provides file and directory abstractions » File system operations: mkdir , create , read , write
Maria Hybinette, UGA^7
Abstraction: File
! User view
» Named collection of bytes (defined by user)
- Untyped or typed
- Examples: text, source, object, executables, application-specific
» Permanently and conveniently available
! Operating system view
» Map bytes as collection of blocks on physical non-
volatile storage device
- Magnetic disks, tapes, NVRAM, battery-backed RAM
- Persistent across reboots and power failure Maria Hybinette, UGA^8
Files Attributes: Meta-Data
System information associated with each file:
! Name – only information kept in human-readable form. ! Type – needed for systems that support different types. ! Location – pointer to file location on device/disk. ! Size – current file size. ! Protection bits – controls who can do reading, writing, executing. ! Time, date, and user identification – data for protection, security, and usage monitoring. ! Special file? » Directory, Symbolic link… Meta-data is stored on disk: » Conceptually: meta-data can be stored as a array on disk (e.g., directory) {atlas:maria:143} ls - lig ch11.ppt 231343 - rw-r--r-- 1 profs 815616 Nov 4 2002 ch11.ppt Maria Hybinette, UGA^9
Abstraction: Directories
! Organization technique: Map file name to blocks of file
data on disk
» Actually (indirectly), map file name to file meta-data (which enables one to find data on disk)
! Simplest approach: Single-level directory
» Each file has unique name » Special part of disk holds directory listing
- Contains <file name, meta-data index> pairs
- How should this data structure be organized???
! Two-level directory
» Directory for each user » Specify file with user name and file name » Disadvantage: Each user cannot organize files Maria Hybinette, UGA^10
Directories: Tree-Structured
! Directory listing contains <name, index>, but name can be
directory
» Directory is stored and treated like a file » Special bit set in meta-data for directories
- User programs can read directories
- Only system programs can write directories » Specify full pathname by separating directories and files with special characters (e.g., \ or /)
! Special directories
» Root: Fixed index for meta-data (e.g., 2) » This directory:. » Parent directory: ..
! Example: mkdir /a/b/c
» Read meta-data 2 (by default 2 is root in linux), look for “a”: find <“a”, 5> » Read 5, look for “b”: find <“b”, 9> » Read 9, verify no “c” exists; allocate c and add “c” to directory Maria Hybinette, UGA^11
Directory Implementation
! Directory system function: Maps ASCII names onto
what is needed to locate the data
! Where do we store the files’ attributes?
» A simple directory: fixed sized entries attributes stored with the entry » Directory in each entry just refers to an i-node (UNIX implementation) work attributes news attributes mail attributes games attributes work news mail games attributes attributes attributes attributes (^) Maria Hybinette, UGA 12
Directory Structure
! A directory “file” is a sequence of lines; each line
holds an i-node number (index-node) and a file
name
! The data is stored as binary so we cannot simply
cat to view it:
» but some UNIXs allow an “octal dump” (other formats
also available) :
287259 “gunnar.txt” 287243 “maria.html” {atlas:maria:187} od -c. 0000000 \0 \r 252 312 \0 \f \0 001. \0 \0 \0 \0 004 g 377 0000020 \0 \f \0 002.. \0 \0 \0 004 b 013 \0 024 \0 \n 0000040 m a r i a. h t m l \0 \0 \0 004 b 033 0000060 \0 024 \0 \n g u n n a r. t x t \0 \
Maria Hybinette, UGA^19
Linking Directories?
! Should it be permitted?
! Problem: Cycles in a file system degrades performance:
- Avoid traversing portion of file system multiple times. » Determine deletion: reference count may be non-zero, even if there is no possible way to refer (find) to file or directory ! Self-referencing
! How do we guarantee no cycles?
» Allow only links to file not subdirectories. » Garbage collection (mark everything that can be accessed via root directory then delete everything else). » Every time a new link is added use a cycle detection algorithm to determine whether it is OK? Maria Hybinette, UGA^20
Symbolic Links
! The links described so far are hard links
» A hard link is a pointer to a file which must be on the
same file system
! A symbolic link is an indirect pointer to a file
» Stores the pathname of the file that it points to
» Symbolic links can link across file systems
! Symbolic links are listed differently:
{saffron:ingrid:62} ln -s dir ~/unix/d/Sdir {saffron:ingrid:62} ls -lFd dir ~/unix/d/Sdir lrwxr-xr-x 1 ingrid staff 3 1 Apr 21:51 /home/ingrid/unix/d/Sdir@ -> dir drwxr-xr-x 3 ingrid staff 102 1 Apr 21:39 dir/ Maria Hybinette, UGA^21
File Operations
! Create file with given pathname /a/b/file
» Traverse pathname, allocate meta-data and directory entry
! Read from (or write to) offset in file
» Find (or allocate) blocks of file on disk; update meta-data
! Delete
» Remove directory entry, free disk space allocated to file
! Truncate file (set size to 0, keep other attributes)
» Free disk space allocated to file
! Rename file
» Change directory entry
! Copy file
» Allocate new directory entry, find space on disk and copy
! Change access permissions
» Change permissions in meta-data