10
1 Silberschatz, Galvin and Gagne 2002 A.1 Operating System Concepts Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories are just files with a special format, so the representation of a file is the basic UNIX concept. Silberschatz, Galvin and Gagne 2002 A.2 Operating System Concepts Blocks and Fragments Most of the file system is taken up by data blocks. 4.2BSD uses two block sized for files which have no indirect blocks: All the blocks of a file are of a large block size (such as 8K), except the last. The last block is an appropriate multiple of a smaller fragment size (i.e., 1024) to fill out the file. Thus, a file of size 18,000 bytes would have two 8K blocks and one 2K fragment (which would not be filled completely). Silberschatz, Galvin and Gagne 2002 A.3 Operating System Concepts Blocks and Fragments (Cont.) The block and fragment sizes are set during file-system creation according to the intended use of the file system: If many small files are expected, the fragment size should be small. If repeated transfers of large files are expected, the basic block size should be large. The maximum block-to-fragment ratio is 8 : 1; the minimum block size is 4K (typical choices are 4096 : 512 and 8192 : 1024).

Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

1

Silberschatz, Galvin and Gagne 2002A.1Operating System Concepts

Esempi di File System: UNIX

� The UNIX file system supports two main objects: files anddirectories.

� Directories are just files with a special format, so therepresentation of a file is the basic UNIX concept.

Silberschatz, Galvin and Gagne 2002A.2Operating System Concepts

Blocks and Fragments

� Most of the file system is taken up by data blocks.� 4.2BSD uses two block sized for files which have no

indirect blocks:✦ All the blocks of a file are of a large block size (such as 8K),

except the last.✦ The last block is an appropriate multiple of a smaller

fragment size (i.e., 1024) to fill out the file.✦ Thus, a file of size 18,000 bytes would have two 8K blocks

and one 2K fragment (which would not be filled completely).

Silberschatz, Galvin and Gagne 2002A.3Operating System Concepts

Blocks and Fragments (Cont.)

� The block and fragment sizes are set during file-systemcreation according to the intended use of the file system:✦ If many small files are expected, the fragment size should

be small.✦ If repeated transfers of large files are expected, the basic

block size should be large.� The maximum block-to-fragment ratio is 8 : 1; the

minimum block size is 4K (typical choices are 4096 : 512and 8192 : 1024).

Page 2: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

2

Silberschatz, Galvin and Gagne 2002A.4Operating System Concepts

Inodes

� A file is represented by an inode — a record that storesinformation about a specific file on the disk.

� The inode also contains 15 pointer to the disk blockscontaining the file’s data contents.✦ First 12 point to direct blocks.✦ Next three point to indirect blocks

✔ First indirect block pointer is the address of a singleindirect block — an index block containing theaddresses of blocks that do contain data.

✔ Second is a double-indirect-block pointer, the address ofa block that contains the addresses of blocks thatcontain pointer to the actual data blocks.

✔ A triple indirect pointer is not needed; files with as manyas 232 bytes will use only double indirection.

Silberschatz, Galvin and Gagne 2002A.5Operating System Concepts

Struttura di un I-node

Silberschatz, Galvin and Gagne 2002A.6Operating System Concepts

Directories

� The inode type field distinguishes between plain files anddirectories.

� Directory entries are of variable length; each entrycontains first the length of the entry, then the file nameand the inode number.

� The user refers to a file by a path name,whereas the filesystem uses the inode as its definition of a file.✦ The kernel has to map the supplied user path name to an

inode✦ Directories are used for this mapping.

Page 3: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

3

Silberschatz, Galvin and Gagne 2002A.7Operating System Concepts

Directories (Cont.)

� First determine the starting directory:✦ If the first character is “/”, the starting directory is the root

directory.✦ For any other starting character, the starting directory is the

current directory.� The search process continues until the end of the path

name is reached and the desired inode is returned.� Once the inode is found, a file structure is allocated to

point to the inode.� 4.3BSD improved file system performance by adding a

directory name cache to hold recent directory-to-inodetranslations.

Silberschatz, Galvin and Gagne 2002A.8Operating System Concepts

Mapping of a File Descriptor to an Inode

� System calls that refer to open files indicate the file ispassing a file descriptor as an argument.

� The file descriptor is used by the kernel to index a table ofopen files for the current process.

� Each entry of the table contains a pointer to a filestructure.

� This file structure in turn points to the inode.� Since the open file table has a fixed length which is only

setable at boot time, there is a fixed limit on the numberof concurrently open files in a system.

Silberschatz, Galvin and Gagne 2002A.9Operating System Concepts

File-System Control Blocks

Page 4: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

4

Silberschatz, Galvin and Gagne 2002A.10Operating System Concepts

