4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; if not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2016, DDN Storage Corporation.
26 * lustre/utils/ll_decode_linkea.c
28 * Tool for printing the MDT link_ea structure on the objects
29 * in human readable form.
31 * Author: Li Xi <lixi@ddn.com>
39 #include <sys/types.h>
40 #include <sys/xattr.h>
41 #include <lustre/lustre_idl.h>
42 #include <lustre/lustre_user.h>
44 #define BUFFER_SIZE 65536
46 int decode_linkea(const char *fname)
48 char buf[BUFFER_SIZE];
49 struct link_ea_header *leh;
51 struct link_ea_entry *lee;
57 size = getxattr(fname, "trusted.link", buf, BUFFER_SIZE);
59 if (errno == ERANGE) {
60 fprintf(stderr, "%s: failed to read trusted.link "
61 "xattr, the buffer size %u might be too "
62 "small\n", fname, BUFFER_SIZE);
65 "%s: failed to read trusted.link xattr: %s\n",
66 fname, strerror(errno));
71 leh = (struct link_ea_header *)buf;
72 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
73 leh->leh_magic = LINK_EA_MAGIC;
74 leh->leh_reccount = __swab32(leh->leh_reccount);
75 leh->leh_len = __swab64(leh->leh_len);
77 if (leh->leh_magic != LINK_EA_MAGIC) {
79 "%s: magic mismatch, expected 0x%lx, got 0x%x\n",
80 fname, LINK_EA_MAGIC, leh->leh_magic);
83 if (leh->leh_reccount == 0) {
84 fprintf(stderr, "%s: empty record count\n", fname);
87 if (leh->leh_len > size) {
89 "%s: invalid length %llu, should smaller than %zd\n",
90 fname, leh->leh_len, size);
94 length = sizeof(struct link_ea_header);
95 lee = (struct link_ea_entry *)(leh + 1);
96 printf("%s: count %u\n", fname, leh->leh_reccount);
97 for (i = 0; i < leh->leh_reccount; i++) {
98 reclen = (lee->lee_reclen[0] << 8) | lee->lee_reclen[1];
100 if (length > leh->leh_len) {
102 "%s: length exceeded, expected %lld, got %lld\n",
103 fname, leh->leh_len, length);
106 memcpy(&pfid, &lee->lee_parent_fid, sizeof(pfid));
107 fid_be_to_cpu(&pfid, &pfid);
109 printf(" %d: pfid "DFID", name '%s'\n", i, PFID(&pfid),
111 lee = (struct link_ea_entry *)((char *)lee + reclen);
114 if (length != leh->leh_len) {
116 "%s: length mismatch, expected %lld, got %lld\n",
117 fname, leh->leh_len, length);
124 int main(int argc, char *argv[])
130 for (i = 1; i < argc; i++) {
131 rc2 = decode_linkea(argv[i]);