99#include "bitmap.h"
1010#include "simplefs.h"
1111
12- /* Map the buffer_head passed in argument with the iblock-th block of the file
13- * represented by inode. If the requested block is not allocated and create is
14- * true, allocate a new block on disk and map it.
12+ /* Associate the provided 'buffer_head' parameter with the iblock-th block of
13+ * the file denoted by inode. Should the specified block be unallocated and the
14+ * create flag is set to true, proceed to allocate a new block on the disk and
15+ * establish a mapping for it.
1516 */
1617static int simplefs_file_get_block (struct inode * inode ,
1718 sector_t iblock ,
@@ -23,7 +24,6 @@ static int simplefs_file_get_block(struct inode *inode,
2324 struct simplefs_inode_info * ci = SIMPLEFS_INODE (inode );
2425 struct simplefs_file_ei_block * index ;
2526 struct buffer_head * bh_index ;
26- bool alloc = false;
2727 int ret = 0 , bno ;
2828 uint32_t extent ;
2929
@@ -43,12 +43,15 @@ static int simplefs_file_get_block(struct inode *inode,
4343 goto brelse_index ;
4444 }
4545
46- /* Check if iblock is already allocated. If not and create is true,
47- * allocate it. Else, get the physical block number.
46+ /* Determine whether the 'iblock' is currently allocated. If it is not and
47+ * the create parameter is set to true, then allocate the block. Otherwise,
48+ * retrieve the physical block number.
4849 */
4950 if (index -> extents [extent ].ee_start == 0 ) {
50- if (!create )
51- return 0 ;
51+ if (!create ) {
52+ ret = 0 ;
53+ goto brelse_index ;
54+ }
5255 bno = get_free_blocks (sbi , 8 );
5356 if (!bno ) {
5457 ret = - ENOSPC ;
@@ -61,13 +64,12 @@ static int simplefs_file_get_block(struct inode *inode,
6164 extent ? index -> extents [extent - 1 ].ee_block +
6265 index -> extents [extent - 1 ].ee_len
6366 : 0 ;
64- alloc = true;
6567 } else {
6668 bno = index -> extents [extent ].ee_start + iblock -
6769 index -> extents [extent ].ee_block ;
6870 }
6971
70- /* Map the physical block to to the given buffer_head */
72+ /* Map the physical block to the given ' buffer_head'. */
7173 map_bh (bh_result , sb , bno );
7274
7375brelse_index :
0 commit comments