Disk Structures

� The one file system that a user ordinarily sees mayactually consist of several physical file systems, each ona different device.

� Partitioning a physical device into multiple file systemshas several benefits.✦ Different file systems can support different uses.✦ Reliability is improved✦ Can improve efficiency by varying file-system parameters.✦ Prevents one program form using all available space for a

large file.✦ Speeds up searches on backup tapes and restoring

partitions from tape.

Silberschatz, Galvin and Gagne 2002A.11Operating System Concepts

Disk Structures (Cont.)

� The root file system is always available on a drive.

� Other file systems may be mounted — i.e., integrated intothe directory hierarchy of the root file system.

� The following figure illustrates how a directory structure ispartitioned into file systems, which are mapped ontological devices, which are partitions of physical devices.

Silberschatz, Galvin and Gagne 2002A.12Operating System Concepts

Mapping File System to Physical Devices

Page 5: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

5

Silberschatz, Galvin and Gagne 2002A.13Operating System Concepts

Implementations

� The user interface to the file system is simple and welldefined, allowing the implementation of the file system itselfto be changed without significant effect on the user.

� For Version 7, the size of inodes doubled, the maximum fileand file system sized increased, and the details of free-listhandling and superblock information changed.

� In 4.0BSD, the size of blocks used in the file system wasincreased form 512 bytes to 1024 bytes — increasedinternal fragmentation, but doubled throughput.

� 4.2BSD added the Berkeley Fast File System, whichincreased speed, and included new features.✦ New directory system calls✦ truncate calls✦ Fast File System found in most implementations of UNIX.

Silberschatz, Galvin and Gagne 2002A.14Operating System Concepts

Layout and Allocation Policy

� The kernel uses a <logical device number, inodenumber> pair to identify a file.✦ The logical device number defines the file system involved.✦ The inodes in the file system are numbered in sequence.

� 4.3BSD introduced the cylinder group — allowslocalization of the blocks in a file.✦ Each cylinder group occupies one or more consecutive

cylinders of the disk, so that disk accesses within thecylinder group require minimal disk head movement.

✦ Every cylinder group has a superblock, a cylinder block, anarray of inodes, and some data blocks.

Silberschatz, Galvin and Gagne 2002A.15Operating System Concepts

4.3BSD Cylinder Group

Page 6: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

6

Silberschatz, Galvin and Gagne 2002A.16Operating System Concepts

File Systems

� To the user, Linux’s file system appears as a hierarchicaldirectory tree obeying UNIX semantics.

� Internally, the kernel hides implementation details andmanages the multiple different file systems via anabstraction layer, that is, the virtual file system (VFS).

� The Linux VFS is designed around object-orientedprinciples and is composed of two components:✦ A set of definitions that define what a file object is allowed to

look like✔ The inode-object and the file-object structures represent

individual files✔ the file system object represents an entire file system

✦ A layer of software to manipulate those objects.

Silberschatz, Galvin and Gagne 2002A.17Operating System Concepts

The Linux Ext2fs File System

� Ext2fs uses a mechanism similar to that of BSD FastFile System (ffs) for locating data blocks belonging to aspecific file.

� The main differences between ext2fs and ffs concerntheir disk allocation policies.✦ In ffs, the disk is allocated to files in blocks of 8Kb, with

blocks being subdivided into fragments of 1Kb to storesmall files or partially filled blocks at the end of a file.

✦ Ext2fs does not use fragments; it performs its allocationsin smaller units. The default block size on ext2fs is 1Kb,although 2Kb and 4Kb blocks are also supported.

✦ Ext2fs uses allocation policies designed to place logicallyadjacent blocks of a file into physically adjacent blocks ondisk, so that it can submit an I/O request for several diskblocks as a single operation.

Silberschatz, Galvin and Gagne 2002A.18Operating System Concepts

Ext2fs Block-Allocation Policies

Page 7: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

7

Silberschatz, Galvin and Gagne 2002A.19Operating System Concepts

File System di Windows 2000

� La struttura fondamentale del file system di Windows2000 (NTFS) è il volume.✦ Creato dal programma di utilità disk administrator.✦ Si basa su una partizione logica del disco.✦ Può occupare una porzione di un disco, un intero disco, o

spaziare su più dischi.� Tutti i metadata, cioè le informazioni sul volume, sono

memorizzate in un normale file.� NTFS usa clusters (gruppi) come unità di allocazione del

disco.✦ Un cluster è un numero di settori del disco che è una

potenza di 2.✦ Siccome la dimensione del cluster è più piccola di quella del

file system FAT a 16 bit, la frammentazione interna èridotta.

Silberschatz, Galvin and Gagne 2002A.20Operating System Concepts

File System — Struttura interna

