From patchwork Mon Sep 19 22:08:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9340725 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 7B616607D0 for ; Mon, 19 Sep 2016 22:08:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59C6629200 for ; Mon, 19 Sep 2016 22:08:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C775299C7; Mon, 19 Sep 2016 22:08:38 +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 4BA0229200 for ; Mon, 19 Sep 2016 22:08:34 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id A7F337CA3; Mon, 19 Sep 2016 17:08:33 -0500 (CDT) X-Original-To: xfs@oss.sgi.com Delivered-To: xfs@oss.sgi.com Received: from relay.sgi.com (relay2.corp.sgi.com [137.38.102.29]) by oss.sgi.com (Postfix) with ESMTP id 395857CA2 for ; Mon, 19 Sep 2016 17:08:31 -0500 (CDT) Received: from cuda.sgi.com (cuda3.sgi.com [192.48.176.15]) by relay2.corp.sgi.com (Postfix) with ESMTP id 0B03A304043 for ; Mon, 19 Sep 2016 15:08:27 -0700 (PDT) X-ASG-Debug-ID: 1474322905-0bf57c67711aa70001-NocioJ Received: from sandeen.net (sandeen.net [63.231.237.45]) by cuda.sgi.com with ESMTP id pqAjuDlfDFHVc15D for ; Mon, 19 Sep 2016 15:08:25 -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 312D7474BA0; Mon, 19 Sep 2016 17:08:09 -0500 (CDT) Subject: [PATCH 1/2] libxfs: move iswritable "fatal" decision to caller To: xfs-oss , linux-xfs@vger.kernel.org X-ASG-Orig-Subj: [PATCH 1/2] libxfs: move iswritable "fatal" decision to caller References: From: Eric Sandeen Message-ID: <62f0019d-c2fb-bda8-8549-a6985d4be6a4@sandeen.net> Date: Mon, 19 Sep 2016 17:08:24 -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: 1474322905 X-Barracuda-URL: https://192.48.176.15:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4606 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.33045 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 --- V2: Rebase 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 44bc1f9..2b67d1a 100644 --- a/libxfs/linux.c +++ b/libxfs/linux.c @@ -85,9 +85,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; @@ -97,7 +96,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) @@ -108,13 +107,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