1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2005 Silicon Graphics, Inc.
20 static int attr_set_f(int argc
, char **argv
);
21 static int attr_remove_f(int argc
, char **argv
);
22 static void attrset_help(void);
24 static const cmdinfo_t attr_set_cmd
=
25 { "attr_set", "aset", attr_set_f
, 1, -1, 0,
26 N_("[-r|-s|-p|-u] [-n] [-R|-C] [-v n] name"),
27 N_("set the named attribute on the current inode"), attrset_help
};
28 static const cmdinfo_t attr_remove_cmd
=
29 { "attr_remove", "aremove", attr_remove_f
, 1, -1, 0,
30 N_("[-r|-s|-p|-u] [-n] name"),
31 N_("remove the named attribute from the current inode"), attrset_help
};
38 " The 'attr_set' and 'attr_remove' commands provide interfaces for debugging\n"
39 " the extended attribute allocation and removal code.\n"
40 " Both commands require an attribute name to be specified, and the attr_set\n"
41 " command allows an optional value length (-v) to be provided as well.\n"
42 " There are 4 namespace flags:\n"
44 " -u -- 'user' (default)\n"
47 " For attr_set, these options further define the type of set operation:\n"
48 " -C -- 'create' - create attribute, fail if it already exists\n"
49 " -R -- 'replace' - replace attribute, fail if it does not exist\n"
50 " The backward compatibility mode 'noattr2' can be emulated (-n) also.\n"
60 add_command(&attr_set_cmd
);
61 add_command(&attr_remove_cmd
);
69 xfs_inode_t
*ip
= NULL
;
70 char *name
, *value
, *sp
;
71 int c
, valuelen
= 0, flags
= 0;
73 if (cur_typ
== NULL
) {
74 dbprintf(_("no current type\n"));
77 if (cur_typ
->typnm
!= TYP_INODE
) {
78 dbprintf(_("current type is not inode\n"));
82 while ((c
= getopt(argc
, argv
, "rusCRnv:")) != EOF
) {
86 flags
|= LIBXFS_ATTR_ROOT
;
87 flags
&= ~LIBXFS_ATTR_SECURE
;
90 flags
&= ~(LIBXFS_ATTR_ROOT
| LIBXFS_ATTR_SECURE
);
93 flags
|= LIBXFS_ATTR_SECURE
;
94 flags
&= ~LIBXFS_ATTR_ROOT
;
99 flags
|= LIBXFS_ATTR_CREATE
;
102 flags
|= LIBXFS_ATTR_REPLACE
;
106 mp
->m_flags
|= LIBXFS_MOUNT_COMPAT_ATTR
;
111 valuelen
= (int)strtol(optarg
, &sp
, 0);
112 if (*sp
!= '\0' || valuelen
< 0 || valuelen
> 64*1024) {
113 dbprintf(_("bad attr_set valuelen %s\n"), optarg
);
119 dbprintf(_("bad option for attr_set command\n"));
124 if (optind
!= argc
- 1) {
125 dbprintf(_("too few options for attr_set (no name given)\n"));
132 value
= (char *)memalign(getpagesize(), valuelen
);
134 dbprintf(_("cannot allocate buffer (%d)\n"), valuelen
);
137 memset(value
, 'v', valuelen
);
142 if (libxfs_iget(mp
, NULL
, iocur_top
->ino
, 0, &ip
,
143 &xfs_default_ifork_ops
)) {
144 dbprintf(_("failed to iget inode %llu\n"),
145 (unsigned long long)iocur_top
->ino
);
149 if (libxfs_attr_set(ip
, (unsigned char *)name
,
150 (unsigned char *)value
, valuelen
, flags
)) {
151 dbprintf(_("failed to set attr %s on inode %llu\n"),
152 name
, (unsigned long long)iocur_top
->ino
);
156 /* refresh with updated inode contents */
157 set_cur_inode(iocur_top
->ino
);
160 mp
->m_flags
&= ~LIBXFS_MOUNT_COMPAT_ATTR
;
173 xfs_inode_t
*ip
= NULL
;
177 if (cur_typ
== NULL
) {
178 dbprintf(_("no current type\n"));
181 if (cur_typ
->typnm
!= TYP_INODE
) {
182 dbprintf(_("current type is not inode\n"));
186 while ((c
= getopt(argc
, argv
, "rusn")) != EOF
) {
190 flags
|= LIBXFS_ATTR_ROOT
;
191 flags
&= ~LIBXFS_ATTR_SECURE
;
194 flags
&= ~(LIBXFS_ATTR_ROOT
| LIBXFS_ATTR_SECURE
);
197 flags
|= LIBXFS_ATTR_SECURE
;
198 flags
&= ~LIBXFS_ATTR_ROOT
;
202 mp
->m_flags
|= LIBXFS_MOUNT_COMPAT_ATTR
;
206 dbprintf(_("bad option for attr_remove command\n"));
211 if (optind
!= argc
- 1) {
212 dbprintf(_("too few options for attr_remove (no name given)\n"));
218 if (libxfs_iget(mp
, NULL
, iocur_top
->ino
, 0, &ip
,
219 &xfs_default_ifork_ops
)) {
220 dbprintf(_("failed to iget inode %llu\n"),
221 (unsigned long long)iocur_top
->ino
);
225 if (libxfs_attr_remove(ip
, (unsigned char *)name
, flags
)) {
226 dbprintf(_("failed to remove attr %s from inode %llu\n"),
227 name
, (unsigned long long)iocur_top
->ino
);
231 /* refresh with updated inode contents */
232 set_cur_inode(iocur_top
->ino
);
235 mp
->m_flags
&= ~LIBXFS_MOUNT_COMPAT_ATTR
;