Whamcloud - gitweb
LU-6027 mdd: Don't list "trusted.link" for orphans
[fs/lustre-release.git] / lustre / tests / orphan_linkea_check.c
1 /*
2  * Check that flistxattr() calls on orphans do not return "trusted.link" EAs.
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10 #include <attr/xattr.h>
11
12 int
13 main(int argc, char *argv[])
14 {
15         char   *names;
16         char   *name;
17         ssize_t size;
18         int     fd;
19         int     rc;
20
21         fd = open(argv[1], O_RDWR | O_CREAT, 0666);
22         if (fd == -1) {
23                 perror("open");
24                 return 1;
25         }
26
27         rc = unlink(argv[1]);
28         if (rc == -1) {
29                 perror("unlink");
30                 close(fd);
31                 return 1;
32         }
33
34         size = flistxattr(fd, NULL, 0);
35         if (size == -1) {
36                 perror("flistxattr size");
37                 close(fd);
38                 return 1;
39         }
40
41         names = malloc(size);
42         if (names == NULL) {
43                 fprintf(stderr, "Cannot allocate names\n");
44                 close(fd);
45                 return 1;
46         }
47
48         size = flistxattr(fd, names, size);
49         if (size == -1) {
50                 perror("flistxattr");
51                 free(names);
52                 close(fd);
53                 return 1;
54         }
55
56         for (name = names; name < names + size; name += strlen(name) + 1)
57                 if (strcmp(name, "trusted.link") == 0) {
58                         free(names);
59                         close(fd);
60                         return 1;
61                 }
62
63         free(names);
64
65         rc = close(fd);
66         if (rc == -1) {
67                 perror("close");
68                 return 1;
69         }
70
71         return 0;
72 }