Skip to content

Commit 9877995

Browse files
committed
5 comments
1 parent 41c3b51 commit 9877995

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

fs/hmfs/file.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
*/
860864
static 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+
*/
871879
static 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

899907
free_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+
*/
906924
static 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+
*/
923944
void hmfs_truncate(struct inode *inode)
924945
{
925946
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)

fs/hmfs/namei.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ int hmfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
371371
}
372372

373373
#ifdef CONFIG_HMFS_ACL
374+
/*
375+
* 更新@inode属性
376+
* @attr指向存储要更新的属性的结构体
377+
*/
374378
static void __setattr_copy(struct inode *inode, const struct iattr *attr)
375379
{
376380
unsigned int ia_valid = attr->ia_valid;
@@ -398,7 +402,12 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr)
398402
#else
399403
#define __setattr_copy setattr_copy
400404
#endif
401-
405+
/*
406+
* 更新文件inode属性的包装函数
407+
* 先判断inode权限决定是否可更新相应属性,再调用__setattr_copy更新属性
408+
* @dentry指向对应文件inode
409+
* @attr指向存储要更新的属性的结构体
410+
*/
402411
int hmfs_setattr(struct dentry *dentry, struct iattr *attr)
403412
{
404413
struct inode *inode = dentry->d_inode;

0 commit comments

Comments
 (0)