Skip to content

Commit 99dd048

Browse files
committed
Merge pull request #26 from timemath/chengweiyu
Chengweiyu
2 parents 314080a + 8a8f585 commit 99dd048

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

fs/hmfs/file.c

Lines changed: 55 additions & 9 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)
@@ -1325,7 +1346,12 @@ static long hmfs_fallocate(struct file *file, int mode, loff_t offset,
13251346

13261347
#define HMFS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL))
13271348
#define HMFS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL)
1328-
1349+
/*
1350+
* 对于@flags进行掩码处理
1351+
* @mode对应目录文件时直接返回falgs
1352+
* @mode对应普通文件时返回flags & HMFS_REG_FLMASK
1353+
* 其他情况时返回flags & HMFS_OTHER_FLMASK
1354+
*/
13291355
static inline __u32 hmfs_mask_flags(umode_t mode, __u32 flags)
13301356
{
13311357
if (S_ISDIR(mode))
@@ -1335,7 +1361,15 @@ static inline __u32 hmfs_mask_flags(umode_t mode, __u32 flags)
13351361
else
13361362
return flags & HMFS_OTHER_FLMASK;
13371363
}
1338-
1364+
/*
1365+
* 向设备发送或接收控制信息
1366+
* @filp指向设备文件标识符
1367+
* @arg指向用户空间目标地址
1368+
* @cmd为HMFS_IOC_GETFLAGS时,将i_flags中用户可见位发送到用户空间目标地址
1369+
* @cmd为HMFS_IOC_SETFLAGS时,将用户空间目标地址的值复制到flags中
1370+
* @cmd为HMFS_IOC_GETVERSION时,将i_generation发送到用户空间目标地址
1371+
* 若不符合以上任何一种情况则返回-ENOTTY
1372+
*/
13391373
long hmfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
13401374
{
13411375
struct inode *inode = file_inode(filp);
@@ -1394,6 +1428,13 @@ long hmfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
13941428
}
13951429

13961430
#ifdef CONFIG_COMPAT
1431+
/*
1432+
* hmfs_ioctl函数的兼容性包装函数
1433+
* 向设备发送或接收控制信息
1434+
* @filp指向设备文件标识符
1435+
* @arg指向用户空间目标地址
1436+
* 调整@cmd的值再调用hmfs_ioctl发送或接收控制信息
1437+
*/
13971438
long hmfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
13981439
{
13991440
switch (cmd) {
@@ -1441,7 +1482,10 @@ const struct inode_operations hmfs_file_inode_operations = {
14411482
.removexattr = generic_removexattr,
14421483
#endif
14431484
};
1444-
1485+
/*
1486+
* 创建slab高速缓存,使mmap_block_slab指向缓存
1487+
* 成功返回0,失败返回-ENOMEM
1488+
*/
14451489
int create_mmap_struct_cache(void)
14461490
{
14471491
mmap_block_slab = hmfs_kmem_cache_create("hmfs_mmap_block",
@@ -1450,7 +1494,9 @@ int create_mmap_struct_cache(void)
14501494
return -ENOMEM;
14511495
return 0;
14521496
}
1453-
1497+
/*
1498+
* 销毁mmap_block_slab指向的slab高速缓存
1499+
*/
14541500
void destroy_mmap_struct_cache(void)
14551501
{
14561502
kmem_cache_destroy(mmap_block_slab);

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)