linux – 获取Inotify以正确发出IN_UNMOUNT事件

linux – 获取Inotify以正确发出IN_UNMOUNT事件,第1张

概述你好我一直试图让Inotify产生一个IN_UNMOUNT事件,但它根本没有与我合作所以我去做了一个简单的inotifywait实验,这是下面的结果: paul@imaskar ~ $inotifywait -r /storage/test/ -mSetting up watches. Beware: since -r was given, this may take a while!Wat @H_502_4@ 你好我一直试图让Inotify产生一个IN_UNMOUNT事件,但它根本没有与我合作所以我去做了一个简单的inotifywait实验,这是下面的结果:

paul@imaskar ~ $inotifywait -r /storage/test/ -mSetting up watches.  Beware: since -r was given,this may take a while!Watches established./storage/test/ CREATE,ISDIR a/storage/test/ OPEN,ISDIR a/storage/test/ CLOSE_NowRITE,CLOSE,ISDIR a/storage/test/ DELETE,ISDIR a/storage/test/a/ DELETE_SELF /storage/test/a/ IGnorED /storage/test/ IGnorED

基本上会发生什么是它会拾取所有其他事件,如创建,打开等……但是当我卸载/ storage / test /它会为它创建的所有手表发出一个IGnorED,但它永远不会发出UNMOUNT活动……

因此,我似乎无法获得IN_UNMOUNT事件,但我读过的所有inotify文档都表示,当卸载受监视的文件/目录后备存储时,内核将向事件添加IN_UNMOUNT位标志…

这是一个来自-Inotify patch的简单C代码

#include <stdio.h>#include <stdlib.h>#include <sys/inotify.h>int main(int argc,char **argv){        char buf[1024];        struct inotify_event *IE;        char *p;        int i;        ssize_t l;        p = argv[1];        i = inotify_init();        inotify_add_watch(i,p,~0);        l = read(i,buf,sizeof(buf));        printf("read %d bytes\n",l);        IE = (struct inotify_event *) buf;        printf("event mask: %x\n",IE->mask);    return 0;}

无论如何,我做了以下步骤:

gcc -oinotify inotify.cmkdir mntsudo mount -ttmpfs none mntmkdir mnt/d./inotify mnt/d/# Different shellsudo umount mnt

最后这是它发出的东西

read 16 bytesevent mask: 8000

所以在这个时候我不确定问题是在代码中还是其他什么?

@H_502_4@解决方法 这似乎是一个内核错误,已根据 LKML修复.大致自内核2.6.31后,当安装inode时,尚未发送IN_UNMOUNT事件…此修补程序用于“34-longterm”又称内核2.6.35( ?).

无论如何,我能够升级到内核2.6.37并重新运行上述测试,结果如下:

mkdir mntsudo mount -ttmpfs none mntmkdir mnt/dinotifywait -r mnt/d/ -m# Different shellsudo umount mnt

这是输出:

Setting up watches.  Beware: since -r was given,this may take a while!Watches established./tmp/test/d/ UNMOUNT /tmp/test/d/ IGnorED /tmp/test/ UNMOUNT /tmp/test/ IGnorED

根据示例C代码,这里是输出:

read 32 bytesevent mask: 2000

并查看inotify.h标头,这是IN_UNMOUNT标志的正确事件掩码,这意味着它最终修复了~2.6.35或后者……

@H_502_4@ @H_502_4@ @H_502_4@ @H_502_4@ 总结

以上是内存溢出为你收集整理的linux – 获取Inotify以正确发出IN_UNMOUNT事件全部内容,希望文章能够帮你解决linux – 获取Inotify以正确发出IN_UNMOUNT事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1018280.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存