From patchwork Fri Sep 30 20:54:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9485647 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,HEADER_FROM_DIFFERENT_DOMAINS=0.001, RP_MATCHES_RCVD=-0.1 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id EE3C01431 for ; Fri, 30 Sep 2016 15:53:50 -0500 (CDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751668AbcI3UyW (ORCPT ); Fri, 30 Sep 2016 16:54:22 -0400 Received: from sandeen.net ([63.231.237.45]:57156 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751321AbcI3UyW (ORCPT ); Fri, 30 Sep 2016 16:54:22 -0400 Received: from Liberator.example.com (74-95-67-117-Minnesota.hfc.comcastbusiness.net [74.95.67.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id 3A7D01431; Fri, 30 Sep 2016 15:53:49 -0500 (CDT) Subject: [PATCH 3/5] xfs_io: move inode command arg handling to top To: Eric Sandeen , linux-xfs References: <9f126dc7-3b1e-a1ed-7f23-48410a76adc2@redhat.com> From: Eric Sandeen Message-ID: <796ceb5c-bd7c-61b3-2c1c-031b2a41db34@sandeen.net> Date: Fri, 30 Sep 2016 15:54:21 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <9f126dc7-3b1e-a1ed-7f23-48410a76adc2@redhat.com> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org As it stands, collecting the inode number and testing args validity is all tangled up; for example the test for "-n" having no inode is buried in an else after a large code block which handles something else. Get inode number argument collection and testing out of the way before doing anything else. Clean up the error message if a non-numeric inode arg is given. Signed-off-by: Eric Sandeen --- io/open.c | 40 +++++++++++++++++++++------------------- 1 files changed, 21 insertions(+), 19 deletions(-) diff --git a/io/open.c b/io/open.c index c8c82b7..ba8b243 100644 --- a/io/open.c +++ b/io/open.c @@ -813,7 +813,7 @@ inode_f( { __s32 count = 0; __u64 lastino = 0; - __u64 userino = 0; + __u64 userino = NULLFSINO; char *p; int c; int verbose = 0; @@ -835,27 +835,32 @@ inode_f( } } - /* - * Inode number can be passed with or without extra arguments, so we - * should handle inode numbers passed by user out of getopt() - */ + /* Last arg (if present) should be an inode number */ if (optind < argc) { - - if (ret_next) { - cmd = XFS_IOC_FSBULKSTAT; - } else { - if ((argc > 2) && !verbose) - return command_usage(&inode_cmd); - else - cmd = XFS_IOC_FSBULKSTAT_SINGLE; - } - userino = strtoull(argv[optind], &p, 10); if ((*p != '\0')) { - printf(_("[num] must be a numeric value\n")); + printf(_("%s is not a numeric inode value\n"), + argv[optind]); exitcode = 1; return 0; } + optind++; + } + + /* Extra junk? */ + if (optind < argc) + return command_usage(&inode_cmd); + + /* -n option requires an inode number */ + if (ret_next && userino == NULLFSINO) + return command_usage(&inode_cmd); + + if (userino != NULLFSINO) { + + if (ret_next) /* get next inode */ + cmd = XFS_IOC_FSBULKSTAT; + else /* get this inode */ + cmd = XFS_IOC_FSBULKSTAT_SINGLE; bulkreq.lastip = &userino; bulkreq.icount = 1; @@ -885,9 +890,6 @@ inode_f( printf("%llu\n", userino); return 0; - /* -n option must not be used stand alone */ - } else if (ret_next) { - return command_usage(&inode_cmd); } /* We are finding last inode in use */