You are on page 1of 24

Module 4.

0: File Systems
File is a contiguous logical address space (of related records)
Access Methods
Directory Structure
Protection
File System implementation

File-system structure
Allocation Methods
Free-space Management
Directory Implementation
Recovery, Efficiency, and Performance

Operating Systems

File Attributes

Name only information kept in human-readable form.

Information about files are kept in the directory structure, which is


maintained on the disk.

Type needed for systems that support different types.


Location pointer to file location on device.
Size current file size.
Protection controls who can do reading, writing, executing.
Time, date, and user identification data for protection,
security, and usage monitoring.

Operating Systems

File Operations

create

close (Fi) move the content of entry Fi in memory to directory


structure/descriptor on disk.

write
read
reposition within file file seek
delete
truncate
open(Fi) search the directory structure/descriptor on disk for
entry Fi, and move the content of entry to memory.

Operating Systems

File Types name, extension


File Type

Usual extension

Function

Operating Systems

File Structure of Data within Data Blocks

None - sequence of words, bytes


Simple record structure
Lines
Fixed length
Variable length

Tree of fixed or variable records with a key for each record.


Who decides:
Operating system
Program

Operating Systems

Access Methods
Sequential Access Tape Model. Reading records in order.

read next
write next
reset

Direct or Random Access Disk Model. Reading records in order and out of order.

read n
write n
position to n
read next
write next

Most files in modern OS are direct access.

Operating Systems

Memory-Mapped Files
Some OS provides map and unmap system calls.
map will map the file into the address space at the virtual

address. System calls like open, read, seek are not applicable.

Eliminates the need for I/O, thus making it easier to program.


Problems
Hard to know the size of the file in advance
Conflicts arise when sharing files between processes
Example: one process uses map and another uses
open, read, write.
How to deal with huge files that are bigger than a segment
or the whole virtual address space.

Operating Systems

Directory Structure

A collection of nodes containing information about all files.


Both the directory structure and the files reside on disk.

Directory

Files

F1

F2

F3

F4
Fn

Operating Systems

Information in a Device Directory

Name
Type
Address
Current length
Maximum length
Date last accessed (for archival)
Date last updated (for dump)
Owner ID (who pays)
Protection information (discuss later)

Operating Systems

Operations Performed on Directory

Search for a file


Create a file
Delete a file
List a directory
Rename a file
Traverse the file system

10

Operating Systems

Actual File Size

In Windows, disk block is 4KB

Size of file reflects the actual


size of data.

Size on disk which is multiple of


data blocks.

Ex, if you create a text file with


xyz with notepad, size of file will
show 3, while Size on disk will
show 4KB.

In Unix, disk block is 512B

11

Operating Systems

Organize the Directory (Logically) to Obtain

Efficiency locating a file quickly.


Naming convenient to users.
Two users can have same name for different files.
The same file can have several different names.

Grouping logical grouping of files by properties, (e.g., all Pascal


programs, all games, )

Directory structure:
Single-level: A single directory of all users
Two-level: Separate directory for each user
Tree-structured: Most common

12

Operating Systems

Tree-Structured Directories
Efficient searching
Grouping Capability
Absolute or relative path name
Current directory (working
directory)
cd /spell/mail/prog
type list
Deleting mail deleting the
entire subtree rooted by mail.

13

Operating Systems

Shared Files/Directories

Symbolic or soft link


A file/directory is a pointer (contains the pathname) to another
file/directory,
e.g., ln s /etc/classes/ics431/class softclass
A new i-node is created for softclass

Takes longer to lookup as the path is traversed


The file pointed to can be deleted or changed
Backup might do multiple copies
Good for linking files on other machines

Hard link
The file/directory points to the same file/directory-structure or I-node
of the other file/directory.
e.g., ln /etc/classes/ics431/class hardclass
No i-node is created. Only entry in the i-node of directory which
hardclass is under
Faster for lookup
Has an owner issue
Need to keep a count in the structure for file deletion

14

Operating Systems

Protection

File owner/creator should be able to control:


what can be done
by whom

Types of access
Read
Write
Execute
Append
Delete
List

15

Operating Systems

Access Lists and Groups

Mode of access: read, write, execute


Three classes of users
a) owner access

b) groups access

c) public access

RWX
111
RWX
110
RWX
001

Ask manager to create a group (unique name), say G, and add


some users to the group.

For a particular file (say game) or subdirectory, define an


appropriate access.
owner

chmod

group
761

public
game

Attach a group to a file


chgrp

G
16

game
Operating Systems

File-System Implementation
Contiguous Allocation

Each file occupies a set of contiguous blocks on the disk.


Simple only starting location (block #) and length (number of
blocks) are required.
Random access.
Wasteful of space (dynamic allocation problem).
Files cannot grow.

Linked Allocation
Indexed Allocation

17

Operating Systems

Linked Allocation
Each file is a linked list of disk

blocks: blocks may be scattered


anywhere on the disk.

Simple need only starting


address

Free-space management

system no waste of space


except for pointers

No random access
File-allocation table (FAT)

disk-space allocation used by


MS-DOS and OS/2.
A table used as a linked list
keeping track of all available
and used blocks. See Fig. 126.

18

Operating Systems

Indexed Allocation
Brings all pointers

together into the index


block. In Unix called (inode).

Random access
Dynamic allocation

without external
fragmentation, but have
overhead of index block.

Wasted space for index

block. Worse than linked


allocation.

How big should the index


block be?

19

Operating Systems

Use of Multi-level Index Unix i-node

20

Operating Systems

Where is the path stored in the inode of a softlink file?


Where is list of file names in a directory inode is stored?

21

Operating Systems

Directory Implementation
Linear list of file names with pointer to the data blocks.
simple to program
time-consuming to execute

Hash Table linear list with hash data structure.


decreases directory search time
collisions situations where two file names hash to the
same location
fixed size

22

Operating Systems

Efficiency and Performance


Efficiency dependent on:
disk allocation and directory algorithms
types of data kept in files directory entry

Performance
disk cache separate section of main memory for frequently
used blocks
free-behind and read-ahead techniques to optimize
sequential access
improve PC performance by dedicating section of memory
as virtual disk, or RAM disk.

23

Operating Systems

Caching and Recovery


Various Disk-Caching Locations:

Consistency checker compares data in directory structure with data


blocks on disk, and tries to fix inconsistencies.
Use system programs to back up data from disk to another storage device
(USB disks, tapes, or Cloud Computing dropbox).
Recover lost file or disk by restoring data from backup.
NTFS Features: Logging or journaling, Encryption, Compression, Larger sizes than FAT, but
more overhead (space and time).
24

Operating Systems

You might also like