+
+static bool
+setDLimitField(struct vc_ctx_dlimit *dst, char const *opt)
+{
+ uint_least32_t *ptr;
+ char const * const orig_opt = opt;
+
+#define GET_VAL_PTR(CMP, VAL) \
+ (strncmp(opt, CMP "=", sizeof(CMP))==0) ? \
+ (opt+=sizeof(CMP), &VAL) : 0
+
+ if ((ptr=GET_VAL_PTR("space_used", dst->space_used))!=0) {}
+ else if ((ptr=GET_VAL_PTR("space_total", dst->space_total))!=0) {}
+ else if ((ptr=GET_VAL_PTR("inodes_used", dst->inodes_used))!=0) {}
+ else if ((ptr=GET_VAL_PTR("inodes_total", dst->inodes_total))!=0) {}
+ else if ((ptr=GET_VAL_PTR("reserved", dst->reserved))!=0) {}
+ else ptr=0;
+
+#undef GET_VAL_PTR
+
+ if (ptr!=0 && *ptr==VC_CDLIM_KEEP) {
+ char *endptr;
+ long val = strtol(opt, &endptr, 0);
+
+ if (*opt==0 || *endptr!='\0') {
+ WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "can not parse number in '");
+ WRITE_STR(2, orig_opt);
+ WRITE_MSG(2, "'\n");
+ return false;
+ }
+
+ *ptr = val;
+ }
+ else if (ptr!=0) {
+ WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "value already set in '");
+ WRITE_STR(2, orig_opt);
+ WRITE_MSG(2, "'\n");
+ return false;
+ }
+ else {
+ WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "unknown limit in '");
+ WRITE_STR(2, orig_opt);
+ WRITE_MSG(2, "'\n");
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ bool do_set = false;
+ bool do_remove = false;
+ xid_t xid = VC_NOCTX;
+ uint32_t flags = 0;
+ char *endptr;
+ int sum = 0;
+
+ struct vc_ctx_dlimit limit = {
+ .space_used = VC_CDLIM_KEEP,
+ .space_total = VC_CDLIM_KEEP,
+ .inodes_used = VC_CDLIM_KEEP,
+ .inodes_total = VC_CDLIM_KEEP,
+ .reserved = VC_CDLIM_KEEP
+ };
+
+ while (1) {
+ int c = getopt_long(argc, argv, "+x:s:df:", CMDLINE_OPTIONS, 0);
+ if (c==-1) break;
+
+ switch (c) {
+ case CMD_HELP : showHelp(1, argv[0]);
+ case CMD_VERSION : showVersion();
+ case 'x' : xid = Evc_xidopt2xid(optarg, true); break;
+ case 's' :
+ if (!setDLimitField(&limit, optarg))
+ return EXIT_FAILURE;
+ else
+ do_set = true;
+ break;
+ case 'd' : do_remove = true; break;
+ case 'f' :
+ {
+ flags = strtol(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;
+ }
+ }
+ break;
+
+ default :
+ WRITE_MSG(2, "Try '");
+ WRITE_STR(2, argv[0]);
+ WRITE_MSG(2, " --help' for more information.\n");
+ return EXIT_FAILURE;
+ break;
+ }
+ }
+
+ sum = ((do_set ? 1 : 0) + (do_remove ? 1 : 0));
+
+ if (sum>1)
+ WRITE_MSG(2, "Can not specify multiple operations; try '--help' for more information\n");
+ else if (optind==argc)
+ WRITE_MSG(2, "No mount point specified; try '--help' for more information\n");
+ else if (xid==VC_NOCTX)
+ WRITE_MSG(2, "No xid specified; try '--help' for more information\n");
+ else {
+ for (; optind < argc; ++optind) {
+ if (do_set) setDlimit(argv[optind], xid, flags, &limit);
+ else if (do_remove) remDlimit(argv[optind], xid, flags);
+ else printDlimit(argv[optind], xid, flags, true);
+ }
+
+ return EXIT_SUCCESS;
+ }
+
+ return EXIT_FAILURE;
+}