Download - File System Implementation - Part1
![Page 1: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/1.jpg)
File System Implementation (Part I)
Amir H. [email protected]
Amirkabir University of Technology(Tehran Polytechnic)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 1 / 57
![Page 2: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/2.jpg)
Motivation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 2 / 57
![Page 3: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/3.jpg)
Motivation
I The file system resides permanently on secondary storage.
I How to• structure file use• allocate disk space• recover free space• track the locations of data• interface other parts of the OS to secondary storage
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 3 / 57
![Page 4: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/4.jpg)
File System Structure
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 4 / 57
![Page 5: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/5.jpg)
File-System Structure
I Disk provides in-place rewrite and random access• I/O transfers performed in blocks of sectors (usually 512 bytes)
I File system resides on secondary storage• User interface to storage, mapping logical to physical• Efficient and convenient access to disk
I File structure• Logical storage unit• Collection of related information
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 5 / 57
![Page 6: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/6.jpg)
File-System Structure
I Disk provides in-place rewrite and random access• I/O transfers performed in blocks of sectors (usually 512 bytes)
I File system resides on secondary storage• User interface to storage, mapping logical to physical• Efficient and convenient access to disk
I File structure• Logical storage unit• Collection of related information
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 5 / 57
![Page 7: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/7.jpg)
File-System Structure
I Disk provides in-place rewrite and random access• I/O transfers performed in blocks of sectors (usually 512 bytes)
I File system resides on secondary storage• User interface to storage, mapping logical to physical• Efficient and convenient access to disk
I File structure• Logical storage unit• Collection of related information
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 5 / 57
![Page 8: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/8.jpg)
File-System Design Problems
I How the file system should look to the user?
• Defining a file and its attributes• The operations allowed on a file• The directory structure for organizing files
I Algorithms and data structures to map the logical file system ontothe physical secondary-storage devices.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 6 / 57
![Page 9: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/9.jpg)
File-System Design Problems
I How the file system should look to the user?• Defining a file and its attributes• The operations allowed on a file• The directory structure for organizing files
I Algorithms and data structures to map the logical file system ontothe physical secondary-storage devices.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 6 / 57
![Page 10: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/10.jpg)
File-System Design Problems
I How the file system should look to the user?• Defining a file and its attributes• The operations allowed on a file• The directory structure for organizing files
I Algorithms and data structures to map the logical file system ontothe physical secondary-storage devices.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 6 / 57
![Page 11: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/11.jpg)
File System Layers (1/6)
I Different levels
I Each level uses the features of lowerlevels to create new features for useby higher levels.
I Reducing complexity and redundancy,but adds overhead and can decreaseperformance.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 7 / 57
![Page 12: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/12.jpg)
File System Layers (2/6)
I Device drivers manage I/O devicesat the I/O control layer.
I Translates high-level commands tolow-level hardware-specific instructions.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 8 / 57
![Page 13: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/13.jpg)
File System Layers (3/6)
I Basic file system translates given commandlike retrieve block 123 to device driver.
I Also manages memory buffers andcaches (allocation, freeing, replacement)
• Buffers hold data in transit• Caches hold frequently used data
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 9 / 57
![Page 14: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/14.jpg)
File System Layers (3/6)
I Basic file system translates given commandlike retrieve block 123 to device driver.
I Also manages memory buffers andcaches (allocation, freeing, replacement)
• Buffers hold data in transit• Caches hold frequently used data
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 9 / 57
![Page 15: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/15.jpg)
File System Layers (4/6)
I File organization understands files, logicaladdress, and physical blocks.
I Translates logical block number to physicalblock number.
I Manages free space and disk allocation.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 10 / 57
![Page 16: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/16.jpg)
File System Layers (4/6)
I File organization understands files, logicaladdress, and physical blocks.
I Translates logical block number to physicalblock number.
I Manages free space and disk allocation.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 10 / 57
![Page 17: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/17.jpg)
File System Layers (4/6)
I File organization understands files, logicaladdress, and physical blocks.
I Translates logical block number to physicalblock number.
I Manages free space and disk allocation.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 10 / 57
![Page 18: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/18.jpg)
File System Layers (5/6)
I Logical file system manages metadatainformation.
I Translates file name into file number, filehandle, location by maintaining filecontrol blocks (inodes in Unix)
I Directory management
I Protection
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 11 / 57
![Page 19: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/19.jpg)
File System Layers (5/6)
I Logical file system manages metadatainformation.
I Translates file name into file number, filehandle, location by maintaining filecontrol blocks (inodes in Unix)
I Directory management
I Protection
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 11 / 57
![Page 20: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/20.jpg)
File System Layers (5/6)
I Logical file system manages metadatainformation.
I Translates file name into file number, filehandle, location by maintaining filecontrol blocks (inodes in Unix)
I Directory management
I Protection
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 11 / 57
![Page 21: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/21.jpg)
File System Layers (6/6)
I Many file systems, sometimes many within an OS
I Each with its own format• CD-ROM: ISO 9660• Unix: UFS, FFS• Windows: FAT, FAT32, NTFS• Linux: more than 40 types, with extended file system (ext2, ext3,
ext4)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 12 / 57
![Page 22: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/22.jpg)
File System Implementation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 13 / 57
![Page 23: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/23.jpg)
File-System Implementation
I Based on several on-disk and in-memory structures.
I On-disk• Boot control block (per volume)• Volume control block (per volume)• Directory structure (per file system)• File control block (per file)
I In-memory• Mount table• Directory structure cache• The open-file table (system-wide and per process)• Buffers of the file-system blocks
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 14 / 57
![Page 24: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/24.jpg)
File-System Implementation
I Based on several on-disk and in-memory structures.
I On-disk• Boot control block (per volume)• Volume control block (per volume)• Directory structure (per file system)• File control block (per file)
I In-memory• Mount table• Directory structure cache• The open-file table (system-wide and per process)• Buffers of the file-system blocks
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 14 / 57
![Page 25: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/25.jpg)
File-System Implementation
I Based on several on-disk and in-memory structures.
I On-disk• Boot control block (per volume)• Volume control block (per volume)• Directory structure (per file system)• File control block (per file)
I In-memory• Mount table• Directory structure cache• The open-file table (system-wide and per process)• Buffers of the file-system blocks
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 14 / 57
![Page 26: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/26.jpg)
On-Disk File System Structures (1/2)
I Boot control block contains information needed by system to bootOS from that volume.
• Needed if volume contains OS, usually first block of volume.• In UFS, it is called boot block, and in NTFS partition boot sector.
I Volume control block contains volume details.
• Total num. of blocks, num. of free blocks, block size, free blockpointers or array
• In UFS, it is called super block, and in NTFS master file table.
UFS on-disk structures
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 15 / 57
![Page 27: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/27.jpg)
On-Disk File System Structures (1/2)
I Boot control block contains information needed by system to bootOS from that volume.
• Needed if volume contains OS, usually first block of volume.• In UFS, it is called boot block, and in NTFS partition boot sector.
I Volume control block contains volume details.
• Total num. of blocks, num. of free blocks, block size, free blockpointers or array
• In UFS, it is called super block, and in NTFS master file table.
UFS on-disk structures
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 15 / 57
![Page 28: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/28.jpg)
On-Disk File System Structures (1/2)
I Boot control block contains information needed by system to bootOS from that volume.
• Needed if volume contains OS, usually first block of volume.• In UFS, it is called boot block, and in NTFS partition boot sector.
I Volume control block contains volume details.
• Total num. of blocks, num. of free blocks, block size, free blockpointers or array
• In UFS, it is called super block, and in NTFS master file table.
UFS on-disk structures
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 15 / 57
![Page 29: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/29.jpg)
On-Disk File System Structures (1/2)
I Boot control block contains information needed by system to bootOS from that volume.
• Needed if volume contains OS, usually first block of volume.• In UFS, it is called boot block, and in NTFS partition boot sector.
I Volume control block contains volume details.• Total num. of blocks, num. of free blocks, block size, free block
pointers or array• In UFS, it is called super block, and in NTFS master file table.
UFS on-disk structures
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 15 / 57
![Page 30: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/30.jpg)
On-Disk File System Structures (2/2)
I Directory structure organizes the files.• In UFS, this includes file names and associated inode numbers.• In NTFS, it is stored in the master file table.
I File control block contains many details about the file.• In UFS, inode number, permissions, size, dates.• In NFTS stores into in master file table.
File Control Block (FCB)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 16 / 57
![Page 31: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/31.jpg)
On-Disk File System Structures (2/2)
I Directory structure organizes the files.• In UFS, this includes file names and associated inode numbers.• In NTFS, it is stored in the master file table.
I File control block contains many details about the file.• In UFS, inode number, permissions, size, dates.• In NFTS stores into in master file table.
File Control Block (FCB)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 16 / 57
![Page 32: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/32.jpg)
In-Memory File System Structures
I Mount table contains information about each mounted volume.
I Directory structure cache holds the directory information of recentlyaccessed directories.
I System-wide open-file table contains a copy of the FCB of each openfile.
I Per-process open-file table contains a pointer to the appropriateentry in the system-wide open-file table.
I Buffers hold file-system blocks when they are being read from diskor written to disk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 17 / 57
![Page 33: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/33.jpg)
In-Memory File System Structures
I Mount table contains information about each mounted volume.
I Directory structure cache holds the directory information of recentlyaccessed directories.
I System-wide open-file table contains a copy of the FCB of each openfile.
I Per-process open-file table contains a pointer to the appropriateentry in the system-wide open-file table.
I Buffers hold file-system blocks when they are being read from diskor written to disk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 17 / 57
![Page 34: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/34.jpg)
In-Memory File System Structures
I Mount table contains information about each mounted volume.
I Directory structure cache holds the directory information of recentlyaccessed directories.
I System-wide open-file table contains a copy of the FCB of each openfile.
I Per-process open-file table contains a pointer to the appropriateentry in the system-wide open-file table.
I Buffers hold file-system blocks when they are being read from diskor written to disk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 17 / 57
![Page 35: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/35.jpg)
In-Memory File System Structures
I Mount table contains information about each mounted volume.
I Directory structure cache holds the directory information of recentlyaccessed directories.
I System-wide open-file table contains a copy of the FCB of each openfile.
I Per-process open-file table contains a pointer to the appropriateentry in the system-wide open-file table.
I Buffers hold file-system blocks when they are being read from diskor written to disk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 17 / 57
![Page 36: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/36.jpg)
In-Memory File System Structures
I Mount table contains information about each mounted volume.
I Directory structure cache holds the directory information of recentlyaccessed directories.
I System-wide open-file table contains a copy of the FCB of each openfile.
I Per-process open-file table contains a pointer to the appropriateentry in the system-wide open-file table.
I Buffers hold file-system blocks when they are being read from diskor written to disk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 17 / 57
![Page 37: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/37.jpg)
Create a File
I A program calls the logical file system.
I The logical file system knows the format of the directory structures,and allocates a new FCB.
I The system, then, reads the appropriate directory into memory, up-dates it with the new file name and FCB, and writes it back to thedisk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 18 / 57
![Page 38: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/38.jpg)
Create a File
I A program calls the logical file system.
I The logical file system knows the format of the directory structures,and allocates a new FCB.
I The system, then, reads the appropriate directory into memory, up-dates it with the new file name and FCB, and writes it back to thedisk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 18 / 57
![Page 39: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/39.jpg)
Create a File
I A program calls the logical file system.
I The logical file system knows the format of the directory structures,and allocates a new FCB.
I The system, then, reads the appropriate directory into memory, up-dates it with the new file name and FCB, and writes it back to thedisk.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 18 / 57
![Page 40: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/40.jpg)
Open a File
I The file must be opened.• The open() passes a file name to the logical file system.
I The open() first searches the system-wide open-file: if the file isalready in use by another process.
• If yes: a per-process open-file table entry is created.• If no: the directory structure is searched for the given file name:
once the file is found, the FCB is copied into a system-wideopen-file table in memory.
I This table stores the FCB as well as the number of processes thathave the file open.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 19 / 57
![Page 41: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/41.jpg)
Open a File
I The file must be opened.• The open() passes a file name to the logical file system.
I The open() first searches the system-wide open-file: if the file isalready in use by another process.
• If yes: a per-process open-file table entry is created.• If no: the directory structure is searched for the given file name:
once the file is found, the FCB is copied into a system-wideopen-file table in memory.
I This table stores the FCB as well as the number of processes thathave the file open.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 19 / 57
![Page 42: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/42.jpg)
Open a File
I The file must be opened.• The open() passes a file name to the logical file system.
I The open() first searches the system-wide open-file: if the file isalready in use by another process.
• If yes: a per-process open-file table entry is created.
• If no: the directory structure is searched for the given file name:once the file is found, the FCB is copied into a system-wideopen-file table in memory.
I This table stores the FCB as well as the number of processes thathave the file open.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 19 / 57
![Page 43: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/43.jpg)
Open a File
I The file must be opened.• The open() passes a file name to the logical file system.
I The open() first searches the system-wide open-file: if the file isalready in use by another process.
• If yes: a per-process open-file table entry is created.• If no: the directory structure is searched for the given file name:
once the file is found, the FCB is copied into a system-wideopen-file table in memory.
I This table stores the FCB as well as the number of processes thathave the file open.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 19 / 57
![Page 44: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/44.jpg)
Open a File
I The file must be opened.• The open() passes a file name to the logical file system.
I The open() first searches the system-wide open-file: if the file isalready in use by another process.
• If yes: a per-process open-file table entry is created.• If no: the directory structure is searched for the given file name:
once the file is found, the FCB is copied into a system-wideopen-file table in memory.
I This table stores the FCB as well as the number of processes thathave the file open.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 19 / 57
![Page 45: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/45.jpg)
Read From a File
I The open() returns a pointer to the appropriate entry in the per-process file-system table.
I All file operations are then performed via this pointer.
I This pointer is called file descriptor in Unix and file handle in Win-dows.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 20 / 57
![Page 46: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/46.jpg)
Close a File
I When a process closes the file:• The per-process table entry is removed.• The system-wide entry’s open count is decremented.
I When all users that have opened the file close it, any updated meta-data is copied back to the disk-based directory structure, and thesystem-wide open-file table entry is removed.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 21 / 57
![Page 47: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/47.jpg)
Close a File
I When a process closes the file:• The per-process table entry is removed.• The system-wide entry’s open count is decremented.
I When all users that have opened the file close it, any updated meta-data is copied back to the disk-based directory structure, and thesystem-wide open-file table entry is removed.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 21 / 57
![Page 48: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/48.jpg)
Partitions and Mounting (1/2)
I Partition can be a volume containing a file system or raw.• Raw partition: just a sequence of blocks with no file system.
I Boot block points to boot volume or boot loader.• Boot loader: knows enough about the file-system structure to be
able to find and load the kernel and start it executing.• Dual-boot that allows to install multiple OS on a single system.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 22 / 57
![Page 49: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/49.jpg)
Partitions and Mounting (1/2)
I Partition can be a volume containing a file system or raw.• Raw partition: just a sequence of blocks with no file system.
I Boot block points to boot volume or boot loader.• Boot loader: knows enough about the file-system structure to be
able to find and load the kernel and start it executing.• Dual-boot that allows to install multiple OS on a single system.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 22 / 57
![Page 50: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/50.jpg)
Partitions and Mounting (2/2)
I Root partition contains the OS• Mounted at boot time• Other partitions can hold other OSes, other file systems, or be raw• Other partitions can mount automatically or manually
I At mount time, file system consistency checked.• Is all metadata correct? if not, fix it, try again, if yes, add to mount
table, allow access
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 23 / 57
![Page 51: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/51.jpg)
Partitions and Mounting (2/2)
I Root partition contains the OS• Mounted at boot time• Other partitions can hold other OSes, other file systems, or be raw• Other partitions can mount automatically or manually
I At mount time, file system consistency checked.• Is all metadata correct? if not, fix it, try again, if yes, add to mount
table, allow access
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 23 / 57
![Page 52: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/52.jpg)
Virtual File Systems
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 24 / 57
![Page 53: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/53.jpg)
Virtual File Systems (1/2)
I Virtual File Systems (VFS) on Unix provide an object-oriented wayof implementing file systems.
I VFS allows the same system call interface (the API) to be used fordifferent types of file systems.
I The API is to the VFS interface, rather than any specific type offile system.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 25 / 57
![Page 54: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/54.jpg)
Virtual File Systems (1/2)
I Virtual File Systems (VFS) on Unix provide an object-oriented wayof implementing file systems.
I VFS allows the same system call interface (the API) to be used fordifferent types of file systems.
I The API is to the VFS interface, rather than any specific type offile system.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 25 / 57
![Page 55: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/55.jpg)
Virtual File Systems (1/2)
I Virtual File Systems (VFS) on Unix provide an object-oriented wayof implementing file systems.
I VFS allows the same system call interface (the API) to be used fordifferent types of file systems.
I The API is to the VFS interface, rather than any specific type offile system.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 25 / 57
![Page 56: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/56.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:
1 It separates file-system-generic operations from their implementa-tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.
• Contains a numerical designator for a network-wide unique file.• Unix inodes are unique within only a single file system.• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 57: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/57.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:1 It separates file-system-generic operations from their implementa-
tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.
• Contains a numerical designator for a network-wide unique file.• Unix inodes are unique within only a single file system.• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 58: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/58.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:1 It separates file-system-generic operations from their implementa-
tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.
• Contains a numerical designator for a network-wide unique file.• Unix inodes are unique within only a single file system.• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 59: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/59.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:1 It separates file-system-generic operations from their implementa-
tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.
• Contains a numerical designator for a network-wide unique file.• Unix inodes are unique within only a single file system.• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 60: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/60.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:1 It separates file-system-generic operations from their implementa-
tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.• Contains a numerical designator for a network-wide unique file.
• Unix inodes are unique within only a single file system.• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 61: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/61.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:1 It separates file-system-generic operations from their implementa-
tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.• Contains a numerical designator for a network-wide unique file.• Unix inodes are unique within only a single file system.
• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 62: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/62.jpg)
Virtual File Systems (2/2)
I VFS layer serves two important functions:1 It separates file-system-generic operations from their implementa-
tion, and allows transparent access to different types of file systemsmounted locally.
2 It provides a mechanism for uniquely representing a file throughouta network.
I The VFS is based on a structure, called a vnode.• Contains a numerical designator for a network-wide unique file.• Unix inodes are unique within only a single file system.• The kernel maintains one vnode structure for each active node.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 26 / 57
![Page 63: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/63.jpg)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 27 / 57
![Page 64: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/64.jpg)
VFS in Linux (1/2)
I The four main object types defined by the Linux VFS are:
• The inode object: represents an individual file
• The file object: represents an open file
• The super block object: represents an entire file system
• The dentry object: represents an individual directory entry
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 28 / 57
![Page 65: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/65.jpg)
VFS in Linux (1/2)
I The four main object types defined by the Linux VFS are:
• The inode object: represents an individual file
• The file object: represents an open file
• The super block object: represents an entire file system
• The dentry object: represents an individual directory entry
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 28 / 57
![Page 66: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/66.jpg)
VFS in Linux (1/2)
I The four main object types defined by the Linux VFS are:
• The inode object: represents an individual file
• The file object: represents an open file
• The super block object: represents an entire file system
• The dentry object: represents an individual directory entry
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 28 / 57
![Page 67: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/67.jpg)
VFS in Linux (1/2)
I The four main object types defined by the Linux VFS are:
• The inode object: represents an individual file
• The file object: represents an open file
• The super block object: represents an entire file system
• The dentry object: represents an individual directory entry
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 28 / 57
![Page 68: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/68.jpg)
VFS in Linux (1/2)
I The four main object types defined by the Linux VFS are:
• The inode object: represents an individual file
• The file object: represents an open file
• The super block object: represents an entire file system
• The dentry object: represents an individual directory entry
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 28 / 57
![Page 69: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/69.jpg)
VFS in Linux (2/2)
I VFS defines a set of operations on the objects that must be imple-mented.
I Every object has a pointer to a function table.
• Function table has addresses of routines to implement that functionon that object.
• For example:int open(...): open a fileint close(...): close an already-open filessize t read(...): read from a filessize t write(...): write to a fileint mmap(...): memory-map a file
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 29 / 57
![Page 70: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/70.jpg)
VFS in Linux (2/2)
I VFS defines a set of operations on the objects that must be imple-mented.
I Every object has a pointer to a function table.
• Function table has addresses of routines to implement that functionon that object.
• For example:int open(...): open a fileint close(...): close an already-open filessize t read(...): read from a filessize t write(...): write to a fileint mmap(...): memory-map a file
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 29 / 57
![Page 71: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/71.jpg)
VFS in Linux (2/2)
I VFS defines a set of operations on the objects that must be imple-mented.
I Every object has a pointer to a function table.• Function table has addresses of routines to implement that function
on that object.
• For example:int open(...): open a fileint close(...): close an already-open filessize t read(...): read from a filessize t write(...): write to a fileint mmap(...): memory-map a file
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 29 / 57
![Page 72: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/72.jpg)
VFS in Linux (2/2)
I VFS defines a set of operations on the objects that must be imple-mented.
I Every object has a pointer to a function table.• Function table has addresses of routines to implement that function
on that object.• For example:int open(...): open a fileint close(...): close an already-open filessize t read(...): read from a filessize t write(...): write to a fileint mmap(...): memory-map a file
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 29 / 57
![Page 73: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/73.jpg)
Directory Implementation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 30 / 57
![Page 74: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/74.jpg)
Directory Implementation
I Linear list
I Hash table
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 31 / 57
![Page 75: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/75.jpg)
Directory Implementation - Linear List
I Linear list of file names with pointer to the data blocks.
I Simple to program.
I Time-consuming to execute.
I Linear search time.
I Could keep ordered alphabetically via linked list or use B+ tree:binary search, but heavy
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 32 / 57
![Page 76: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/76.jpg)
Directory Implementation - Linear List
I Linear list of file names with pointer to the data blocks.
I Simple to program.
I Time-consuming to execute.
I Linear search time.
I Could keep ordered alphabetically via linked list or use B+ tree:binary search, but heavy
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 32 / 57
![Page 77: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/77.jpg)
Directory Implementation - Linear List
I Linear list of file names with pointer to the data blocks.
I Simple to program.
I Time-consuming to execute.
I Linear search time.
I Could keep ordered alphabetically via linked list or use B+ tree:binary search, but heavy
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 32 / 57
![Page 78: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/78.jpg)
Directory Implementation - Linear List
I Linear list of file names with pointer to the data blocks.
I Simple to program.
I Time-consuming to execute.
I Linear search time.
I Could keep ordered alphabetically via linked list or use B+ tree:binary search, but heavy
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 32 / 57
![Page 79: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/79.jpg)
Directory Implementation - Linear List
I Linear list of file names with pointer to the data blocks.
I Simple to program.
I Time-consuming to execute.
I Linear search time.
I Could keep ordered alphabetically via linked list or use B+ tree:binary search, but heavy
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 32 / 57
![Page 80: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/80.jpg)
Directory Implementation - Hash Table
I Hash Table: linear list with hash data structure
I Decreases directory search time
I Collisions: situations where two file names hash to the same location
I Chained-overflow method.• Each hash entry can be a linked list instead of an individual value.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 33 / 57
![Page 81: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/81.jpg)
Directory Implementation - Hash Table
I Hash Table: linear list with hash data structure
I Decreases directory search time
I Collisions: situations where two file names hash to the same location
I Chained-overflow method.• Each hash entry can be a linked list instead of an individual value.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 33 / 57
![Page 82: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/82.jpg)
Directory Implementation - Hash Table
I Hash Table: linear list with hash data structure
I Decreases directory search time
I Collisions: situations where two file names hash to the same location
I Chained-overflow method.• Each hash entry can be a linked list instead of an individual value.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 33 / 57
![Page 83: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/83.jpg)
Directory Implementation - Hash Table
I Hash Table: linear list with hash data structure
I Decreases directory search time
I Collisions: situations where two file names hash to the same location
I Chained-overflow method.• Each hash entry can be a linked list instead of an individual value.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 33 / 57
![Page 84: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/84.jpg)
Allocation Methods
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 34 / 57
![Page 85: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/85.jpg)
Allocation Methods
I How disk blocks are allocated to files?
I Methods:• Contiguous allocation• Linked allocation• Indexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 35 / 57
![Page 86: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/86.jpg)
Allocation Methods
I How disk blocks are allocated to files?
I Methods:• Contiguous allocation• Linked allocation• Indexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 35 / 57
![Page 87: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/87.jpg)
Contiguous Allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 36 / 57
![Page 88: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/88.jpg)
Contiguous Allocation (1/2)
I Contiguous allocation: each file occupies set of contiguous blocks.
• Best performance in most cases• Simple: only starting location (block number) and length (number
of blocks) are required.• Supports both sequential and direct access.
I Allocation strategies like contiguous memory allocation:• First fit• Best fit• Worst fit
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 37 / 57
![Page 89: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/89.jpg)
Contiguous Allocation (1/2)
I Contiguous allocation: each file occupies set of contiguous blocks.• Best performance in most cases• Simple: only starting location (block number) and length (number
of blocks) are required.
• Supports both sequential and direct access.
I Allocation strategies like contiguous memory allocation:• First fit• Best fit• Worst fit
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 37 / 57
![Page 90: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/90.jpg)
Contiguous Allocation (1/2)
I Contiguous allocation: each file occupies set of contiguous blocks.• Best performance in most cases• Simple: only starting location (block number) and length (number
of blocks) are required.• Supports both sequential and direct access.
I Allocation strategies like contiguous memory allocation:• First fit• Best fit• Worst fit
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 37 / 57
![Page 91: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/91.jpg)
Contiguous Allocation (1/2)
I Contiguous allocation: each file occupies set of contiguous blocks.• Best performance in most cases• Simple: only starting location (block number) and length (number
of blocks) are required.• Supports both sequential and direct access.
I Allocation strategies like contiguous memory allocation:• First fit• Best fit• Worst fit
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 37 / 57
![Page 92: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/92.jpg)
Contiguous Allocation (2/2)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 38 / 57
![Page 93: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/93.jpg)
Contiguous Allocation Problems
I Finding space for file
I External fragmentation
I Need for compaction (fragmentation) off-line or on-line: lose ofperformance
I Knowing file size
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 39 / 57
![Page 94: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/94.jpg)
Contiguous Allocation Problems
I Finding space for file
I External fragmentation
I Need for compaction (fragmentation) off-line or on-line: lose ofperformance
I Knowing file size
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 39 / 57
![Page 95: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/95.jpg)
Contiguous Allocation Problems
I Finding space for file
I External fragmentation
I Need for compaction (fragmentation) off-line or on-line: lose ofperformance
I Knowing file size
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 39 / 57
![Page 96: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/96.jpg)
Contiguous Allocation Problems
I Finding space for file
I External fragmentation
I Need for compaction (fragmentation) off-line or on-line: lose ofperformance
I Knowing file size
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 39 / 57
![Page 97: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/97.jpg)
Extent-Based Systems
I A modified contiguous allocation scheme.• E.g., Veritas file system
I Extent-based file systems allocate disk blocks in extents.
I An extent is a contiguous block of disks.• Extents are allocated for file allocation.• A file consists of one or more extents.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 40 / 57
![Page 98: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/98.jpg)
Extent-Based Systems
I A modified contiguous allocation scheme.• E.g., Veritas file system
I Extent-based file systems allocate disk blocks in extents.
I An extent is a contiguous block of disks.• Extents are allocated for file allocation.• A file consists of one or more extents.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 40 / 57
![Page 99: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/99.jpg)
Extent-Based Systems
I A modified contiguous allocation scheme.• E.g., Veritas file system
I Extent-based file systems allocate disk blocks in extents.
I An extent is a contiguous block of disks.• Extents are allocated for file allocation.• A file consists of one or more extents.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 40 / 57
![Page 100: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/100.jpg)
Linked Allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 41 / 57
![Page 101: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/101.jpg)
Linked Allocation (1/2)
I Linked allocation: each file is a linked list of blocks.• Each block contains pointer to next block.• File ends at null pointer.
I No external fragmentation, no compaction.
I Free space management system called when new block needed.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 42 / 57
![Page 102: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/102.jpg)
Linked Allocation (1/2)
I Linked allocation: each file is a linked list of blocks.• Each block contains pointer to next block.• File ends at null pointer.
I No external fragmentation, no compaction.
I Free space management system called when new block needed.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 42 / 57
![Page 103: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/103.jpg)
Linked Allocation (1/2)
I Linked allocation: each file is a linked list of blocks.• Each block contains pointer to next block.• File ends at null pointer.
I No external fragmentation, no compaction.
I Free space management system called when new block needed.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 42 / 57
![Page 104: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/104.jpg)
Linked Allocation (2/2)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 43 / 57
![Page 105: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/105.jpg)
Linked Allocation Problems
I Locating a block can take many I/Os and disk seeks.
I Reliability can be a problem.
I The space required for the pointers.• Efficiency can be improved by clustering blocks into groups but
increases internal fragmentation.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 44 / 57
![Page 106: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/106.jpg)
Linked Allocation Problems
I Locating a block can take many I/Os and disk seeks.
I Reliability can be a problem.
I The space required for the pointers.• Efficiency can be improved by clustering blocks into groups but
increases internal fragmentation.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 44 / 57
![Page 107: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/107.jpg)
Linked Allocation Problems
I Locating a block can take many I/Os and disk seeks.
I Reliability can be a problem.
I The space required for the pointers.• Efficiency can be improved by clustering blocks into groups but
increases internal fragmentation.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 44 / 57
![Page 108: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/108.jpg)
File-Allocation Table (FAT)
I Beginning of volume has a table, indexed by block number.
I Much like a linked list, but faster on disk and cacheable.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 45 / 57
![Page 109: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/109.jpg)
Indexed Allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 46 / 57
![Page 110: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/110.jpg)
Indexed Allocation (1/2)
I Indexed allocation: each file has its own index block(s) of pointersto its data blocks.
I Need index table
I Random access
I Dynamic access without external fragmentation, but have overheadof index block
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 47 / 57
![Page 111: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/111.jpg)
Indexed Allocation (1/2)
I Indexed allocation: each file has its own index block(s) of pointersto its data blocks.
I Need index table
I Random access
I Dynamic access without external fragmentation, but have overheadof index block
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 47 / 57
![Page 112: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/112.jpg)
Indexed Allocation (1/2)
I Indexed allocation: each file has its own index block(s) of pointersto its data blocks.
I Need index table
I Random access
I Dynamic access without external fragmentation, but have overheadof index block
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 47 / 57
![Page 113: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/113.jpg)
Indexed Allocation (1/2)
I Indexed allocation: each file has its own index block(s) of pointersto its data blocks.
I Need index table
I Random access
I Dynamic access without external fragmentation, but have overheadof index block
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 47 / 57
![Page 114: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/114.jpg)
Indexed Allocation (2/2)
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 48 / 57
![Page 115: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/115.jpg)
Indexed Allocation Problems
I Wasted space: overhead of the index blocks.
I For example, even with a file of only one or two blocks, we need anan entire index block.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 49 / 57
![Page 116: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/116.jpg)
Index Block Size
I How large the index block should be?
I Keep the index block as small as possible.• We need a mechanism to hold pointers for large files.
I Mechanisms for this purpose include the following:• Linked scheme• Multi-level index• Combined scheme
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 50 / 57
![Page 117: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/117.jpg)
Index Block Size
I How large the index block should be?
I Keep the index block as small as possible.• We need a mechanism to hold pointers for large files.
I Mechanisms for this purpose include the following:• Linked scheme• Multi-level index• Combined scheme
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 50 / 57
![Page 118: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/118.jpg)
Index Block Size
I How large the index block should be?
I Keep the index block as small as possible.• We need a mechanism to hold pointers for large files.
I Mechanisms for this purpose include the following:• Linked scheme• Multi-level index• Combined scheme
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 50 / 57
![Page 119: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/119.jpg)
Linked Scheme
I Linked scheme: link blocks of index table (no limit on size)
I For example, an index block might contain a small header giving thename of the file and a set of the first 100 disk-block addresses.
I The next address is null or is a pointer to another index block.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 51 / 57
![Page 120: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/120.jpg)
Linked Scheme
I Linked scheme: link blocks of index table (no limit on size)
I For example, an index block might contain a small header giving thename of the file and a set of the first 100 disk-block addresses.
I The next address is null or is a pointer to another index block.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 51 / 57
![Page 121: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/121.jpg)
Multi-Level Index
I Two-level index
I A first-level index block to point to a set of second-level index blocks,which in turn point to the file blocks.
I Could be continued to a third or fourth level.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 52 / 57
![Page 122: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/122.jpg)
Combined Scheme
I Combine scheme: used in Unix/Linux FS
I The first 12 pointers point to direct blocks• The data for small files do not need a separate index block.
I The next 3 pointers point to indirect blocks.• Single indirect• Double indirect• Triple indirect
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 53 / 57
![Page 123: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/123.jpg)
Performance
I Best method depends on file access type.
I Contiguous is great for sequential and random.
I Linked is good for sequential, not random.
I Indexed is more complex• Single block access could require 2 index block reads then data
block read• Clustering can help improve throughput, reduce CPU overhead
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 54 / 57
![Page 124: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/124.jpg)
Performance
I Best method depends on file access type.
I Contiguous is great for sequential and random.
I Linked is good for sequential, not random.
I Indexed is more complex• Single block access could require 2 index block reads then data
block read• Clustering can help improve throughput, reduce CPU overhead
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 54 / 57
![Page 125: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/125.jpg)
Performance
I Best method depends on file access type.
I Contiguous is great for sequential and random.
I Linked is good for sequential, not random.
I Indexed is more complex• Single block access could require 2 index block reads then data
block read• Clustering can help improve throughput, reduce CPU overhead
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 54 / 57
![Page 126: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/126.jpg)
Performance
I Best method depends on file access type.
I Contiguous is great for sequential and random.
I Linked is good for sequential, not random.
I Indexed is more complex• Single block access could require 2 index block reads then data
block read• Clustering can help improve throughput, reduce CPU overhead
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 54 / 57
![Page 127: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/127.jpg)
Summary
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 55 / 57
![Page 128: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/128.jpg)
Summary
I FS layers: device, I/O control, basic FS, file-organization, logicalFS, application
I FS implementation:• On-disk structures: boot control block, volume control block,
directory structure, and file control block• In-memory structures: mount table, directory structure, open-file
tables, and buffers
I Virtual file system (VFS)
I Directory implementation: linear list, and hash table
I Allocation methods: contiguous allocation, linked allocation, andindexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 56 / 57
![Page 129: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/129.jpg)
Summary
I FS layers: device, I/O control, basic FS, file-organization, logicalFS, application
I FS implementation:• On-disk structures: boot control block, volume control block,
directory structure, and file control block• In-memory structures: mount table, directory structure, open-file
tables, and buffers
I Virtual file system (VFS)
I Directory implementation: linear list, and hash table
I Allocation methods: contiguous allocation, linked allocation, andindexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 56 / 57
![Page 130: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/130.jpg)
Summary
I FS layers: device, I/O control, basic FS, file-organization, logicalFS, application
I FS implementation:• On-disk structures: boot control block, volume control block,
directory structure, and file control block• In-memory structures: mount table, directory structure, open-file
tables, and buffers
I Virtual file system (VFS)
I Directory implementation: linear list, and hash table
I Allocation methods: contiguous allocation, linked allocation, andindexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 56 / 57
![Page 131: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/131.jpg)
Summary
I FS layers: device, I/O control, basic FS, file-organization, logicalFS, application
I FS implementation:• On-disk structures: boot control block, volume control block,
directory structure, and file control block• In-memory structures: mount table, directory structure, open-file
tables, and buffers
I Virtual file system (VFS)
I Directory implementation: linear list, and hash table
I Allocation methods: contiguous allocation, linked allocation, andindexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 56 / 57
![Page 132: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/132.jpg)
Summary
I FS layers: device, I/O control, basic FS, file-organization, logicalFS, application
I FS implementation:• On-disk structures: boot control block, volume control block,
directory structure, and file control block• In-memory structures: mount table, directory structure, open-file
tables, and buffers
I Virtual file system (VFS)
I Directory implementation: linear list, and hash table
I Allocation methods: contiguous allocation, linked allocation, andindexed allocation
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 56 / 57
![Page 133: File System Implementation - Part1](https://reader034.vdocuments.mx/reader034/viewer/2022042602/55bae691bb61ebe2508b479f/html5/thumbnails/133.jpg)
Questions?
Acknowledgements
Some slides were derived from Avi Silberschatz slides.
Amir H. Payberah (Tehran Polytechnic) File System Implementation 1393/9/8 57 / 57