file management module 7

18
File Management If there is one singular characteristic that makes human unique among others it is their natural instinct to manage things Prof. Hemang Kothari

Upload: hemang-kothari

Post on 06-May-2015

334 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: File management module 7

File ManagementIf there is one singular characteristic that makes human unique among

others it is their natural instinct to manage things

Prof. Hemang Kothari

Page 2: File management module 7

Motivation for file system

• Applications can store it in the process address space• Why is it a bad idea?

• Size is limited to size of virtual address space• May not be sufficient for airline reservations, banking, etc.

• The data is lost when the application terminates• Even when computer doesn’t crash!

• Multiple process might want to access the same data• Imagine a telephone directory part of one process

Prof. Hemang Kothari

Page 3: File management module 7

Motivation Continue .....

• 3 criteria for long-term information storage:• Should be able to store very large amount of information• Information must survive the processes using it• Should provide concurrent access to multiple processes

• Solution:• Store information on disks in units called files• Files are persistent, and only owner can explicitly delete it• Files are managed by the OS

• File Systems: How the OS manages files!

Prof. Hemang Kothari

Page 4: File management module 7

Files• Data collections created by users• Desirable properties of files:

Long-term existence

• Files are stored on disk or other secondary storage and do not disappear when a user logs off

Sharable between processes

• Files have names and can have associated access permissions that permit controlled sharing

Structure

• Files can be organized into hierarchical or more complex structure to reflect the relationships among files

Prof. Hemang Kothari

Page 5: File management module 7

File Naming

• Motivation: Files abstract information stored on disk• You do not need to remember block, sector, …• We have human readable names

• How does it work?• Process creates a file, and gives it a name

• Other processes can access the file by that name

• Naming conventions are OS dependent• Usually names as long as 255 characters is allowed• Digits and special characters are sometimes allowed• MS-DOS and Windows are not case sensitive, UNIX family is

Prof. Hemang Kothari

Page 6: File management module 7

File Structure

Four terms are commonly used when

discussing files:

Field Record File Database

Prof. Hemang Kothari

Page 7: File management module 7

File Structure

Field• basic element of data• contains a single value• fixed or variable length

Database• Collection of related data• Relationships among elements of data are

explicit• Designed for use by a number of different

applications• Consists of one or more types of files

File• Collection of similar records• Treated as a single entity• May be referenced by name• Access control restrictions

usually apply at the file level

Record• Collection of related fields that can be treated

as a unit by some application program• One field is the key – a unique identifierProf. Hemang Kothari

Page 8: File management module 7

File Structure

• Files can be structured as a collection of records or as asequence of bytes

• UNIX, Linux, Windows, Mac OS’s consider files as a sequenceof bytes

• Other OS’s, notably many IBM mainframes, adopt thecollection-of-records approach; useful for DB

• COBOL supports the collection-of-records file and canimplement it even on systems that don’t provide such filesnatively.

Prof. Hemang Kothari

Page 9: File management module 7

File Types – Name , Extension

Prof. Hemang Kothari

Page 10: File management module 7

File Access

• Sequential access• Read all bytes/records from the beginning• Cannot jump around, could rewind or back up• Convenient when medium was magnetic tape

• Random access• Bytes/records read in any order• Essential for many applications• Read can be …• move file pointer (seek), then read or …• read and then move file marker

All modern OS have all files as random

access

Prof. Hemang Kothari

Page 11: File management module 7

File Attributes

• File name• Size information• Physical address• File type

• ASCII vs binary• Temporary vs Permanent

• Access rights: owner, protection (who can access it)• Access type: Sequential/Random• History: Creator, time of last access/modification, other usage data• Info for managing links

Prof. Hemang Kothari

Page 12: File management module 7

File Operation

• Create • Delete • Open• Close• Read• Write• Append

• Seek (lseek)• Get attributes– stat, lstat, fstat, fcntl• Set Attributes (fcntl)• Rename

Prof. Hemang Kothari

Page 13: File management module 7

Directories

Prof. Hemang Kothari

Page 14: File management module 7

Single-Level Directory Systems

A single level directory system • Contains 4 files• Owned by 3 different people, A, B, and C• Ownerships are shown, not file names

Prof. Hemang Kothari

Page 15: File management module 7

Two-level Directory Systems

Prof. Hemang Kothari

Page 16: File management module 7

Hierarchical Directory Systems

Prof. Hemang Kothari

Page 17: File management module 7

Path Names

A UNIX directory treeProf. Hemang Kothari

Page 18: File management module 7

Directory Operations

1. Create2. Delete3. Opendir4. Closedir5. Readdir6. Rename7. Link8. Unlink

Prof. Hemang Kothari