1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
8 #include <attr/attributes.h>
13 #include <asm/types.h>
15 #include <xfs/handle.h>
17 #define ATTRBUFSZ 1024
18 #define BSTATBUF_NR 32
20 /* Read all the extended attributes of a file handle. */
23 struct xfs_handle *handle)
25 struct attrlist_cursor cur;
26 char attrbuf[ATTRBUFSZ];
27 char *firstname = NULL;
28 struct attrlist *attrlist = (struct attrlist *)attrbuf;
29 struct attrlist_ent *ent;
34 memset(&cur, 0, sizeof(cur));
35 while ((error = attr_list_by_handle(handle, sizeof(*handle),
36 attrbuf, ATTRBUFSZ, flags,
38 for (i = 0; i < attrlist->al_count; i++) {
39 ent = ATTR_ENTRY(attrlist, i);
44 if (firstname == NULL) {
45 firstname = malloc(ent->a_valuelen);
46 memcpy(firstname, ent->a_name, ent->a_valuelen);
48 if (memcmp(firstname, ent->a_name,
49 ent->a_valuelen) == 0)
51 "Saw duplicate xattr \"%s\", buggy XFS?\n",
60 if (!attrlist->al_more)
68 perror("attr_list_by_handle");
76 struct xfs_handle *fshandle;
78 struct xfs_handle *handle;
83 fprintf(stderr, "Usage: %s filename\n", argv[0]);
87 error = path_to_fshandle(argv[1], (void **)&fshandle, &fshandle_len);
89 perror("getting fshandle");
93 error = path_to_handle(argv[1], (void **)&handle, &handle_len);
95 perror("getting handle");
99 read_handle_xattrs(handle);
101 free_handle(handle, handle_len);
102 free_handle(fshandle, fshandle_len);