Presentation is loading. Please wait.

Presentation is loading. Please wait.

W4118 Operating Systems Instructor: Junfeng Yang.

Similar presentations


Presentation on theme: "W4118 Operating Systems Instructor: Junfeng Yang."— Presentation transcript:

1 W4118 Operating Systems Instructor: Junfeng Yang

2 File Systems  File system concepts  What is a file?  What operations can be performed on files?  What is a directory and how is it organized?  File system implementation  What are typical file access patterns?  How to allocate disk space to files? 1

3 What is a File  User view  Named byte array Types defined by user  Persistent across reboots and power failures  OS view  Map bytes as collection of blocks on physical storage  Stored on nonvolatile storage device Magnetic Disks 2

4 Role of File System  Naming  How to “name” files  Translate “name” + offset  logical block #  Reliability  Must not lose file data  Protection  Must mediate file access from different users  Disk Management  Fair, efficient use of disk space  Fast access to files 3

5 Metadata  Name – only information kept in human-readable form  Identifier – unique tag (number) identifies file within file system (inode number in UNIX)  Location – pointer to file location on device  Size – current file size  Protection – controls who can do reading, writing, executing  Time, date, and user identification – data for protection, security, and usage monitoring  How is metadata stored? (inode in UNIX) 4

6 File Operations  File is an abstract data type  Create  Write  Read  Reposition within file  Delete  Truncate  Rename 5

7 Open Files  Problem: expensive to resolve name to identifier on each access  Solution: open file before first access  Search directories for file name and check permissions (“name resolution”)  Read relevant metadata into open file table in memory  Return index in open file table (“file descriptor”)  Application pass index to OS for subsequent file access  System open file table shared acorss procsses  Per-process open file table  Current position pointer  Index in system open file table 6

8 Directories  Organization technique  Map file name to location on disk  Also stored on disk  Single-Level directory  Single directory for entire disk Each file must have unique name  Not very usable  Two-level directory  Directory for each user  Still not very usable 7

9 Tree-Structured Directory  Directory stored on disk just like files  Data consists of pairs Name can be another directory  Designated by special bit in meta-data  Reference by separating names with slashes  Operations User programs can read Only special system programs can write  Special directories  Root (/): fixed index for metadata . : this directory .. : parent directory 8

10 Acyclic-Graph Directories  Directories can share files  Create links from one file  Two types of links  Hard link Multiple directory entries point to same file Store reference count in file metadata Cannot refer to directories; why?  Symbolic link Special file, designated by bit in meta-data  File data is name to another file 9

11 Path Names  Absolute path name (full path name)  Start at root directory E.g. /home/junfeng/teaching  Relative path name  Full path is lengthy and inflexible  Give each process current working directory  Assume file in current directory 10

12 File Systems  File system concepts  What is a file?  What operations can be performed on files?  What is a directory and how is it organized?  File system implementation  What are typical file access patterns?  How to allocate disk space to files? 11

13 Typical File Access Patterns  Sequential Access  Data read or written in order Most common access pattern –E.g., copy files, compiler read and write files,  Can be made very fast (peak transfer rate from disk)  Random Access  Randomly address any block E.g., update records in a database file  Difficult to make fast (seek and rotational delays) 12

14 Disk Management  Need to track where file data is on disk  How should we map logical sector # to surface #, track #, and sector #? Order disk sectors to minimize seek time for sequential access  Need to track where file metadata is on disk  Need to track free versus allocated areas of disk  E.g., block allocation bitmap (Unix) Array of bits, one per block Usually keep entire bitmap in memory 13

15 Allocation Strategies  Various approaches (similar to memory allocation)  Contiguous  Extent-based  Linked  FAT tables  Indexed  Multi-Level Indexed  Key questions  Fragmentation (internal & external)?  Grow file over time after initial creation?  Fast to find data for sequential and random access?  Easy to implement?  Storage overhead? 14

16 Contiguous Allocation  Allocate files like Segment memory (base & bounds)  User specifies length, file system allocates space all at once  Finding disk space by examining bitmap (best-fit or first-fit)  Metadata: contains starting location and size of file 15

17 Contiguous Allocation Example

18 Pros and Cons  Pros  Cons 17

19 Extent-Based Allocation  Multiple contiguous regions per file  Each region is an extent  Metadata: contains small array of entries designating extents Each entry: start and size of extent 18

20 Pros and Cons  Pros  Cons 19

21 Linked Allocation  All blocks (fixed-size) of a file on linked list  Each block has a pointer to next  Metadata: pointer to the first block 20 pointer block

22 Linked Allocation Example

23 Variation: FAT table  Store linked-list pointers outside block in File- Allocation Table  One entry for each block  Linked-list of entries for each file 22

24 FAT Example

25 Pros and Cons  Pros  Cons 24

26 Indexed Allocation  File has array of pointers (index) to block  Allocate block pointers contiguously in metadata Must set max length when file created Allocate pointers at creation, allocate blocks on demand Cons:  Maintain multiple lists of block pointers Last entry points to next block of pointers Cons: 25 block pointers

27 Indexed Allocation Example

28 Pros and Cons  Pros  Cons 27

29 Multi-Level Indexed Files  Block index has multiple levels 28  outer-index index table file

30 Multi-level Indexed Allocation Example (UNIX FFS, Linux ext2, 4K bytes per block)

31 Pros and Cons  Pros  Cons 30


Download ppt "W4118 Operating Systems Instructor: Junfeng Yang."

Similar presentations


Ads by Google