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
19
#include <xfs/libxfs.h>
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
"[-r|-s|-p|-u] [-n] [-R|-C] [-v n] name",
39
"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
"[-r|-s|-p|-u] [-n] name",
43
"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, namelen, 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");
142
namelen = strlen(name);
145
value = (char *)memalign(getpagesize(), valuelen);
147
dbprintf("cannot allocate buffer (%d)\n", valuelen);
150
memset(value, 0xfeedface, valuelen);
155
if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip, 0)) {
156
dbprintf(_("failed to iget inode %llu\n"),
157
(unsigned long long)iocur_top->ino);
161
if (libxfs_attr_set_int(ip, name, namelen, 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;
186
int c, namelen, flags = 0;
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");
228
namelen = strlen(name);
230
if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip, 0)) {
231
dbprintf(_("failed to iget inode %llu\n"),
232
(unsigned long long)iocur_top->ino);
236
if (libxfs_attr_remove_int(ip, name, namelen, flags)) {
237
dbprintf(_("failed to remove attr %s from inode %llu\n"),
238
name, (unsigned long long)iocur_top->ino);
242
/* refresh with updated inode contents */
243
set_cur_inode(iocur_top->ino);
246
mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;