File System
Outlook
File-System Interface
Allocation-Methods
Free Space Management
File System Interface
File Concept
File system is the most visible part of an OS
Files – storing related data
Directory structure – organize and provide information about files
Information stored on various storage media
File system provides a uniform logical view of information storage
File system implementation has two major issues
How should it look to the user
(attributes, operations, structure)
Typical File Attributes
Each file is named human readable form which identifies the file
Identifier – unique tag identifying the file within the file system
Type – support different types of files
Location – pointer to a device and the location on that device
Size – current size in bytes, words, blocks
Protection – who can do reading, writing, executing
Time, date, and user identification – kept for creation, last modification, last use
Useful for protection, security, usage monitoring
Information is kept in a directory structure
Sequential File Access
Information passed in order, one record after another (tape model)
read: read the next portion of data; advance a read pointer
write: append data to the end of the file;
advance the file end
reset: skip file pointer forward/backward
Direct Access
File consists of fixed-length logical records;
readable/writable with no particular order (disk model)
Operations: read n, write n
Alternatively position n and read/write
Block numbers are generally an index relative to the beginning of a file
Request for record N with L being the record length
Start I/O at location L*N
Directory Structure
Disk can be used for more than one file system
Disk storage can be split into partitions (slices, minidisks)
Each can hold a different file system
Possibly other things like swap space, or
raw disk space
Directory Structure
Each file system needs a directory storing
file name, location, size, type, …
Tree Structured Directories
File-System Mounting
File system may be built from multiple volumes
Mounting
Name of the device
Mount point (typically an empty directory)
Possible implementations
Allow the same file system to be mounted repeatedly
One mount point per file system
Automatic mounting or explicit mounting
File-System Mounting
Possible implementations
Disallow nonempty mount points
Obscure the nonempty directory files
File Sharing
Requires more directory and file attributes
Most common model: user, group, others
Owner – can change attributes and grant access
Group – can share access to the file
Others – the remaining system users
When a user issues a command
User ID = owner ID user permissions
Group ID = file group ID group permissions
Otherwise other permissions
Allocation Methods
Allocation Methods
How to allocate disk space to files so that
Disk space is allocated efficiently
Files can be accessed quickly
Three major methods
Contiguous
Linked
Indexed
Contiguous Allocation
Each file
occupies a set of contiguous
blocks
Reading a block b+1 after block b requires no head movement except for
Last block in a cylinder requires one step to the next one
Contiguous Allocation
Access is easy to implement
Sequential access: remember current block; read next one if necessary
Direct access of block i of file starting at n: load block n+i
Problem: finding space for a new file
First fit, best fit, worst fit
External fragmentation problem
Older solution: copy disk on a temporary device; write back by allocating contiguous space
Time is the major concern on large devices
Contiguous Allocation
Contiguous allocation requires estimating the space needed for file creation
Solutions in case of size exceeded
Terminate the writing process
Relocate file blocks to a greater hole slows down the performance but does not disturb file operation
Slow growing file causes a large amount of
internal fragmentation
Linked Allocation
File is organized as a linked list of blocks
create – add “dir entry
nil”
write – add a free block at the end
read – traverse the list
No external fragmentation
File size need not be known in advance
No compactation required
Linked Allocation
Problems
Direct access to a given block requires traversal of the list
Next pointer in each block consumes space
Each block may require a seek
Solution
Allocate clusters (a set of blocks)
Expense: internal fragmentation
Further problems
Loss of a link or link error
Improvement
Doubly linked list
Linked Allocation: File-Allocation Table (FAT)
Indexed Allocation
Indexed Allocation
Supports direct access
No external fragmentation
Index block has to satisfy the largest possible file
Problem: index block wastes space
E.g. a file using only one block?
Solutions
Linked scheme – link index blocks together
Multilevel index – index block referring to second level index blocks (possibly more than two levels)
Combined scheme – UNIX inodes (see next)
Indexed Allocation: UNIX inodes
Free-Space Management
Free-Space Management
System has to keep track of free disk space
Use a free-space list
Creating a file – search free space list for
required amount of space; allocate that space
Deleting a file – free allocated blocks and add to free space list again
Implementation
Bit vector
Linked list
Free-Space Management: Bit Vectors
Each block represented by one bit
1=free, 0=allocated
Example: free-space bit map for
2,3,4,5,8,9,10,11,12,13,17,18,25,26,27 results in 001111001111110001100000011100000 …
Special hardware instructions make this scheme efficient
Check a word for 0
Find the index of the first 1-Bit in a word
Entire vector has to be kept in main memory
limited to small disks (e.g. 40 GB and 1 KB
blocks over 5 MB bit vector size)
Free-Space Management: Linked List
Not efficient if more blocks are needed
However,
traversing the list is not a frequent
action
In general, only
one next block is
required
Free-Space Management
Grouping
Block can store n pointers
Store addresses of n-1 free blocks and the address of the next n-free-block
Counting
Reasonable for contiguous allocation scheme
Store in the first block the number of the following free ones
Size of the linked list is reduced
Summary and References
Summary
File System is the most visible part of the OS
Provides access to data on secondary storage (sequential access, random access)
Organizing Files in directories
Mounting, sharing, remote access
The most important data structure: file concept
Major task of the OS with file systems: mapping of logical file concept onto physical storage devices
Major components (discussed here)
Allocation methods (contiguous, linked, indexed)
Free space management (bitmap, linked list, (grouping, counting))
References
Silberschatz, Galvin, Gagne, „Operating
System Concepts“, Seventh Edition, Wiley, 2005
Chapter 10 „File-System Interface“ (Section 10.1.1, 10.2, 10.4, 10.5, 10.6)