11 #include <lustre/lustreapi.h>
12 #include <linux/lustre/lustre_idl.h>
14 int main(int argc, char **argv)
18 bool f_opt = false, d_opt = false, h_opt = false;
19 /* buf must be large enough to receive biggest possible
22 char buf[XATTR_SIZE_MAX];
23 struct lmv_foreign_md *lfm = (void *)buf;
25 while ((c = getopt(argc, argv, "hf:d:")) != -1) {
31 "only one foreign symlink file or dir can be specified at a time\n");
40 "only one foreign symlink file or dir can be specified at a time\n");
49 "Usage: %s [-[f,d] <foreign file/dir pathname>]\n",
56 if (foreign == NULL) {
58 "a foreign file/dir pathname must be provided\n");
62 /* in case foreign fake symlink feature is active, file/dir must be
63 * opened with O_NOFOLLOW to avoid symlink resolution
65 fd = open(foreign, O_RDONLY|O_NONBLOCK|O_NOFOLLOW);
67 fprintf(stderr, "open() of '%s' error, rc : %d\n", foreign, fd);
72 rc = snprintf(buf, PATH_MAX, "%s", foreign);
73 if (rc >= PATH_MAX || rc < 0) {
75 "unexpected return code or size from snprintf() : %d\n",
81 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, &buf);
83 lfm->lfm_magic = LMV_MAGIC_V1;
84 rc = ioctl(fd, LL_IOC_LMV_GETSTRIPE, &buf);
88 fprintf(stderr, "%s: %s error: %s\n", foreign,
89 f_opt ? "getstripe" : "getdirstripe", strerror(errno));
93 if (lfm->lfm_magic != LOV_USER_MAGIC_FOREIGN &&
94 lfm->lfm_magic != LMV_MAGIC_FOREIGN)
95 fprintf(stderr, "unexpected magic : 0x%08X, expected 0x%08X\n",
96 lfm->lfm_magic, LOV_USER_MAGIC_FOREIGN);
97 if (lfm->lfm_type != LU_FOREIGN_TYPE_SYMLINK)
98 fprintf(stderr, "unexpected type : 0x%08X, expected 0x%08X\n",
99 lfm->lfm_type, LU_FOREIGN_TYPE_SYMLINK);
100 printf("lfm_magic: 0x%08X, lfm_length: %u, lfm_type: 0x%08X, lfm_flags: 0x%08X, lfm_value: '%.*s'\n",
101 lfm->lfm_magic, lfm->lfm_length, lfm->lfm_type, lfm->lfm_flags,
102 lfm->lfm_length, lfm->lfm_value);