1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <sys/fanotify.h>
19 #include "test.h"
20
21 /**
22 * @tc.name : fanotify_init_0100
23 * @tc.desc : Initializes a new fanotify group and returns a file descriptor for the event queue associated with
24 * the group.
25 * @tc.level : Level 0
26 */
fanotify_init_0100(void)27 void fanotify_init_0100(void)
28 {
29 errno = 0;
30
31 int fd = fanotify_init(0, 0);
32 if (fd < 0) {
33 switch (errno) {
34 case ENOSYS:
35 t_error("%s SKIP: missing support for fanotify (check CONFIG_FANOTIFY=y)\n", __func__);
36 case EPERM:
37 t_error("%s SKIP: missing proper permissions for runtime test\n", __func__);
38 }
39
40 t_error("%s fanotify_init failed\n", __func__);
41 }
42
43 int result = fanotify_mark(fd,
44 FAN_MARK_ADD | FAN_MARK_MOUNT,
45 FAN_ACCESS | FAN_MODIFY | FAN_OPEN | FAN_CLOSE | FAN_ONDIR | FAN_EVENT_ON_CHILD,
46 AT_FDCWD,
47 ".");
48
49 if (result) {
50 t_error("%s fanotify_mark (...) failed\n", __func__);
51 }
52 }
53
main(int argc, char *argv[])54 int main(int argc, char *argv[])
55 {
56 // fanotify_init_0100();
57 return t_status;
58 }
59