SlideShare a Scribd company logo
Part III
    Storage Management
Chapter 11: File System Implementation
Layered
File System
Overview: 1/4
qA file system has on-disk and in-memory
 information.
qA disk may contain the following for
 implementing a file system on it:
  vA boot control block per volume
  vA partition control block per volume
  vA directory structure per file system
  vA file control block per file
qIn-memory information include
  vAn in-memory partition table
  vAn in-memory directory structure
  vThe system-wide open-file table
  vThe per-process open-file table
Overview: 2/4
a typical file control block FCB   qA FCB, file control
                                    block, contains the
 file permission                    details of a file.
 file date                         qIn Unix, a FCB is
 file owner, group, ACL
                                    called an i-node.

 file size

 file data blocks
Overview: 3/4               3: read the directory
     4: update FCB and directory
                         kernel memory                 disk memory
   user program




  open(filename)                                      directory structure
                             directory structure



1: create a new file
                                                            FCB
 5: a file descriptor/file handle
   is returned
                                    2: allocate a new FCB
Overview: 4/4
        index
                   kernel memory       disk memory
user program         per-process
                     open-file table



                                        Data blocks

read(index)          system-wide
                     open-file table




                                          FCB
Directory Implementation
qA File directory is usually implemented as a
 linked-list or a tree (e.g., B-tree), a hash table
 with chaining, or the combination of both.
qThe problem with the linked-list approach is
 the poor performance in searching for a file.
 Directory search is a very frequently
 performed operation.
qThe hash table approach speeds up search;
 however, we must deal with the problem of
 collisions. Thus, chaining is necessary.
Directory Entries: 1/2
qA directory is simply a file!
qA directory entry may be very simple like the
 one used by MS-DOS. Or, it may be quite
 complex like the Unix i-node.




  extended MS-DOS directory entry used in Windows 98
Directory Entries: 2/2

Unix directory entry
                       find /usr/ast/mbox
File Allocation Methods

qThere are three typical file space allocation
 methods:
 vContiguous Allocation
 vLinked Allocation
 vIndexed Allocation
Contiguous Allocation: 1/3
qWith the contiguous allocation method, a user
 must indicate the file size before creating the file.
qThen, the operating system searches the disk to
 find contiguous disk blocks for the file.
qThe directory entry is easy. It contains the initial
 disk address of this file and the number of disk
 blocks.
qTherefore, if the initial address is b and the
 number of blocks is n, the file will occupy blocks b,
 b+1, b+2, …, b+n-1.
Contiguous Allocation: 2/3

                         directory




               Since blocks are allocated
               contiguously, external
               fragmentation may occur.
               Thus, compaction may be
               needed.
Contiguous Allocation: 3/3
qContiguous allocation is easy to implement.
qIts disadvantages are
  vIt can be considered as a form of dynamic
    memory allocation, and external fragmentation
    may occur and compaction may be needed.
  vIt is difficult to estimate the file size. The size of
    a file may grow at run time and may be larger
    than the specified number of allocated blocks.
    In this case, the OS must move the blocks in
    order to provide mode space. In some systems,
    this is simply an error.
Linked Allocation: 1/3
qWith the linked allocation approach, disk
 blocks of a file are chained together with a
 linked-list.
qThe directory entry of a file contains a pointer
 to the first block and a pointer to the last block.
qTo create a file, we create a new directory entry
 and the pointers are initialized to nil.
qWhen a write occurs, a new disk block is
 allocated and chained to the end of the list.
Linked Allocation: 2/3
            directory

                        28   Last Block




      qFile blocks are chained into a
       linked-list.
      qThe directory entry has pointers
       to the first and last file blocks.
      qAppend is difficult to do without
       the last pointer.
Linked Allocation: 3/3
qAdvantages:
 vFile size does not have to be specified.
 vNo external fragmentation.
qDisadvantages:
 vIt does sequential access efficiently and is not
   for direct access
 vEach block contains a pointer, wasting space
 vBlocks scatter everywhere and a large number
   of disk seeks may be necessary
 vReliability: what if a pointer is lost or damaged?
File Allocation Table (FAT)
                          FAT
                    0                 q This is a variation of the
                                        linked allocation by
                                        pulling all pointers into a
                  217      618          table, the file allocation
