From: Daniel Hokka Zakrisson Date: Tue, 31 May 2011 12:16:24 +0000 (+0200) Subject: Support any flag for setattr X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ba3827e88c18b00e610b6680e1ca6434d8eadef;p=util-vserver.git Support any flag for setattr --- diff --git a/src/fstool.c b/src/fstool.c index fa701ee..34dc976 100644 --- a/src/fstool.c +++ b/src/fstool.c @@ -191,6 +191,8 @@ int main(int argc, char *argv[]) while (1) { int c = getopt_long(argc, argv, CMDLINE_OPTIONS_SHORT, CMDLINE_OPTIONS, 0); + long flags; + char *endptr; if (c==-1) break; switch (c) { @@ -214,6 +216,20 @@ int main(int argc, char *argv[]) case CMD_UNSET_BARRIER : args.del_mask |= VC_IATTR_BARRIER; break; case CMD_UNSET_WRITE : args.del_mask |= VC_IATTR_WRITE; break; case CMD_UNSET_COW : args.del_mask |= VC_IATTR_COW; break; + case CMD_FLAGS : + case CMD_UNSET_FLAGS : + flags = strtoul(optarg, &endptr, 0); + if ((flags == 0 && errno != 0) || *endptr != '\0') { + WRITE_MSG(2, "Invalid flags argument: '"); + WRITE_STR(2, optarg); + WRITE_MSG(2, "'; try '--help' for more information\n"); + return EXIT_FAILURE; + } + if (c == CMD_FLAGS) + args.set_mask |= flags; + else + args.del_mask |= flags; + break; case 'R' : args.do_recurse = true; break; case 'a' : args.do_display_dot = true; break; case 'd' : args.do_display_dir = true; break; diff --git a/src/fstool.h b/src/fstool.h index e8505cd..f7c2879 100644 --- a/src/fstool.h +++ b/src/fstool.h @@ -35,6 +35,7 @@ #define CMD_IMMUX 0x8015 #define CMD_WRITE 0x8016 #define CMD_COW 0x8017 +#define CMD_FLAGS 0x8018 #define CMD_UNSET_IMMU 0x8020 #define CMD_UNSET_ADMIN 0x8021 #define CMD_UNSET_WATCH 0x8022 @@ -44,6 +45,7 @@ #define CMD_UNSET_IMMUTABLE 0x8026 #define CMD_UNSET_WRITE 0x8027 #define CMD_UNSET_COW 0x8028 +#define CMD_UNSET_FLAGS 0x8029 struct stat; diff --git a/src/setattr.c b/src/setattr.c index 8063754..5ff9aa2 100644 --- a/src/setattr.c +++ b/src/setattr.c @@ -35,8 +35,8 @@ struct option const CMDLINE_OPTIONS[] = { - { "help", no_argument, 0, CMD_HELP }, - { "version", no_argument, 0, CMD_VERSION }, + { "help", no_argument, 0, CMD_HELP }, + { "version", no_argument, 0, CMD_VERSION }, { "immu", no_argument, 0, CMD_IMMU }, { "iunlink", no_argument, 0, CMD_IMMU }, { "admin", no_argument, 0, CMD_ADMIN }, @@ -64,9 +64,14 @@ CMDLINE_OPTIONS[] = { { "write", no_argument, 0, CMD_WRITE }, { "~write", no_argument, 0, CMD_UNSET_WRITE }, { "!write", no_argument, 0, CMD_UNSET_WRITE }, - { "cow", no_argument, 0, CMD_COW }, - { "~cow", no_argument, 0, CMD_UNSET_COW }, - { "!cow", no_argument, 0, CMD_UNSET_COW }, + { "cow", no_argument, 0, CMD_COW }, + { "~cow", no_argument, 0, CMD_UNSET_COW }, + { "!cow", no_argument, 0, CMD_UNSET_COW }, + { "ixunlink", no_argument, 0, CMD_IMMUX }, + { "~ixunlink", no_argument, 0, CMD_UNSET_IMMUX }, + { "!ixunlink", no_argument, 0, CMD_UNSET_IMMUX }, + { "flags", required_argument, 0, CMD_FLAGS }, + { "~flags", required_argument, 0, CMD_UNSET_FLAGS }, { 0,0,0,0 } }; @@ -78,7 +83,7 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [-Rx] [--[~](iunlink|admin|watch|hide|barrier|iunlink-but-not-immutable|immutable|write|cow)]* [--] +\n\n" + " [-Rx] [--[~](iunlink|admin|watch|hide|barrier|iunlink-but-not-immutable|immutable|write|cow|ixunlink)]* [--] +\n\n" " Options:\n" " -R ... recurse through directories\n" " -x ... do not cross filesystems\n\n"