From patchwork Fri Jul 20 02:57:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142410 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2436330ljj; Thu, 19 Jul 2018 19:58:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcEBgEQRqerd2GyjHp61e5WDvP1eXR9XPhCqFPineukOFugNkOZA+zPv34wT0rPxQ8QVjNi X-Received: by 2002:a50:8be8:: with SMTP id n37-v6mr490247edn.216.1532055504502; Thu, 19 Jul 2018 19:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055504; cv=none; d=google.com; s=arc-20160816; b=hMu2csohC+FLMVB4TtwcOU4dkCuXFpQMlgw6a/dhBMRUqFnn0sq72Vaw6osXrcjD+Z uJ76HcS+yjCtTYQHMblf4UfG/6tAefQLtMuxKXTOQO/JBMaJWDXt0dJVk2Ohif4Twd/y KkuFsAHB1/zy10P5U3f4LRWgr+IBfUOA7vaF8UfbuW8bm9wMS994+Dg0ZdM+yitwqZEQ roWcmO7MEJVJtZeCqvXkmV5GeotuFSTz5ClTFZCz1PZkvCK799B7q5rsuZVRErRzE5VZ 3tDcE0QQ4UfZxTcO/kymTy6+AP2cQWlg8Ha3Ozkx30MwpCc7Nhhv/o8rSl+Q4yrC2cKA 4udw== 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=+UzCazrtQoPHZ+PrwynK67nMR48wW209EPlVe1A1eLA=; b=W6AXOX3DzleCnQmq5a2yqKFnwIRsoH13ckshY1HvDFHwDjMxLUmKTma76wRGMXOyh4 eMmbwC1qAb3WFUFGjBAaJXZdpb7L1F8QRLVkdjO2qAKeSgdAWjZCHZQxZZf5NYmHVCGL xrjgXxy20qnSTL1qYvg3PuZPOf5ybDlVdOL88owJRf3XJZNaM8jhXm1Jd9OyoBMA1cOG xeuJjqInraYyFRNKwYM3Q9Ws+So392bCtn3TW4CAN4rBmnGg7qUWogiOufi8qHL/483/ Hz/HdBOP7llYmk/UNCGqDUarnAbLDaleuQoYj45wJ7vwT4tevDNf+qrw55ItAAETjj/4 Npkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XmK6hHGq; 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 n14-v6si694528edq.198.2018.07.19.19.58.24; Thu, 19 Jul 2018 19:58:24 -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=XmK6hHGq; 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 F150EC21C4A; Fri, 20 Jul 2018 02:57:30 +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=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 5C477C21DED; Fri, 20 Jul 2018 02:57:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6528DC21D74; Fri, 20 Jul 2018 02:57:12 +0000 (UTC) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lists.denx.de (Postfix) with ESMTPS id 90AB2C21E1B for ; Fri, 20 Jul 2018 02:57:08 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id y4-v6so5500032pgp.9 for ; Thu, 19 Jul 2018 19:57:08 -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=AflR2hL6TKDn+EZgEb8Y89lODSYrzM80W2mn/VncO7I=; b=XmK6hHGqFmgsLkxWc5YEWyWRYWiRioslD4ZZs1VpukeC5Dj6ue/tUleVtNa6n8lJyY QPrB0xtX/qhrO72Kfg4FUjACUsf4V+qeaE6VJaelxhQuHVzwUOq/yyCtBAyhZNKLz2RR LdVDSHww7kTMfhSF2Afc8mWan1Y7e/58reIA4= 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=AflR2hL6TKDn+EZgEb8Y89lODSYrzM80W2mn/VncO7I=; b=Cx902so2Nr3bteg5KGxcfu2kzeP92u3HObuoXcBpElK33EfAV6UEQ3SfWgq6fhQNj0 bEw02OFtPPJG9vgcf2Ekcc8VU74qPwYYsecQ59UPGSq42ou9nlF3x3siXje+cHSwoEq6 4nZjzoqYhIHYS+NkhCUV4K28ZvUp5AnZWJoRMkj128EOf6aEy4AnBlQ2YW/ZlQBCZOtJ SuG2Y6LDWkLagkIxsQZXpE/HWg+ypzrKd92i1/BMZZ0MCLxpGC7YM4NPeopSqf+9e2h/ DFYv6gGvDBIcL4VOwXm8wAB0ZnmLr8iJBgo0nef8d+PH22FzLMILsUiGLOC5uDrPW5H/ emzw== X-Gm-Message-State: AOUpUlEwgVjHIZtBzDxjJ3butUdAdwSjnqPIRxWvYPhaM0I/9s+hy26T aX8D+ddhsWvH/ONmJqWQYOEiFQ== X-Received: by 2002:aa7:8591:: with SMTP id w17-v6mr297241pfn.77.1532055427242; Thu, 19 Jul 2018 19:57:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j191-v6sm695153pfc.136.2018.07.19.19.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:06 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:10 +0900 Message-Id: <20180720025723.6736-5-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 04/17] fs: fat: assure iterator's ->dent belongs to ->clust 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" In my attempt to re-work write operation, it was revealed that iterator's "clust" does not always point to a cluster to which a current directory entry ("dent") belongs. This patch assures that it is always true by adding "next_clust" which is used solely for dereferencing a cluster chain. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 24 ++++++++++++++++-------- include/fat.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 0f82cbe1bd..d9bfb08d97 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -649,6 +649,7 @@ int fat_itr_root(fat_itr *itr, fsdata *fsdata) itr->fsdata = fsdata; itr->clust = fsdata->root_cluster; + itr->next_clust = fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; @@ -684,9 +685,11 @@ void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->fsdata = parent->fsdata; if (clustnum > 0) { itr->clust = clustnum; + itr->next_clust = clustnum; itr->is_root = 0; } else { itr->clust = parent->fsdata->root_cluster; + itr->next_clust = parent->fsdata->root_cluster; itr->is_root = 1; } itr->dent = NULL; @@ -704,7 +707,7 @@ void *next_cluster(fat_itr *itr) if (itr->last_cluster) return NULL; - sect = clust_to_sect(itr->fsdata, itr->clust); + sect = clust_to_sect(itr->fsdata, itr->next_clust); debug("FAT read(sect=%d), clust_size=%d, DIRENTSPERBLOCK=%zd\n", sect, itr->fsdata->clust_size, DIRENTSPERBLOCK); @@ -725,18 +728,19 @@ void *next_cluster(fat_itr *itr) return NULL; } + itr->clust = itr->next_clust; if (itr->is_root && itr->fsdata->fatsize != 32) { - itr->clust++; - sect = clust_to_sect(itr->fsdata, itr->clust); + itr->next_clust++; + sect = clust_to_sect(itr->fsdata, itr->next_clust); if (sect - itr->fsdata->rootdir_sect >= itr->fsdata->rootdir_size) { - debug("cursect: 0x%x\n", itr->clust); + debug("nextclust: 0x%x\n", itr->next_clust); itr->last_cluster = 1; } } else { - itr->clust = get_fatent(itr->fsdata, itr->clust); - if (CHECK_CLUST(itr->clust, itr->fsdata->fatsize)) { - debug("cursect: 0x%x\n", itr->clust); + itr->next_clust = get_fatent(itr->fsdata, itr->next_clust); + if (CHECK_CLUST(itr->next_clust, itr->fsdata->fatsize)) { + debug("nextclust: 0x%x\n", itr->next_clust); itr->last_cluster = 1; } } @@ -752,8 +756,11 @@ static dir_entry *next_dent(fat_itr *itr) itr->fsdata->clust_size; /* have we reached the last cluster? */ - if (!dent) + if (!dent) { + /* a sign for no more entries left */ + itr->dent = NULL; return NULL; + } itr->remaining = nbytes / sizeof(dir_entry) - 1; itr->dent = dent; @@ -906,6 +913,7 @@ int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) (((next - path) == 2) && !strncmp(path, "..", 2))) { /* point back to itself */ itr->clust = itr->fsdata->root_cluster; + itr->next_clust = itr->fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; diff --git a/include/fat.h b/include/fat.h index 577e6b4592..bc0f77abb5 100644 --- a/include/fat.h +++ b/include/fat.h @@ -198,6 +198,7 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) typedef struct { fsdata *fsdata; /* filesystem parameters */ unsigned clust; /* current cluster */ + unsigned next_clust; /* next cluster if remaining == 0 */ int last_cluster; /* set once we've read last cluster */ int is_root; /* is iterator at root directory */ int remaining; /* remaining dent's in current cluster */