2 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <sys/types.h>
22 #include <attr/attributes.h>
27 #include <asm/types.h>
29 #include <xfs/handle.h>
31 #define ATTRBUFSZ 1024
32 #define BSTATBUF_NR 32
34 /* Read all the extended attributes of a file handle. */
37 struct xfs_handle *handle)
39 struct attrlist_cursor cur;
40 char attrbuf[ATTRBUFSZ];
41 char *firstname = NULL;
42 struct attrlist *attrlist = (struct attrlist *)attrbuf;
43 struct attrlist_ent *ent;
48 memset(&cur, 0, sizeof(cur));
49 while ((error = attr_list_by_handle(handle, sizeof(*handle),
50 attrbuf, ATTRBUFSZ, flags,
52 for (i = 0; i < attrlist->al_count; i++) {
53 ent = ATTR_ENTRY(attrlist, i);
58 if (firstname == NULL) {
59 firstname = malloc(ent->a_valuelen);
60 memcpy(firstname, ent->a_name, ent->a_valuelen);
62 if (memcmp(firstname, ent->a_name,
63 ent->a_valuelen) == 0)
65 "Saw duplicate xattr \"%s\", buggy XFS?\n",
74 if (!attrlist->al_more)
82 perror("attr_list_by_handle");
90 struct xfs_handle *fshandle;
92 struct xfs_handle *handle;
97 fprintf(stderr, "Usage: %s filename\n", argv[0]);
101 error = path_to_fshandle(argv[1], (void **)&fshandle, &fshandle_len);
103 perror("getting fshandle");
107 error = path_to_handle(argv[1], (void **)&handle, &handle_len);
109 perror("getting handle");
113 read_handle_xattrs(handle);
115 free_handle(handle, handle_len);
116 free_handle(fshandle, fshandle_len);