1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #if defined(__x86_64__) # define __NR_fanotify_init 300 # define __NR_fanotify_mark 301 #elif defined(__i386__) # define __NR_fanotify_init 338 # define __NR_fanotify_mark 339 #else # error "System call numbers not defined for this architecture" #endif static inline int fanotify_init(unsigned int flags, unsigned int event_f_flags) { return syscall(__NR_fanotify_init, flags, event_f_flags); } static inline int fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, int dfd, const char *pathname) { return syscall(__NR_fanotify_mark, fanotify_fd, flags, mask, dfd, pathname); } #endif |
1 2 | FANOTIFY -- “Filesystem wide access notification” FANOTIFY_ACCESS_PERMISSIONS -- "fanotify permissions checking" |
1 2 3 4 5 6 7 8 9 10 11 | [lm@localhost inotify]$ ./av USAGE: ./av [-cdfhmnp] [-o {open,close,access,modify,open_perm,access_perm}] file ... -c: learn about events on children of a directory (not decendants) -d: send events which happen to directories -f: set premptive ignores (go faster) -h: this help screen -m: place mark on the whole mount point, not just the inode -n: do not ignore repeated permission checks -p: check permissions, not just notification -s N: sleep N seconds before replying to perm events |
1 | ./av /home/lm/f1 |
1 2 | cd /hom/lm echo “test” >f1 |
1 | /home/lm/f1: pid=2079 open modify close(writable) |
1 | ./av -c /home/lm |
1 | fan_fd = fanotify_init(init_flags, O_RDONLY | O_LARGEFILE); |
1 2 3 4 | if (fan_mask & FAN_ALL_PERM_EVENTS) init_flags |= FAN_CLASS_CONTENT; else init_flags |= FAN_CLASS_NOTIF; |
1 2 3 | for (; optind < argc; optind++) if (mark_object(fan_fd, argv[optind], AT_FDCWD, fan_mask, mark_flags) != 0) goto fail; |
1 2 3 4 | int mark_object(int fan_fd, const char *path, int fd, uint64_t mask, unsigned int flags) { return fanotify_mark(fan_fd, flags, mask, fd, path); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |