2 * Copyright (c) 2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 static int attr_set_f(int argc
, char **argv
);
33 static int attr_remove_f(int argc
, char **argv
);
34 static void attrset_help(void);
36 static const cmdinfo_t attr_set_cmd
=
37 { "attr_set", "aset", attr_set_f
, 1, -1, 0,
38 N_("[-r|-s|-p|-u] [-n] [-R|-C] [-v n] name"),
39 N_("set the named attribute on the current inode"), attrset_help
};
40 static const cmdinfo_t attr_remove_cmd
=
41 { "attr_remove", "aremove", attr_remove_f
, 1, -1, 0,
42 N_("[-r|-s|-p|-u] [-n] name"),
43 N_("remove the named attribute from the current inode"), attrset_help
};
50 " The 'attr_set' and 'attr_remove' commands provide interfaces for debugging\n"
51 " the extended attribute allocation and removal code.\n"
52 " Both commands require an attribute name to be specified, and the attr_set\n"
53 " command allows an optional value length (-v) to be provided as well.\n"
54 " There are 4 namespace flags:\n"
56 " -u -- 'user' (default)\n"
59 " For attr_set, these options further define the type of set operation:\n"
60 " -C -- 'create' - create attribute, fail if it already exists\n"
61 " -R -- 'replace' - replace attribute, fail if it does not exist\n"
62 " The backward compatibility mode 'noattr2' can be emulated (-n) also.\n"
72 add_command(&attr_set_cmd
);
73 add_command(&attr_remove_cmd
);
81 xfs_inode_t
*ip
= NULL
;
82 char *name
, *value
, *sp
;
83 int c
, valuelen
= 0, flags
= 0;
85 if (cur_typ
== NULL
) {
86 dbprintf(_("no current type\n"));
89 if (cur_typ
->typnm
!= TYP_INODE
) {
90 dbprintf(_("current type is not inode\n"));
94 while ((c
= getopt(argc
, argv
, "rusCRnv:")) != EOF
) {
98 flags
|= LIBXFS_ATTR_ROOT
;
99 flags
&= ~LIBXFS_ATTR_SECURE
;
102 flags
&= ~(LIBXFS_ATTR_ROOT
| LIBXFS_ATTR_SECURE
);
105 flags
|= LIBXFS_ATTR_SECURE
;
106 flags
&= ~LIBXFS_ATTR_ROOT
;
111 flags
|= LIBXFS_ATTR_CREATE
;
114 flags
|= LIBXFS_ATTR_REPLACE
;
118 mp
->m_flags
|= LIBXFS_MOUNT_COMPAT_ATTR
;
123 valuelen
= (int)strtol(optarg
, &sp
, 0);
124 if (*sp
!= '\0' || valuelen
< 0 || valuelen
> 64*1024) {
125 dbprintf(_("bad attr_set valuelen %s\n"), optarg
);
131 dbprintf(_("bad option for attr_set command\n"));
136 if (optind
!= argc
- 1) {
137 dbprintf(_("too few options for attr_set (no name given)\n"));
144 value
= (char *)memalign(getpagesize(), valuelen
);
146 dbprintf(_("cannot allocate buffer (%d)\n"), valuelen
);
149 memset(value
, 'v', valuelen
);
154 if (libxfs_iget(mp
, NULL
, iocur_top
->ino
, 0, &ip
)) {
155 dbprintf(_("failed to iget inode %llu\n"),
156 (unsigned long long)iocur_top
->ino
);
160 if (libxfs_attr_set(ip
, (unsigned char *)name
,
161 (unsigned char *)value
, valuelen
, flags
)) {
162 dbprintf(_("failed to set attr %s on inode %llu\n"),
163 name
, (unsigned long long)iocur_top
->ino
);
167 /* refresh with updated inode contents */
168 set_cur_inode(iocur_top
->ino
);
171 mp
->m_flags
&= ~LIBXFS_MOUNT_COMPAT_ATTR
;
184 xfs_inode_t
*ip
= NULL
;
188 if (cur_typ
== NULL
) {
189 dbprintf(_("no current type\n"));
192 if (cur_typ
->typnm
!= TYP_INODE
) {
193 dbprintf(_("current type is not inode\n"));
197 while ((c
= getopt(argc
, argv
, "rusn")) != EOF
) {
201 flags
|= LIBXFS_ATTR_ROOT
;
202 flags
&= ~LIBXFS_ATTR_SECURE
;
205 flags
&= ~(LIBXFS_ATTR_ROOT
| LIBXFS_ATTR_SECURE
);
208 flags
|= LIBXFS_ATTR_SECURE
;
209 flags
&= ~LIBXFS_ATTR_ROOT
;
213 mp
->m_flags
|= LIBXFS_MOUNT_COMPAT_ATTR
;
217 dbprintf(_("bad option for attr_remove command\n"));
222 if (optind
!= argc
- 1) {
223 dbprintf(_("too few options for attr_remove (no name given)\n"));
229 if (libxfs_iget(mp
, NULL
, iocur_top
->ino
, 0, &ip
)) {
230 dbprintf(_("failed to iget inode %llu\n"),
231 (unsigned long long)iocur_top
->ino
);
235 if (libxfs_attr_remove(ip
, (unsigned char *)name
, flags
)) {
236 dbprintf(_("failed to remove attr %s from inode %llu\n"),
237 name
, (unsigned long long)iocur_top
->ino
);
241 /* refresh with updated inode contents */
242 set_cur_inode(iocur_top
->ino
);
245 mp
->m_flags
&= ~LIBXFS_MOUNT_COMPAT_ATTR
;