Conversion of Byte Offset to Block Number in File System
algorithm bmap /* block map of logical file byte of offset to file system block*/
input : (1) inode
(2) byte offset
output: (1) block number in file system
(2) byte offset into block
(3) byte of I/O in block
(4) read ahead block number
{
calculate logical block number in file from byte offset ;
calculate start byte in block for I/O ;
calculate number of bytes to copy to user ;
check if read - ahead applicale , mark inode ;
determine level of indirection ;
while( not at necessary level of indirection)
{
calculate index into inode or indirect block from logical block number in file ;
get disk block number from inode or indirect block ;
release buffer from previous disk read , if any (algorithm brelease );
if(no more levels of indirection)
return(block number);
read indirect disk block(algorithm bread);
adjust logical block number in file according to level of indirection ;
}
}
algorithm bmap /* block map of logical file byte of offset to file system block*/
input : (1) inode
(2) byte offset
output: (1) block number in file system
(2) byte offset into block
(3) byte of I/O in block
(4) read ahead block number
{
calculate logical block number in file from byte offset ;
calculate start byte in block for I/O ;
calculate number of bytes to copy to user ;
check if read - ahead applicale , mark inode ;
determine level of indirection ;
while( not at necessary level of indirection)
{
calculate index into inode or indirect block from logical block number in file ;
get disk block number from inode or indirect block ;
release buffer from previous disk read , if any (algorithm brelease );
if(no more levels of indirection)
return(block number);
read indirect disk block(algorithm bread);
adjust logical block number in file according to level of indirection ;
}
}
No comments:
Post a Comment