SlideShare a Scribd company logo
1 of 4
Download to read offline
Reading
                                                                                                 • Peterson and Silbershatz: 8.3-8.7

                                                                                                 • Peterson, Silbershatz and Galvin: 9.3-9.10
                          File Structure
                                                                                                 • Silbershatz and Galvin: 11.1-11.3, 11.5, 12.1-12.6, 13.1-
                                                                                                   13.3
                                      Steve Martin
                                      Dave Latham                                                • Dietel, pp. 305-316, 322-336

                                                                                                 • Tannenbaum: 6.1-6.3

  Copyright note: figures and some elements from slides by Hank Levy, CSE451, University of
                                Washington. Thank you, Hank!
                                                                                                 • Silbershatz, Galvin, and Gagne: 11, 12




 Review: physical disk structure                                                                                      What is a File?
• Disk components                                                                                • A named collection of bits, usually stored on a disk, with some
                                                                                                   properties
   –   platters
                                                                                                     – contents, size, owner, last read/write time, protection, type…
   –   surfaces
                                                                     sector
   –   tracks                                    track                                           • From the OS’s standpoint, a file is a bunch of disk blocks on a
   –   sectors                                                                                     secondary storage device.
   –   cylinders                                                                                     – Even if the file is used at a higher level of abstraction (records,
                                                                                       surface
                                                                                                       bytestreams), this doesn’t matter to the file management system.
   –   arm
   –   heads                                                                                     • A file’s type can be encoded in the file’s name or contents
                           cylinder
                                                                                                     – Windows encodes type in name
                                                                                                        • .com, .exe, .bat, .dll, .jpg, .mov, .mp3, …
                           platter                                                                   – Unix has a smattering of both
                                                                                       arm
                                                                                                        • in content via magic numbers or initial characters (e.g., #!)
                                                                         head
                                                                                                 • Files are managed by the file system




               Basic file operations                                                                           File access methods
 Unix                                           Windows NT                                       • Some file systems provide different access methods that specify
 • create(name)                                 • CreateFile(name, CREATE)                         ways the application will access data
 • open(name, mode)                             • CreateFile(name, OPEN)
                                                                                                 • Sequential access
 • read(fd, buf, len)                           • ReadFile(handle, …)                                – Read bytes one at a time, in order
 • write(fd, buf, len)                          • WriteFile(handle, …)                               – This is the most common mode.

 • sync(fd)                                     • FlushFileBuffers(handle, …)
                                                                                                 • Random access
 • seek(fd, pos)                                • SetFilePointer(handle, …)                          – Random access given a block/byte #
 • close(fd)                                    • CloseHandle(handle, …)                             – Examples: data set for demand paging, libraries, databases. . .
 • unlink(name)                                 • DeleteFile(name)
                                                                                                 • Keyed/Indexed access
 • rename(old, new)                             • CopyFile(name)
                                                                                                     – FS contains an index to a particular field of each record in a file
                                                • MoveFile(name)                                     – Apps can find a file based on value in that record (similar to DB)
                                                                                                     – Can be considered a form of random access




                                                                                                                                                                             1
Directories                                                               Directories (2)
• Directories provide:                                                       • Let’s say you want to open “/one/two/three” in Unix
                                                                                 fd = open(“/one/two/three”, O_RDWR);
    – A way for users to organize their files
    – A convenient file name space for both users and FS’s
                                                                             • What goes on inside the Unix file system?
                                                                                 –   Open directory “/” (well known, can always find)
• Most file systems support multi-level directories                              –   Search the directory for “one”, get location of “one”
    – Naming hierarchies (/, /usr, /usr/local, /usr/local/bin, …)                –   Open directory “one”, search for “two”, get location of “two”
                                                                                 –   Open directory “two”, search for “three”, get loc. of “three”
• Most file systems support the notion of current directory                      –   Open file “three”
                                                                                 –   Permissions are checked at each step

• A directory is typically just a file that contains special metadata
                                                                             • Unix FS spends lots of time walking down directory paths
    – Directory = list of (name of file, file attributes)
                                                                                 – This is why open is separate from read/write (session state)
    – Attributes include such things as:
                                                                                 – OS will cache prefix lookups to enhance performance
       • Size, protection, location on disk, creation time, access time, …          • /a/b, /a/bb, /a/bbb all share the “/a” prefix




                File System Issues                                                    Disk Management Issues
• Disk Management                                                            • How should the blocks of a file be placed on disk?
    – Make efficient use of disk space                                           – How should files be organized for best performance?
    – Fast access to files
    – Provide hardware independent view of disk to user (and somewhat, to
      OS also)                                                               • How should the map to find and access the blocks in a file look?
• Naming
    – How do users refer to files? (directories, links, etc)                 • Must take into account user and file characteristics
                                                                                 –   Most files are small, especially in Unix
• Protection                                                                     –   A large proportion of the disk is allocated to a few large files.
    – Want to protect users from each other                                      –   Many I/O operations are made to large files
    – Want to have files from various users on same disk
                                                                                 –   Most file I/O operations (60-80%) are reads
    – Want to permit controlled sharing
                                                                                 –   Most file I/O operations are sequential
• Reliability
    – Information must be persistent—must last safely for long periods of    • From the above characteristics, per-file cost must be low but large
      time.
                                                                               files must have good performance.




   File Block Layout and Access                                                            Contiguous Allocation
• File Descriptors                                                           • Contiguous allocation
    – Data structure that stores:
                                                                                 – Allocate file in contiguous set of blocks or tracks
        • file attributes
        • map which tells you where the blocks of your file are.                    • When creating a file, make user specify length and allocate
    – Stored on disk along with the files                                              all at once, record in file descriptor.
    – In Unix, called inodes                                                     – Keep a ‘free list’ of unused areas of the disk
    – Don’t get confused from Nachos!
                                                                             • What are some advantages of this scheme?
• File block layout and access
    – Contiguous
    – Linked                                                                 • Disadvantages?
    – Index or tree structured

• This is just standard data structures stuff, only on disk
    – Pointers now point to blocks instead of addresses in memory




                                                                                                                                                         2
Contiguous Allocation (2)                                                             Linked Allocation
• Contiguous allocation advantages                                           • Linked Allocation
   –   Sequential and random access are easy
                                                                                – Link the blocks of the file together as a linked list.
   –   Low overhead
   –   Simple                                                                   – In file descriptor, just keep pointer to first block.
   –   Few seeks                                                                – In each block of file keep pointer to next block.
   –   Very good sequential access performance
                                                                             • Advantages?
• Disadvantages:
   –   Horrible fragmentation!
   –   Hard to predict needs at file creation time                           • Disadvantages?
   –   May over-allocate
   –   Hard to enlarge files

• Can improve this scheme by allocating in fixed contiguous blocks
  called extents—i.e. if one block isn't enough, ask for another
   – Does this sort of fix sound familiar?




              Linked Allocation (2)                                                         Indexed Allocation
• Advantages of linked file allocation:                                      • (Simple) Indexed allocation
   – Files can be extended easily                                               – Keep array of block pointers for each file
   – No external fragmentation problem                                          – File maximum length must be declared at creation time
   – Sequential access is easy—just chase links!                                – Allocate an array to hold pointers to all blocks
                                                                                   • But don’t allocate blocks
• Disadvantages:                                                                – Fill in the pointers dynamically using a free list of open blocks.
   – How can we do random access?
   – Lots of seeking, blocks are likely not laid on the disk right next to   • Advantages?
     one another
      • Why is this bad?
                                                                             • Disadvantages?
   – Some overhead in each block for link.




            Indexed Allocation (2)                                              Multi-level Indexed Allocation
• Advantages of indexed file allocation:                                     • This is the VAX Unix solution.
   – Not as much space wasted by over predicting                                – In general, any sort of multi-level treelike structure. Specifically,
      • Why?                                                                      what we will describe is what Berkeley 4.3 BSD Unix does.
   – Sequential and random access are easy
   – Only waste space in index                                               • Each file descriptor contains file properties and 15
                                                                               pointers.
• Disadvantages                                                                 – First 12 point to data blocks
   – Still have to set maximum file size                                        – Next three to indirect, doubly-indirect, and triply-indirect blocks
       • Can have overflow scheme if file is larger than predicted                 • 256 pointers in each block
   – Blocks are probably allocated all over disk, so will have lots of          – Descriptor space isn’t allocated until needed
     seeks.
   – Index array may be large
                                                                             • File is a tree of pointers to blocks.
       • Requires a large file descriptor, more overhead.




                                                                                                                                                          3
Indexed allocation example                                                       Multi-level Indexed Allocation (2)
• Create a ‘tree’ of block pointers to find all the blocks of a                     • Advantages of Multi-level Indexed Allocation
                                                                                        –   Simple
  given file:                                                                           –   Easy to implement
                                                                                        –   Incremental expansion
                                                                                        –   Easy access to small files
            0                                                                                 • Why?
                                       …
            1                                                                           –   Good random access to blocks




                                                        …
                                                                                        –   Easy to insert blocks in the middle of file
                …




                                                                                        –   Easy to append to file
           12
                                                                                        –   Small file map
                                …




           13
           14




                                                               …
                                                …


                                                                                    • Disadvantages
                            …




                                                                                        – Maximum file size is still fixed, although it is large
                                                                                        – Indirect mechanism isn’t efficient for large files
                                                                                            • Three descriptor ops for each operation
                                                                                        – File usually isn’t allocated continuously, so need to seek between
                                                                                          blocks.




    How do we find a free block?                                                    How do we find a free block? (2)
• If all blocks are the same size, can use bit map                                  • A more efficient solution
    – One bit per disk block, cache parts of map in memory                              – Allocate groups of sequential blocks
                                                                                        – Use multi-level index scheme, except each pointer is to a sequence of
• If blocks are variable size, use free list                                              free blocks on disk.
    – Requires free storage area management
       • Fragmentation and compaction                                               • When we need a free block, try to allocate next physical block on
                                                                                      track (or in cylinder)
• In Unix, blocks are grouped for efficiency
    – Each block in free list contains pointers to many free blocks, plus pointer
      to next block on list.                                                        • If we have detected a sequence of sequential writes, grab a group of
    – Aren’t many references involved in allocation or de-allocation                  blocks at a time, and release them later if unused
                                                                                        – Size of group depends on number of sequential writes we’ve seen so
• Organization of free list means files get spread to different blocks all                far.
  over disk.
    – Why is this bad?                                                              • Keep part of disk unallocated always to maximize probability of
                                                                                      finding a sequential block to allocate.




                                                                                                                                                                  4

More Related Content

Viewers also liked (7)

File structure
File structureFile structure
File structure
 
storage and file structure
storage and file structurestorage and file structure
storage and file structure
 
Discussion : File structure of Meteor Apps
Discussion : File structure of Meteor AppsDiscussion : File structure of Meteor Apps
Discussion : File structure of Meteor Apps
 
File Structure Concepts
File Structure ConceptsFile Structure Concepts
File Structure Concepts
 
File organisation
File organisationFile organisation
File organisation
 
File structures
File structuresFile structures
File structures
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 

Similar to File structure

Microsoft power point chapter 5 file edited
Microsoft power point   chapter 5 file editedMicrosoft power point   chapter 5 file edited
Microsoft power point chapter 5 file edited
Linga Lgs
 
Unit3 browsing the filesystem
Unit3 browsing the filesystemUnit3 browsing the filesystem
Unit3 browsing the filesystem
root_fibo
 
2.7 Use of ICT in Data Management
2.7 Use of ICT in Data Management2.7 Use of ICT in Data Management
2.7 Use of ICT in Data Management
Momina Mateen
 

Similar to File structure (20)

Unix File System
Unix File SystemUnix File System
Unix File System
 
Os6
Os6Os6
Os6
 
5263802.ppt
5263802.ppt5263802.ppt
5263802.ppt
 
File System.pptx
File System.pptxFile System.pptx
File System.pptx
 
Workshop 3
Workshop 3Workshop 3
Workshop 3
 
10 File System
10 File System10 File System
10 File System
 
Windowsforensics
WindowsforensicsWindowsforensics
Windowsforensics
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
File system
File systemFile system
File system
 
The evolution of linux file system
The evolution of linux file systemThe evolution of linux file system
The evolution of linux file system
 
UNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptxUNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptx
 
ITFT_File system interface in Operating System
ITFT_File system interface in Operating SystemITFT_File system interface in Operating System
ITFT_File system interface in Operating System
 
Ch10 file system interface
Ch10   file system interfaceCh10   file system interface
Ch10 file system interface
 
Microsoft power point chapter 5 file edited
Microsoft power point   chapter 5 file editedMicrosoft power point   chapter 5 file edited
Microsoft power point chapter 5 file edited
 
Unit3 browsing the filesystem
Unit3 browsing the filesystemUnit3 browsing the filesystem
Unit3 browsing the filesystem
 
File System Interface
File System InterfaceFile System Interface
File System Interface
 
Introduction to the design and specification of file structures
Introduction to the design and specification of file structuresIntroduction to the design and specification of file structures
Introduction to the design and specification of file structures
 
File Management & Access Control
File Management & Access Control File Management & Access Control
File Management & Access Control
 
2.7 Use of ICT in Data Management
2.7 Use of ICT in Data Management2.7 Use of ICT in Data Management
2.7 Use of ICT in Data Management
 
File management
File managementFile management
File management
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Recently uploaded (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

File structure

  • 1. Reading • Peterson and Silbershatz: 8.3-8.7 • Peterson, Silbershatz and Galvin: 9.3-9.10 File Structure • Silbershatz and Galvin: 11.1-11.3, 11.5, 12.1-12.6, 13.1- 13.3 Steve Martin Dave Latham • Dietel, pp. 305-316, 322-336 • Tannenbaum: 6.1-6.3 Copyright note: figures and some elements from slides by Hank Levy, CSE451, University of Washington. Thank you, Hank! • Silbershatz, Galvin, and Gagne: 11, 12 Review: physical disk structure What is a File? • Disk components • A named collection of bits, usually stored on a disk, with some properties – platters – contents, size, owner, last read/write time, protection, type… – surfaces sector – tracks track • From the OS’s standpoint, a file is a bunch of disk blocks on a – sectors secondary storage device. – cylinders – Even if the file is used at a higher level of abstraction (records, surface bytestreams), this doesn’t matter to the file management system. – arm – heads • A file’s type can be encoded in the file’s name or contents cylinder – Windows encodes type in name • .com, .exe, .bat, .dll, .jpg, .mov, .mp3, … platter – Unix has a smattering of both arm • in content via magic numbers or initial characters (e.g., #!) head • Files are managed by the file system Basic file operations File access methods Unix Windows NT • Some file systems provide different access methods that specify • create(name) • CreateFile(name, CREATE) ways the application will access data • open(name, mode) • CreateFile(name, OPEN) • Sequential access • read(fd, buf, len) • ReadFile(handle, …) – Read bytes one at a time, in order • write(fd, buf, len) • WriteFile(handle, …) – This is the most common mode. • sync(fd) • FlushFileBuffers(handle, …) • Random access • seek(fd, pos) • SetFilePointer(handle, …) – Random access given a block/byte # • close(fd) • CloseHandle(handle, …) – Examples: data set for demand paging, libraries, databases. . . • unlink(name) • DeleteFile(name) • Keyed/Indexed access • rename(old, new) • CopyFile(name) – FS contains an index to a particular field of each record in a file • MoveFile(name) – Apps can find a file based on value in that record (similar to DB) – Can be considered a form of random access 1
  • 2. Directories Directories (2) • Directories provide: • Let’s say you want to open “/one/two/three” in Unix fd = open(“/one/two/three”, O_RDWR); – A way for users to organize their files – A convenient file name space for both users and FS’s • What goes on inside the Unix file system? – Open directory “/” (well known, can always find) • Most file systems support multi-level directories – Search the directory for “one”, get location of “one” – Naming hierarchies (/, /usr, /usr/local, /usr/local/bin, …) – Open directory “one”, search for “two”, get location of “two” – Open directory “two”, search for “three”, get loc. of “three” • Most file systems support the notion of current directory – Open file “three” – Permissions are checked at each step • A directory is typically just a file that contains special metadata • Unix FS spends lots of time walking down directory paths – Directory = list of (name of file, file attributes) – This is why open is separate from read/write (session state) – Attributes include such things as: – OS will cache prefix lookups to enhance performance • Size, protection, location on disk, creation time, access time, … • /a/b, /a/bb, /a/bbb all share the “/a” prefix File System Issues Disk Management Issues • Disk Management • How should the blocks of a file be placed on disk? – Make efficient use of disk space – How should files be organized for best performance? – Fast access to files – Provide hardware independent view of disk to user (and somewhat, to OS also) • How should the map to find and access the blocks in a file look? • Naming – How do users refer to files? (directories, links, etc) • Must take into account user and file characteristics – Most files are small, especially in Unix • Protection – A large proportion of the disk is allocated to a few large files. – Want to protect users from each other – Many I/O operations are made to large files – Want to have files from various users on same disk – Most file I/O operations (60-80%) are reads – Want to permit controlled sharing – Most file I/O operations are sequential • Reliability – Information must be persistent—must last safely for long periods of • From the above characteristics, per-file cost must be low but large time. files must have good performance. File Block Layout and Access Contiguous Allocation • File Descriptors • Contiguous allocation – Data structure that stores: – Allocate file in contiguous set of blocks or tracks • file attributes • map which tells you where the blocks of your file are. • When creating a file, make user specify length and allocate – Stored on disk along with the files all at once, record in file descriptor. – In Unix, called inodes – Keep a ‘free list’ of unused areas of the disk – Don’t get confused from Nachos! • What are some advantages of this scheme? • File block layout and access – Contiguous – Linked • Disadvantages? – Index or tree structured • This is just standard data structures stuff, only on disk – Pointers now point to blocks instead of addresses in memory 2
  • 3. Contiguous Allocation (2) Linked Allocation • Contiguous allocation advantages • Linked Allocation – Sequential and random access are easy – Link the blocks of the file together as a linked list. – Low overhead – Simple – In file descriptor, just keep pointer to first block. – Few seeks – In each block of file keep pointer to next block. – Very good sequential access performance • Advantages? • Disadvantages: – Horrible fragmentation! – Hard to predict needs at file creation time • Disadvantages? – May over-allocate – Hard to enlarge files • Can improve this scheme by allocating in fixed contiguous blocks called extents—i.e. if one block isn't enough, ask for another – Does this sort of fix sound familiar? Linked Allocation (2) Indexed Allocation • Advantages of linked file allocation: • (Simple) Indexed allocation – Files can be extended easily – Keep array of block pointers for each file – No external fragmentation problem – File maximum length must be declared at creation time – Sequential access is easy—just chase links! – Allocate an array to hold pointers to all blocks • But don’t allocate blocks • Disadvantages: – Fill in the pointers dynamically using a free list of open blocks. – How can we do random access? – Lots of seeking, blocks are likely not laid on the disk right next to • Advantages? one another • Why is this bad? • Disadvantages? – Some overhead in each block for link. Indexed Allocation (2) Multi-level Indexed Allocation • Advantages of indexed file allocation: • This is the VAX Unix solution. – Not as much space wasted by over predicting – In general, any sort of multi-level treelike structure. Specifically, • Why? what we will describe is what Berkeley 4.3 BSD Unix does. – Sequential and random access are easy – Only waste space in index • Each file descriptor contains file properties and 15 pointers. • Disadvantages – First 12 point to data blocks – Still have to set maximum file size – Next three to indirect, doubly-indirect, and triply-indirect blocks • Can have overflow scheme if file is larger than predicted • 256 pointers in each block – Blocks are probably allocated all over disk, so will have lots of – Descriptor space isn’t allocated until needed seeks. – Index array may be large • File is a tree of pointers to blocks. • Requires a large file descriptor, more overhead. 3
  • 4. Indexed allocation example Multi-level Indexed Allocation (2) • Create a ‘tree’ of block pointers to find all the blocks of a • Advantages of Multi-level Indexed Allocation – Simple given file: – Easy to implement – Incremental expansion – Easy access to small files 0 • Why? … 1 – Good random access to blocks … – Easy to insert blocks in the middle of file … – Easy to append to file 12 – Small file map … 13 14 … … • Disadvantages … – Maximum file size is still fixed, although it is large – Indirect mechanism isn’t efficient for large files • Three descriptor ops for each operation – File usually isn’t allocated continuously, so need to seek between blocks. How do we find a free block? How do we find a free block? (2) • If all blocks are the same size, can use bit map • A more efficient solution – One bit per disk block, cache parts of map in memory – Allocate groups of sequential blocks – Use multi-level index scheme, except each pointer is to a sequence of • If blocks are variable size, use free list free blocks on disk. – Requires free storage area management • Fragmentation and compaction • When we need a free block, try to allocate next physical block on track (or in cylinder) • In Unix, blocks are grouped for efficiency – Each block in free list contains pointers to many free blocks, plus pointer to next block on list. • If we have detected a sequence of sequential writes, grab a group of – Aren’t many references involved in allocation or de-allocation blocks at a time, and release them later if unused – Size of group depends on number of sequential writes we’ve seen so • Organization of free list means files get spread to different blocks all far. over disk. – Why is this bad? • Keep part of disk unallocated always to maximize probability of finding a sequential block to allocate. 4