Line 0
Link Here
|
|
|
1 |
/* |
2 |
* This header is used if <sys/inotify.h> cannot be found. |
3 |
* |
4 |
* Inode based directory notification for Linux |
5 |
* |
6 |
* Copyright (C) 2005 John McCutchan |
7 |
*/ |
8 |
|
9 |
#ifndef _LINUX_INOTIFY_H |
10 |
#define _LINUX_INOTIFY_H |
11 |
|
12 |
#include <stdint.h> |
13 |
#include <sys/syscall.h> |
14 |
#include <unistd.h> |
15 |
|
16 |
/* |
17 |
* struct inotify_event - structure read from the inotify device for each event |
18 |
* |
19 |
* When you are watching a directory, you will receive the filename for events |
20 |
* such as IN_CREATE, IN_DELETE, IN_OPEN, IN_CLOSE, ..., relative to the wd. |
21 |
*/ |
22 |
struct inotify_event { |
23 |
int wd; /* watch descriptor */ |
24 |
uint32_t mask; /* watch mask */ |
25 |
uint32_t cookie; /* cookie to synchronize two events */ |
26 |
uint32_t len; /* length (including nulls) of name */ |
27 |
char name __flexarr; /* stub for possible name */ |
28 |
}; |
29 |
|
30 |
/* the following are legal, implemented events that user-space can watch for */ |
31 |
#define IN_ACCESS 0x00000001 /* File was accessed */ |
32 |
#define IN_MODIFY 0x00000002 /* File was modified */ |
33 |
#define IN_ATTRIB 0x00000004 /* Metadata changed */ |
34 |
#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */ |
35 |
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ |
36 |
#define IN_OPEN 0x00000020 /* File was opened */ |
37 |
#define IN_MOVED_FROM 0x00000040 /* File was moved from X */ |
38 |
#define IN_MOVED_TO 0x00000080 /* File was moved to Y */ |
39 |
#define IN_CREATE 0x00000100 /* Subfile was created */ |
40 |
#define IN_DELETE 0x00000200 /* Subfile was deleted */ |
41 |
#define IN_DELETE_SELF 0x00000400 /* Self was deleted */ |
42 |
#define IN_MOVE_SELF 0x00000800 /* Self was moved */ |
43 |
|
44 |
/* the following are legal events. they are sent as needed to any watch */ |
45 |
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */ |
46 |
#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ |
47 |
#define IN_IGNORED 0x00008000 /* File was ignored */ |
48 |
|
49 |
/* helper events */ |
50 |
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */ |
51 |
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ |
52 |
|
53 |
/* special flags */ |
54 |
#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */ |
55 |
#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */ |
56 |
#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */ |
57 |
#define IN_ISDIR 0x40000000 /* event occurred against dir */ |
58 |
#define IN_ONESHOT 0x80000000 /* only send event once */ |
59 |
|
60 |
/* |
61 |
* All of the events - we build the list by hand so that we can add flags in |
62 |
* the future and not break backward compatibility. Apps will get only the |
63 |
* events that they originally wanted. Be sure to add new events here! |
64 |
*/ |
65 |
#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \ |
66 |
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \ |
67 |
IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \ |
68 |
IN_MOVE_SELF) |
69 |
|
70 |
#if defined (__alpha__) |
71 |
# define __NR_inotify_init 444 |
72 |
# define __NR_inotify_add_watch 445 |
73 |
# define __NR_inotify_rm_watch 446 |
74 |
|
75 |
#elif defined (__arm__) |
76 |
# define __NR_inotify_init (__NR_SYSCALL_BASE+316) |
77 |
# define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) |
78 |
# define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) |
79 |
|
80 |
#elif defined (__frv__) |
81 |
# define __NR_inotify_init 291 |
82 |
# define __NR_inotify_add_watch 292 |
83 |
# define __NR_inotify_rm_watch 293 |
84 |
|
85 |
#elif defined(__i386__) |
86 |
# define __NR_inotify_init 291 |
87 |
# define __NR_inotify_add_watch 292 |
88 |
# define __NR_inotify_rm_watch 293 |
89 |
|
90 |
#elif defined (__ia64__) |
91 |
# define __NR_inotify_init 1277 |
92 |
# define __NR_inotify_add_watch 1278 |
93 |
# define __NR_inotify_rm_watch 1279 |
94 |
|
95 |
#elif defined (__mips__) |
96 |
# if _MIPS_SIM == _MIPS_SIM_ABI32 |
97 |
# define __NR_inotify_init (__NR_Linux + 284) |
98 |
# define __NR_inotify_add_watch (__NR_Linux + 285) |
99 |
# define __NR_inotify_rm_watch (__NR_Linux + 286) |
100 |
# endif |
101 |
# if _MIPS_SIM == _MIPS_SIM_ABI64 |
102 |
# define __NR_inotify_init (__NR_Linux + 243) |
103 |
# define __NR_inotify_add_watch (__NR_Linux + 243) |
104 |
# define __NR_inotify_rm_watch (__NR_Linux + 243) |
105 |
# endif |
106 |
# if _MIPS_SIM == _MIPS_SIM_NABI32 |
107 |
# define __NR_inotify_init (__NR_Linux + 247) |
108 |
# define __NR_inotify_add_watch (__NR_Linux + 248) |
109 |
# define __NR_inotify_rm_watch (__NR_Linux + 249) |
110 |
# endif |
111 |
|
112 |
#elif defined(__parisc__) |
113 |
# define __NR_inotify_init (__NR_Linux + 269) |
114 |
# define __NR_inotify_add_watch (__NR_Linux + 270) |
115 |
# define __NR_inotify_rm_watch (__NR_Linux + 271) |
116 |
|
117 |
#elif defined(__powerpc__) || defined(__powerpc64__) |
118 |
# define __NR_inotify_init 275 |
119 |
# define __NR_inotify_add_watch 276 |
120 |
# define __NR_inotify_rm_watch 277 |
121 |
|
122 |
#elif defined (__s390__) |
123 |
# define __NR_inotify_init 284 |
124 |
# define __NR_inotify_add_watch 285 |
125 |
# define __NR_inotify_rm_watch 286 |
126 |
|
127 |
#elif defined (__sh__) |
128 |
# define __NR_inotify_init 290 |
129 |
# define __NR_inotify_add_watch 291 |
130 |
# define __NR_inotify_rm_watch 292 |
131 |
|
132 |
#elif defined (__sh64__) |
133 |
# define __NR_inotify_init 318 |
134 |
# define __NR_inotify_add_watch 319 |
135 |
# define __NR_inotify_rm_watch 320 |
136 |
|
137 |
#elif defined (__sparc__) || defined (__sparc64__) |
138 |
# define __NR_inotify_init 151 |
139 |
# define __NR_inotify_add_watch 152 |
140 |
# define __NR_inotify_rm_watch 156 |
141 |
|
142 |
#elif defined(__x86_64__) |
143 |
# define __NR_inotify_init 253 |
144 |
# define __NR_inotify_add_watch 254 |
145 |
# define __NR_inotify_rm_watch 255 |
146 |
|
147 |
#else |
148 |
# error "Unsupported architecture!" |
149 |
#endif |
150 |
|
151 |
static inline int inotify_init (void) |
152 |
{ |
153 |
return syscall (__NR_inotify_init); |
154 |
} |
155 |
|
156 |
static inline int inotify_add_watch (int fd, const char *name, uint32_t mask) |
157 |
{ |
158 |
return syscall (__NR_inotify_add_watch, fd, name, mask); |
159 |
} |
160 |
|
161 |
static inline int inotify_rm_watch (int fd, uint32_t wd) |
162 |
{ |
163 |
return syscall (__NR_inotify_rm_watch, fd, wd); |
164 |
} |
165 |
|
166 |
|
167 |
#endif /* _LINUX_INOTIFY_H */ |