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

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

Dec 17, 2015

Download

Documents

Corey Fields
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: File System Interface CSCI 444/544 Operating Systems Fall 2008.

File System Interface

CSCI 444/544 Operating Systems

Fall 2008

Page 2: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Agenda

• File system abstraction

• Directory structure

• File operations

• File system mounting

Page 3: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

Page 4: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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)

Page 5: File System Interface CSCI 444/544 Operating Systems Fall 2008.

File Structure

Sequence of words, bytes

Simple record structure• Lines • Fixed length• Variable length

Complex Structures• Formatted document

Page 6: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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.

Page 7: File System Interface CSCI 444/544 Operating Systems Fall 2008.

File Systems

OK, we have files

How can we name them?

How can we organize them?

Page 8: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

Page 9: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

Page 10: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Operations Performed on Directory

Search for a file

Create a file

Delete a file

List a directory

Rename a file

Traverse the file system

Page 11: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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, …)

Page 12: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Single-Level Directory

A single directory for all users

Naming problem

Grouping problem

Page 13: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Two-Level Directory

Separate directory for each user

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

Page 14: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Tree-Structured Directories

Page 15: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Tree-Structured Directories (Cont)

Efficient searching

Grouping Capability

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

Page 16: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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”

Page 17: File System Interface CSCI 444/544 Operating Systems Fall 2008.

Acyclic-Graph DirectoriesHave shared subdirectories and files

Page 18: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

Page 19: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

Page 20: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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.

Page 21: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

Page 22: File System Interface CSCI 444/544 Operating Systems Fall 2008.

04/18/23 22

Data Structures for a File

Processcontrolblock

...

Openfile

pointerarray

Open filetable

(system-wide)i-node table

Filei-node

Page 23: File System Interface CSCI 444/544 Operating Systems Fall 2008.

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

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

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