Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Slide 07

Download as pdf or txt
Download as pdf or txt
You are on page 1of 100

Operating System

Nguyen Tri Thanh


ntthanh@vnu.edu.vn

1
File System
Implementation
File-System Structure
File-System Implementation
Directory Implementation
Allocation Methods
Free-Space Management
Efficiency and Performance
Recovery
2
Objectives
 Introduce what a file is
 Introduce file system implementation
 Introduce directory implementation
 Introduce 3 allocation methods
 Introduce free space management

3
Reference
 Chapter 10, 11 of Operating System
Concepts

4
File Concept
 Contiguous logical address space
 Types:
 Data
 numeric
 character
 binary
 Program

5
File Structure
 None - sequence of words, bytes
 Simple record structure
 Lines
 Fixed length
 Variable length
 Complex Structures
 Formatted document
 Relocatable load file
 Can simulate last two with first method by
inserting appropriate control characters
 Who decides:
 Operating system
6
 Program
File Attributes
 Name
 only information kept in human-readable form
 Identifier
 unique (number) identifies file within file system
 Type
 needed for systems that support different types
 Location
 pointer to file location on storage device

7
File Attributes (cont’d)
 Size
 current file size
 Protection
 controls who can do reading, writing, executing
 Time, date, and user identification
 data for protection, security, and usage monitoring
 Information about files are kept in the
directory structure on the disk

8
File Attributes (cont’d)

9
File System Structure
 File system resides on secondary storage
 HDD disks, CD ROM, DVD, flash drive, SSD, …
 File system organized into layers
 File control block (FCB)
 storage structure of information about a file
 inode (index node) has partial information of FCB
on Linux

10
A Typical File Control Block

11
Inode on Linux

12
Question
 Which of the following is incorrect about file
control block (FCB)?
A. a data structure containing information of a file
B. OS needs a FCB to access a file
C. FCB of a file is updated when a file is accessed
D. FCBs reside in memory

13
Layered File System

14
Virtual File Systems
 Virtual File Systems (VFS)
 provide an object-oriented way of implementing
file systems
 allow the same system call interface (the API) to
be used for different types of file systems
 the API is to the VFS interface, rather than any
specific type of file system.

15
Schematic View of
Virtual File System

16
Linux VFS

FAT NTFS

17
File system list

18
File system list

19
Question
 Which of the following is incorrect about
VFS?
A. VFS allows an OS to support many different file
systems
B. VFS provides the same API for all file systems
C. VFS is available in all OSes
D. VFS hides the detailed implementation of each
file system from programmers

20
Question
 Which of the following is a correct description
of a directory?
A. a directory is a disk partition to contain files
B. a directory is actually a file containing partial
information about its files
C. a directory is a container of files’ data
D. a directory contains the FCB and data of files

21
Directory Structure
 A collection of nodes containing information
about all files

Directory

Files
F1 F2 F4
F3
Fn

22
Directory Implementation
 Linear list
 list of file names with pointer to the data blocks
 simple to program
 time-consuming to execute
 FAT http://en.wikipedia.org/wiki/File_Allocation_Table
 Linux FS (Ext3)
 Hash Table
 linear list with hash data structure
 decreases directory search time
 collisions resolution
 fixed size 23
Directory Implementation
 Balanced binary tree
 RAISERFS http://en.wikipedia.org/wiki/ReiserFS

24
Directory in Linux

25
Directory in Linux

26
Directory in Linux

27
File management API

28
File Operations
 Create
 Write
 Read
 Reposition within file
 Delete
 Truncate
 Open(Fi)
 search the directory structure on disk for entry Fi, and
move the content of entry to memory
 Close (Fi)
 move the content of entry Fi in memory to directory 29

structure on disk
File Operations

30
File Operations

31
Operations Performed on
Directory
 Search for a file
 Create a directory
 Delete a directory
 List a directory
 Rename a directory
 Traverse the file system

32
Operations Performed on
Directory

33
Operations Performed on
Directory

34
File/directory protection

