10 #include <sys/xattr.h>
13 #include <lustre/lustreapi.h>
15 int main(int argc, char **argv)
20 struct lov_foreign_md *lfm;
22 while ((c = getopt(argc, argv, "f:")) != -1) {
28 fprintf(stderr, "Usage: %s -f <filename>\n", argv[0]);
33 len = getxattr(fname, "lustre.lov", NULL, 0);
38 if (len > XATTR_SIZE_MAX || len <= 0) {
40 "invalid LOV EA length %zu > XATTR_SIZE_MAX (%u)\n",
51 len2 = getxattr(fname, "lustre.lov", lfm, len);
59 "trusted.lov xattr size changed, before=%zu now=%zu\n",
62 if (len2 < offsetof(struct lov_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 != LOV_USER_MAGIC_FOREIGN) {
72 if (lfm->lfm_magic == bswap_32(LOV_USER_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");
84 "wrong internal length=%u vs xattr size=%zu\n",
85 lfm->lfm_length, len2);
88 if (lfm->lfm_magic == bswap_32(LOV_USER_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, "lov_xattr_size: %zu\n", len2);
96 fprintf(stdout, "lov_foreign_magic: 0x%08X\n", lfm->lfm_magic);
97 fprintf(stdout, "lov_foreign_size: %u\n", lfm->lfm_length);
98 fprintf(stdout, "lov_foreign_type: %u\n", lfm->lfm_type);
99 fprintf(stdout, "lov_foreign_flags: 0x%08X\n", lfm->lfm_flags);
100 fprintf(stdout, "lov_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");