Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne  2002 12.1 Operating System Concepts File-System Structure File structure user view  Logical storage unit  Collection.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne  2002 12.1 Operating System Concepts File-System Structure File structure user view  Logical storage unit  Collection."— Presentation transcript:

1 Silberschatz, Galvin and Gagne  2002 12.1 Operating System Concepts File-System Structure File structure user view  Logical storage unit  Collection of related information File system physical view  Resides on secondary storage (disks)  Partitions and mounting  Blocks

2 Silberschatz, Galvin and Gagne  2002 12.2 Operating System Concepts Moving-Head Disk Mechanism

3 Silberschatz, Galvin and Gagne  2002 12.3 Operating System Concepts Low Level Format Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write.  Zones of cylinders allow more (up to 40%) sectors on outer tracks The sectors and tracks are mapped to a large 1- dimensional array of logical blocks,  Block 0 is the first sector of the first track on the outermost or innermost cylinder.  Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost.  The block is the smallest unit of transfer.

4 Silberschatz, Galvin and Gagne  2002 12.4 Operating System Concepts Blocks and Fragments Block sizes  Smaller => less internal fragmentation  Larger => larger transfers Can improve efficiency by varying file-system parameters, e.g., block size = frame size on swap device 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 (e.g., 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).

5 Silberschatz, Galvin and Gagne  2002 12.5 Operating System Concepts High Level Format To use a disk to hold files, the operating system still needs to record its own data structures on the disk. Partition the disk into one or more groups of cylinders. Logical formatting or “making a file system”.

6 Silberschatz, Galvin and Gagne  2002 12.6 Operating System Concepts Partitions and Disks A physical device may support several partitions, each hosting a physical file system.

7 Silberschatz, Galvin and Gagne  2002 12.7 Operating System Concepts Partitions and Disks Different file systems can support different uses. Potentially different OSs in different partitions Prevents one program from using all available space for a large file. Speeds up searches on backup tapes and restoring partitions from tape. Known as  IBM minidisks  Mac volumes  UNIX file systems  Windows drives

8 Silberschatz, Galvin and Gagne  2002 12.8 Operating System Concepts Partitions Boot block - for booting the OS Partition control block  Information about the partition  Free space list  Free directory space list  Superblock in UNIX, Master File Table in NTFS Directory structure  Directory nodes, exactly one per file  Inodes in UNIX  MFT entries in NTFS  Organization links nodes into a data structure  Provides naming Data blocks

9 Silberschatz, Galvin and Gagne  2002 12.9 Operating System Concepts Directory Implementation Linear list of file names with pointer to the data blocks.  Simple to program  Inefficient - searching, empty entries  UNIX directory files Sorted tree, e.g., B-tree  NTFS B+ tree Hash Table – linear list with hash data structure.  Decreases directory search time  Collisions – situations where two file names hash to the same location  Fixed size, or overflow facilities

10 Silberschatz, Galvin and Gagne  2002 12.10 Operating System Concepts Disk Structures A logical file system that a user ordinarily sees may consist of several physical file systems, each hosted in a partition of a physical device.  Permits very large logical file systems  Makes monolithic backups possible The root file system is always available on a partition. Other file systems may be mounted — i.e., integrated into the directory hierarchy of the root file system.  A file system must be mounted before it can be accessed.  A unmounted file system mounted at a mount point.

11 Silberschatz, Galvin and Gagne  2002 12.11 Operating System Concepts Mapping File System to Physical Devices

12 Silberschatz, Galvin and Gagne  2002 12.12 Operating System Concepts Layered File System Applications call the LFS via system calls LFS deals with file names, file and directory operations, file tables, security FOM maps logical to physical, buffers, tracks free blocks, tracks bad blocks BFS sends commands to DDs to access specified blocks on the device I/O control consists of device drivers and interrupts handlers for each device.

13 Silberschatz, Galvin and Gagne  2002 12.13 Operating System Concepts File Tables Draw my example To open a file  System wide file table is search to see if already open  If no, the directory structure is searched (cached if possible)  Node copied to system wide file table  A new entry in the per-process file table  Refers to the existing SW file table entry  Contains mode of access, and offset  Counter incremented in the SW file table To close a file  Per-process file table entry is removed  Count decremented in SW file table, and if 0 the node is written to disk To create a file  LFS allocates a new directory node  Reads in, updates, and writes out the directory

