aboutsummaryrefslogtreecommitdiff
path: root/lib/support/parse_qtype.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2016-05-08 21:11:18 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-05-08 21:25:55 -0400
commita195e862cae6e96895b702efa52a38458dc4b42b (patch)
tree9d248f60597d95c8f715f826e607a87514811c96 /lib/support/parse_qtype.c
parent1973233e530fbe49694cc26d5c351e7a11470fa2 (diff)
downloade2fsprogs-a195e862cae6e96895b702efa52a38458dc4b42b.tar.gz
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 <tytso@mit.edu>
Diffstat (limited to 'lib/support/parse_qtype.c')
-rw-r--r--lib/support/parse_qtype.c88
1 files changed, 88 insertions, 0 deletions
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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#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