directory                               table (FAT).
   test                               q Large no. of disk seeks.
                  339   end-of-file
                                      q Can do direct access.
                                      q FAT needs space.
   217                                q The left diagram shows
                  618      339          file test has its first
                                        block at 217, followed by
                                        618, 339 (end of file).
      no. of blocks-1                 q What if FAT is damaged?
                                        We all know it well!
Indexed Allocation: 1/4
qEach file has an index block that is an array of
 disk block addresses.
qThe i-th entry in the index block points to the i-th
 block of the file.
qA file’s directory entry contains a pointer to its
 index. Hence, the index block of an indexed
 allocation plays the same role as the page table.
qIndex allocation supports both sequential and
 direct access without external fragmentation.
Indexed Allocation: 2/4

                   directory




             index block
Indexed Allocation: 3/4
qThe indexed allocation suffers from wasted space.
 The index block may not be fully used (i.e., internal
 fragmentation).
qThe number of entries of an index table determines
 the size of a file. To overcome this problem, we can
  vHave multiple index blocks and chain them into
    a linked-list
  vHave multiple index blocks, but make them a
    tree just like the indexed access method
  vA combination of both
Indexed Allocation: 4/4

 i-node
  10 direct blocks




256 entries per index table.
What is the maximum size of a file?
Free Space Management
qHow do we keep track free blocks on a disk?
qA free-list is maintained. When a new block is
 requested, we search this list to find one.
qThe following are commonly used techniques:
  vBit Vector
  vLinked List
  vLinked List + Grouping
  vLinked List+Address+Count
Bit Vector
qEach block is represented by a bit in a table. Thus,
 if there are n disk blocks, the table has n bits.
qIf a block is free, its corresponding bit is 1.
qWhen a block is needed, the table is searched. If a 1
 bit is found in position k, block k is free.
qIf the disk capacity is small, the whole bit vector can
 be stored in memory. For a large disk, this bit
 vector will consume too much memory.
qWe could group a few blocks into a cluster and
 allocate clusters. This saves space and may cause
 internal fragmentation.
qAnother possibility is the use of a summary table.
Linked List
qLike the linked allocation method, free blocks can
 be chained into a linked list.
qWhen a free block is needed, the first in the chain is
 allocated.
qHowever, this method has the same disadvantages
 of the linked allocation method.
qWe can use a FAT for the disk and chain the free
 block pointers together. Keep in mind that the
 FAT may be very large and consume space if it is
 stored in memory.
Grouping
qThe first free block contains the addresses of n
 other free blocks.
qFor each group, the first n-1 blocks are actually
 free and the last (i.e., n-th) block contains the
 addresses of the next group.
qIn this way, we can quickly locate free blocks.

    3     8 50        3                         6
   (3 & 8 are free)
      8
                            12

           20
                                                50
                            (6 & 12 are free)   6 12 20
Address + Counting
qWe can make the list short with the following trick:
 vBlocks are often allocated and freed in groups
 vWe can store the address of the first free block
  and the number of the following n free blocks.


  free block list



             5


             3
                                      disk

More Related Content

What's hot

Corso Linux
Corso LinuxCorso Linux
Corso Linux
agnelloe
 

What's hot (20)

Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Understanding das-nas-san
Understanding das-nas-sanUnderstanding das-nas-san
Understanding das-nas-san
 
Description of GRUB 2
Description of GRUB 2Description of GRUB 2
Description of GRUB 2
 
Système RAID
Système RAIDSystème RAID
Système RAID
 
OS Memory Management
OS Memory ManagementOS Memory Management
OS Memory Management
 
Présentation du stockage RAID
Présentation du stockage RAIDPrésentation du stockage RAID
Présentation du stockage RAID
 
Memory management
Memory managementMemory management
Memory management
 
Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 5: File Handling Internals Course 102: Lecture 5: File Handling Internals
Course 102: Lecture 5: File Handling Internals
 
Archiving in linux tar
Archiving in linux tarArchiving in linux tar
Archiving in linux tar
 
Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview
 
File system
File systemFile system
File system
 
Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts) Course 102: Lecture 20: Networking In Linux (Basic Concepts)
Course 102: Lecture 20: Networking In Linux (Basic Concepts)
 
