Whamcloud - gitweb
LU-15152 tests: auster reports wrong testsuite status
[fs/lustre-release.git] / lustre / tests / create_foreign_dir.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <limits.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <libgen.h>
7 #include <sys/ioctl.h>
8 #include <sys/xattr.h>
9 #include <sys/file.h>
10
11 #include <lustre/lustreapi.h>
12
13 int main(int argc, char **argv)
14 {
15         char *dir = "foreign_dir", *end;
16         char *xval = "UUID@UUID";
17         mode_t mode = 0700;
18         __u32 type = LU_FOREIGN_TYPE_SYMLINK, flags = 0xda05;
19         int c, rc;
20
21         while ((c = getopt(argc, argv, "hd:f:m:t:x:")) != -1) {
22                 switch (c) {
23                 case 'd':
24                         dir = optarg;
25                         break;
26                 case 'x':
27                         xval = optarg;
28                         break;
29                 case 'm':
30                         mode = strtoul(optarg, &end, 8);
31                         if (*end != '\0') {
32                                 fprintf(stderr,
33                                         "%s: invalid mode '%s'\n", argv[0],
34                                         optarg);
35                                 exit(1);
36                         }
37                         break;
38                 case 'f':
39                         errno = 0;
40                         flags = strtoul(optarg, &end, 0);
41                         if (errno != 0 || *end != '\0' ||
42                             flags >= UINT32_MAX) {
43                                 fprintf(stderr,
44                                         "%s: invalid flags '%s'\n", argv[0],
45                                         optarg);
46                                 exit(1);
47                         }
48                         break;
49                 case 't':
50                         type = strtoul(optarg, &end, 0);
51                         if (*end != '\0') {
52                                 fprintf(stderr,
53                                         "%s: invalid type '%s'\n", argv[0],
54                                         optarg);
55                                 exit(1);
56                         }
57                         break;
58                 case 'h':
59                 default:
60                         fprintf(stderr,
61                                 "Usage: %s [-d <dirname>] [-m <octalmode>] [-x <LOV EA content>] [-t <type>] [-f <hexflags>]\n",
62                                 argv[0]);
63                         exit(0);
64                         break;
65                 }
66         }
67
68         rc = llapi_dir_create_foreign(dir, mode, type, flags, xval);
69         if (rc < 0)
70                 fprintf(stderr, "llapi_dir_create_foreign() error : %d\n", rc);
71
72         return rc;
73 }