fsnotify_move,文件年腋荷琐目次移动到另一个目次fsnotify_nameremove,文件大年夜目次中删除fsnotify_inoderemove,自删除fsnotify_create,创建新文件fsnotify_mkdir,创建新目次fsnotify_access,文件被读fsnotify_modify,文件被写fsnotify_open,文件被打开fsnotify_close,文件被封闭fsnotify_xattr,文件的扩大属性被修改fsnotify_change,文件被修改或原数据被修改有一个例外情况,就是 inotify_unmount_inodes,它会在文件体系被 umount 时调用来通知 umount 事宜给 inotify 体系。
- struct inotify_device {
- wait_queue_head_t wq; /* wait queue for i/o */
- struct idr idr; /* idr mapping wd -> watch */
- struct semaphore sem; /* protects this bad boy */
- struct list_head events; /* list of queued events */
- struct list_head watches; /* list of watches */
- atomic_t count; /* reference count */
- struct user_struct *user; /* user who opened this dev */
- unsigned int queue_size; /* size of the queue (bytes) */
- unsigned int event_count; /* number of pending events */
- unsigned int max_events; /* maximum number of events */
- u32 last_wd; /* the last wd allocated */
- };
4. 应用示例
以上提到的通知函数最后都调用 inotify_inode_queue_event(inotify_unmount_inodes直接调用 inotify_dev_queue_event ),该函数起首断定对应的inode是否被监督,这经由过程查看 inotify_watches 列表是否为空来实现,如不雅发明 inode 没有被监督,什么也不做,急速返回,反之,遍历 inotify_watches 列表,看是否当前的文件操作事宜被某个 watch 监督,如不雅是,调用 inotify_dev_queue_event,不然,返回。函数inotify_dev_queue_event 起首断定该事宜是否是上一个事宜的反复,如不雅是就丢弃该事宜并返回,不然,它断定是否 inotify 实例即 inotify_device 的事宜队列是否溢出,如不雅溢出,产生一个溢出事宜,不然产生一个当前的文件操作事宜,这些事宜经由过程kernel_event 构建,kernel_event 将创建一个 inotify_kernel_event 构造,然后把该构造插入到对应的 inotify_device 的 events 事宜列表,然后唤醒等待在inotify_device 构造中的 wq 指向的等待队列。想监督文件体系事宜的用户态过程在inotify 实例(即 inotify_init() 返回的文件描述符)上调用 read 时但没有事宜时就挂在等待队列 wq 上。
- #include
- #include
- #include
- _syscall0(int, inotify_init)
- _syscall3(int, inotify_add_watch, int, fd, const char *, path, __u32, mask)
- _syscall2(int, inotify_rm_watch, int, fd, __u32, mask)
- char * monitored_files[] = {
推荐阅读
云给安然带来的影响距离2006年Amazon宣布EC2办事已经以前了11年,在这11年迈,产生的不仅仅是AWS收入大年夜几十万美金上涨到100多亿美金,更重要的是云计算已经走进每一俭朴业。根据信通院宣布的&ldquo>>>详细阅读
本文标题:Linux inotify功能及实现原理
地址:http://www.17bianji.com/lsqh/37802.html
1/2 1