vi - file system [modo de compatibilidade]ricroc/aulas/1415/so/... · also called boot block in ufs...

49
Ricardo Rocha Department of Computer Science Faculty of Sciences Operating Systems 2014/2015 Part VI – File System Faculty of Sciences University of Porto Slides based on the book ‘Operating System Concepts, 9th Edition, Abraham Silberschatz, Peter B. Galvin and Greg Gagne, Wiley’ Chapters 10 and 11

Upload: others

Post on 09-Mar-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Ricardo Rocha

Department of Computer Science

Faculty of Sciences

Operating Systems 2014/2015 Part VI – File System

Faculty of Sciences

University of Porto

Slides based on the book

‘Operating System Concepts, 9th Edition,

Abraham Silberschatz, Peter B. Galvin and Greg Gagne, Wiley’

Chapters 10 and 11

Page 2: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Types

� Many file systems are in use today, and most operating systems supportmore than one

� UNIX uses the UNIX file system (UFS) which is based on the Berkeley Fast

File System (FFS)

� The standard Linux file system is the extended file system (most common

versions being ext3 and ext4)

DCC-FCUP # 1

� Windows uses the FAT, FAT32 and NTFS file systems

� CD-ROMs are written in the ISO 9660 format

� New ones are still arriving since file system continues to be an activeresearch area

� GoogleFS

� Oracle ASM

� FUSE

Page 3: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Concept

� For most users, the file system is the most visible aspect of an operatingsystem as it provides the mechanism for storage and access to bothdata and programs of the operating system

� A file system consists of two distinct parts:

� A collection of files, each file defines a logical storage unit with related data

DCC-FCUP # 2

� A directory structure, which organizes and provides information about all the

files in the system

� The operating system abstracts the physical properties of its storagedevices to organize the directory structure and its files

� These storage devices are usually nonvolatile, so the contents are persistent

between system reboots

Page 4: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File Attributes

� A file is defined by a set of attributes that vary from one operating systemto another. Typical attributes are:

� Name – for the convenience of the human users

� Identifier – unique tag (number) that identifies the file within the file system

� Type – to indicate the type of operations that can be done on the file (included

in the name as an extension, usually separated by a period)

DCC-FCUP # 3

in the name as an extension, usually separated by a period)

� Location – pointer to file location on device

� Size – current file size

� Protection – controls who can do reading, writing, executing, and so on

� Time, date, and user identification – data useful for protection, security, and

usage monitoring

Page 5: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Common File Types

DCC-FCUP # 4

Page 6: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File Sharing and Protection

� When an operating system accommodates multiple users, it mustmediate how file sharing and file protection is done

� The system can either allow a user to access the files of other users by

default or require that a user specifically grant access to its files

� To implement sharing and protection, most systems have evolved to usethe concepts of file owner and group

DCC-FCUP # 5

the concepts of file owner and group

� The owner is the user who has the most control over a file

� The group defines a subset of users who can share special access rights to a

file

� Which access rights can be executed by group members and other users is

definable by the file’s owner

Page 7: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File Sharing and Protection

� Typical access rights are:

� Read – read from the file

� Write – write or rewrite the file

� Execute – load the file into memory and execute it

� Append – write new information at the end of the file

� Delete – delete the file and free its space for possible reuse

DCC-FCUP # 6

� Delete – delete the file and free its space for possible reuse

� List – list the name and attributes of the file

Page 8: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File Sharing Semantics

� File sharing semantics specify how multiple users access a shared filesimultaneously, i.e., they specify when modifications of data by oneuser will be observable by other users

� UNIX semantics

� Writes to a file are immediately visible to all users who have same file open

DCC-FCUP # 7

� Session semantics, as used by the OpenAFS (Andrew file system)

� Already open instances of the file do not reflect any changes done by others

� Writes to a file are only visible when the file is closed and to sessions starting

after the file is closed

Page 9: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Organization

