From patchwork Tue Sep 4 07:49:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145853 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3363464ljw; Tue, 4 Sep 2018 00:51:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZIs6C0PLUUqXTHqJMZ611nNbyPxKYjAIbek9p1ZhDw6Me75Cu12Vg4viYtwtAjKNEDn4Cd X-Received: by 2002:a50:bf0d:: with SMTP id f13-v6mr35818109edk.157.1536047488774; Tue, 04 Sep 2018 00:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047488; cv=none; d=google.com; s=arc-20160816; b=pit6gsbkkUdf5u2icg3AbXDF37BGMvClRf2sIHTaScHKZpBwR/PYL3N4IBO9lAKA5P gpIaiEshGwyA26y1UlWAzsv132hHxHEPjVk8uZu+On3KCIMXHSMiZE0OHpqjcIEaMLaI QqDeakUR7pEDTtlriR1GKx3/eBzV+UfXJ9wMLghUqsZth+wqIQeXpAnOIjxB9VGqD3WI ShzgWazmEhS++Ldx7Co/TE0GNhubFNh9hgZNRR18CNSucFm623spjUdG+b5/4Qdin/37 oDmzH6K1xTZ6rw5j4cXV5AXrtlSENC8fzbW/0kLP8eY9WzQykPFT6qVe5BtuDLw0KS9G pv4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=UjCjUbNIC7BvJhbxggVu4pNJuVle7DnrTmTsil27Gx4=; b=eYYTvbzn01I8Xv3cqlbdgDxBS1h6/uy6573sPdMT3ucgRqYii8A3Ygq1xD4skfJ5Fr nLiciCzFOtGey89dPBVgdM4Tcm8/C+BJb/hV+kwzWpeJMtaN2SzZ+4l2gc1RgK7Z7iEX P9CAMdnT6YFn7sNTBD63A0LvIT4i60RawLFv2jj969AeCZWb3eE5CEDmPgLxgCaNc42l etdM2YPkTGR2f+5QudX1XoBJT6wpUdGS/5chjU7HdOQ5VVGavtFueood6uhQI8RUZir9 y8Qv7yiLbJUvYwScgSfv/kaIxSYsK/IhocGhDdlmIdpG8sq2b5C/0i3LhJRh8DjcS56T x4cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ddls1zua; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id f17-v6si30824edq.89.2018.09.04.00.51.28; Tue, 04 Sep 2018 00:51:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ddls1zua; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 3D5F3C21F05; Tue, 4 Sep 2018 07:50:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 54695C21EE8; Tue, 4 Sep 2018 07:50:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 90250C21EC8; Tue, 4 Sep 2018 07:50:22 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id AF578C21F34 for ; Tue, 4 Sep 2018 07:50:17 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id x26-v6so1234961pge.12 for ; Tue, 04 Sep 2018 00:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U+cSG0JMd3XVUOKmfaA+19W2ms/NtV5geclg5/GnRdc=; b=Ddls1zuamcWBOEVnz20WomZoKH13HxhvBnbQ03ArkssaQlglxGRPCBJwkK8g4oBlpM z9oLD5XNJ1UWiO9sCkXykd+GRldQZdwjxamVs5i4DoySS4QpHQvWTdXuzLs7RbaB3YX3 g5fkZrMPs4LX4fSNAGkRB5uUJnJBy60IoB+iE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U+cSG0JMd3XVUOKmfaA+19W2ms/NtV5geclg5/GnRdc=; b=kNyyuQkgOlSjpCS4NNfFCevmisGknbJTUdDk9S32FdMqPOWZepHu3XtDOXy20JK6+k 034QDVjMpJHoG53J+kRzlodiOhwpykMs7ezT7xq2LMDAOrE5f0BhbFeK2MtuQqUKM4S4 jqo0/slDXBU9lvxV+KLZFew3lOUCkev795f/AyGZbSDdCRihdMA4h0PgFME/f+lQ7cJB Fw48M3qBQm0E8kTe7vMb/gBmaqMWsgUdr8gPc/EImrWNHrJnINIqgYB7nTNlPQdKLlUt bTgjCO7QF+mrUVOGy8JnEl879PHR6Fre54b9hqzC23IhLh9ZVCLZfw3CYmjK/M3//Ntf UvkQ== X-Gm-Message-State: APzg51Aqpj0I4cbgVS8aMVqJAU67z3GFqPCdth81mIirYLjPNV19ffKI sPLzDTkOd3s3GYB+tywODrMgSw== X-Received: by 2002:a63:d518:: with SMTP id c24-v6mr28787442pgg.357.1536047416381; Tue, 04 Sep 2018 00:50:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e190-v6sm46295120pfc.81.2018.09.04.00.50.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:15 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:28 +0900 Message-Id: <20180904074948.18146-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 03/23] fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" FAT's root directory does not have "." nor ".." So care must be taken when scanning root directory with fat_itr_resolve(). Without this patch, any file path starting with "." or ".." will not be resolved at all. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 0576658dde09..eaea9300fd7f 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -931,6 +931,27 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) while (next[0] && !ISDIRDELIM(next[0])) next++; + if (itr->is_root) { + /* root dir doesn't have "." nor ".." */ + if ((((next - path) == 1) && !strncmp(path, ".", 1)) || + (((next - path) == 2) && !strncmp(path, "..", 2))) { + /* point back to itself */ + itr->clust = itr->fsdata->root_cluster; + itr->dent = NULL; + itr->remaining = 0; + itr->last_cluster = 0; + + if (next[0] == 0) { + if (type & TYPE_DIR) + return 0; + else + return -ENOENT; + } + + return fat_itr_resolve(itr, next, type); + } + } + while (fat_itr_next(itr)) { int match = 0; unsigned n = max(strlen(itr->name), (size_t)(next - path));