From a195e862cae6e96895b702efa52a38458dc4b42b Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 8 May 2016 21:11:18 -0400 Subject: mke2fs: fix the parsing used for -E quotatype=usrquota:grpquota:prjquota Commit 2d2d799c7261 tried to use parse_quota_options(), which uses commas to separate out the quota types. Unfortunately, when parsing extended options, commands are used to separate different extended options. To fix this, I've add a new support function parse_quota_type(), which allows either commas or colons to used as a separator character, and which manipulates a bit field to indicate which quota types should be enabled. Eventually tune2fs should be converted to use parse_quota_type() as well, thus obsoleting parse_quota_options(), but that's a more complicated cleanup patch for later. Fix a lint warning which could the number of blocks to be incorretly printed if it exceeds 2**32. Also fix some typos and other minor bugs in the usage message. Signed-off-by: Theodore Ts'o --- lib/support/parse_qtype.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 lib/support/parse_qtype.c (limited to 'lib/support/parse_qtype.c') diff --git a/lib/support/parse_qtype.c b/lib/support/parse_qtype.c new file mode 100644 index 00000000..098639e1 --- /dev/null +++ b/lib/support/parse_qtype.c @@ -0,0 +1,88 @@ +/* + * parse_qtype.c + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include + +#include "quotaio.h" + +#define PARSE_DELIM ":," + +int parse_quota_types(const char *in_str, unsigned int *qtype_bits, + char **err_token) +{ + char *buf, *token, *next, *tmp; + unsigned int qtype = *qtype_bits; + int len, ret = 0; + + if (!in_str) + return 0; + + len = strlen(in_str); + buf = malloc(len + 1); + if (!buf) + return ENOMEM; + strcpy(buf, in_str); + + for (token = buf, next = strtok_r(buf, PARSE_DELIM, &tmp); + token && *token; token = next) { + int not = 0; + char *p = token; + + if (*p == '^') { + not = 1; + p++; + } + if (!strcmp(p, "usr") || !strcmp(p, "usrquota")) { + if (not) + qtype &= ~QUOTA_USR_BIT; + else + qtype |= QUOTA_USR_BIT; + } else if (!strcmp(p, "grp") || !strcmp(p, "grpquota")) { + if (not) + qtype &= ~QUOTA_GRP_BIT; + else + qtype |= QUOTA_GRP_BIT; + } else if (!strcmp(p, "prj") || !strcmp(p, "prjquota")) { + if (not) + qtype &= ~QUOTA_PRJ_BIT; + else + qtype |= QUOTA_PRJ_BIT; + } else { + if (err_token) { + *err_token = malloc(strlen(token) + 1); + if (*err_token) + strcpy(*err_token, token); + } + ret = EINVAL; + goto errout; + } + printf("word: %s\n", token); + next = strtok_r(NULL, PARSE_DELIM, &tmp); + } + *qtype_bits = qtype; +errout: + free(buf); + return ret; +} + +#if 0 +int main(int argc, char **argv) +{ + unsigned int qtype_bits = 0; + int ret; + char *err_token = 0; + + ret = parse_quota_types(argv[1], &qtype_bits, &err_token); + printf("parse_quota_types returns %d, %d\n", ret, qtype_bits); + if (err_token) + printf("err_token is %s\n", err_token); + return 0; +} +#endif -- cgit v1.2.3