From patchwork Sun May 31 02:26:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hua Shao X-Patchwork-Id: 478548 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DDA71140F91 for ; Sun, 31 May 2015 12:27:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.b=WRxaEoEi; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 9B205280BEB; Sun, 31 May 2015 04:25:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 47971280950 for ; Sun, 31 May 2015 04:25:25 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .163. - helo: .m12-12.163. - helo-domain: .163.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by arrakis.dune.hu (Postfix) with ESMTP for ; Sun, 31 May 2015 04:25:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=T2ALq7DCgzP0wpNpLb +e4LkxKAxDtgjSK0MU3LyLjUc=; b=WRxaEoEibGhw6HslHYhFhqPNmj4xCSpY8d qjoBRuDlvYiyMLuuaA0/RybSmsW9NkpG7iOw1EBui7wiE5voH+GYjgPyv+nwk49F g2QG0elSIQQihAbH7jWiwRHkIMoa6Xs9grZEfpooCAa/i0o03xxQVWCqtqYzBtb9 fAY1fAFDc= Received: from localhost (unknown [171.213.63.131]) by smtp8 (Coremail) with SMTP id DMCowEBpXExncWpV9mfnBA--.1239S2; Sun, 31 May 2015 10:26:49 +0800 (CST) From: Hua Shao To: nbd@openwrt.org Date: Sun, 31 May 2015 10:26:47 +0800 Message-Id: <1433039207-14268-1-git-send-email-nossiac@163.com> X-Mailer: git-send-email 1.8.3.1 X-CM-TRANSID: DMCowEBpXExncWpV9mfnBA--.1239S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr43CF4DXw1rAw4fKr47twb_yoW8ZFyDpF s3GFyavFWkXrW2gFnxJa15XF1rAayrK3WUAr1xW3yxtw1fXrnI9ayFqF4fKF43tFy0kayS vFy3JF4q9w48trJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UVWlPUUUUU= X-Originating-IP: [171.213.63.131] X-CM-SenderInfo: 5qrv2xldf6il2tof0z/xtbBRwoLaVO-ubx4cAAAsO Cc: openwrt-devel@lists.openwrt.org, Hua Shao Subject: [OpenWrt-Devel] [PATCH] block: support to mount read-only devices X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" A read-only device will fail to mount without MS_RDONLY flag. Signed-off-by: Hua Shao --- block.c | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index 4c8dda9..a3c0ea5 100644 --- a/block.c +++ b/block.c @@ -734,11 +734,24 @@ static int mount_device(struct blkid_struct_probe *pr, int hotplug) err = mount(pr->dev, target, pr->id->name, m->flags, (m->options) ? (m->options) : ("")); - if (err) - ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n", - pr->dev, pr->id->name, target, err, strerror(err)); - else - handle_swapfiles(true); + while (1) { + err = mount(pr->dev, target, pr->id->name, mflags, + (m->options) ? (m->options) : ("")); + if (err) { + if (!(mflags & MS_RDONLY)) { + ERROR("fall back on RO mount. %s.\n", strerror(errno)); + mflags |= MS_RDONLY; + continue; + } else { + ERROR("mounting %s (%s) as %s failed (%d) - %s\n", + pr->dev, pr->id->name, target, err, strerror(errno)); + break; + } + } else { + handle_swapfiles(true); + break; + } + } return err; } @@ -752,12 +765,26 @@ static int mount_device(struct blkid_struct_probe *pr, int hotplug) if (check_fs) check_filesystem(pr); - err = mount(pr->dev, target, pr->id->name, 0, ""); - if (err) - ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n", - pr->dev, pr->id->name, target, err, strerror(err)); - else - handle_swapfiles(true); + err = mount(pr->dev, target, pr->id->name, m->flags, + (m->options) ? (m->options) : ("")); + while (1) { + err = mount(pr->dev, target, pr->id->name, mflags, + (m->options) ? (m->options) : ("")); + if (err) { + if (!(mflags & MS_RDONLY)) { + ERROR("fall back on RO mount. %s.\n", strerror(errno)); + mflags |= MS_RDONLY; + continue; + } else { + ERROR("mounting %s (%s) as %s failed (%d) - %s\n", + pr->dev, pr->id->name, target, err, strerror(errno)); + break; + } + } else { + handle_swapfiles(true); + break; + } + } return err; }