SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler 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

Mais conteúdo relacionado

Destaque

storage and file structure
storage and file structurestorage and file structure
storage and file structureSheshan Sheniwal
 
Discussion : File structure of Meteor Apps
Discussion : File structure of Meteor AppsDiscussion : File structure of Meteor Apps
Discussion : File structure of Meteor AppsSangwon Lee
 
File Structure Concepts
File Structure ConceptsFile Structure Concepts
File Structure ConceptsDileep Kodira
 
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 DBMSkoolkampus
 

Destaque (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
 

Semelhante a File structure

The evolution of linux file system
The evolution of linux file systemThe evolution of linux file system
The evolution of linux file systemGang He
 
UNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptxUNIT7-FileMgmt.pptx
UNIT7-FileMgmt.pptxNavyaKumar22
 
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 SystemSneh Prabha
 
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 editedLinga Lgs
 
Unit3 browsing the filesystem
Unit3 browsing the filesystemUnit3 browsing the filesystem
Unit3 browsing the filesystemroot_fibo
 
File System Interface
File System InterfaceFile System Interface
File System Interfacechandinisanz
 
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 structuresDevyani Vaidya
 
File Management & Access Control
File Management & Access Control File Management & Access Control
File Management & Access Control YuvrajWadavale
 
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 ManagementMomina Mateen
 

Semelhante a 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
 

Último

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
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 FellowsMebane Rash
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
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...Poonam Aher Patil
 

Último (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
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