35
Protection
 File owner/creator should be able to control:
 what can be done
 by whom
 Types of access
 Read
 Write
 Execute
 Append
 Delete
 List
36
Access Lists and Groups
 Mode of access: read, write, execute
 Three classes of users
RWX
a) owner access 7  111
RWX
b) group access 6  110
RWX
c) public access 1  001
 Ask manager to create a group (unique name), say G, and add
some users to the group.
 For a particular file (say game) or subdirectory, define an
appropriate access.

owner group public

Attach a group to a file chmod 761 game

chgrp G game

37
Question
 Suppose a file has access mode 664. Which
is correct ?
A. Any user can execute the file

B. Users of the owner group can execute the


file
C. Any user can read the file

D. The owner cannot write the file

38
Windows XP
Access-control
List
Management

39
Storage Allocation
Methods

40
Disk partitions
 A disk can be split into partitions
 each is a consecutive range of cylinders
 each is also called logic disk
 e.g., Windows called: C, D, E drives

41
Disk partitions
 A disk can be split into partitions
 each is a consecutive range of cylinders
 each is also called logic disk
 e.g., Windows called: C, D, E drives

42
Disk partitions
 A disk can be split into partitions
 each is a consecutive range of cylinders
 each is also called logic disk
 e.g., Windows called: C, D, E drives

43
Disk partitions
 A disk can be split into partitions
 each is a consecutive range of cylinders
 each is also called logic disk
 e.g., Windows called: C, D, E drives

44
Partition organization
 Organization is specific to each OS
 region for storing data is divided into equal
blocks
 block is a read/write unit of OS

45
Partition organization
 Organization is specific to each OS
 region for storing data is divided into equal
blocks
 block is a read/write unit of OS

EXT3

This part is divided


into blocks

46
Format logical volume

47
Format logical volume

48
xfs format

49
ext4 format

50
Allocation Methods
 An allocation method refers to how disk
blocks are allocated for files
 Contiguous allocation
 Linked allocation
 Indexed allocation
 Each method needs an appropriate way to
access file

51
Contiguous Allocation
 Each file occupies a set of contiguous blocks
on the disk
 Simple
 only starting location (block #) and length (number
of blocks) are required
 Random access
 Wasteful of space
 dynamic storage-allocation problem
 Files cannot grow

52
Mapping from logical add into
block/offset
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 …
0 1 2 3

• Logical address = x
• Q (blockid) = x / block_size
• R (offset) = x % block_size
• X = 9 => Q= 9/4 = 2; R= 9%2 =1

53
Contiguous Allocation
 Mapping from logical to physical
 LA is position to access
Q - block

LA/512

R - offset

Suppose block size is 512KB


Block to be accessed = Q + starting address
Displacement/offset into block = R

54
Contiguous Allocation
of Disk Space

55
Question
 A system using contiguous allocation
 block size is 2KB
 a file has the length of 12.5MB
 Which of the following is the correct location of
file at position 50.5KB
A. block 25, offset 512
B. block 24, offset 1024
C. block 25, offset 510
D. block 24, offset 2512

56
Extent-Based Systems
 Many newer file systems (I.e. Veritas File
System)
 use a modified contiguous allocation scheme
 Extent-based file systems
 allocate disk blocks in extents
 An extent is a contiguous blocks of disk
 Extents are allocated for file allocation
 A file consists of one or more extents
 extents of a file are not necessarily contiguous
57
Question
 An extent-based file system
 an extent has 100 blocks
 a block has size 2KB
 a file has size 25.3MB
 Which of the following is the correct extent
number (started by 0) of file at position 15MB?
A. 74
B. 75
C. 76
D. 77
58
Question
 An extent-based file system
 an extent has 100 blocks
 a block has size 2KB
 a file has size 25.3MB
 Which of the following is the correct block
(started by 0) number in the extent containing
the data of file at position 15MB?
A. 77
B. 78
C. 79
D. 80 59
Question
 An extent-based file system
 an extent has 100 blocks
 a block has size 2KB
 a file has size 25.3MB
 Which of the following is the correct offset of