Allocation and free space management
Allocation and free space managementAllocation and free space management
Allocation and free space management
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Corso Linux
Corso LinuxCorso Linux
Corso Linux
 
Linux file system
Linux file systemLinux file system
Linux file system
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 

Viewers also liked

File management ppt
File management pptFile management ppt
File management ppt
marotti
 
Intermediate Operating Systems
Intermediate Operating SystemsIntermediate Operating Systems
Intermediate Operating Systems
John Cutajar
 
Linked allocation 48
Linked  allocation 48Linked  allocation 48
Linked allocation 48
myrajendra
 
Overview of System Virtualization
Overview of System VirtualizationOverview of System Virtualization
Overview of System Virtualization
Andre Odendaal
 
File management
File managementFile management
File management
Mohd Arif
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating system
tittuajay
 

Viewers also liked (14)

Htcia an introduction to the microsoft ex fat file system 1.01 final
Htcia   an introduction to the microsoft ex fat file system 1.01 finalHtcia   an introduction to the microsoft ex fat file system 1.01 final
Htcia an introduction to the microsoft ex fat file system 1.01 final
 
File management
File managementFile management
File management
 
File management ppt
File management pptFile management ppt
File management ppt
 
Operating Systems - File Management
Operating Systems -  File ManagementOperating Systems -  File Management
Operating Systems - File Management
 
Ch11: File System Interface
Ch11: File System InterfaceCh11: File System Interface
Ch11: File System Interface
 
Intermediate Operating Systems
Intermediate Operating SystemsIntermediate Operating Systems
Intermediate Operating Systems
 
Deepak's green computing
Deepak's green computingDeepak's green computing
Deepak's green computing
 
Linked allocation 48
Linked  allocation 48Linked  allocation 48
Linked allocation 48
 
File System and File allocation tables
File System and File allocation tablesFile System and File allocation tables
File System and File allocation tables
 
Overview of System Virtualization
Overview of System VirtualizationOverview of System Virtualization
Overview of System Virtualization
 
File management
File managementFile management
File management
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating system
 
File system
File systemFile system
File system
 

Similar to File implementation

Ch12 OS
Ch12 OSCh12 OS
Ch12 OS
C.U
 
Query processing and optimization
Query processing and optimizationQuery processing and optimization
Query processing and optimization
Arif A.
 

Similar to File implementation (20)

File System Implementation.pptx
File System Implementation.pptxFile System Implementation.pptx
File System Implementation.pptx
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashing
 
Chapter13
Chapter13Chapter13
Chapter13
 
Ch11
Ch11Ch11
Ch11
 
OS_Ch12
OS_Ch12OS_Ch12
OS_Ch12
 
OSCh12
OSCh12OSCh12
OSCh12
 
Ch12 OS
Ch12 OSCh12 OS
Ch12 OS
 
Query processing and optimization
Query processing and optimizationQuery processing and optimization
Query processing and optimization
 
File Allocation Methods.ppt
File Allocation Methods.pptFile Allocation Methods.ppt
File Allocation Methods.ppt
 
6 chapter 6 record storage and primary file organization
6 chapter 6  record storage and primary file organization6 chapter 6  record storage and primary file organization
6 chapter 6 record storage and primary file organization
 
file management_part2_os_notes.ppt
file management_part2_os_notes.pptfile management_part2_os_notes.ppt
file management_part2_os_notes.ppt
 
OS_Assignment for Disk Space & File System & File allocation table(FAT)
OS_Assignment for Disk Space & File System & File allocation table(FAT)OS_Assignment for Disk Space & File System & File allocation table(FAT)
OS_Assignment for Disk Space & File System & File allocation table(FAT)
 
File System Implementation
File System ImplementationFile System Implementation
File System Implementation
 
Updates
UpdatesUpdates
Updates
 
Updates
UpdatesUpdates
Updates
 
File Access & File System & File Allocation Table
File Access & File System & File Allocation TableFile Access & File System & File Allocation Table
File Access & File System & File Allocation Table
 
Free Space Management, Efficiency & Performance, Recovery and NFS
Free Space Management, Efficiency & Performance, Recovery and NFSFree Space Management, Efficiency & Performance, Recovery and NFS
Free Space Management, Efficiency & Performance, Recovery and NFS
 
