Professional Documents
Culture Documents
Unit 2
Unit 2
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
Introduction (1)
process to access a file.
File ownership Access rights File size Location of file data
calls by specifying the path name Kernel converts the path name to the files inode.
Introduction (2)
Gives insight into
How the kernel manipulates the inode The internal structure of regular files and how the
kernel reads and writes their data Structure of the directory Structure of the superblock Assignment of disk inodes and disk block to file file types : pipes and device file
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
Definition of Inodes
Every file has a unique inode
Contain the information necessary for a
process to access a file Exist in a static form on disk Kernel reads them into an in-core inode to manipulate them.
File type (regular, directory,..) File access permission (owner,group,other) File access time Number of links to the file Table of contents for the disk address of data in a file
Kernel saves the data in discontiguous disk blocks The Inodes identifies the disk blocks
File size
1 greater than the highest byte offset of data Byte offset 1000 -> the size of the file : 1001 byte
File owner identifier File type File access permission File access time Number of links to the file Table of contents for the disk address of data in a file File size
Owner mjb Group os Type regular file Perms rwxr-xr-x Accessed Oct 23 1984 1:45 P.M Modified Oct 22 1984 10:3 A.M Inode Oct 23 1984 1:30 P.M Size 6030 bytes Disk addresses
10
the data in the inode Differ from the disk copy as a result of a change to the file data File is a mount point
11
12
13
14
} }
15
Accessing Inodes
Kernel identifies inodes by their file system and
inode number Allocate in-core inodes at the request of higherlevel algorithms (in-core inode, by iget algorithm) Kernel maps the device number & inode number into a hash queue Search the queue for the inode
16
Block Number
Computing logical disk block number
Block number
= ((inode number 1) / number of inodes per block) + start block inode list Example 1
Block 2 : beginning of the inode list 8 inodes per block Inode number 8 is in disk block ? Inode number 9 is ?
Example 2 Block 2 : beginning of the inode list 16 inodes per block Inode number 8 is in disk block ? Inode number 9 is ? Inode number 17 is ?
Internal representation of files 17
Byte Offset
Read the block using bread
Computing byte offset of the inode in the block ((inode number 1) mod (number of inodes per block))* size of disk inode Example
Each disk inode 64 bytes 1 block : 8 inodes Inode 8 starts at byte offset 448 in the disk block
18
from accessing the inode while it is in use. Kernel releases the lock at the conclusion of the system call Inode is never locked across system calls.
Reference count
Kernel increase/decrease when reference is active/inactive Prevent the kernel from reallocating an active in-core inode
Thus kernel can lock and unlock an allocated inode independent of the value of the reference count.
19
Releasing an Inodes(1)
Using algorithm iput
decrements in-core reference count Write the inode to disk Reference count is 0 The in-core copy differs from the disk copy Add the inode on the free list of inodes For caching
20
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
22
Not contiguous file allocation strategy Why ? When a file expand or contract Fragmentations occur
23
Sample - Fragmentation
. 40 File A 50 File B 60 File C 70 .
. 40
File A 50
Free 60
File C 70
File B 85
Assume
a logical block = 1K bytes a block number is addressable by a 32 bit (4 bytes) integer a block can hold up to 256 block numbers
10 direct blocks with 1K bytes each= 10K bytes 1 indirect block with 256 direct blocks= 1K*256 = 256K bytes 1 double indirect block with 256 indirect blocks = 256K*256= 64M bytes 1 triple indirect block with 256 double indirect blocks=64M*256=16G bytes
25
direct1
direct2 direct3 direct4
direct5
direct6 direct7 direct8 direct9 single indirect double indirect triple indirect
Internal representation of files 26
Kernel accesses the inode and converts the logical file block into the appropriate disk block (bmap algorithm)
27
4096
228
45423 0 0 11111 0 101
8 367 Data block Byte 9000 in a file -> 8block 808th byte
75 3333
11
29
#1008th byte in block 367 Byte number 355,000 is calculated as follows: a. 1st byte of the double indirect block is 256k+10k = 272,384 b. byte number 355,000 is number 82,616 in the double indirect block c. every single indirect block has 256k bytes --> byte 355,000 is in the 0th single indirect block - 231 d. Every entry is 1k, so byte 82,616 is in the 80th block - 123 e. within block 123 it is byte #696
231
80
123 231
123
31
single operation, the faster file access becomes But it increase block fragmentation Solution : One disk block can contain fragments belonging to several files
32
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
33
Directories
A directory is a file
of an inode number and the name of a file contained in the directory Path name is a null terminated character string divided by / Each component except the last must be the name of a directory, last component may be a non-directory file
34
File Names
. .. init fsck crash mkfs inittab
35
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
Internal representation of files 36
else
working inode= current directory inode
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
38
Super block
File System
boot block super block inode list data blocks
Consists of
the size of the file system the number of free blocks in the file system a list of free blocks available on the file system the index of the next free block in the free block list the size of the inode list the number of free inodes in the file system a list of free inodes in the file system the index of the next free inode in the free inode list lock fields for the free block and free inode lists a flag indicating that the super block has been modified
39
Table of Contents
Introduction Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
40
41
42
43
index
Super Block Free Inode List free inodes 83 18 19 20 index
empty array
44
index
48
49
50
index
45
free inodes
index
Original Super Block List of Free Inodes 499 471 remembered inode Free Inode 499 499 471 remembered inode Free Inode 601 476 475 free inodes index 476 475 free inodes index
47
Tries to assign inode from super block Super block empty(b) Search for free inodes on disk, puts inode I in super block (c)
Inode I in core Does usual activity Completes search, assigns another inode(d)
48
(b)
empty
(c)
Free inodes
I K
(d)
Free inodes
(e)
Free inodes
49
Table of Contents
Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary
Internal representation of files 50
109 106 103 100 .. 109 211 208 205 202 211 310 307 304 301
112
214
313
51
52
205 202
..
original configuration 109 949 .. 109 211 208 205 202 . 112 After freeing block number 949
53
After assigning block number(949) 211 208 205 202 112 211 344 341 338 335 . 243 After assigning block number(109) replenish super block free list
Internal representation of files 54
Table of Contents
Introduction Inodes Structure of a regular file Directories Conversion of a path name to an Inode Super block Inode assignment to a new file Allocation of disk blocks Other file types Summary
Internal representation of files 55
56
Table of Contents
Introduction Inodes Structure of a regular file Directories Conversion of a path name to an Inode Super block Inode assignment to a new file Allocation of disk blocks Other file types Summary
Internal representation of files 57
Summary
Inode is the data structure that describes the attributes of a
file, including the layout of its data on disk. Two version of the inode
Disk copy : store the inode information when file is not in use In-core copy : record the information about active files.
ialloc/ifree : assignment of a disk inode iget/iput : allocation of in-core inodes bmap : locate disk blocks of a file, according to byte offset Directories : files that correlate file name components to inode numbers namei : convert file names to inodes alloc/free : assignment of new disk blocks to a file
Internal representation of files 58