the of file at position 15MB in the block
containing data?
A. 0
B. 2047
C. 2048
D. 512 60
Linked Allocation
 Each file is a linked list of disk blocks:
 blocks may be scattered anywhere on the disk.

block = pointer

Data

61
Linked Allocation

62
Question
 A system uses linked list allocation
 partition size 500GB (1GB=1024MB,1MB=1024KB,…)
 block size 1KB
 Which of the following is the correct size of the
pointer of each block?
A. short (2 bytes)
B. int (4 bytes)
C. float (4 bytes)
D. long (8 bytes)

63
Question
 A system uses linked list allocation
 Which of the following is the correct reason for
no direct access?
A. because we don’t know the location of block n
directly
B. because data blocks of a file may be scattered
C. because of security reason
D. because the information of data block location is
hidden

64
Question
 A system uses linked list allocation
 Which of the following is the correct way to
access block n of a file?
A. read the first block to find the location of block n
B. look up the location of block n from a table
C. recursively read block n-1 to find out the location
of block n
D. there is no way to find the location of block n

65
Linked Allocation (Cont.)
 Simple
 need only starting address
 Free-space management system
 no waste of space
 No random access
 File-allocation table (FAT) – disk-space allocation
used by MS-DOS and OS/2.

66
Question
 A system uses linked list allocation
 block size 2KB
 pointer size 4 bytes
 file size 15.4MB
 Which of the following is the correct block of file
at position 15.25KB?
A. 7
B. 8
C. 9
D. 10
67
Question
 A system uses linked list allocation
 block size 2KB
 pointer size 4 bytes
 file size 15.4MB
 Which of the following is the correct offset in the
block of file at position 15.25KB?
A. 1311
B. 1312
C. 1313
D. 1314
68
File-Allocation Table (DOS)

• Separate the
pointers from
data
• pointers are
stored in File
-1 Allocation Table
(FAT)
• The system
stores two
identical copies
of FAT
69
Question
 Which of the following is incorrect about
FAT?
A. it is fast to access the block n of a file
B. it is slow to access the block n of a file
C. if FAT is corrupted the whole partition is
corrupted
D. the system keeps two copies of FAT in order to
reduce the risk of FAT corruption

70
Indexed Allocation

 Brings all pointers together into the index block


 Logical view

index block data blocks

71
Example of Indexed Allocation

72
Indexed Allocation (Cont.)
 Need index block
 Random access
 Dynamic allocation without external
fragmentation
 have overhead of index block

73
Question
 System uses indexed allocation
 block size 4KB
 pointer size 4 bytes
 Which of the following is the correctly
maximum file size?
A. 4MB
B. 8MB
C. 16MB
D. 32MB

74
Question
 System uses indexed allocation
 block size 4KB
 pointer size 4 bytes
 file size 3MB
 Which of the following is the correct block
(starting from 0) and offset at file position
35KB?
A. (block, offset)=(9, 3071)
B. (block, offset)=(9, 3070)
C. (block, offset)=(8, 3072)
D. (block, offset)=(8, 3070)
75
Indexed Allocation (cont’d)
 Two-level index
 Two level of index block
 Method to increase file size
File entry

outer-index

76

index table data


Address locating

Go to USA 
San Francisco

California St
 3333

77
Indexed Allocation (cont’d)
 A system uses two-level index
 block size 4KB
 pointer size 4 Bytes
 Which of the following is the correct maximum
file size?
A. 4GB
B. 1GB
C. 8GB
D. 2GB

78
Indexed Allocation (cont’d)
 A system uses two-level index
 Which of the following is the correct steps to
locate the data at file position n?
A. Identify block number  block number in block
table  offset
B. Identify block number in outer index block  block
number  offset
C. Identify offset  block number
D. none of the above

79
Indexed Allocation (cont’d)
 A system uses two-level index
 block size 4KB
 pointer size 4 Bytes
 File size 20MB
 Which is the correct address of file at position
