From patchwork Thu Dec 14 06:47:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10111557 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 130B2602C2 for ; Thu, 14 Dec 2017 06:42:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0180429B0B for ; Thu, 14 Dec 2017 06:42:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA91F29B44; Thu, 14 Dec 2017 06:42:07 +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 8AEF429B0B for ; Thu, 14 Dec 2017 06:42:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751459AbdLNGmH (ORCPT ); Thu, 14 Dec 2017 01:42:07 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11984 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbdLNGmC (ORCPT ); Thu, 14 Dec 2017 01:42:02 -0500 Received: from 172.30.72.60 (EHLO DGGEMS414-HUB.china.huawei.com) ([172.30.72.60]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DMD34184; Thu, 14 Dec 2017 14:41:50 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Thu, 14 Dec 2017 14:41:39 +0800 From: "zhangyi (F)" To: , CC: , , , , , Subject: [PATCH v2 05/18] fsck.overlay: convert path parse to use helper function Date: Thu, 14 Dec 2017 14:47:34 +0800 Message-ID: <20171214064747.20999-6-yi.zhang@huawei.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171214064747.20999-1-yi.zhang@huawei.com> References: <20171214064747.20999-1-yi.zhang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.5A321D2E.004E, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 8fda7f533b872bcedd4efdb4a67916b0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: zhangyi (F) --- check.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/check.c b/check.c index 1794501..add7e11 100644 --- a/check.c +++ b/check.c @@ -113,9 +113,13 @@ static int ovl_get_redirect(const char *pathname, size_t dirlen, buf = srealloc(buf, ret + baselen + 1); memmove(buf + baselen, buf, ret); memcpy(buf, pathname+dirlen, baselen); - buf[ret + baselen] = '\0'; + ret += baselen; } + ret -= 1; + memmove(buf, buf+1, ret); + buf[ret] = '\0'; + *redirect = buf; return 0; } @@ -143,7 +147,7 @@ static inline int ovl_create_whiteout(const char *pathname) * skip: skip whiteout. * */ -static int ovl_check_lower(const char *path, unsigned int start, +static int ovl_check_lower(const char *pathname, unsigned int start, struct ovl_lower_check *chk, bool skip) { char lower_path[PATH_MAX]; @@ -151,7 +155,7 @@ static int ovl_check_lower(const char *path, unsigned int start, unsigned int i; for (i = start; i < lower_num; i++) { - snprintf(lower_path, sizeof(lower_path), "%s%s", lowerdir[i], path); + path_pack(lower_path, sizeof(lower_path), lowerdir[i], pathname); if (lstat(lower_path, &st) != 0) { if (errno != ENOENT && errno != ENOTDIR) { @@ -165,9 +169,10 @@ static int ovl_check_lower(const char *path, unsigned int start, if (skip && is_whiteout(&st)) continue; + strncpy(chk->path, lower_path, sizeof(chk->path)); chk->exist = true; chk->st = st; - strncpy(chk->path, lower_path, sizeof(chk->path)); + break; } @@ -200,7 +205,8 @@ static int ovl_check_whiteout(struct scan_ctx *sctx) * check is there a file or dir with the same name. */ start = (sctx->dirtype == OVL_LOWER) ? sctx->num + 1 : 0; - ret = ovl_check_lower(pathname + sctx->dirlen, start, &chk, true); + ret = ovl_check_lower(path_pick(pathname, sctx->dirlen), + start, &chk, true); if (ret) return ret; if (chk.exist && !is_whiteout(&chk.st)) @@ -234,7 +240,7 @@ out: static int ovl_check_opaque(struct scan_ctx *sctx) { const char *pathname = sctx->pathname; - char parent_path[PATH_MAX]; + char parent[PATH_MAX]; struct ovl_lower_check chk = {0}; unsigned int start; int ret = 0; @@ -252,15 +258,17 @@ static int ovl_check_opaque(struct scan_ctx *sctx) * check if there is a file or dir with the same name. */ start = (sctx->dirtype == OVL_LOWER) ? sctx->num + 1 : 0; - ret = ovl_check_lower(pathname + sctx->dirlen, start, &chk, true); + ret = ovl_check_lower(path_pick(pathname, sctx->dirlen), + start, &chk, true); if (ret) return ret; if (chk.exist && !is_whiteout(&chk.st)) goto out; /* Check parent directory merged or pure */ - memcpy(parent_path, pathname, sctx->pathlen-sctx->filelen); - ret = ovl_check_lower(parent_path + sctx->dirlen, start, &chk, false); + path_truncate(parent, sizeof(parent), pathname, sctx->filename); + ret = ovl_check_lower(path_pick(parent, sctx->dirlen), + start, &chk, false); if (ret) return ret; if (chk.exist && is_dir(&chk.st)) @@ -396,8 +404,8 @@ static int ovl_check_redirect(struct scan_ctx *sctx) sctx->num, chk.path); /* Check and fix whiteout or opaque dir */ - snprintf(redirect_rpath, sizeof(redirect_rpath), "%s%s", - sctx->dirname, redirect); + path_pack(redirect_rpath, sizeof(redirect_rpath), + sctx->dirname, redirect); if (lstat(redirect_rpath, &rst) != 0) { if (errno != ENOENT && errno != ENOTDIR) { print_err(_("Cannot stat %s: %s\n"),