99#include "bitmap.h"
1010#include "simplefs.h"
1111
12- /*
13- * Map the buffer_head passed in argument with the iblock-th block of the file
12+ /* Map the buffer_head passed in argument with the iblock-th block of the file
1413 * represented by inode. If the requested block is not allocated and create is
1514 * true, allocate a new block on disk and map it.
1615 */
@@ -44,8 +43,7 @@ static int simplefs_file_get_block(struct inode *inode,
4443 goto brelse_index ;
4544 }
4645
47- /*
48- * Check if iblock is already allocated. If not and create is true,
46+ /* Check if iblock is already allocated. If not and create is true,
4947 * allocate it. Else, get the physical block number.
5048 */
5149 if (index -> extents [extent ].ee_start == 0 ) {
@@ -56,6 +54,7 @@ static int simplefs_file_get_block(struct inode *inode,
5654 ret = - ENOSPC ;
5755 goto brelse_index ;
5856 }
57+
5958 index -> extents [extent ].ee_start = bno ;
6059 index -> extents [extent ].ee_len = 8 ;
6160 index -> extents [extent ].ee_block =
@@ -77,8 +76,7 @@ static int simplefs_file_get_block(struct inode *inode,
7776 return ret ;
7877}
7978
80- /*
81- * Called by the page cache to read a page from the physical disk and map it in
79+ /* Called by the page cache to read a page from the physical disk and map it in
8280 * memory.
8381 */
8482#if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 19 , 0 )
@@ -93,17 +91,15 @@ static int simplefs_readpage(struct file *file, struct page *page)
9391}
9492#endif
9593
96- /*
97- * Called by the page cache to write a dirty page to the physical disk (when
94+ /* Called by the page cache to write a dirty page to the physical disk (when
9895 * sync is called or when memory is needed).
9996 */
10097static int simplefs_writepage (struct page * page , struct writeback_control * wbc )
10198{
10299 return block_write_full_page (page , simplefs_file_get_block , wbc );
103100}
104101
105- /*
106- * Called by the VFS when a write() syscall occurs on file before writing the
102+ /* Called by the VFS when a write() syscall occurs on file before writing the
107103 * data in the page cache. This functions checks if the write will be able to
108104 * complete and allocates the necessary blocks through block_write_begin().
109105 */
@@ -131,6 +127,7 @@ static int simplefs_write_begin(struct file *file,
131127 /* Check if the write can be completed (enough space?) */
132128 if (pos + len > SIMPLEFS_MAX_FILESIZE )
133129 return - ENOSPC ;
130+
134131 nr_allocs = max (pos + len , file -> f_inode -> i_size ) / SIMPLEFS_BLOCK_SIZE ;
135132 if (nr_allocs > file -> f_inode -> i_blocks - 1 )
136133 nr_allocs -= file -> f_inode -> i_blocks - 1 ;
@@ -139,7 +136,7 @@ static int simplefs_write_begin(struct file *file,
139136 if (nr_allocs > sbi -> nr_free_blocks )
140137 return - ENOSPC ;
141138
142- /* prepare the write */
139+ /* prepare the write */
143140#if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 19 , 0 )
144141 err = block_write_begin (mapping , pos , len , pagep , simplefs_file_get_block );
145142#else
@@ -152,8 +149,7 @@ static int simplefs_write_begin(struct file *file,
152149 return err ;
153150}
154151
155- /*
156- * Called by the VFS after writing data from a write() syscall to the page
152+ /* Called by the VFS after writing data from a write() syscall to the page
157153 * cache. This functions updates inode metadata and truncates the file if
158154 * necessary.
159155 */
@@ -216,6 +212,7 @@ static int simplefs_write_end(struct file *file,
216212 index = (struct simplefs_file_ei_block * ) bh_index -> b_data ;
217213
218214 first_ext = simplefs_ext_search (index , inode -> i_blocks - 1 );
215+
219216 /* Reserve unused block in last extent */
220217 if (inode -> i_blocks - 1 != index -> extents [first_ext ].ee_block )
221218 first_ext ++ ;
0 commit comments