gpt4 book ai didi

c - inotify_add_watch 用于几个掩码

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:58 24 4
gpt4 key购买 nike

我想监控目录/文件的更改。如果我想监控说只有 5 个事件用下面的面具

IN_OPEN
IN_CREATE
IN_DELETE
IN_CLOSE_WRITE

例如,

我必须在每个掩码上调用 inotify_add_watch() 还是有办法将掩码捆绑在一起以调用 inotify_add_watch一次?

最佳答案

它们可以在对 inotify_add_watch() 的一次调用中进行“或”运算,即:

wd = inotify_add_watch(fd, path, IN_CREATE|IN_DELETE);

任何位的组合都可以在以下限制内进行“或”运算:

/* the following are legal, implemented events that user-space can watch for */
#define IN_ACCESS 0x00000001 /* File was accessed */
#define IN_MODIFY 0x00000002 /* File was modified */
#define IN_ATTRIB 0x00000004 /* Metadata changed */
#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
#define IN_OPEN 0x00000020 /* File was opened */
#define IN_MOVED_FROM 0x00000040 /* File was moved from X */
#define IN_MOVED_TO 0x00000080 /* File was moved to Y */
#define IN_CREATE 0x00000100 /* Subfile was created */
#define IN_DELETE 0x00000200 /* Subfile was deleted */
#define IN_DELETE_SELF 0x00000400 /* Self was deleted */

/* the following are legal events. they are sent as needed to any watch */
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
#define IN_IGNORED 0x00008000 /* File was ignored */

/* helper events */
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */

/* special flags */
#define IN_ISDIR 0x40000000 /* event occurred against dir */
#define IN_ONESHOT 0x80000000 /* only send event once */

/*
* All of the events - we build the list by hand so that we can add flags in
* the future and not break backward compatibility. Apps will get only the
* events that they originally wanted. Be sure to add new events here!
*/
#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF)

(以上来自inotify.h)

关于c - inotify_add_watch 用于几个掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23644313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com