file system interface csci 444/544 operating systems fall 2008

24
File System Interface CSCI 444/544 Operating Systems Fall 2008

Upload: corey-fields

Post on 17-Dec-2015

220 views

Category:

Documents


1 download

TRANSCRIPT

File System Interface

CSCI 444/544 Operating Systems

Fall 2008

Agenda

• File system abstraction

• Directory structure

• File operations

• File system mounting

File System Abstraction

File system is the OS abstraction for storage resources (especially, disk)

Track/sector <=> files

• Provides a uniform logical view of information storage

• File is a logical storage unit in the OS abstract interface for storage resources

• Directory is a logical “container” for a group of files

File ConceptTo a user process, a file is a contiguous block of bytes

User view: named collection of bytes

OS view: collection of blocks on physical non-volatile storage device

Types: • Data

– numeric– character– binary

• Program (source and object)

File Structure

Sequence of words, bytes

Simple record structure• Lines • Fixed length• Variable length

Complex Structures• Formatted document

File Attributes (Meta-data)

Name – a string used to uniquely identify a fileIdentifier – unique tag (number) identifies file within file systemType – needed for systems that support different typesLocation – pointer to file location on deviceSize – current file sizeProtection – controls who can do reading, writing, executingTime, date, and user identification – data for protection,

security, and usage monitoring

These meta-data (Information about files) are kept in the directory structure, which is maintained on the disk but cached in memory if the file is open.

File Systems

OK, we have files

How can we name them?

How can we organize them?

File Naming

Each file has an associated human-readable name• e.g., usr, bin, mid-term.pdf, design.pdf

OS must maintain a mapping between file names and the set of blocks belong to that file• In Unix, this is a mapping between names and i-nodes

Mappings are kept in directories

Directory StructureA 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 diskBackups of these two structures are kept on tapes

Operations Performed on Directory

Search for a file

Create a file

Delete a file

List a directory

Rename a file

Traverse the file system

Organize the Directory 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 Java programs, all games, …)

Single-Level Directory

A single directory for all users

Naming problem

Grouping problem

Two-Level Directory

Separate directory for each user

Path name Can have the same file name for different user Efficient searching No grouping capability

Tree-Structured Directories

Tree-Structured Directories (Cont)

Efficient searching

Grouping Capability

Current directory (working directory)• cd /spell/mail/prog• type list

Tree-Structured Directories (Cont)Absolute or relative path nameCreating a new file is done in current directoryDelete a file

rm <file-name>Creating a new subdirectory is done in current directory

mkdir <dir-name>

Example: if in current directory /mailmkdir count

mail

prog copy prtexpcount

Deleting “mail” deleting the entire subtree rooted by “mail”

Acyclic-Graph DirectoriesHave shared subdirectories and files

Acyclic-Graph Directories (Cont.)

More general than tree structure• Add connections across the tree (no cycles)• Create links from one file (or directory) to another

Two different names (aliasing)

New directory entry type• Link – another name (pointer) to an existing file• Resolve the link – follow pointer to locate the file

File Operations

CreateWriteReadReposition within fileDeleteTruncate

Open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory

Close (Fi) – move the content of entry Fi in memory to directory structure on disk

Open FilesOpen() file before first access

• User specifies mode: read and/or write• Search directories for filename and check permissions• Copy relevant information to open file table in memory• Return index in open file table to process (file descriptor)• Process uses file descriptor to read/write to file

Two levels of open file tables• Per-process open file table

– Track all files that a process has open– Current file pointer indicating the current read or write position

• System-wide open-file table– Contains process-independent file information

• Location of the file on disk, file size, etc.

Related Information to an Open File

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

process that has the file open• Access rights: per-process access mode information• File-open count: counter of number of times a file is

open – to allow removal of data from system-wide open-file table when last processes closes it

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

04/18/23 22

Data Structures for a File

Processcontrolblock

...

Openfile

pointerarray

Open filetable

(system-wide)i-node table

Filei-node

Access Methods

Sequential Accessread nextwrite next resetno read after last write

Direct Accessread nwrite nposition to n

read nextwrite next

rewrite nn = relative block number

File System Mounting

A file system must be mounted before it can be accessed

A unmounted file system is mounted at a mount point• Mount point is typical an empty directory