� A storage device can be used entirety for a file system or subdivided intopartitions. Partitioning allows for:

� Multiple file-system types to be on the same device

� Specific needs where no file system is appropriate (raw partition), such as for

swap space or databases that want to format data according to their needs

� A entity containing a file system is generally known as a volume

DCC-FCUP # 8

� A entity containing a file system is generally known as a volume

� A volume may be a whole device, a subset of a device, or multiple devices

linked together

� The information about the file system in a volume is kept in the:

� Boot control bock

� Volume control block

� Directory structure

Page 10: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Organization

� Boot control block

� Typically the first block of a volume which contains the info needed to boot an

OS from that volume (can be empty if volume does not contain an OS)

� Also called boot block in UFS and partition boot sector in NTFS

� Volume control block

DCC-FCUP # 9

� Contains volume details, such as total number of blocks, total number of free

blocks, block size, free block pointers, …

� Also called superblock in UFS and is part of the master file table in NTFS

� Directory structure

� Used to organize the directory and files

� Part of the master file table in NTFS

Page 11: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Organization

Volume ADisk 2

Disk 1

DCC-FCUP # 10

Volume B

Volume C

Disk 3

Disk 1

Page 12: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Directory Overview

� The directory structure can be viewed as a symbol table that translatesfile names into directory entries

� The directory itself can be organized in many different ways, but must:

� Allow to insert entries, to delete entries, to search for a named entry, and to

list all the entries in the directory

Be efficient (locate a file quickly)

DCC-FCUP # 11

� Be efficient (locate a file quickly)

� Be convenient to users (e.g., allow two users to have same name for different

files or allow grouping files by some characteristic)

Page 13: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Single-Level Directory

� All files are contained in the same directory for all users

DCC-FCUP # 12

� Problems

� All files must have unique names

� No grouping capability

� Multiple users cannot have files with the same name

Page 14: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Two-Level Directory

� Separate directory for each user

� A user name and a file name define a path name

DCC-FCUP # 13

� Problems:

� All files must have unique names for a particular user

� No grouping capability

Page 15: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Tree-Structured Directories

� Generalization of the two-level directory to a tree of arbitrary height

� The tree has a unique root directory, and every file has a unique path name

DCC-FCUP # 14

Page 16: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Tree-Structured Directories

� A directory contains a set of files and/or subdirectories

� A subdirectory can be seen as a common file that is treated in a special way

� Each process has a current (or working) directory

� When a reference to a file is made, the current directory is searched

Path names can be of two types:

DCC-FCUP # 15

� Path names can be of two types:

� Absolute path name – begins at the root and follows a path down to the

specified file, giving the directory names on the path (e.g., /root/spell/mail/exp)

� Relative path name – defines a path starting from the current directory (e.g.,

mail/exp if the current directory is /root/spell)

Page 17: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Acyclic-Graph Directories

� Generalization of the tree-structured directory to allow directories to sharefiles and subdirectories

� The same file or subdirectory may be in two different directories

DCC-FCUP # 16

Page 18: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Acyclic-Graph Directories

� A common way to implement shared files/subdirectories is to use links(or shortcuts)

� A link is effectively a pointer (path name) to another file or subdirectory

� A link may be implemented as an absolute or a relative path name

� When a reference to a link is made, we resolve the link by following the

pointer to locate the real file/subdirectory

DCC-FCUP # 17

pointer to locate the real file/subdirectory

� A file/subdirectory can now have multiple absolute path names

� Can be problematic when traversing the file system to accumulate statistics

on all files or to copy all files to backup storage, since we do not want to

traverse shared structures more than once

Page 19: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Acyclic-Graph Directories

� How to handle the deletion of shared files/subdirectories?

� It depends if links are symbolic links or hard (nonsymbolic) links

� Deletion with symbolic links

� The deletion of a link does not affect the original file/subdirectory (only the link

is removed)

DCC-FCUP # 18

� If original file/subdirector is deleted, the existing links turn invalid and are

