The inotify_event structure is as follows:
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 (and not the file path). How do we get the full path from the inotify_event structure or do I need to wrap my own structure around it?
Edit: I wait for events for about 2 seconds and then process them at a time. I maintain an event queue. My question is, can I only get the full path to my file from the inotify_event structure?
The number of events per second is large.
There are two options:
You are watching a file. You passed your name inotify_add_watchand got a clock handle. If you receive an event, you can define the file using the clock descriptor.
inotify_add_watch
. , inotify_add_watch , , watch. inotify_event.name . , .
inotify_event.name
, , - ( , ). , , , wd .
wd , . , inotify_add_watch (2).
http://www.kernel.org/doc/man-pages/online/pages/man7/inotify.7.html
, ...
, , .
, dir, :/root/dir1 /root/dir 2, , dir1 dir2, .
Inotify , .
( ) , . , . , , , , . , , , . , , , .
The inotify system uses continuous numbers as view descriptors, let's say you want to look at 3 directories, .. /A,../B and ../ C, if you can say, I create a file inside .. / A, then return the clock descriptor from read () there will be 1. if I create a file inside .. / C, the clock descriptor will be 3 and so on. Thus, the association is quite simple, you can create an array with paths and apply inotify_add_watch () to each of them, then if the event has a clock descriptor x, just compose pathsArray [x-1] with event-> name and you have there is a way :)
std::string getPathFromEvent(struct inotify_event *ptr){ std::stringstream builder ; builder<<directories->DetectedDirectories.operator[](ptr->wd-1).string(); builder<<ptr->name; return builder.str(); }