检索inotify_event的全路径名 [英] Retrieve the full path name from inotify_event

查看:550
本文介绍了检索inotify_event的全路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该inotify_event结构是这样的:

The inotify_event struct looks like this :

struct inotify_event {
int      wd;       /* Watch descriptor */
uint32_t mask;     /* Mask of events */
uint32_t cookie;   /* Unique cookie associating related
                      events (for rename(2)) */
uint32_t len;      /* Size of name field */
char     name[];   /* Optional null-terminated name */

};

名称部分仅存储文件名(不是文件路径)。我们如何得到来自inotify_event结构的完全限定路径或我环绕我自己的结构?

The name part stores only the file name(not the path to the file). How do we get the fully qualified path from the inotify_event struct or do I have to wrap my own struct around it ?

编辑:我等周边2秒的事件,然后处理它在一个go.I保持活动的队列中。我的问题是我是否可以从inotify_event结构得到完整的路径,我的文件只?

I wait for the events for around 2s and then process it on one go.I maintain a queue of events. My question is whether I can get the complete path to my file from the inotify_event struct only ?

每秒的事件的数目是大的。

The number of events per second is large.

推荐答案

有两种选择:结果


  1. 您正在观看的文件。您已通过其更名为 inotify_add_watch ,找来一块手表描述符。如果你得到一个事件,您可以通过手表描述找出文件。结果

  1. You're watching a file. You have passed its name to inotify_add_watch, and got a watch descriptor. If you get an event, you can figure out the file by the watch descriptor.

您正在观看的目录。同样,你已通过目录名 inotify_add_watch ,并可以找到它的名字是根据手表ID。现在 inotify_event.name 包含文件名。将两者连接起来,就大功告成了。

You're watching a directory. Again, you have passed the directory name to inotify_add_watch, and can find which name it was, based on the watch ID. Now inotify_event.name contains the file name. Concatenate the two and you're done.

这篇关于检索inotify_event的全路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