File Management.ppt
File Management.pptFile Management.ppt
File Management.ppt
 
Ch12_OS_Lecture 5.pdf
Ch12_OS_Lecture 5.pdfCh12_OS_Lecture 5.pdf
Ch12_OS_Lecture 5.pdf
 
Plam15 slides.potx
Plam15 slides.potxPlam15 slides.potx
Plam15 slides.potx
 

More from Mohd Arif

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcp
Mohd Arif
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
Mohd Arif
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
Mohd Arif
 
Project identification
Project identificationProject identification
Project identification
Mohd Arif
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniques
Mohd Arif
 
Presentation
PresentationPresentation
Presentation
Mohd Arif
 
Pointers in c
Pointers in cPointers in c
Pointers in c
Mohd Arif
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peer
Mohd Arif
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systems
Mohd Arif
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
Mohd Arif
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgeting
Mohd Arif
 
Network management
Network managementNetwork management
Network management
Mohd Arif
 
Networing basics
Networing basicsNetworing basics
Networing basics
Mohd Arif
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platform
Mohd Arif
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
Mohd Arif
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psec
Mohd Arif
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardware
Mohd Arif
 

More from Mohd Arif (20)

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcp
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
Project identification
Project identificationProject identification
Project identification
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniques
 
Presentation
PresentationPresentation
Presentation
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peer
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systems
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgeting
 
Network management
Network managementNetwork management
Network management
 
Networing basics
Networing basicsNetworing basics
Networing basics
 
Loaders
LoadersLoaders
Loaders
 
Lists
ListsLists
Lists
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platform
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psec
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardware
 
Heap sort
Heap sortHeap sort
Heap sort
 

Recently uploaded

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 

