kernel inotify api问题
Kernel版本2.6.32
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/namei.h>
#include <linux/path.h>
#include <linux/inotify.h>
MODULE_LICENSE("GPL");
struct inotify_handle *ih;
void m_handle_event(struct inotify_watch *watch,u32 wd,u32 mask,u32 cookie,const char *name,struct inode *inode) {
printk("monitor handle event\n");
}
void m_destroy_watch(struct inotify_watch *watch) {
inotify_rm_watch(ih,watch);
printk("monitor destroy watch\n");
}
int init_module() {
struct inotify_watch iw;
struct inode *id;
struct path path;
struct inotify_operations ops;
char *p = "/root/test";
int err;
ops.handle_event = m_handle_event;
ops.destroy_watch = m_destroy_watch;
ih = inotify_init(&ops);
err = kern_path(p, LOOKUP_FOLLOW, &path);
if (err)
return err;
id = path.dentry->d_inode;
inotify_init_watch(&iw);
inotify_add_watch(ih,&iw,id,IN_OPEN);
return 0;
}
void cleanup_module() {
inotify_destroy(ih);
printk(KERN_ALERT"Remove Module!\n");
}
make没问题,insmod之后打开“/root/test”文件就crash了。。。
求大佬给看看。。。