Upload
hemang-kothari
View
332
Download
0
Embed Size (px)
Citation preview
File ManagementIf there is one singular characteristic that makes human unique among
others it is their natural instinct to manage things
Prof. Hemang Kothari
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
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
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
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
File Structure
Four terms are commonly used when
discussing files:
Field Record File Database
Prof. Hemang Kothari
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
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
File Types – Name , Extension
Prof. Hemang Kothari
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
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
File Operation
• Create • Delete • Open• Close• Read• Write• Append
• Seek (lseek)• Get attributes– stat, lstat, fstat, fcntl• Set Attributes (fcntl)• Rename
Prof. Hemang Kothari
Directories
Prof. Hemang Kothari
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
Two-level Directory Systems
Prof. Hemang Kothari
Hierarchical Directory Systems
Prof. Hemang Kothari
Path Names
A UNIX directory treeProf. Hemang Kothari
Directory Operations
1. Create2. Delete3. Opendir4. Closedir5. Readdir6. Rename7. Link8. Unlink
Prof. Hemang Kothari