Operating Systems
Module-4
File Sysytem
1
• File systems and IOCS
• File Operations, File Organizations
• Directory structures, File Protection
• Interface between File system and IOCS
• Allocation of disk space, Implementing file access
Outline
2
Module-4
File system
3
Overview of File systems
4
4.1 File System and the IOCS
5
4.1 File System and the IOCS
File System and the IOCS facilities
• File system views a file as a collection of data that is owned
by a user, shared by a set of authorized users, and reliably
stored over an extended period
• IOCS views it as a repository of data that is accessed speedily
and stored on I/O device that is used efficiently
• Two kinds of data: file data and control data
6
4.1 File System and the IOCS
Logical organization of a file system
7
4.1 File System and the IOCS
File Processing in a Program
• At programming language level:
• File: object with attributes describing organization of its data
and the method of accessing the data
8
4.2 Files and File Operations
• File types can be grouped into two classes:
• Structured files: Collection of records
• Record: collection of fields
• Field: contains a single data item
• Each record is assumed to contain a unique key field
• Byte stream files: “Flat”
• A file has attributes, stored in its directory entry
9
4.2 Files and File Operations
10
4.3Fundamental File Organizations
• Records are stored in an ascending or descending sequence
according to the key field
• Record access pattern of an application is expected to follow
suit
• Two kinds of operations:
• Read the next (or previous) record
• Skip the next (or previous) record
• Uses:
• When data can be conveniently presorted into an ascending or
descending order
• For byte stream files
Sequential File Organization
11
4.3Fundamental File Organizations
Direct File Organization
• Provides convenience/efficiency of file processing when
records are accessed in a random order
• Files are called direct-access files
• Read/write command indicates value in key field
• Key value is used to generate address of record in storage
medium
• Disadvantages:
• Record address calculation consumes CPU time
• Some recording capacity of disk is wasted
• Dummy records exist for key values that are not in use
12
4.3Fundamental File Organizations
Index Sequential File Organization
• An index helps determine location of a record from its key
value
• Pure indexed organization: (key value, disk address)
• Index sequential organization uses index to identify section of
disk surface that may contain the record
• Records in the section are then searched sequentially
13
4.3Fundamental File Organizations
Access Methods
• Access method: IOCS module that implements accesses to a
class of files using a specific file organization
• Procedure determined by file organization
• Advanced I/O techniques are used for efficiency:
• Buffering of records
• Records of an input file are read ahead of the time when they are
needed by a process
• Blocking of records
• A large block of data, whose size exceeds the size of a record in
the file, is always read from, or written onto, the I/O medium
14
4.4Directory Structure
File system needs to grant users:
File naming freedom
File sharing
File system creates several directories
Uses a directory structure to organize
them
Provides file naming freedom and
file sharing
15
4.4Directory Structure
• Some concepts: home directory, current directory
• Path names used to uniquely identify files
• Relative path name
• Absolute path name
16
4.4Directory Structure
• Tree structure leads to a fundamental asymmetry in the way
different users can access a shared file
• Solution: use acyclic graph structure for directories
• A link is a directed connection between two existing files in the
directory structure
Tree and Graph directory structure
17
4.4Directory Structure
• Most frequent operation on directories: search
• Other operations are maintenance operations like:
• Creating or deleting files
• Updating file entries (upon a close operation)
• Listing a directory
• Deleting a directory
• Deletion becomes complicated when directory structure is a
graph
• A file may have multiple parents
• File system maintains a link count with each file
Operations on Directories
18
4.4Directory Structure
• There can be many file systems in an OS
• Each file system is constituted on a logical disk
• i.e., on a partition of a disk
• Files can be accessed only when file system is mounted
Mounting of File Systems
19
4.5 File Protection
• Users need controlled sharing of files
• Protection info field of the file’s directory entry used to control
access to the file
• Usually, protection info. stored in access control list
• List of (<user_name>,<list_of_access_privileges>)
• User groups can be used to reduce size of list
• In most file systems, privileges are of three kinds:
• Read
• Write
• Execute
20
4.6 Interface Between File System and IOCS
• Interface between file system and IOCS consists of
• File map table (FMT)
• Open files table (OFT)
• File control block (FCB)
21
4.6 Interface Between File System and IOCS
22
4.6 Interface Between File System and IOCS
When alpha is opened:
• File system copies FMTalpha in memory
• Creates fcbalpha in the OFT
• Initializes fields appropriately
• Passes offset in OFT to process, as
internal_idalpha
23
4.7 Allocation of Disk Space
• Disk space allocation is performed by file system
• Before  contiguous memory allocation model
• Led to external fragmentation
• Now  noncontiguous memory allocation model
• Issues:
• Managing free disk space
• Use: free list or disk status map (DSM)
• Avoiding excessive disk head movement
• Use: Extents (clusters) or cylinder groups
• Accessing file data
• Depends on approach: linked or indexed
24
4.7 Allocation of Disk Space
Linked Allocation
• Each disk block has data, address of next disk block
• Simple to implement
• Low allocation/deallocation overhead
• Supports sequential files quite efficiently
• Files with nonsequential organization cannot be accessed
efficiently
• Reliability is poor (metadata corruption)
25
4.7 Allocation of Disk Space
FAT (File Allocation table)
• MS-DOS uses a variant of linked allocation that stores the
metadata separately from the file data
• FAT has one element corresponding to every disk block in the
disk
• Penalty: FAT has to be accessed to obtain the address of the next
disk block
• Solution: FAT is held in memory during file processing
26
4.7 Allocation of Disk Space
• An index (file map table (FMT)) is maintained to note the
addresses of disk blocks allocated to a file
• Simplest form: FMT can be an array of disk block addresses
Indexed Allocation
27
4.8 Allocation of Disk Space
Indexed Allocation
• Other variations:
• Two-level FMT organization: compact, but access to data blocks
is slower
• Hybrid FMT organization: small files of n or fewer data blocks
continue to be accessible efficiently
28
4.9 Implementing file Access
• File System Actions at open
• Sets up the arrangement involving FCB and AFT
• File System Actions during a File Operation
• Performs disk space allocation if necessary
• File System Actions at close
• Updates directories if necessary
29
4.9 Implementing file Access
• Perform path name resolution
• For each component in the path name, locate the correct
directory or file
• Handle path names passing through mount points
• A file should be allocated disk space in its own file system
• Build FCB for the file
• Retain sufficient information to perform a close operation on
the file
• Close may have to update the file’s entry in the parent directory
• It may cause changes in the parent directory’s entry in ancestor
directories
File system actions at open
30
4.9 Implementing file Access
File system actions at open
31
4.9 Implementing file Access
File system actions at File Operation
• Each file operation is translated into a call:
• < opn > (internal_id, record_id,< IO_areaaddr >);
• Internal_id is the internal id of <file_name> returned by the open
call
• Record_id is absent for sequential-access files
• Operation is performed on the next record
• Disk block address obtained from record_id
32
4.9 Implementing file Access
File system actions at Close

