原标题:Linux完整性保护机制模块实现分析(10)
2.4.3.3结构体定义
文件inotify_user.c中涉及的结构体定义有:
1.结构体fsnotify_event
结构体fsnotify_event定义的字段如下表:
类型
字段
含义
int
data_type
值上述类型中所包含的
atomic_t
refcnt
有多少组仍然使用的是/需要发送这个事件
__u32
mask
访问事件类型为32位
u32
sync_cookie
用于corrolate事件,即inotify的文件被移动的事件
__u32
response
用户态回答问题
表2-11:结构体fsnotify_event中定义的字段
2.结构体fsnotify_group
该结构体定义的字段如下表:
类型
字段
含义
atomic_t
refcnt
表示本组中感兴趣的事件
unsigned int
q_len
在队列中的事件
unsigned int
max_events
最大允许列表上的事件
unsigned int
priority
本组存储所有FASTPATH标记,可以清理注销
表2-11:结构体fsnotify_group中定义的字段
3. 结构体inotify_event
结构体inotify_event定义的字段如下表:
类型
字段
含义
__s32
wd
监视的目标
__u32
mask
监视掩码
__u32
cookie
cookie来同步两个事件
__u32
len
名称的长度(包括空值)
char
name[0]
事件可选的名字
表2-13:结构体inotify_event中定义的字段
4.结构体fsnotify_mark
结构体fsnotify_mark定义的字段如下表:
类型
字段
含义
__u32
mask
这个掩码标志是用于
atomic_t
refcnt
这个掩码的积极事件
spinlock_t
lock
保护组和inode
unsigned int
flags
vfs挂载的掩码还是inode的掩码
表2-14:结构体fsnotify_mark中定义的字段
2.4.3.4外部函数
文件inotify_user.c中涉及的主要外部函数有:
1.函数名称:fsnotify_final_destory_group()
函数原型:void fsnotify_final_destroy_group(struct fsnotify_group *group)
函数功能:最终释放一个group。
参数:group表示指定的要释放的组。
返回值:无返回值。
2.函数名称:fsnotify_alloc_group()
函数原型:struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
函数功能:创建一个新的fsnotify_group。
参数:ops表示对新建组的基础操作。
返回值:返回group
3.函数名称:__fsnotify_inode_delete()
函数原型:void __fsnotify_inode_delete(struct inode *inode)。
函数功能:当监视删除时,清除所有inode上的监视事件。
参数:inode表示要清除事件对应的inode。
返回值:无返回值。
4.函数名称:__fsnotify_update_child_dentry_flags()
函数原型:void __fsnotify_update_child_dentry_flags(struct inode *inode)
函数功能:对于给定的inode首先进行检查,当监视的文件上一个事件发生时它可以迅速的判断是否要将该事件发送给监视者。
参数:inode表示监视对应的inode。
返回值:无返回值
5.函数名称:fsnotify_add_mark()
函数原型:int fsnotify_add_mark(struct fsnotify_mark *mark,struct fsnotify_group *group, struct inode *inode,struct vfsmount *mnt, int allow_dups)
函数功能:给对应的group中添加一个mark.并且将一个给定的组和fs对象的初始化标志。这些标记可用于为fsnotify后端,以确定哪些事件类型应交付给哪个组。
参数:mark表示指向要添加的mark。
group表示指向要将mark添加进的组。
inode表示添加mark的监视对象的inode。
返回值:执行正确返回0,执行错误返回-1。
6.函数名称:fsnotify_clear_marks_by_group_flags()
函数原型:void fsnotify_clear_marks_by_group_flags(struct fsnotify_group *group,unsigned int flags)
函数功能:清除在组中任何一个mark指向flags,且flags为true。
参数:group表示指定的组。
flags表示标记位。
返回值:无返回值。
7.函数名称:fsnotify_init_mark()
函数原型:void fsnotify_init_mark(struct fsnotify_mark *mark,void (*free_mark)(struct fsnotify_mark *mark))
函数功能:该函数将初始化列表锁和计数器。
参数:mark标记是否被监视。
8.函数名称:fsnotify_dear_marks_by_inodes()
函数原型:void fsnotify_clear_marks_by_inode(struct inode *inode)
函数功能:给定一个inode,破坏与索引节点相关联的所有的标记。
参数:inode表示一个指定的inode。
返回值:无返回值。
9.函数名称:fsnotify_add_inode_mark()
函数原型:int fsnotify_add_inode_mark(struct fsnotify_mark *mark,struct fsnotify_group *group, struct inode *inode,int allow_dups)
函数功能:将初始化给定的索引节点的mark。
参数:mark表示要被初始化的mark。
group表示要被初始化mark所在的group。
inode表示给定的索引节点。
返回值:执行成功返回0,执行失败返回-1。
责任编辑: