From patchwork Fri Jul 20 02:57:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 946690 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="M11GzLof"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41WwY64lglz9s4V for ; Fri, 20 Jul 2018 12:57:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 44D9EC21D74; Fri, 20 Jul 2018 02:57:13 +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_H2, 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 6BE30C21E26; Fri, 20 Jul 2018 02:56:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 26127C21E07; Fri, 20 Jul 2018 02:56:53 +0000 (UTC) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by lists.denx.de (Postfix) with ESMTPS id 80415C21E02 for ; Fri, 20 Jul 2018 02:56:52 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id r1-v6so5503059pgp.11 for ; Thu, 19 Jul 2018 19:56:52 -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=08IvreLHSrgS9LZ/K9Zw3LEmGXjsS+QfeRN8njFFcg4=; b=M11GzLofH23W8kHcBM4yE/38ndQS9V97fgl72cOG6eII30ONubZ51/XgLxkduB4bnP xbJx7KFso2qSbqaJMkbL8pYmDLAFLv0Oek4geu+UyZVSTo0iEs6nIqHCACAkjsjPQh5d wU+5NK3rDXrsbcxStylzCHnt99D2dq5hVIs+w= 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=08IvreLHSrgS9LZ/K9Zw3LEmGXjsS+QfeRN8njFFcg4=; b=aHl6RY6OmNvESt2A6j5hXXV9ARyrpUnEPd59nhSt+hg5sdLTfDV+qoPtJX37xMFEs3 GgHMMT29zdajOGIyeQBDz1S/phikpcGG13NkveP9ieu36HNAbMxQCvTd9ZoX0B46P44T 2aQHrNZbwQVZ3VAQ0qLdPtKa/PIDeZgHgE0wq1BTGYet/Nr/a2THtOl2qtIcg1ujHwyw X4L65Q0+blhHY74KxrWjqwZw8z9dZ7aWi/Fcbq1wLmwtKbCu8YiMKhZ9D8ROlg1zQ0Pg l34bcsbI3jZqHDWvquFSeUZQmBFUKWFTcM52dSUPndRdxCgAUNMxzeCpzDl4Lx/b5S+x bjKA== X-Gm-Message-State: AOUpUlGd71uvkU3h+FqHEet6t8GjOIBqxD5ERl1XKTooupg5SEjcca4e XH4NfOI+No6zMRRF9M9FO6/REw== X-Google-Smtp-Source: AAOMgpe7NWQqyMNfKrWXy8lCQ+z32ZagxUsHGOWbiDMtF5j1VSt4Qw+NpeZfIyAo2oqulJcNKbtYVg== X-Received: by 2002:a63:1b5c:: with SMTP id b28-v6mr308489pgm.204.1532055411247; Thu, 19 Jul 2018 19:56:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d132-v6sm616819pgc.93.2018.07.19.19.56.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:56:50 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:08 +0900 Message-Id: <20180720025723.6736-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180720025723.6736-1-takahiro.akashi@linaro.org> References: <20180720025723.6736-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH 02/17] 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 b48f48a751..fd6523c66b 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -927,6 +927,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));