treated as illegal file name (links become valid if another file/subdirectory with

the same name is created)

� Deletion with hard links

� We keep a counter of the number of references to a shared file/subdirectory

� Adding/deleting a link increments/decrements the counter

� When the count reaches 0, the file/subdirectory can be deleted since no

remaining references exist

Page 20: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

� A serious problem with a graph structure is the creation of cycles

General Graph Directory

� Might be difficult to detect if a

file/subdirectory can be deleted

� The reference count may not

be 0 even when it is no longer

possible to refer to a

file/subdirectory

DCC-FCUP # 19

file/subdirectory

� Some garbage collection

mechanism might be needed

to determine when the last

reference has been deleted

and the disk space can be

reallocated

� Problem can be avoided if we

only allow links to files and not

to subdirectories

Page 21: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Structure

� File system resides permanently on disks

� Disks provide in-place rewrite and random access

� I/O transfers performed in blocks of sectors (usually

512 bytes per sector)

� A major problem is how to map the logical filesystem (user’s view) onto the physical disks

DCC-FCUP # 20

system (user’s view) onto the physical disks

� The file system itself is generally composed of

several different layers

� Layering is useful for reducing complexity and

redundancy, but adds overhead and can decrease

performance

Page 22: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Layers

� Logical file system

� Manages the directory, file structure and metadata information (i.e., all data

except the contents of the files)

� File organization module

� Understands files, logical blocks and physical blocks

DCC-FCUP # 21

� Translates logical blocks to physical blocks (each file’s logical blocks are

numbered from 0 through N)

� Also manages free space disk allocation

Page 23: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Layers

� Basic file system

� Translates instructions like “retrieve block 123” to device driver instructions

� Also manages memory buffers and caches for optimum system performance

� I/O control

� Consists of device drivers and interrupt handlers to transfer information

DCC-FCUP # 22

� Consists of device drivers and interrupt handlers to transfer information

between the main memory and the physical device

� Translates instructions like “read drive1, cylinder 72, track 2, sector 10, into

memory location 1060” to low-level specific commands to the hardware

controller

Page 24: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Open Files

� Typically, to manage open files, operating systems use two levels ofinternal tables

� System-wide open-file table – contains process-independent information for

all open files

� Per-process open-file table – contains specific info for the files that a

process has open

DCC-FCUP # 23

� Most of the operations on files involve searching for the entry associatedwith the named file

� To avoid this constant searching, many operating systems require that an

open() system call be made before a file is first used

� On success, the open() system call returns an index to the per-process

open-file table – called file descriptor in UNIX systems and file handle in

Windows systems – for subsequent use

Page 25: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Open Files

� The system-wide open-file table stores per open file the following info:

� File control block (FCB) which contains information about the file so that the

system does not have to read this information from disk on each operation

� File-open count to indicate how many processes have the file open – allows

removal of FCB when the last process closes the file

� The per-process open-file table stores per open file the following info:

DCC-FCUP # 24

� The per-process open-file table stores per open file the following info:

� Reference to the appropriate entry in the system-wide open-file table

� Access mode in which the file is open

� File pointer to last read/write location

Page 26: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Typical File Control Block

DCC-FCUP # 25

Page 27: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

In-Memory File System Structures

Opening a file

DCC-FCUP # 26

Opening a file

Reading from an open file

Page 28: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Mounting

� Just as a file must be opened before it is used, a file system must bemounted before it can be accessed

� The directory structure may be built out of multiple volumes, which must be

mounted to make them available within the file-system name space

� Volumes can be mounted at boot time or later, either automatically or

manually

DCC-FCUP # 27

� The mount procedure is straightforward, the operating system is given the

name of a volume and the mount point – the location within the file structure

where the new file system is to be attached

� Typically, a mount point is an empty directory

Page 29: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File System Mounting

DCC-FCUP # 28

Unmounted volume After mounting volume onmount point /users

Page 30: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Virtual File System

