Alex Rivera | Logout

Retrieve the full path name from inotify_event

Asked 2012-02-16T14:39:46.507
9

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 */

};

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 ?

Edit: 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.

Edit
Report

1 Answer

0

This is ok as far as it goes, but it is not the whole answer.

If you have a directory structure and you are watching file & dir events and it looks like this: /root/dir1 & /root/dir2, then you will not have correct resolution of where a file or dir was created in dir1 or dir2, even after you add them to the watch list.

Inotify returns the name of the item and does not tell you which dir it was in.

answered 2013-04-24T16:57:27.797

Your Answer