From patchwork Thu Sep 8 14:10:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9321477 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 25FFC607D3 for ; Thu, 8 Sep 2016 14:10:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15E40297EF for ; Thu, 8 Sep 2016 14:10:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A6D229833; Thu, 8 Sep 2016 14:10:24 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from oss.sgi.com (oss.sgi.com [192.48.182.195]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6DD13297EF for ; Thu, 8 Sep 2016 14:10:22 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id 44E967CA1; Thu, 8 Sep 2016 09:10:21 -0500 (CDT) X-Original-To: xfs@oss.sgi.com Delivered-To: xfs@oss.sgi.com Received: from relay.sgi.com (relay3.corp.sgi.com [198.149.34.15]) by oss.sgi.com (Postfix) with ESMTP id 0952B7CA0 for ; Thu, 8 Sep 2016 09:10:19 -0500 (CDT) Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by relay3.corp.sgi.com (Postfix) with ESMTP id 680A0AC002 for ; Thu, 8 Sep 2016 07:10:15 -0700 (PDT) X-ASG-Debug-ID: 1473343811-0bf57b15a82f9370001-NocioJ Received: from sandeen.net (sandeen.net [63.231.237.45]) by cuda.sgi.com with ESMTP id VD6NW2rCXFEuuehR for ; Thu, 08 Sep 2016 07:10:12 -0700 (PDT) X-Barracuda-Envelope-From: sandeen@sandeen.net X-Barracuda-Effective-Source-IP: sandeen.net[63.231.237.45] X-Barracuda-Apparent-Source-IP: 63.231.237.45 Received: from [10.0.0.4] (liberator [10.0.0.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id 93E8AEC2 for ; Thu, 8 Sep 2016 09:10:11 -0500 (CDT) Subject: [PATCH 1/2] libxfs: move iswritable "fatal" decision to caller To: xfs@oss.sgi.com X-ASG-Orig-Subj: [PATCH 1/2] libxfs: move iswritable "fatal" decision to caller References: From: Eric Sandeen Message-ID: <39fbb09c-698f-58cf-99d2-013726773bcb@sandeen.net> Date: Thu, 8 Sep 2016 09:10:11 -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: X-Barracuda-Connect: sandeen.net[63.231.237.45] X-Barracuda-Start-Time: 1473343812 X-Barracuda-URL: https://192.48.176.25:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4590 X-Virus-Scanned: by bsmtpd at sgi.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.7 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.32721 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: xfs@oss.sgi.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: XFS Filesystem from SGI List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: xfs-bounces@oss.sgi.com Sender: xfs-bounces@oss.sgi.com X-Virus-Scanned: ClamAV using ClamSMTP Simplify platform_check_iswritable by moving the "fatal" decision up to the (one) caller. In other words, simply return whether mounted+writable is true, and return 1 if so. Caller decides what to do with that info based on /its/ "fatal" argument. Signed-off-by: Eric Sandeen diff --git a/libxfs/darwin.c b/libxfs/darwin.c index 017e190..19d2ab6 100644 --- a/libxfs/darwin.c +++ b/libxfs/darwin.c @@ -33,7 +33,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose) } int -platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) +platform_check_iswritable(char *name, char *block, struct stat64 *s) { int fd, writable; diff --git a/libxfs/freebsd.c b/libxfs/freebsd.c index 6c9f089..9e22183 100644 --- a/libxfs/freebsd.c +++ b/libxfs/freebsd.c @@ -66,7 +66,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose) } int -platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) +platform_check_iswritable(char *name, char *block, struct stat64 *s) { int cnt, i; struct statfs *fsinfo; @@ -74,7 +74,7 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) { fprintf(stderr, _("%s: %s contains a possibly writable, " "mounted filesystem\n"), progname, name); - return fatal; + return 1; } for (i = 0; i < cnt; i++) { @@ -88,7 +88,7 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) if (i == cnt) { fprintf(stderr, _("%s: %s contains a mounted and writable " "filesystem\n"), progname, name); - return fatal; + return 1; } return 0; } diff --git a/libxfs/init.c b/libxfs/init.c index c13b123..828ae3e 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -75,7 +75,9 @@ check_isactive(char *name, char *block, int fatal) return 0; if (platform_check_ismounted(name, block, &st, 0) == 0) return 0; - return platform_check_iswritable(name, block, &st, fatal); + if (platform_check_iswritable(name, block, &st)) + return fatal ? 1 : 0; + return 0; } /* libxfs_device_to_fd: diff --git a/libxfs/init.h b/libxfs/init.h index 112febb..4dda3ee 100644 --- a/libxfs/init.h +++ b/libxfs/init.h @@ -22,8 +22,7 @@ struct stat64; extern int platform_check_ismounted (char *path, char *block, struct stat64 *sptr, int verbose); -extern int platform_check_iswritable (char *path, char *block, - struct stat64 *sptr, int fatal); +extern int platform_check_iswritable (char *path, char *block, struct stat64 *sptr); extern int platform_set_blocksize (int fd, char *path, dev_t device, int bsz, int fatal); extern void platform_flush_device (int fd, dev_t device); extern char *platform_findrawpath(char *path); diff --git a/libxfs/irix.c b/libxfs/irix.c index 65aaa7e..c23ebe0 100644 --- a/libxfs/irix.c +++ b/libxfs/irix.c @@ -31,7 +31,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose) } int -platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) +platform_check_iswritable(char *name, char *block, struct stat64 *s) { return 1; } diff --git a/libxfs/linux.c b/libxfs/linux.c index c9f2baf..67b615b 100644 --- a/libxfs/linux.c +++ b/libxfs/linux.c @@ -74,9 +74,8 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose) } int -platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) +platform_check_iswritable(char *name, char *block, struct stat64 *s) { - int sts = 0; FILE *f; struct stat64 mst; struct mntent *mnt; @@ -86,7 +85,7 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) if ((f = setmntent(mounts, "r")) == NULL) { fprintf(stderr, _("%s: %s contains a possibly writable, " "mounted filesystem\n"), progname, name); - return fatal; + return 1; } while ((mnt = getmntent(f)) != NULL) { if (stat64(mnt->mnt_fsname, &mst) < 0) @@ -97,13 +96,14 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) && hasmntopt(mnt, MNTOPT_RO) != NULL) break; } + endmntent(f); + if (mnt == NULL) { fprintf(stderr, _("%s: %s contains a mounted and writable " "filesystem\n"), progname, name); - sts = fatal; + return 1; } - endmntent(f); - return sts; + return 0; } int