14 Silberschatz, Galvin and Gagne  2002 12.14 Operating System Concepts Contiguous Allocation Each file occupies a set of contiguous blocks on the disk  E.g., IBM, VMS

15 Silberschatz, Galvin and Gagne  2002 12.15 Operating System Concepts Contiguous Allocation Random access Block = LA / BlockSize Offset = LA % BlockSize Simple – only starting location (block #) and length (number of blocks) are required in a directory node Wasteful of space  Dynamic storage-allocation problem  External fragmentation Files cannot grow easily  Initial allocation?

16 Silberschatz, Galvin and Gagne  2002 12.16 Operating System Concepts Linked Allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. Block is a pointer (disk address) and data pointer block =

17 Silberschatz, Galvin and Gagne  2002 12.17 Operating System Concepts Linked Allocation (Cont.) Random access Block in chain = LA / (BlockSize - LinkSize) Offset = LA % (BlockSize - LinkSize) Simple – need only starting address Free-space management system – no waste of space  New file has NULL pointer in directory  Easy to get another or release a block Slow random access

18 Silberschatz, Galvin and Gagne  2002 12.18 Operating System Concepts Linked Allocation (Cont.) FAT variation  Table with index corresponding to blocks  Linked table entries - cached for fast traversal  Used by DOS and OS/2

19 Silberschatz, Galvin and Gagne  2002 12.19 Operating System Concepts Extent-Based Systems Many newer file systems (e.g., Veritas File System) use a modified contiguous allocation scheme. Extent-based file systems allocate disk blocks in extents. An extent is a contiguous block of disks. Extents are allocated for file allocation. A file consists of one or more extents. Extents are linked together Extents reduce LinkSize overhead E.g., NTFS

20 Silberschatz, Galvin and Gagne  2002 12.20 Operating System Concepts Indexed Allocation Brings all pointers together into the index block. index table

21 Silberschatz, Galvin and Gagne  2002 12.21 Operating System Concepts Indexed Allocation (Cont.) Random access Index table entry = LA / BlockSize Offset = LA % BlockSize Fast random access  Cached for speed Need index block  Small files have mostly empty index block Fixed maximal file size

22 Silberschatz, Galvin and Gagne  2002 12.22 Operating System Concepts Linked - Indexed Allocation Linked scheme – Link blocks of index table Random access Index block in chain = LA / (((BlockSize-LinkSize)/LinkSize) * BlockSize) LAInBlock = LA % (((BlockSize-LinkSize)/LinkSize) * BlockSize) Index table entry = LAInBlock / BlockSize Offset = LAInBlock % BlockSize

23 Silberschatz, Galvin and Gagne  2002 12.23 Operating System Concepts Two Level Indexed Allocation  outer-index index table file

24 Silberschatz, Galvin and Gagne  2002 12.24 Operating System Concepts Two Level Indexed Allocation Random access Outer index table entry = LA / (BlockSize 2 /LinkSize) LAInBlock = LA % (BlockSize 2 /LinkSize) Inner index table entry = LAInBlock / BlockSize Offset = LAInBlock % BlockSize Fixed, but large maximal size Fast random access if cached

25 Silberschatz, Galvin and Gagne  2002 12.25 Operating System Concepts Combined Scheme: UNIX (4K bytes per block) Fast for small files Gradual degradation as file size increases

26 Silberschatz, Galvin and Gagne  2002 12.26 Operating System Concepts Free-Space Management Linked list (free list)  Cannot get contiguous space easily  No waste of space  Can use same routines as for file management

27 Silberschatz, Galvin and Gagne  2002 12.27 Operating System Concepts Free-Space Management Bit vector (n blocks) (e.g., Mac) … 012n-1 bit[i] =  1  block[i] free 0  block[i] occupied Can use Motorola “find bit” instruction Easy to get contiguous blocks Needs to be kept in memory block size = 2 12 bytes (4KB) disk size = 2 36 bytes (64GB) n = 2 36 /2 12 = 2 24 bits = 2 21 bytes (2MB (!))

28 Silberschatz, Galvin and Gagne  2002 12.28 Operating System Concepts Efficiency and Performance Efficiency dependent on:  Disk allocation and directory algorithms  Types of data kept in file’s directory entry Performance  Disk cache – separate section of main memory for frequently used blocks  Free-behind and read-ahead – techniques to optimize cache performance for sequential access  A page cache caches pages rather than disk blocks using virtual memory techniques.  Improve PC performance by dedicating section of memory as virtual disk, or RAM disk.

29 Silberschatz, Galvin and Gagne  2002 12.29 Operating System Concepts Log Structured File Systems Log structured (or journaling) file systems record each update to the file system as a transaction. All transactions are written to a log. A transaction is considered committed once it is written to the log. However, the file system may not yet be updated. The transactions in the log are asynchronously written to the file system. When the file system is modified, the transaction is removed from the log. If the file system crashes, all remaining transactions in the log must still be performed.

30 Silberschatz, Galvin and Gagne  2002 12.30 Operating System Concepts UNIX File Systems Size of a block is given in sys/param.h as BSIZE, and is typically 512 or 1024 bytes. The area of disc set aside for a file system is split into 4 regions:  Block 0 is set aside for a bootstrap program if required  Block 1 contains the superblock which describes the file system as a whole, including free blocks and inodes lists.  Block 2 starts the inode area (fixed size)  Remaining blocks are allocated to files 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.

31 Silberschatz, Galvin and Gagne  2002 12.31 Operating System Concepts Inodes A file (could be a directory) is represented by an inode — a record that stores information about a specific file on the disk.  Type of file  Plain  Directory  FIFO  Special, …  Access permissions.  Number of links to this inode  User and group IDs of the file owner.  Size of file in bytes for files, device number for devices.  Times of creation, last access, and last modification  Addresses of the files data blocks. Inodes are numbered from 1  Inode 1 is reserved for the bad blocks list  Inode 2 for the root directory of the file system.

32 Silberschatz, Galvin and Gagne  2002 12.32 Operating System Concepts Directories The inode type field distinguishes between plain files and directories. Directory entries are of variable length, with fields:  The length of the entry  The file name  The inode number.

33 Silberschatz, Galvin and Gagne  2002 12.33 Operating System Concepts Finding Inodes The OS has to map the supplied user path name to an inode  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. 4.3BSD improved file system performance by adding a directory name cache to hold recent directory-to-inode translations.

34 Silberschatz, Galvin and Gagne  2002 12.34 Operating System Concepts File System Data Structures UNIX maintains  System inode table - inodes of files that are open + name + counter  System file table - offset, mode + counter  Per process file table - not much Tables are of fixed length

35 Silberschatz, Galvin and Gagne  2002 12.35 Operating System Concepts Files To create a file  Allocate new inode  Write new entry in directory file To open a file  Search inode table  If open, create system & process file table entries, increment counters  If not open, read in inode and create table entries To use a file, use the process file table entry To close a file  Delete process file table entry, decrement system file table counter  If system file table counter is 0, delete and decrement inode table counter  If inode table counter is 0, write out inode and delete To delete a file  Delete directory entry  Decrement link counter  If link counter is 0, and inode not in inode table, delete inode

36 Silberschatz, Galvin and Gagne  2002 12.36 Operating System Concepts Schematic View of NFS Architecture

37 Silberschatz, Galvin and Gagne  2002 12.37 Operating System Concepts NFS Protocol Provides a set of remote procedure calls for remote file operations. The procedures support the following operations:  searching for a file within a directory  reading a set of directory entries  manipulating links and directories  accessing file attributes  reading and writing files NFS servers are stateless; each request has to provide a full set of arguments. Modified data must be committed to the server’s disk before results are returned to the client (lose advantages of caching). The NFS protocol does not provide concurrency-control mechanisms.


Download ppt "Silberschatz, Galvin and Gagne  2002 12.1 Operating System Concepts File-System Structure File structure user view  Logical storage unit  Collection."

Similar presentations


Ads by Google