15MB?
A. (4,3072,0)
B. (3,768,1023)
C. (3,768,0)
D. (3,3072,0)
80
Indexed Allocation (Cont.)
 Linked scheme
 no limit on file size
 Combine linked list with
index block
 index blocks are linked
 last pointer of a index block is
the address of the next one

index table data blocks

81
Question
 Linked index block allocation
 block size 2KB
 pointer size 4 bytes
 File size 20MB
 Which of the following is the correct steps to read
file at position 15.5MB
A. identify index block  offset  block number  read
B. identify offset  block number  index block  read
C. identify offset  index block  block number  read
D. identify index block  block number offset  read

82
Question
 Linked index block allocation
 block size 2KB
 pointer size 4 bytes
 File size 20MB
 Which of the following is the correct index block
number at file position 15.5MB (start from 0)

83
Question
 Linked index block allocation
 block size 2KB
 pointer size 4 bytes
 File size 20MB
 Which of the following is the correct index block
number at file position 15.5MB (start from 0)
A. 13
B. 14
C. 15
D. 16
84
Question
 Linked index block allocation
 block size 2KB
 pointer size 4 bytes
 File size 20MB
 Which of the following is the correct block
number and offset at file position 15.5MB
A. (block, offset)=(271, 2047)
B. (block, offset)=(271, 0)
C. (block, offset)=(270, 2047)
D. (block, offset)=(270, 0)
85
86
Combined Scheme: UNIX
(4K bytes per block)
87
(10 direct pointers)
Question
 A UNIX system
 pointer size 4 bytes
 block size 4 KB
 12 direct pointers, 1 single indirect, 1 double indirect,
1 triple indirect pointers
 Which of the following is the correct maximum
file size?
A. (12+210+220+230)KB
B. 4*(210+220+230)KB
C. 232KB
D. 4*(12+210+220+230)KB
88
Question
 A UNIX system
 pointer size 4 bytes
 block size 4 KB
 12 direct pointer, 1 single indirect, 1 double indirect, 1
triple indirect pointers
 Which of the following is the correct maximum
number of indexed blocks?
A. (1+210+220)
B. (2+210+220)
C. (3+211+220)
D. 220
89
Question
 A UNIX system
 pointer size 4 bytes
 block size 4 KB
 12 direct pointer, 1 single indirect, 1 double indirect, 1
triple indirect pointers
 File size 78MB
 Which of the following is the correct location at file
position 95KB?
A. triple indirect block, (block, offset)=(12,3071)
B. double indirect block, (block, offset)=(12,3071)
C. single indirect block, (block, offset)=(11,3071)
D. single indirect block, (block, offset)=(11,3072)
90
Free-Space Management
 Bit vector (n blocks), e.g. Linux (ext3)
 Easy to get contiguous blocks
0 1 2 n-1

 0  block[i] free


bit[i] =
1  block[i] occupied

• Bit map requires extra space


Example:
block size = 212 bytes
disk size = 230 bytes (1 gigabyte)
n = 230/212 = 218 bits (or 32K bytes)
91
Free-Space Management
(Cont.)
 Linked list (free list)
 Cannot get contiguous space easily
 No waste of space
 Grouping
 Use linked blocks to store pointers to free blocks
 Last pointer in a block is the address of the next one
 Counting
 several contiguous blocks are freed/allocated for a file
 each entry has
 address of the first free block
 number of contiguously free blocks 92
Free-Space Management
(Cont.)
 Need to protect:
 Pointer to free list
 Bit map
 Must be kept on disk
 Copy in memory and disk may differ
 Cannot allow for block[i] to have a situation where bit[i] =
1 in memory and bit[i] = 0 on disk
 Solution:
 Set bit[i] = 1 in disk
 Allocate block[i]
 Set bit[i] = 1 in memory

93
Linked Free Space List on Disk

94
Shared file systems
 A file system is shared to other machines
 the file system may be large and powerful
 file sharing is needed in many applications
 available in many systems, e.g., Windows, Linux
(NFS)

95
Shared file systems

96
Shared file systems

97
Shared file systems

98
Network File System (NFS)
Architecture

99
Question? 100

You might also like