@@ -78,22 +78,23 @@ static struct superblock *write_superblock(int fd, struct stat *fstats)
7878
7979static int write_inode_store (int fd , struct superblock * sb )
8080{
81- /* Allocate a zeroed block for inode store */
81+ /* Allocate a block of zeroed-out memory space for the inode storage. */
8282 char * block = malloc (SIMPLEFS_BLOCK_SIZE );
8383 if (!block )
8484 return -1 ;
8585
8686 memset (block , 0 , SIMPLEFS_BLOCK_SIZE );
8787
88- /* Root inode (inode 0 ) */
88+ /* Root inode (inode 1 ) */
8989 struct simplefs_inode * inode = (struct simplefs_inode * ) block ;
9090 uint32_t first_data_block = 1 + le32toh (sb -> info .nr_bfree_blocks ) +
9191 le32toh (sb -> info .nr_ifree_blocks ) +
9292 le32toh (sb -> info .nr_istore_blocks );
9393
94- /* Use inode 1 for root.
95- * If system use glibc, readdir will skip inode 0, and vfs also avoid
96- * using inode 0
94+ /* Designate inode 1 as the root inode.
95+ * When the system uses the glibc, the readdir function will skip over
96+ * inode 0. Additionally, the VFS layer avoids using inode 0 to prevent
97+ * potential issues.
9798 */
9899 inode += 1 ;
99100 inode -> i_mode = htole32 (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR |
@@ -112,7 +113,7 @@ static int write_inode_store(int fd, struct superblock *sb)
112113 goto end ;
113114 }
114115
115- /* Reset inode store blocks to zero */
116+ /* Clear all memory blocks allocated for inode storage. */
116117 memset (block , 0 , SIMPLEFS_BLOCK_SIZE );
117118 uint32_t i ;
118119 for (i = 1 ; i < sb -> info .nr_istore_blocks ; i ++ ) {
@@ -145,7 +146,7 @@ static int write_ifree_blocks(int fd, struct superblock *sb)
145146 /* Set all bits to 1 */
146147 memset (ifree , 0xff , SIMPLEFS_BLOCK_SIZE );
147148
148- /* First ifree block, containing first used inode */
149+ /* The initial ifree block holds the first inode marked as in-use. */
149150 ifree [0 ] = htole64 (0xfffffffffffffffc );
150151 int ret = write (fd , ifree , SIMPLEFS_BLOCK_SIZE );
151152 if (ret != SIMPLEFS_BLOCK_SIZE ) {
@@ -184,8 +185,9 @@ static int write_bfree_blocks(int fd, struct superblock *sb)
184185 return -1 ;
185186 uint64_t * bfree = (uint64_t * ) block ;
186187
187- /* First blocks (incl. sb + istore + ifree + bfree + 1 used block)
188- * we suppose it won't go further than the first block
188+ /* The first blocks refer to the superblock (metadata about the fs), inode
189+ * store (where inode data is stored), ifree (list of free inodes), bfree
190+ * (list of free data blocks), and one data block marked as used.
189191 */
190192 memset (bfree , 0xff , SIMPLEFS_BLOCK_SIZE );
191193 uint32_t i = 0 ;
0 commit comments