� To simplify and modularize the support for multiple types of filesystems, most modern operating systems use a virtual file system(VFS) layer

� The file-system interface, based on the open(), read(), write() and close()calls, rather than interacting with each specific type of file system,interacts only with the VFS layer

DCC-FCUP # 29

interacts only with the VFS layer

� Allows the same system call interface to be used with different types of file

systems

� Separates the file system interface from the file system implementation details

� The VFS then dispatches the calls to appropriate file system implementation

routines

� The VFS is based on a unique file-representation structure, called a vnode

Page 31: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Virtual File System

DCC-FCUP # 30

Page 32: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Designing the File System

� The direct-access nature of disks gives us flexibility in the implementationof files but the key design problem is how to allocate files so that diskspace is utilized effectively and files can be accessed quickly

� File access patterns:

� Sequential access – bytes read/write in order (most file accesses are of this

flavor)

DCC-FCUP # 31

flavor)

� Random access – bytes read/write without order (less frequent, but still

important – don’t want to read all bytes to get to a particular point of the file)

� Usage patterns:

� Most files are small (for example, .doc, .txt, .c, .java files)

� A few files are big (for example, executables, swap, core files, …)

� Large files use most of the disk space and bandwidth to/from disk

Page 33: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Designing the File System

� File system main goals:

� Maximize sequential access performance

� Efficient random access to file

� Easy management of files (growth, truncation, …)

� Three major methods of allocating disk space are in wide use:

DCC-FCUP # 32

� Three major methods of allocating disk space are in wide use:

� Contiguous allocation

� Linked allocation

� Indexed allocation

Page 34: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Contiguous Allocation

� With contiguous allocation, each file occupies a set of contiguousblocks on disk

� Disk addresses define a linear ordering on the disk

