22
File Systems

File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

Embed Size (px)

Citation preview

Page 1: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

File Systems

Page 2: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

2

What is a file?

• A repository for data

• Is long lasting (until explicitly deleted).

Page 3: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

3

Why not just an address space?

• You may want data to persist longer than a process

• You may want data that is larger than a virtual address space

• Easier to share the data across processes.

Page 4: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

4

Two aspects to consider …

• User’s view– Naming, type, structure, access,

attributes, operations, …

• System implementation

Page 5: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

5

Naming

• Typically x.y

• x is supposed to give some clue about contents

• y is supposed to be the nature of the file.

Page 6: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

6

Structure

• Byte stream

• Sequence of Records/Blocks

• Indexed Records

Page 7: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

7

Type

• Regular files (containing data)

• Directories

• Character special files (access a character at a time)– To access serial communication devices (e.g.,

modems)

• Block special files (access a block at a time)– To access block devices (e.g., disk drives, CDs)

Page 8: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

8

Access

• Sequential

• Random

Page 9: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

9

Attributes

• protection, creator, owner, creation time, access time, current size, max size, record length, lock flags, ...

Page 10: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

10

File Operations

• Create, Delete, Open, Close, Read, Write, Append, Seek, Get attributes, Set attributes, Rename

Page 11: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

11

Directory

• A way of organizing files.

• Each directory entry has:– File/directory name– A way (pointer) to get to the data

blocks of that file/directory

Page 12: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

12

• Flat/Single-Level Directory

• Hierarchical/Tree-Structured Directory

Page 13: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

13

Directories

• File names: relative vs. absolute

• Directory Operations: Create: Delete directory Open Dir Close Dir Read Dir Rename Link (allow a file to appear in more than 1

directory) Unlink

Page 14: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

14

File System Implementation

• View the disk as a logical sequence of blocks (typically 512 bytes)

• A block is the smallest unit of allocation.

• Issues:– How do you assign the blocks to files?– Given a file, how do you find its

blocks?

Page 15: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

15

Contiguous Allocation

• Allocate a sequence of contiguous blocks to a file.

• Advantages:– Need to remember only starting location

to access any block– Good performance when reading

successive blocks on disk

• Disadvantages:– File size has to be known a priori.– External fragmentation

Page 16: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

16

Linked List Allocation• Keep a pointer to first block of a

file. • The first few bytes of each block

point to the next block of this file.• Advantages: No external

fragmentation• Disadvantages: Random access is

slow!

File 1 File 2

Page 17: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

17

Linked List Allocn. Using an Index (e.g. DOS)

• In the prev. scheme, we needed to go to disk to chase pointers.

• Can remove the pointers from the blocks, and maintain them separately.– Could be made to fit in memory

• Allocation is still done using linked list, but pointer chasing done in memory

Page 18: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

18

File 1 File 2

Disk Blocks

File-Allocation Table (FAT)

Page 19: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

19

Indexed Allocation(e.g. UNIX)

• For each file, you directly have a pointers to all its blocks.

• However, the number of pointers for a file can itself become large.

• UNIX uses i-nodes.• An i-node contains:

– File attributes (time of creation, permissions, ….)– 10 direct pointers (logical disk block ids)– 1 one-level indirect pointer (points to a disk block

which in turn contains pointers)– 1 two-level indirect pointer (points to a disk block

of pointers to disk blocks of pointers)– 1 three-level indirect pointer (points to a disk

block of pointers to disk blocks of pointers to pointers of disk blocks)

Page 20: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

20

i-nodeFilenameTimePerm. …

Disk Block

Disk Block Disk Block

Disk Block Disk Block Disk Block

Data

Disk Block

Data

Disk Block

Data

Disk Block

Data

Disk Block

Page 21: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

21

Tracking free blocks

• List of free blocks– bit map: used when you can store

the entire bit map in memory.– linked list of free blocks

•each block contains ptrs to free blocks, and last ptr points to another block of ptrs. (in UNIX).

•Pointer to a free FAT entry, which in turn points to another free entry, etc. (in DOS)

Page 22: File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted)

22

• Now we know how to retrieve the blocks of a file once we know:– The FAT entry for DOS– The i-node of the file in UNIX

• But how do we find these in the first place?– The directory where this file resides

should contain this information