2 * filewatcher.c: File System Watcher internal calls
5 * Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
14 #include <mono/metadata/appdomain.h>
15 #include <mono/metadata/exception.h>
16 #include <mono/metadata/filewatcher.h>
17 #include <mono/metadata/marshal.h>
18 #include <mono/utils/mono-dl.h>
19 #include <mono/utils/mono-io-portability.h>
24 * We use the managed watcher on windows, so the code inside this #if is never used
27 ves_icall_System_IO_FSW_SupportsFSW (void)
33 ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
34 MonoString **filename,
43 static int (*FAMNextEvent) (gpointer, gpointer);
46 ves_icall_System_IO_FSW_SupportsFSW (void)
52 int lib_used = 4; /* gamin */
56 inotify_instance = ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ();
57 if (inotify_instance != -1) {
58 close (inotify_instance);
59 return 5; /* inotify */
62 fam_module = mono_dl_open ("libgamin-1.so", MONO_DL_LAZY, NULL);
63 if (fam_module == NULL) {
64 lib_used = 2; /* FAM */
65 fam_module = mono_dl_open ("libfam.so", MONO_DL_LAZY, NULL);
68 if (fam_module == NULL)
71 err = mono_dl_symbol (fam_module, "FAMNextEvent", (gpointer *) &FAMNextEvent);
73 if (FAMNextEvent == NULL)
80 /* Almost copied from fam.h. Weird, I know */
85 typedef struct FAMEvent {
89 gchar filename [PATH_MAX];
95 ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
96 MonoString **filename,
102 if (FAMNextEvent (conn, &ev) == 1) {
103 *filename = mono_string_new (mono_domain_get (), ev.filename);
105 *reqnum = ev.fr.reqnum;
113 #ifndef HAVE_SYS_INOTIFY_H
114 int ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ()
119 int ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *directory, gint32 mask)
124 int ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, gint32 watch_descriptor)
129 #include <sys/inotify.h>
133 ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ()
135 return inotify_init ();
139 ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 mask)
147 str = mono_string_to_utf8 (name);
148 path = mono_portability_find_file (str, TRUE);
152 retval = inotify_add_watch (fd, path, mask);
156 errno = ERROR_ACCESS_DENIED;
159 errno = ERROR_INVALID_HANDLE;
162 errno = ERROR_INVALID_ACCESS;
165 errno = ERROR_INVALID_DATA;
168 errno = ERROR_NOT_ENOUGH_MEMORY;
171 errno = ERROR_TOO_MANY_OPEN_FILES;
174 errno = ERROR_GEN_FAILURE;
177 mono_marshal_set_last_error ();
186 ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, gint32 watch_descriptor)
188 return inotify_rm_watch (fd, watch_descriptor);