• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * inotify testcase common definitions.
4  *
5  * Copyright (c) 2012-2019 Linux Test Project.  All Rights Reserved.
6  * Ngie Cooper, April 2012
7  */
8 
9 #ifndef	_INOTIFY_H
10 #define	_INOTIFY_H
11 
12 #include "lapi/syscalls.h"
13 
14 /* inotify(7) wrappers */
15 
16 #if __NR_inotify_init != __LTP__NR_INVALID_SYSCALL
17 #define myinotify_init() \
18 	tst_syscall(__NR_inotify_init)
19 #else
20 #define myinotify_init() \
21 	tst_syscall(__NR_inotify_init1, 0)
22 #endif
23 
24 #define myinotify_init1(flags) \
25 	tst_syscall(__NR_inotify_init1, flags)
26 
27 #define myinotify_add_watch(fd, pathname, mask)	\
28 	tst_syscall(__NR_inotify_add_watch, fd, pathname, mask)
29 
30 #define myinotify_rm_watch(fd, wd) \
31 	tst_syscall(__NR_inotify_rm_watch, fd, wd)
32 
safe_myinotify_init(const char * file,const int lineno,int fd)33 static inline int safe_myinotify_init(const char *file, const int lineno, int fd)
34 {
35 	if (fd < 0) {
36 		if (errno == ENOSYS) {
37 			tst_brk(TCONF,
38 				"%s:%d: inotify is not configured in this kernel",
39 				file, lineno);
40 		} else {
41 			tst_brk(TBROK | TERRNO, "%s:%d: inotify_init failed",
42 				file, lineno);
43 		}
44 	}
45 	return fd;
46 }
47 
48 #define SAFE_MYINOTIFY_INIT() \
49 	safe_myinotify_init(__FILE__, __LINE__, myinotify_init())
50 
51 #define SAFE_MYINOTIFY_INIT1(flags) \
52 	safe_myinotify_init(__FILE__, __LINE__, myinotify_init1(flags))
53 
safe_myinotify_watch(const char * file,const int lineno,int wd,int fd,const char * fname,const char * mask)54 static inline int safe_myinotify_watch(const char *file, const int lineno, int wd, int fd, const char* fname, const char* mask)
55 {
56 	if (wd < 0) {
57 		tst_brk(TBROK | TERRNO,
58 			"%s:%d: inotify_add_watch (%d, %s, %s) failed",
59 			file, lineno, fd, fname, mask);
60 	}
61 	return wd;
62 }
63 
64 #define SAFE_MYINOTIFY_ADD_WATCH(fd, pathname, mask)	\
65 	safe_myinotify_watch(__FILE__, __LINE__, myinotify_add_watch(fd, pathname, mask), fd, pathname, #mask)
66 
67 #endif /* _INOTIFY_H */
68