10 #include <sys/xattr.h>
13 #include <linux/lustre/lustre_idl.h>
15 int main(int argc, char **argv)
20 struct lmv_foreign_md *lfm;
22 while ((c = getopt(argc, argv, "d:")) != -1) {
28 fprintf(stderr, "Usage: %s -d <dirname>\n", argv[0]);
33 len = getxattr(dname, "trusted.lmv", NULL, 0);
38 if (len > XATTR_SIZE_MAX || len <= 0) {
39 fprintf(stderr, "invalid LMV EA length %zu "
41 "XATTR_SIZE_MAX(%u))\n", len,
52 len2 = getxattr(dname, "trusted.lmv", lfm, len);
59 fprintf(stderr, "trusted.lmv xattr size changed, before=%zu "
60 "now=%zu\n", len, len2);
62 if (len2 < offsetof(struct lmv_foreign_md, lfm_value)) {
63 fprintf(stderr, "trusted.lov size=%zu too small\n", len2);
64 fprintf(stderr, "printing its content in hex anyway :\n");
65 for (i = 0; i < len2; i++)
66 fprintf(stderr, "%02x", *((char *)lfm + i));
71 if (lfm->lfm_magic != LMV_MAGIC_FOREIGN) {
72 if (lfm->lfm_magic == bswap_32(LMV_MAGIC_FOREIGN))
73 fprintf(stderr, "magic is swapped\n");
75 fprintf(stderr, "wrong magic=(0x%x)\n", lfm->lfm_magic);
78 if (lfm->lfm_length != len2 - offsetof(typeof(*lfm), lfm_value)) {
79 if (bswap_32(lfm->lfm_length) == len2 - offsetof(typeof(*lfm),
81 fprintf(stderr, "length is swapped\n");
83 fprintf(stderr, "wrong internal length=%u(0x%x) vs "
84 "xattr size=%zu\n", lfm->lfm_length,
85 lfm->lfm_length, len2);
88 if (lfm->lfm_magic == bswap_32(LMV_MAGIC_FOREIGN)) {
89 lfm->lfm_magic = bswap_32(lfm->lfm_magic);
90 lfm->lfm_length = bswap_32(lfm->lfm_length);
91 lfm->lfm_type = bswap_32(lfm->lfm_type);
92 lfm->lfm_flags = bswap_32(lfm->lfm_flags);
95 fprintf(stdout, "lmv_xattr_size: %zu\n", len2);
96 fprintf(stdout, "lmv_foreign_magic: 0x%x\n", lfm->lfm_magic);
97 fprintf(stdout, "lmv_foreign_size: %u\n", lfm->lfm_length);
98 fprintf(stdout, "lmv_foreign_type: %u\n", lfm->lfm_type);
99 fprintf(stdout, "lmv_foreign_flags: %u\n", lfm->lfm_flags);
100 fprintf(stdout, "lmv_foreign_value: 0x");
101 for (i = 0; i < len2 - offsetof(typeof(*lfm), lfm_value); i++)
102 fprintf(stdout, "%02x", lfm->lfm_value[i]);
104 fprintf(stdout, "\n");