2 * setfattr - set extended attributes of filesystem objects.
4 * Copyright (C) 2017 by Denys Vlasenko <vda.linux@googlemail.com>
6 * Licensed under GPLv2, see file LICENSE in this source tree.
8 //config:config SETFATTR
9 //config: bool "setfattr"
12 //config: Set/delete extended attributes on files
14 //applet:IF_SETFATTR(APPLET_NOEXEC(setfattr, setfattr, BB_DIR_USR_BIN, BB_SUID_DROP, setfattr))
16 //kbuild:lib-$(CONFIG_SETFATTR) += setfattr.o
18 #include <sys/xattr.h>
21 //usage:#define setfattr_trivial_usage
22 //usage: "[-h] -n|-x ATTR [-v VALUE] FILE..."
23 //usage:#define setfattr_full_usage "\n\n"
24 //usage: "Set extended attributes"
26 //usage: "\n -h Do not follow symlinks"
27 //usage: "\n -x ATTR Remove attribute ATTR"
28 //usage: "\n -n ATTR Set attribute ATTR to VALUE"
29 //usage: "\n -v VALUE (default: empty)"
30 int setfattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
31 int setfattr_main(int argc UNUSED_PARAM, char **argv)
34 const char *value = "";
42 opt = getopt32(argv, "^"
44 /* Min one arg, either -x or -n is a must, -x does not allow -v */
45 "\0" "-1:x:n:n--x:x--nv:v--x"
46 , &name, &name, &value
50 status = EXIT_SUCCESS;
54 r = ((opt & OPT_h) ? lremovexattr : removexattr)(*argv, name);
56 r = ((opt & OPT_h) ? lsetxattr : setxattr)(
58 value, strlen(value), /*flags:*/ 0
62 bb_simple_perror_msg(*argv);
63 status = EXIT_FAILURE;