@@ -833,7 +833,7 @@ int truncate_data_blocks_range(struct dnode_of_data *dn, int count)
833833 * in its parent indirect node to be NULL_ADDR
834834 */
835835/*
836- * 缩短dn指向的direct node中的数据
836+ * 截断dn指向的direct node中的数据
837837 * 检查dn->node_block中的每个地址指向的块是否为最新版本,若不是则删除无效块
838838 * 再将删除后的有效块数量更新到inode和超级块中,并将inode标记为脏
839839 */
@@ -856,7 +856,11 @@ void truncate_data_blocks(struct dnode_of_data *dn)
856856 mark_inode_dirty (dn -> inode );
857857 }
858858}
859-
859+ /*
860+ * 将文件某个偏移量from所对应块在from之后的内容清零(只清除该块内容)
861+ * @inode对应文件
862+ * @from对应在文件中的偏移量
863+ */
860864static void truncate_partial_data_page (struct inode * inode , block_t from )
861865{
862866 unsigned offset = from & (HMFS_PAGE_SIZE - 1 );
@@ -867,7 +871,11 @@ static void truncate_partial_data_page(struct inode *inode, block_t from)
867871 HMFS_PAGE_SIZE , true);
868872 return ;
869873}
870-
874+ /*
875+ * 清除普通文件某个偏移量之后的全部内容
876+ * @inode对应文件
877+ * @from对应偏移量
878+ */
871879static int __truncate_blocks (struct inode * inode , block_t from )
872880{
873881 struct dnode_of_data dn ;
@@ -897,12 +905,22 @@ static int __truncate_blocks(struct inode *inode, block_t from)
897905 }
898906
899907free_next :
908+ /*
909+ * 先调用truncate_inode_blocks删除偏移量之后的所有块内容
910+ * 再调用truncate_partial_data_page删除偏移量所在的块在其之后的内容
911+ */
900912 err = truncate_inode_blocks (inode , free_from );
901913 truncate_partial_data_page (inode , from );
902914
903915 return err ;
904916}
905-
917+ /*
918+ * 清除文件某个偏移量之后的全部内容
919+ * @inode对应文件
920+ * @from对应偏移量
921+ * 若为内嵌型文件直接在本函数处理
922+ * 否则调用__truncate_blocks处理普通文件
923+ */
906924static int truncate_blocks (struct inode * inode , block_t from )
907925{
908926 struct hmfs_inode * inode_block ;
@@ -919,7 +937,10 @@ static int truncate_blocks(struct inode *inode, block_t from)
919937
920938 return __truncate_blocks (inode , from );
921939}
922-
940+ /*
941+ * 清除@inode对应文件在i_size之后的内容
942+ * 再修改i_mtime及i_ctime并将inode标记为脏
943+ */
923944void hmfs_truncate (struct inode * inode )
924945{
925946 if (!(S_ISREG (inode -> i_mode ) || S_ISDIR (inode -> i_mode )
0 commit comments