Whamcloud - gitweb
LU-13404 utils: fix lfs mirror duplicate file check
[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_DAOS, flags = 0;
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                         flags = strtoul(optarg, &end, 0);
40                         if (*end != '\0') {
41                                 fprintf(stderr,
42                                         "%s: invalid flags '%s'\n", argv[0],
43                                         optarg);
44                                 exit(1);
45                         }
46                         break;
47                 case 't':
48                         type = strtoul(optarg, &end, 0);
49                         if (*end != '\0') {
50                                 fprintf(stderr,
51                                         "%s: invalid type '%s'\n", argv[0],
52                                         optarg);
53                                 exit(1);
54                         }
55                         break;
56                 case 'h':
57                 default:
58                         fprintf(stderr,
59                                 "Usage: %s [-d <dirname>] [-m <octalmode>] [-x <LOV EA content>] [-t <type>] [-f <hexflags>]\n",
60                                 argv[0]);
61                         exit(0);
62                         break;
63                 }
64         }
65
66         rc = llapi_dir_create_foreign(dir, mode, type, flags, xval);
67         if (rc < 0)
68                 fprintf(stderr, "llapi_dir_create_foreign() error : %d\n", rc);
69
70         return rc;
71 }