From patchwork Thu Jul 20 09:29:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Tulak X-Patchwork-Id: 9854399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD7CF600F5 for ; Thu, 20 Jul 2017 09:29:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C52BE28760 for ; Thu, 20 Jul 2017 09:29:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8CC928784; Thu, 20 Jul 2017 09:29:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2524828760 for ; Thu, 20 Jul 2017 09:29:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934694AbdGTJ3q (ORCPT ); Thu, 20 Jul 2017 05:29:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10810 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934247AbdGTJ3m (ORCPT ); Thu, 20 Jul 2017 05:29:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FB5F7F6B4 for ; Thu, 20 Jul 2017 09:29:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3FB5F7F6B4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jtulak@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3FB5F7F6B4 Received: from honza-mbp.redhat.com (ovpn-204-167.brq.redhat.com [10.40.204.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B2477982A; Thu, 20 Jul 2017 09:29:41 +0000 (UTC) From: Jan Tulak To: linux-xfs@vger.kernel.org Cc: Jan Tulak Subject: [PATCH 5/7] mkfs: move getnum within the file Date: Thu, 20 Jul 2017 11:29:30 +0200 Message-Id: <20170720092932.32580-6-jtulak@redhat.com> In-Reply-To: <20170720092932.32580-1-jtulak@redhat.com> References: <20170720092932.32580-1-jtulak@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Jul 2017 09:29:42 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move getnum, check_opt and illegal_option within the file. We have to do this to avoid dependency issues with the following patch. There is no other change in this patch, just cut&paste of these functions. Signed-off-by: Jan Tulak Reviewed-by: Eric Sandeen --- mkfs/xfs_mkfs.c | 236 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 118 insertions(+), 118 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index f10cb15a..9d2db2a2 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -761,6 +761,124 @@ get_conf_raw(int opt, int subopt) return opts[opt].subopt_params[subopt].raw_input; } +static __attribute__((noreturn)) void +illegal_option( + const char *value, + struct opt_params *opts, + int index, + const char *reason) +{ + fprintf(stderr, + _("Illegal value %s for -%c %s option. %s\n"), + value, opts->name, opts->subopts[index], + reason ? reason : ""); + usage(); +} + +/* + * Check for conflicts and option respecification. + */ +static void +check_opt( + struct opt_params *opts, + int index, + bool str_seen) +{ + struct subopt_param *sp = &opts->subopt_params[index]; + int i; + + if (sp->index != index) { + fprintf(stderr, + ("Developer screwed up option parsing (%d/%d)! Please report!\n"), + sp->index, index); + reqval(opts->name, (char **)opts->subopts, index); + } + + /* + * Check for respecification of the option. This is more complex than it + * seems because some options are parsed twice - once as a string during + * input parsing, then later the string is passed to getnum for + * conversion into a number and bounds checking. Hence the two variables + * used to track the different uses based on the @str parameter passed + * to us. + */ + if (!str_seen) { + if (sp->seen) + respec(opts->name, (char **)opts->subopts, index); + sp->seen = true; + } else { + if (sp->str_seen) + respec(opts->name, (char **)opts->subopts, index); + sp->str_seen = true; + } + + /* check for conflicts with the option */ + for (i = 0; i < MAX_CONFLICTS; i++) { + int conflict_opt = sp->conflicts[i]; + + if (conflict_opt == LAST_CONFLICT) + break; + if (opts->subopt_params[conflict_opt].seen || + opts->subopt_params[conflict_opt].str_seen) + conflict(opts->name, (char **)opts->subopts, + conflict_opt, index); + } +} + +static long long +getnum( + const char *str, + struct opt_params *opts, + int index) +{ + struct subopt_param *sp = &opts->subopt_params[index]; + long long c; + + check_opt(opts, index, false); + set_conf_raw(opts->index, index, str); + /* empty strings might just return a default value */ + if (!str || *str == '\0') { + if (sp->flagval == SUBOPT_NEEDS_VAL) + reqval(opts->name, (char **)opts->subopts, index); + return sp->flagval; + } + + if (sp->minval == 0 && sp->maxval == 0) { + fprintf(stderr, + _("Option -%c %s has undefined minval/maxval." + "Can't verify value range. This is a bug.\n"), + opts->name, opts->subopts[index]); + exit(1); + } + + /* + * Some values are pure numbers, others can have suffixes that define + * the units of the number. Those get passed to cvtnum(), otherwise we + * convert it ourselves to guarantee there is no trailing garbage in the + * number. + */ + if (sp->convert) + c = cvtnum(blocksize, sectorsize, str); + else { + char *str_end; + + c = strtoll(str, &str_end, 0); + if (c == 0 && str_end == str) + illegal_option(str, opts, index, NULL); + if (*str_end != '\0') + illegal_option(str, opts, index, NULL); + } + + /* Validity check the result. */ + if (c < sp->minval) + illegal_option(str, opts, index, _("value is too small")); + else if (c > sp->maxval) + illegal_option(str, opts, index, _("value is too large")); + if (sp->is_power_2 && !ispow2(c)) + illegal_option(str, opts, index, _("value must be a power of 2")); + return c; +} + /* * Convert lsu to lsunit for 512 bytes blocks and check validity of the values. */ @@ -1285,124 +1403,6 @@ sb_set_features( } -static __attribute__((noreturn)) void -illegal_option( - const char *value, - struct opt_params *opts, - int index, - const char *reason) -{ - fprintf(stderr, - _("Illegal value %s for -%c %s option. %s\n"), - value, opts->name, opts->subopts[index], - reason ? reason : ""); - usage(); -} - -/* - * Check for conflicts and option respecification. - */ -static void -check_opt( - struct opt_params *opts, - int index, - bool str_seen) -{ - struct subopt_param *sp = &opts->subopt_params[index]; - int i; - - if (sp->index != index) { - fprintf(stderr, - ("Developer screwed up option parsing (%d/%d)! Please report!\n"), - sp->index, index); - reqval(opts->name, (char **)opts->subopts, index); - } - - /* - * Check for respecification of the option. This is more complex than it - * seems because some options are parsed twice - once as a string during - * input parsing, then later the string is passed to getnum for - * conversion into a number and bounds checking. Hence the two variables - * used to track the different uses based on the @str parameter passed - * to us. - */ - if (!str_seen) { - if (sp->seen) - respec(opts->name, (char **)opts->subopts, index); - sp->seen = true; - } else { - if (sp->str_seen) - respec(opts->name, (char **)opts->subopts, index); - sp->str_seen = true; - } - - /* check for conflicts with the option */ - for (i = 0; i < MAX_CONFLICTS; i++) { - int conflict_opt = sp->conflicts[i]; - - if (conflict_opt == LAST_CONFLICT) - break; - if (opts->subopt_params[conflict_opt].seen || - opts->subopt_params[conflict_opt].str_seen) - conflict(opts->name, (char **)opts->subopts, - conflict_opt, index); - } -} - -static long long -getnum( - const char *str, - struct opt_params *opts, - int index) -{ - struct subopt_param *sp = &opts->subopt_params[index]; - long long c; - - check_opt(opts, index, false); - set_conf_raw(opts->index, index, str); - /* empty strings might just return a default value */ - if (!str || *str == '\0') { - if (sp->flagval == SUBOPT_NEEDS_VAL) - reqval(opts->name, (char **)opts->subopts, index); - return sp->flagval; - } - - if (sp->minval == 0 && sp->maxval == 0) { - fprintf(stderr, - _("Option -%c %s has undefined minval/maxval." - "Can't verify value range. This is a bug.\n"), - opts->name, opts->subopts[index]); - exit(1); - } - - /* - * Some values are pure numbers, others can have suffixes that define - * the units of the number. Those get passed to cvtnum(), otherwise we - * convert it ourselves to guarantee there is no trailing garbage in the - * number. - */ - if (sp->convert) - c = cvtnum(blocksize, sectorsize, str); - else { - char *str_end; - - c = strtoll(str, &str_end, 0); - if (c == 0 && str_end == str) - illegal_option(str, opts, index, NULL); - if (*str_end != '\0') - illegal_option(str, opts, index, NULL); - } - - /* Validity check the result. */ - if (c < sp->minval) - illegal_option(str, opts, index, _("value is too small")); - else if (c > sp->maxval) - illegal_option(str, opts, index, _("value is too large")); - if (sp->is_power_2 && !ispow2(c)) - illegal_option(str, opts, index, _("value must be a power of 2")); - return c; -} - /* * Option is a string - do all the option table work, and check there * is actually an option string. Otherwise we don't do anything with the string