summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <andreas.gruenbacher@gmail.com>2015-02-20 22:48:26 +0100
committerAndreas Gruenbacher <andreas.gruenbacher@gmail.com>2015-02-20 22:52:04 +0100
commitc252ef434219891f616d891b46aad6b06efdd185 (patch)
tree17931b5c4710c42d12e355a1de23530d1be5c007
parent0550d2bc989d390eb25f7004ee0fae2dbc693a0d (diff)
downloadattr-c252ef434219891f616d891b46aad6b06efdd185.tar.gz
Add setfattr --raw option
With this option, attribute values are taken as they are, without traing to decode them. This can be thought of as the counterpart to "getfattr --only-values".
-rw-r--r--man/man1/setfattr.14
-rw-r--r--tools/setfattr.c10
2 files changed, 13 insertions, 1 deletions
diff --git a/man/man1/setfattr.1 b/man/man1/setfattr.1
index 75a4375..62055fd 100644
--- a/man/man1/setfattr.1
+++ b/man/man1/setfattr.1
@@ -78,6 +78,10 @@ is given as the file name,
.B setfattr
reads from standard input.
.TP
+.B \-\-raw
+Do not decode the attribute value. Can be used to set values obtained with
+.BR "getfattr --only-values" .
+.TP
.B \-\-version
Print the version of
.B setfattr
diff --git a/tools/setfattr.c b/tools/setfattr.c
index 33a4282..e209b0d 100644
--- a/tools/setfattr.c
+++ b/tools/setfattr.c
@@ -42,6 +42,7 @@ struct option long_options[] = {
{ "value", 1, 0, 'v' },
{ "no-dereference", 0, 0, 'h' },
{ "restore", 1, 0, 'B' },
+ { "raw", 0, 0, CHAR_MAX + 1 },
{ "version", 0, 0, 'V' },
{ "help", 0, 0, 'H' },
{ NULL, 0, 0, 0 }
@@ -53,6 +54,7 @@ int opt_set; /* set an attribute */
int opt_remove; /* remove an attribute */
int opt_restore; /* restore has been run */
int opt_deref = 1; /* dereference symbolic links */
+int opt_raw; /* attribute value is not encoded */
int had_errors;
const char *progname;
@@ -182,6 +184,7 @@ void help(void)
" -v, --value=value use value as the attribute value\n"
" -h, --no-dereference do not dereference symbolic links\n"
" --restore=file restore extended attributes\n"
+" --raw attribute value is not encoded\n"
" --version print version and exit\n"
" --help this help text\n"));
}
@@ -217,6 +220,10 @@ int main(int argc, char *argv[])
opt_value = optarg;
break;
+ case CHAR_MAX + 1:
+ opt_raw = 1;
+ break;
+
case 'x': /* remove attribute */
if (opt_name || opt_set)
goto synopsis;
@@ -266,7 +273,8 @@ int do_set(const char *path, const char *name, const char *value)
if (value) {
size = strlen(value);
- value = decode(value, &size);
+ if (!opt_raw)
+ value = decode(value, &size);
if (!value)
return 1;
}