-
Notifications
You must be signed in to change notification settings - Fork 1
/
wrap-inotify.h
66 lines (54 loc) · 1.77 KB
/
wrap-inotify.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* A Simple interface to inotify Linux subsystem, focusing on recursively
* monitoring.
*
*
* Copyright (c) 2010, 2011 lxd <i@lxd.me>
*
* This file is part of File Synchronization System(fss).
*
* fss is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* (at your option) any later version.
*
* fss is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with fss. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _WRAP_INOTIFY_H_
#define _WRAP_INOTIFY_H_
#include "utils.h"
#include <inttypes.h>
#include <sys/inotify.h>
#define MAX_DIR_LEVEL MAX_PATH_LEN
#define MAX_PATH_LEN 1024
#define BUF_LEN 1024
#define DEPTH_OF_NFTW 10
typedef struct _watcher watcher;
struct _watcher {
int wd; // defined by inotify
int level; // temporary level in current nftw()
char *path;
// hashtable linked list chain
watcher *chain_wd;
watcher *chain_path;
// watcher's connected as tree according to monitored directory structure,
// so when sub directores are removed, their corresponding wd(s) can be
// removed directly
watcher *prev; // refers to father or left-sibling
watcher *child;
watcher *sibling; // refers to right-sibling
};
typedef struct {
watcher* head;
watcher* tail;
} dirlist;
// return a fd from which messages can be read when something happen
int init_watchers(const char *path, uint32_t mask, uint64_t htbsz);
void cleanup_watchers();
#endif