� Only starting location (block #) and length (number of blocks) are required

� Sequential access – we only need to keep a reference R to the last blockread since the next one to read is always R+1

DCC-FCUP # 33

read since the next one to read is always R+1

� Random access – given a block N of a file that starts at block B, we canimmediately access block B+N

Page 35: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Contiguous Allocation

DCC-FCUP # 34

Page 36: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Contiguous Allocation

� Advantages

� The number of disk seeks required for accessing contiguously allocated files

is minimal (disk head only needs to move from one track to the next when

reaching the last sector on a track)

� Problems

� Finding free space (first-fit, best-fit, worst-fit, …)

DCC-FCUP # 35

� Finding free space (first-fit, best-fit, worst-fit, …)

� Knowing file size beforehand (might be difficult to know)

� Hard to grow files (if we allocate too little space to a file, we may not be able

to extended it later)

� External fragmentation (requires regular use of defragmentation techniques to

compact all free space into one contiguous space)

Page 37: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Linked Allocation

� With linked allocation, each file is a linked list of disk blocks (blocksmay be scattered anywhere on the disk)

� The directory contains a pointer to the first and last blocks of the file

� Each block contains pointer to next block

� Last block ends with nil pointer

DCC-FCUP # 36

� Sequential access – keep reference to last block read and follow thepointers from block to block

� Random access – must follow N pointers until we get to the Nth block

Page 38: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Linked Allocation

16

10

25

DCC-FCUP # 37

16

1

25

-1

Page 39: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Linked Allocation

� Advantages

� Easy to grow and no need to know file size beforehand (a file can continue to

grow as long as free blocks are available)

� No external fragmentation (any free block can be used to satisfy a request,

consequently, it is never necessary to compact disk space)

� Problems

DCC-FCUP # 38

� Problems

� Less efficient sequential access support and very inefficient random access

support – each access to a block requires a disk read, and some require a

disk seek

� Requires space for pointers in data blocks (if a pointer requires 4 bytes out of

a 512-byte block, then 0.78% of the disk is wasted on pointers)

� Reliability can be a problem (a bug or disk failure might result in picking up a

wrong pointer, which could result in corrupting other parts of the file system)

Page 40: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File-Allocation Table (FAT)

� FAT is an important variation of linked allocation

� Section at the beginning of each volume is set aside to contain the FAT

� Has one entry for each disk block and is indexed by block number

� Used as a linked list, the directory entry stores the first block of a file and then

each FAT’s block entry contains pointer to next block

DCC-FCUP # 39

� Advantages

� Requires no space for pointers in data blocks

� Free blocks can also be stored as a linked list

� Random access more efficient and really efficient if FAT cached in memory

� Problems

� Sequential access still less efficient even if FAT cached in memory

Page 41: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

File-Allocation Table (FAT)

DCC-FCUP # 40

FAT

– 1

Page 42: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Indexed Allocation

� With indexed allocation, each file has its own index block, which is anarray of disk block pointers

� The directory contains the address of the index block

� The Nth entry in the index block points to the Nth block of the file

� Sequential/random access – both require a first access to the indexblock

DCC-FCUP # 41

block

Page 43: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Indexed Allocation

DCC-FCUP # 42

Page 44: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Indexed Allocation

� Problems

� Overhead of the index block

� If index block not enough, requires some sort of linked allocation

� This raises the question of how large the index block should be?

� On one hand, we want the index block to be as small as possible since every

DCC-FCUP # 43

� On one hand, we want the index block to be as small as possible since every

file requires an index block

� On the other hand, if the index block is too small, it will not be able to hold

enough pointers for larger files

Page 45: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Indexed Allocation

� Schemes to allow for larger files:

� Linked scheme – links together several index blocks (no limit on file size)

� Multilevel index – a first-level index block points to a set of second-level

index blocks (could be continued to more levels), which in turn point to the file

blocks (limit on file size)

� UNIX inodes – combined scheme that uses some pointers as pointers to

direct blocks and the last three pointers as pointers to indirect blocks: the

DCC-FCUP # 44

direct blocks and the last three pointers as pointers to indirect blocks: the

first points to a single indirect block, the second points to a double indirect

block and the third points to a triple indirect block

Page 46: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Indexed Allocation – Multilevel Index

� With 4,096 byte blocks, we

could store 1,024 four-byte

pointers in an index block

M

Directory entry

DCC-FCUP # 45

� Two levels of indexes allow

1,048,576 (1,024*1,024) data

blocks and a file size of up to

4 GB (4,096*1,048,576)

First-level

index block

Second-level

index blocksFile blocks

Page 47: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Indexed Allocation – UNIX Inodes

� Under this method, the number ofblocks that can be allocated to a fileexceeds the amount of spaceaddressable by the 4-byte file pointersused by most operating systems

DCC-FCUP # 46

Page 48: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Free-Space Management

� To keep track of free disk space, the file system maintains a free-spacelist which records the blocks not allocated to any file or directory

� Despite its name, the free-space list may not be implemented as a list.Three well-know schemes are:

� Bit vector

DCC-FCUP # 47

� Linked list

� Counting

Page 49: VI - File System [Modo de Compatibilidade]ricroc/aulas/1415/so/... · Also called boot block in UFS and partition boot sector in NTFS Volume control block DCC-FCUP # 9 Contains volume

Operating Systems 2014/2015 Part VI – File System

Free-Space Management

� Bit vector – each block is represented by one bit and if the block is free,the bit is 1, otherwise the bit is 0

� The first non-0 word is scanned for the first 1 bit, which is the location of the

first free block. The calculation of the block number is:

(number of bits per word) * (number of 0-value words) + (offset of first 1 bit)

� Inefficient unless the entire vector is kept in main memory

DCC-FCUP # 48

Inefficient unless the entire vector is kept in main memory

� Linked list – each free block contains pointer to next free block

� No waste of space

� Cannot get contiguous space easily

� Counting – each free block keeps not only the pointer to next free block,but also the number of free contiguous blocks that follow that block

� Free space list then has entries containing pointers and counts