File implementation

  • 1. Part III Storage Management Chapter 11: File System Implementation
  • 3. Overview: 1/4 qA file system has on-disk and in-memory information. qA disk may contain the following for implementing a file system on it: vA boot control block per volume vA partition control block per volume vA directory structure per file system vA file control block per file qIn-memory information include vAn in-memory partition table vAn in-memory directory structure vThe system-wide open-file table vThe per-process open-file table
  • 4. Overview: 2/4 a typical file control block FCB qA FCB, file control block, contains the file permission details of a file. file date qIn Unix, a FCB is file owner, group, ACL called an i-node. file size file data blocks
  • 5. Overview: 3/4 3: read the directory 4: update FCB and directory kernel memory disk memory user program open(filename) directory structure directory structure 1: create a new file FCB 5: a file descriptor/file handle is returned 2: allocate a new FCB
  • 6. Overview: 4/4 index kernel memory disk memory user program per-process open-file table Data blocks read(index) system-wide open-file table FCB
  • 7. Directory Implementation qA File directory is usually implemented as a linked-list or a tree (e.g., B-tree), a hash table with chaining, or the combination of both. qThe problem with the linked-list approach is the poor performance in searching for a file. Directory search is a very frequently performed operation. qThe hash table approach speeds up search; however, we must deal with the problem of collisions. Thus, chaining is necessary.
  • 8. Directory Entries: 1/2 qA directory is simply a file! qA directory entry may be very simple like the one used by MS-DOS. Or, it may be quite complex like the Unix i-node. extended MS-DOS directory entry used in Windows 98
  • 9. Directory Entries: 2/2 Unix directory entry find /usr/ast/mbox
  • 10. File Allocation Methods qThere are three typical file space allocation methods: vContiguous Allocation vLinked Allocation vIndexed Allocation
  • 11. Contiguous Allocation: 1/3 qWith the contiguous allocation method, a user must indicate the file size before creating the file. qThen, the operating system searches the disk to find contiguous disk blocks for the file. qThe directory entry is easy. It contains the initial disk address of this file and the number of disk blocks. qTherefore, if the initial address is b and the number of blocks is n, the file will occupy blocks b, b+1, b+2, …, b+n-1.
  • 12. Contiguous Allocation: 2/3 directory Since blocks are allocated contiguously, external fragmentation may occur. Thus, compaction may be needed.
  • 13. Contiguous Allocation: 3/3 qContiguous allocation is easy to implement. qIts disadvantages are vIt can be considered as a form of dynamic memory allocation, and external fragmentation may occur and compaction may be needed. vIt is difficult to estimate the file size. The size of a file may grow at run time and may be larger than the specified number of allocated blocks. In this case, the OS must move the blocks in order to provide mode space. In some systems, this is simply an error.
  • 14. Linked Allocation: 1/3 qWith the linked allocation approach, disk blocks of a file are chained together with a linked-list. qThe directory entry of a file contains a pointer to the first block and a pointer to the last block. qTo create a file, we create a new directory entry and the pointers are initialized to nil. qWhen a write occurs, a new disk block is allocated and chained to the end of the list.
  • 15. Linked Allocation: 2/3 directory 28 Last Block qFile blocks are chained into a linked-list. qThe directory entry has pointers to the first and last file blocks. qAppend is difficult to do without the last pointer.
  • 16. Linked Allocation: 3/3 qAdvantages: vFile size does not have to be specified. vNo external fragmentation. qDisadvantages: vIt does sequential access efficiently and is not for direct access vEach block contains a pointer, wasting space vBlocks scatter everywhere and a large number of disk seeks may be necessary vReliability: what if a pointer is lost or damaged?
  • 17. File Allocation Table (FAT) FAT 0 q This is a variation of the linked allocation by pulling all pointers into a 217 618 table, the file allocation directory table (FAT). test q Large no. of disk seeks. 339 end-of-file q Can do direct access. q FAT needs space. 217 q The left diagram shows 618 339 file test has its first block at 217, followed by 618, 339 (end of file). no. of blocks-1 q What if FAT is damaged? We all know it well!
  • 18. Indexed Allocation: 1/4 qEach file has an index block that is an array of disk block addresses. qThe i-th entry in the index block points to the i-th block of the file. qA file’s directory entry contains a pointer to its index. Hence, the index block of an indexed allocation plays the same role as the page table. qIndex allocation supports both sequential and direct access without external fragmentation.
  • 19. Indexed Allocation: 2/4 directory index block
  • 20. Indexed Allocation: 3/4 qThe indexed allocation suffers from wasted space. The index block may not be fully used (i.e., internal fragmentation). qThe number of entries of an index table determines the size of a file. To overcome this problem, we can vHave multiple index blocks and chain them into a linked-list vHave multiple index blocks, but make them a tree just like the indexed access method vA combination of both
  • 21. Indexed Allocation: 4/4 i-node 10 direct blocks 256 entries per index table. What is the maximum size of a file?
  • 22. Free Space Management qHow do we keep track free blocks on a disk? qA free-list is maintained. When a new block is requested, we search this list to find one. qThe following are commonly used techniques: vBit Vector vLinked List vLinked List + Grouping vLinked List+Address+Count
  • 23. Bit Vector qEach block is represented by a bit in a table. Thus, if there are n disk blocks, the table has n bits. qIf a block is free, its corresponding bit is 1. qWhen a block is needed, the table is searched. If a 1 bit is found in position k, block k is free. qIf the disk capacity is small, the whole bit vector can be stored in memory. For a large disk, this bit vector will consume too much memory. qWe could group a few blocks into a cluster and allocate clusters. This saves space and may cause internal fragmentation. qAnother possibility is the use of a summary table.
  • 24. Linked List qLike the linked allocation method, free blocks can be chained into a linked list. qWhen a free block is needed, the first in the chain is allocated. qHowever, this method has the same disadvantages of the linked allocation method. qWe can use a FAT for the disk and chain the free block pointers together. Keep in mind that the FAT may be very large and consume space if it is stored in memory.
  • 25. Grouping qThe first free block contains the addresses of n other free blocks. qFor each group, the first n-1 blocks are actually free and the last (i.e., n-th) block contains the addresses of the next group. qIn this way, we can quickly locate free blocks. 3 8 50 3 6 (3 & 8 are free) 8 12 20 50 (6 & 12 are free) 6 12 20
  • 26. Address + Counting qWe can make the list short with the following trick: vBlocks are often allocated and freed in groups vWe can store the address of the first free block and the number of the following n free blocks. free block list 5 3 disk