データ構造 | |
struct | inotify_private |
struct | inotify_watch_context |
関数 | |
static int | inotify_init (void) |
static int | inotify_add_watch (int fd, const char *path, __u32 mask) |
static int | inotify_rm_watch (int fd, int wd) |
static int | inotify_destructor (struct inotify_private *in) |
static BOOL | filter_match (struct inotify_watch_context *w, struct inotify_event *e) |
static void | inotify_dispatch (struct inotify_private *in, struct inotify_event *e, uint32_t prev_cookie, struct inotify_event *e2) |
static void | inotify_handler (struct event_context *ev, struct fd_event *fde, uint16_t flags, void *private_data) |
static NTSTATUS | inotify_setup (struct sys_notify_context *ctx) |
static uint32_t | inotify_map (struct notify_entry *e) |
static int | watch_destructor (struct inotify_watch_context *w) |
NTSTATUS | inotify_watch (struct sys_notify_context *ctx, struct notify_entry *e, void(*callback)(struct sys_notify_context *ctx, void *private_data, struct notify_event *ev), void *private_data, void *handle_p) |
変数 | |
struct { | |
uint32_t notify_mask | |
uint32_t inotify_mask | |
} | inotify_mapping [] |
static int inotify_init | ( | void | ) | [static] |
static int inotify_add_watch | ( | int | fd, | |
const char * | path, | |||
__u32 | mask | |||
) | [static] |
notify_inotify.c の 47 行で定義されています。
参照元 inotify_watch().
00048 { 00049 return syscall(__NR_inotify_add_watch, fd, path, mask); 00050 }
static int inotify_rm_watch | ( | int | fd, | |
int | wd | |||
) | [static] |
notify_inotify.c の 52 行で定義されています。
参照元 inotify_watch()・watch_destructor().
00053 { 00054 return syscall(__NR_inotify_rm_watch, fd, wd); 00055 }
static int inotify_destructor | ( | struct inotify_private * | in | ) | [static] |
notify_inotify.c の 95 行で定義されています。
参照先 inotify_private::fd.
参照元 inotify_setup().
00096 { 00097 close(in->fd); 00098 return 0; 00099 }
static BOOL filter_match | ( | struct inotify_watch_context * | w, | |
struct inotify_event * | e | |||
) | [static] |
notify_inotify.c の 106 行で定義されています。
参照先 inotify_watch_context::filter・inotify_watch_context::mask.
参照元 inotify_dispatch().
00108 { 00109 DEBUG(10, ("filter_match: e->mask=%x, w->mask=%x, w->filter=%x\n", 00110 e->mask, w->mask, w->filter)); 00111 00112 if ((e->mask & w->mask) == 0) { 00113 /* this happens because inotify_add_watch() coalesces watches on the same 00114 path, oring their masks together */ 00115 return False; 00116 } 00117 00118 /* SMB separates the filters for files and directories */ 00119 if (e->mask & IN_ISDIR) { 00120 if ((w->filter & FILE_NOTIFY_CHANGE_DIR_NAME) == 0) { 00121 return False; 00122 } 00123 } else { 00124 if ((e->mask & IN_ATTRIB) && 00125 (w->filter & (FILE_NOTIFY_CHANGE_ATTRIBUTES| 00126 FILE_NOTIFY_CHANGE_LAST_WRITE| 00127 FILE_NOTIFY_CHANGE_LAST_ACCESS| 00128 FILE_NOTIFY_CHANGE_EA| 00129 FILE_NOTIFY_CHANGE_SECURITY))) { 00130 return True; 00131 } 00132 if ((e->mask & IN_MODIFY) && 00133 (w->filter & FILE_NOTIFY_CHANGE_ATTRIBUTES)) { 00134 return True; 00135 } 00136 if ((w->filter & FILE_NOTIFY_CHANGE_FILE_NAME) == 0) { 00137 return False; 00138 } 00139 } 00140 00141 return True; 00142 }
static void inotify_dispatch | ( | struct inotify_private * | in, | |
struct inotify_event * | e, | |||
uint32_t | prev_cookie, | |||
struct inotify_event * | e2 | |||
) | [static] |
notify_inotify.c の 151 行で定義されています。
参照先 notify_event::action・inotify_watch_context::callback・inotify_private::ctx・inotify_watch_context::filter・filter_match()・inotify_watch_context::next・notify_event::path・inotify_watch_context::private_data・inotify_private::watches・inotify_watch_context::wd.
参照元 inotify_handler().
00155 { 00156 struct inotify_watch_context *w, *next; 00157 struct notify_event ne; 00158 00159 DEBUG(10, ("inotify_dispatch called with mask=%x, name=[%s]\n", 00160 e->mask, e->len ? e->name : "")); 00161 00162 /* ignore extraneous events, such as unmount and IN_IGNORED events */ 00163 if ((e->mask & (IN_ATTRIB|IN_MODIFY|IN_CREATE|IN_DELETE| 00164 IN_MOVED_FROM|IN_MOVED_TO)) == 0) { 00165 return; 00166 } 00167 00168 /* map the inotify mask to a action. This gets complicated for 00169 renames */ 00170 if (e->mask & IN_CREATE) { 00171 ne.action = NOTIFY_ACTION_ADDED; 00172 } else if (e->mask & IN_DELETE) { 00173 ne.action = NOTIFY_ACTION_REMOVED; 00174 } else if (e->mask & IN_MOVED_FROM) { 00175 if (e2 != NULL && e2->cookie == e->cookie) { 00176 ne.action = NOTIFY_ACTION_OLD_NAME; 00177 } else { 00178 ne.action = NOTIFY_ACTION_REMOVED; 00179 } 00180 } else if (e->mask & IN_MOVED_TO) { 00181 if (e->cookie == prev_cookie) { 00182 ne.action = NOTIFY_ACTION_NEW_NAME; 00183 } else { 00184 ne.action = NOTIFY_ACTION_ADDED; 00185 } 00186 } else { 00187 ne.action = NOTIFY_ACTION_MODIFIED; 00188 } 00189 ne.path = e->name; 00190 00191 DEBUG(10, ("inotify_dispatch: ne.action = %d, ne.path = %s\n", 00192 ne.action, ne.path)); 00193 00194 /* find any watches that have this watch descriptor */ 00195 for (w=in->watches;w;w=next) { 00196 next = w->next; 00197 if (w->wd == e->wd && filter_match(w, e)) { 00198 w->callback(in->ctx, w->private_data, &ne); 00199 } 00200 } 00201 00202 /* SMB expects a file rename to generate three events, two for 00203 the rename and the other for a modify of the 00204 destination. Strange! */ 00205 if (ne.action != NOTIFY_ACTION_NEW_NAME || 00206 (e->mask & IN_ISDIR) != 0) { 00207 return; 00208 } 00209 00210 ne.action = NOTIFY_ACTION_MODIFIED; 00211 e->mask = IN_ATTRIB; 00212 00213 for (w=in->watches;w;w=next) { 00214 next = w->next; 00215 if (w->wd == e->wd && filter_match(w, e) && 00216 !(w->filter & FILE_NOTIFY_CHANGE_CREATION)) { 00217 w->callback(in->ctx, w->private_data, &ne); 00218 } 00219 } 00220 }
static void inotify_handler | ( | struct event_context * | ev, | |
struct fd_event * | fde, | |||
uint16_t | flags, | |||
void * | private_data | |||
) | [static] |
notify_inotify.c の 225 行で定義されています。
参照先 inotify_private::broken_inotify・errno・inotify_private::fd・inotify_dispatch()・talloc_free().
参照元 inotify_setup().
00227 { 00228 struct inotify_private *in = talloc_get_type(private_data, 00229 struct inotify_private); 00230 int bufsize = 0; 00231 struct inotify_event *e0, *e; 00232 uint32_t prev_cookie=0; 00233 00234 /* 00235 we must use FIONREAD as we cannot predict the length of the 00236 filenames, and thus can't know how much to allocate 00237 otherwise 00238 */ 00239 00240 if ((ioctl(in->fd, FIONREAD, &bufsize) != 0) && (errno == EACCES)) { 00241 /* 00242 * Workaround for broken SELinux policies on Fedora 00243 */ 00244 TALLOC_FREE(fde); 00245 in->broken_inotify = True; 00246 return; 00247 } 00248 if (bufsize == 0) { 00249 DEBUG(0,("No data on inotify fd?!\n")); 00250 return; 00251 } 00252 00253 e0 = e = (struct inotify_event *)TALLOC_SIZE(in, bufsize); 00254 if (e == NULL) return; 00255 00256 if (read(in->fd, e0, bufsize) != bufsize) { 00257 DEBUG(0,("Failed to read all inotify data\n")); 00258 talloc_free(e0); 00259 return; 00260 } 00261 00262 /* we can get more than one event in the buffer */ 00263 while (bufsize >= sizeof(*e)) { 00264 struct inotify_event *e2 = NULL; 00265 bufsize -= e->len + sizeof(*e); 00266 if (bufsize >= sizeof(*e)) { 00267 e2 = (struct inotify_event *)(e->len + sizeof(*e) + (char *)e); 00268 } 00269 inotify_dispatch(in, e, prev_cookie, e2); 00270 prev_cookie = e->cookie; 00271 e = e2; 00272 } 00273 00274 talloc_free(e0); 00275 }
static NTSTATUS inotify_setup | ( | struct sys_notify_context * | ctx | ) | [static] |
notify_inotify.c の 281 行で定義されています。
参照先 inotify_private::broken_inotify・inotify_private::ctx・ctx・errno・event_add_fd()・inotify_private::fd・inotify_destructor()・inotify_handler()・inotify_init()・lp_parm_bool()・map_nt_error_from_unix()・strerror()・talloc_free()・inotify_private::watches.
参照元 inotify_watch().
00282 { 00283 struct inotify_private *in; 00284 00285 if (!lp_parm_bool(-1, "notify", "inotify", True)) { 00286 return NT_STATUS_INVALID_SYSTEM_SERVICE; 00287 } 00288 00289 in = talloc(ctx, struct inotify_private); 00290 NT_STATUS_HAVE_NO_MEMORY(in); 00291 in->fd = inotify_init(); 00292 if (in->fd == -1) { 00293 DEBUG(0,("Failed to init inotify - %s\n", strerror(errno))); 00294 talloc_free(in); 00295 return map_nt_error_from_unix(errno); 00296 } 00297 in->ctx = ctx; 00298 in->watches = NULL; 00299 in->broken_inotify = False; 00300 00301 ctx->private_data = in; 00302 talloc_set_destructor(in, inotify_destructor); 00303 00304 /* add a event waiting for the inotify fd to be readable */ 00305 event_add_fd(ctx->ev, in, in->fd, EVENT_FD_READ, inotify_handler, in); 00306 00307 return NT_STATUS_OK; 00308 }
static uint32_t inotify_map | ( | struct notify_entry * | e | ) | [static] |
notify_inotify.c の 328 行で定義されています。
参照先 notify_entry::filter・inotify_mapping・notify_mask.
参照元 inotify_watch().
00329 { 00330 int i; 00331 uint32_t out=0; 00332 for (i=0;i<ARRAY_SIZE(inotify_mapping);i++) { 00333 if (inotify_mapping[i].notify_mask & e->filter) { 00334 out |= inotify_mapping[i].inotify_mask; 00335 e->filter &= ~inotify_mapping[i].notify_mask; 00336 } 00337 } 00338 return out; 00339 }
static int watch_destructor | ( | struct inotify_watch_context * | w | ) | [static] |
notify_inotify.c の 344 行で定義されています。
参照先 errno・inotify_private::fd・inotify_watch_context::in・inotify_rm_watch()・inotify_watch_context::next・strerror()・inotify_private::watches・inotify_watch_context::wd.
参照元 inotify_watch().
00345 { 00346 struct inotify_private *in = w->in; 00347 int wd = w->wd; 00348 DLIST_REMOVE(w->in->watches, w); 00349 00350 /* only rm the watch if its the last one with this wd */ 00351 for (w=in->watches;w;w=w->next) { 00352 if (w->wd == wd) break; 00353 } 00354 if (w == NULL) { 00355 DEBUG(10, ("Deleting inotify watch %d\n", wd)); 00356 if (inotify_rm_watch(in->fd, wd) == -1) { 00357 DEBUG(1, ("inotify_rm_watch returned %s\n", 00358 strerror(errno))); 00359 } 00360 00361 } 00362 return 0; 00363 }
NTSTATUS inotify_watch | ( | struct sys_notify_context * | ctx, | |
struct notify_entry * | e, | |||
void(*)(struct sys_notify_context *ctx, void *private_data, struct notify_event *ev) | callback, | |||
void * | private_data, | |||
void * | handle_p | |||
) |
notify_inotify.c の 370 行で定義されています。
参照先 inotify_private::broken_inotify・inotify_watch_context::callback・errno・inotify_private::fd・notify_entry::filter・inotify_watch_context::filter・handle・inotify_watch_context::in・inotify_add_watch()・inotify_map()・inotify_rm_watch()・inotify_setup()・map_nt_error_from_unix()・inotify_watch_context::mask・inotify_watch_context::path・notify_entry::path・inotify_watch_context::private_data・status・strerror()・talloc_strdup()・watch_destructor()・inotify_private::watches・inotify_watch_context::wd.
00377 { 00378 struct inotify_private *in; 00379 int wd; 00380 uint32_t mask; 00381 struct inotify_watch_context *w; 00382 uint32_t filter = e->filter; 00383 void **handle = (void **)handle_p; 00384 00385 /* maybe setup the inotify fd */ 00386 if (ctx->private_data == NULL) { 00387 NTSTATUS status; 00388 status = inotify_setup(ctx); 00389 NT_STATUS_NOT_OK_RETURN(status); 00390 } 00391 00392 in = talloc_get_type(ctx->private_data, struct inotify_private); 00393 00394 if (in->broken_inotify) { 00395 return NT_STATUS_OK; 00396 } 00397 00398 mask = inotify_map(e); 00399 if (mask == 0) { 00400 /* this filter can't be handled by inotify */ 00401 return NT_STATUS_INVALID_PARAMETER; 00402 } 00403 00404 /* using IN_MASK_ADD allows us to cope with inotify() returning the same 00405 watch descriptor for muliple watches on the same path */ 00406 mask |= (IN_MASK_ADD | IN_ONLYDIR); 00407 00408 /* get a new watch descriptor for this path */ 00409 wd = inotify_add_watch(in->fd, e->path, mask); 00410 if (wd == -1) { 00411 e->filter = filter; 00412 DEBUG(1, ("inotify_add_watch returned %s\n", strerror(errno))); 00413 return map_nt_error_from_unix(errno); 00414 } 00415 00416 DEBUG(10, ("inotify_add_watch for %s mask %x returned wd %d\n", 00417 e->path, mask, wd)); 00418 00419 w = talloc(in, struct inotify_watch_context); 00420 if (w == NULL) { 00421 inotify_rm_watch(in->fd, wd); 00422 e->filter = filter; 00423 return NT_STATUS_NO_MEMORY; 00424 } 00425 00426 w->in = in; 00427 w->wd = wd; 00428 w->callback = callback; 00429 w->private_data = private_data; 00430 w->mask = mask; 00431 w->filter = filter; 00432 w->path = talloc_strdup(w, e->path); 00433 if (w->path == NULL) { 00434 inotify_rm_watch(in->fd, wd); 00435 e->filter = filter; 00436 return NT_STATUS_NO_MEMORY; 00437 } 00438 00439 (*handle) = w; 00440 00441 DLIST_ADD(in->watches, w); 00442 00443 /* the caller frees the handle to stop watching */ 00444 talloc_set_destructor(w, watch_destructor); 00445 00446 return NT_STATUS_OK; 00447 }
uint32_t notify_mask |
uint32_t inotify_mask |
notify_inotify.c の 317 行で定義されています。
struct { ... } inotify_mapping[] [static] |
参照元 inotify_map().