� NTFS usa logical cluster numbers (LCNs) come indirizzidi disco.

� Un file in NTFS non è una semplice sequenza di byte,come in MS-DOS o UNIX, ma è un oggetto strutturatoche consiste di attributi.

� Ogni file in NTFS è descritto da uno o più record in unvettore memorizzato in un file speciale chiamato MasterFile Table (MFT).

� Ogni file in un volume NTFS ha un ID univoco chiamatofile reference.✦ Valore a 64-bit suddiviso in 48-bit per numero file e 16-bit

per numero di sequenza.✦ Può essere usato per eseguire controlli di consistenza.

� Lo spazio dei nomi in NTFS è organizzato come unagerarchia di directory.

Silberschatz, Galvin and Gagne 2002A.21Operating System Concepts

File System — Ripristino

� Tutte le modifiche alle strutture del file system sonoeseguite come transazioni che vengono tracciate.✦ Prima di alterare una struttura dati, la transazione scrive un

record di log che contiene informazioni sull’operazione dafare.

✦ Dopo che la struttura dati è stata modificata, viene scritto unrecord di commit per dire che la transazione ha avutosuccesso.

✦ Dopo un crash del sistema, le strutture dati del file systempossono essere ripristinate ad uno stato consistenteripetendo le transazioni nel log.

Page 8: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

8

Silberschatz, Galvin and Gagne 2002A.22Operating System Concepts

File System — Ripristino (Cont.)

� Questo schema non garantisce che tutti i dati dell’utentesiano ripristinati dopo un crash, ma solo le strutture delfile system sono riportate ad uno stato consistente cheriflette una situazione stabile prima del crash.

� Il file di log è memorizato nel terzo file di metadatiall’inizio del volume.

� La funzionalità di log è fornita dal servizio di Windows2000 log file service.

Silberschatz, Galvin and Gagne 2002A.23Operating System Concepts

File System — Sicurezza

� La sicurezza su un volume NTFS è derivata dal modelload oggetti di Windows 2000.

� Ogni oggetto di tipo file ha un attributo di sicurezzamemorizzato nella Master File Table.

� Questo attributo contiene le informazioni di accesso delproprietario del fule, e una lista di accesso che elenca iprivilegi di accessi che sono permessi a ciascun utenteche accede al file.

Silberschatz, Galvin and Gagne 2002A.24Operating System Concepts

Gestione dei Volumi e Tolleranza ai guasti

FtDisk, è il driver di disco tollerante ai guasti di 2000, efornisce diversi modi per combinare i dischi in un unicovolume logico.

� Un volume set è una concatenzaione logica di più dischia formare un grande volume logico.

� Uno stripe set organizza più partizioni fisiche in manieracircolare (anche chiamato RAID di livello 0, o “diskstriping”).✦ Variazione: stripe set with parity, o RAID livello 5.

� Disk mirroring, o RAID livello 1, è uno schema robustoche usa un mirror set : due partizioni di egual misura sidue dischi diversi con identici contenuti.

� Per gestire malfunzionamenti, FtDisk, usa una tecnicahardware chiamata sector sparing e NTFS usa unattecnica software chiamata cluster remapping.

Page 9: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

9

Silberschatz, Galvin and Gagne 2002A.25Operating System Concepts

Volume Set On Two Drives

Silberschatz, Galvin and Gagne 2002A.26Operating System Concepts

Stripe Set on Two Drives

Silberschatz, Galvin and Gagne 2002A.27Operating System Concepts

Stripe Set With Parity on Three Drives

Page 10: Esempi di File System: UNIXbotta/didattica/EsempiDiFileSystems.pdf · Esempi di File System: UNIX The UNIX file system supports two main objects: files and directories. Directories

10

Silberschatz, Galvin and Gagne 2002A.28Operating System Concepts

Mirror Set on Two Drives

Silberschatz, Galvin and Gagne 2002A.29Operating System Concepts

File System — Compression

� To compress a file, NTFS divides the file’s data intocompression units, which are blocks of 16 contiguousclusters.

� For sparse files, NTFS uses another technique to savespace.✦ Clusters that contain all zeros are not actually allocated or

stored on disk.✦ Instead, gaps are left in the sequence of virtual cluster

numbers stored in the MFT entry for the file.✦ When reading a file, if a gap in the virtual cluster numbers is

found, NTFS just zero-fills that portion of the caller’s buffer.

Silberschatz, Galvin and Gagne 2002A.30Operating System Concepts

File System — Reparse Points

� A reparse point returns an error code when accessed.The reparse data tells the I/O manager what to do next.

� Reparse points can be used to provide the functionality ofUNIX mounts

� Reparse points can also be used to access files that havebeen moved to offline storage.