00001 #ifndef INOTIFY_WATCH_H 00002 #define INOTIFY_WATCH_H 00003 00004 00005 /*****************************************************************************/ 00006 /******************************** Documentation ******************************/ 00007 /*****************************************************************************/ 00008 00009 /** 00010 * \file 00011 * Public interface for inotify backend to log watch. 00012 */ 00013 00014 /*****************************************************************************/ 00015 /******************************* Include Files *******************************/ 00016 /*****************************************************************************/ 00017 00018 #include "lwatch.h" 00019 00020 /*****************************************************************************/ 00021 /*********************************** Defines *********************************/ 00022 /*****************************************************************************/ 00023 00024 /** 00025 * Base error code (minimum value) for inotify watch errors 00026 */ 00027 #define INOTIFY_WATCH_ERROR_BASE -2500 00028 /** 00029 * Maximum error code for inotify errors 00030 */ 00031 #define INOTIFY_WATCH_ERROR_LIMIT (INOTIFY_WATCH_ERROR_BASE + 50) 00032 /** 00033 * Return true if error code is within the range for inotify watch errors. 00034 * 00035 * \param[in] error The error code to test if it's a inotify watch error code. 00036 * \return True if error code is a inotify watch error. 00037 */ 00038 #define IS_INOTIFY_WATCH_ERROR(error) (((error) >= INOTIFY_WATCH_ERROR_BASE) && ((error) < INOTIFY_WATCH_ERROR_LIMIT)) 00039 00040 #define INOTIFY_WATCH_ERROR_NULL_WATCH (INOTIFY_WATCH_ERROR_BASE + 1) /**< watch invalid, was NULL */ 00041 #define INOTIFY_WATCH_ERROR_WATCH_ID_NOT_FOUND (INOTIFY_WATCH_ERROR_BASE + 2) /**< could not look up watch id */ 00042 #define INOTIFY_WATCH_ALREADY_WATCHING (INOTIFY_WATCH_ERROR_BASE + 3) /**< already being watched */ 00043 #define INOTIFY_WATCH_NOT_WATCHED (INOTIFY_WATCH_ERROR_BASE + 4) /**< not being watched */ 00044 00045 /*****************************************************************************/ 00046 /******************************* Type Definitions ****************************/ 00047 /*****************************************************************************/ 00048 00049 /** 00050 * When a watch is established on a filesystem directory this struct is used to 00051 * track it. See \ref HowFilesAreWatchedDoc 00052 */ 00053 struct path_watch_t { 00054 char path[PATH_MAX]; /**< the pathname the watch was established on */ 00055 int watch_id; /**< the id (e.g. handle) assigned by the watch 00056 subsystem to this watch. When the subsystem 00057 sends us a notification it will contain this id 00058 and we'll have to look up this stuct via that id. */ 00059 hash_table_t *descendant_path_table; /**< the set of non-existant descendants of this directory 00060 whose creation we have watch for */ 00061 }; 00062 00063 00064 /*****************************************************************************/ 00065 /************************* External Global Variables ***********************/ 00066 /*****************************************************************************/ 00067 00068 /** 00069 * Flag used to indicate if the read_events() loop should terminate or 00070 * continue. 00071 */ 00072 extern bool keep_watching; 00073 00074 /*****************************************************************************/ 00075 /**************************** Exported Functions ***************************/ 00076 /*****************************************************************************/ 00077 00078 int inotify_watch_init(void); 00079 int inotify_watch_fini(void); 00080 bool is_watch_target(const char *path); 00081 bool is_path_watched(const char* path); 00082 const char *inotify_watch_error_string(int error); 00083 char *inotify_mask_string(unsigned int mask, const char *separator); 00084 char *path_watch_string(struct path_watch_t *pw); 00085 struct path_watch_t *find_watch_by_path(const char* path); 00086 struct path_watch_t *find_watch_by_watch_id(int watch_id); 00087 int inotify_start_monitoring(const char *path); 00088 int inotify_stop_monitoring(const char *path); 00089 int read_events(void); 00090 int get_inotify_fd(void); 00091 lwatch_event_callback_t register_lwatch_event_callback(lwatch_event_callback_t callback); 00092 00093 00094 #endif