os Module-4 ppt (1).pptx,...........................

  • 1.
  • 2.
    • File systemsand IOCS • File Operations, File Organizations • Directory structures, File Protection • Interface between File system and IOCS • Allocation of disk space, Implementing file access Outline 2 Module-4 File system
  • 3.
  • 4.
    4 4.1 File Systemand the IOCS
  • 5.
    5 4.1 File Systemand the IOCS File System and the IOCS facilities • File system views a file as a collection of data that is owned by a user, shared by a set of authorized users, and reliably stored over an extended period • IOCS views it as a repository of data that is accessed speedily and stored on I/O device that is used efficiently • Two kinds of data: file data and control data
  • 6.
    6 4.1 File Systemand the IOCS Logical organization of a file system
  • 7.
    7 4.1 File Systemand the IOCS File Processing in a Program • At programming language level: • File: object with attributes describing organization of its data and the method of accessing the data
  • 8.
    8 4.2 Files andFile Operations • File types can be grouped into two classes: • Structured files: Collection of records • Record: collection of fields • Field: contains a single data item • Each record is assumed to contain a unique key field • Byte stream files: “Flat” • A file has attributes, stored in its directory entry
  • 9.
    9 4.2 Files andFile Operations
  • 10.
    10 4.3Fundamental File Organizations •Records are stored in an ascending or descending sequence according to the key field • Record access pattern of an application is expected to follow suit • Two kinds of operations: • Read the next (or previous) record • Skip the next (or previous) record • Uses: • When data can be conveniently presorted into an ascending or descending order • For byte stream files Sequential File Organization
  • 11.
    11 4.3Fundamental File Organizations DirectFile Organization • Provides convenience/efficiency of file processing when records are accessed in a random order • Files are called direct-access files • Read/write command indicates value in key field • Key value is used to generate address of record in storage medium • Disadvantages: • Record address calculation consumes CPU time • Some recording capacity of disk is wasted • Dummy records exist for key values that are not in use
  • 12.
    12 4.3Fundamental File Organizations IndexSequential File Organization • An index helps determine location of a record from its key value • Pure indexed organization: (key value, disk address) • Index sequential organization uses index to identify section of disk surface that may contain the record • Records in the section are then searched sequentially
  • 13.
    13 4.3Fundamental File Organizations AccessMethods • Access method: IOCS module that implements accesses to a class of files using a specific file organization • Procedure determined by file organization • Advanced I/O techniques are used for efficiency: • Buffering of records • Records of an input file are read ahead of the time when they are needed by a process • Blocking of records • A large block of data, whose size exceeds the size of a record in the file, is always read from, or written onto, the I/O medium
  • 14.
    14 4.4Directory Structure File systemneeds to grant users: File naming freedom File sharing File system creates several directories Uses a directory structure to organize them Provides file naming freedom and file sharing
  • 15.
    15 4.4Directory Structure • Someconcepts: home directory, current directory • Path names used to uniquely identify files • Relative path name • Absolute path name
  • 16.
    16 4.4Directory Structure • Treestructure leads to a fundamental asymmetry in the way different users can access a shared file • Solution: use acyclic graph structure for directories • A link is a directed connection between two existing files in the directory structure Tree and Graph directory structure
  • 17.
    17 4.4Directory Structure • Mostfrequent operation on directories: search • Other operations are maintenance operations like: • Creating or deleting files • Updating file entries (upon a close operation) • Listing a directory • Deleting a directory • Deletion becomes complicated when directory structure is a graph • A file may have multiple parents • File system maintains a link count with each file Operations on Directories
  • 18.
    18 4.4Directory Structure • Therecan be many file systems in an OS • Each file system is constituted on a logical disk • i.e., on a partition of a disk • Files can be accessed only when file system is mounted Mounting of File Systems
  • 19.
    19 4.5 File Protection •Users need controlled sharing of files • Protection info field of the file’s directory entry used to control access to the file • Usually, protection info. stored in access control list • List of (<user_name>,<list_of_access_privileges>) • User groups can be used to reduce size of list • In most file systems, privileges are of three kinds: • Read • Write • Execute
  • 20.
    20 4.6 Interface BetweenFile System and IOCS • Interface between file system and IOCS consists of • File map table (FMT) • Open files table (OFT) • File control block (FCB)
  • 21.
    21 4.6 Interface BetweenFile System and IOCS
  • 22.
    22 4.6 Interface BetweenFile System and IOCS When alpha is opened: • File system copies FMTalpha in memory • Creates fcbalpha in the OFT • Initializes fields appropriately • Passes offset in OFT to process, as internal_idalpha
  • 23.
    23 4.7 Allocation ofDisk Space • Disk space allocation is performed by file system • Before  contiguous memory allocation model • Led to external fragmentation • Now  noncontiguous memory allocation model • Issues: • Managing free disk space • Use: free list or disk status map (DSM) • Avoiding excessive disk head movement • Use: Extents (clusters) or cylinder groups • Accessing file data • Depends on approach: linked or indexed
  • 24.
    24 4.7 Allocation ofDisk Space Linked Allocation • Each disk block has data, address of next disk block • Simple to implement • Low allocation/deallocation overhead • Supports sequential files quite efficiently • Files with nonsequential organization cannot be accessed efficiently • Reliability is poor (metadata corruption)
  • 25.
    25 4.7 Allocation ofDisk Space FAT (File Allocation table) • MS-DOS uses a variant of linked allocation that stores the metadata separately from the file data • FAT has one element corresponding to every disk block in the disk • Penalty: FAT has to be accessed to obtain the address of the next disk block • Solution: FAT is held in memory during file processing
  • 26.
    26 4.7 Allocation ofDisk Space • An index (file map table (FMT)) is maintained to note the addresses of disk blocks allocated to a file • Simplest form: FMT can be an array of disk block addresses Indexed Allocation
  • 27.
    27 4.8 Allocation ofDisk Space Indexed Allocation • Other variations: • Two-level FMT organization: compact, but access to data blocks is slower • Hybrid FMT organization: small files of n or fewer data blocks continue to be accessible efficiently
  • 28.
    28 4.9 Implementing fileAccess • File System Actions at open • Sets up the arrangement involving FCB and AFT • File System Actions during a File Operation • Performs disk space allocation if necessary • File System Actions at close • Updates directories if necessary
  • 29.
    29 4.9 Implementing fileAccess • Perform path name resolution • For each component in the path name, locate the correct directory or file • Handle path names passing through mount points • A file should be allocated disk space in its own file system • Build FCB for the file • Retain sufficient information to perform a close operation on the file • Close may have to update the file’s entry in the parent directory • It may cause changes in the parent directory’s entry in ancestor directories File system actions at open
  • 30.
    30 4.9 Implementing fileAccess File system actions at open
  • 31.
    31 4.9 Implementing fileAccess File system actions at File Operation • Each file operation is translated into a call: • < opn > (internal_id, record_id,< IO_areaaddr >); • Internal_id is the internal id of <file_name> returned by the open call • Record_id is absent for sequential-access files • Operation is performed on the next record • Disk block address obtained from record_id
  • 32.
    32 4.9 Implementing fileAccess File system actions at Close