From patchwork Tue Sep 11 06:59:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146400 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3311756ljw; Tue, 11 Sep 2018 00:01:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbaDXGRezfWF8N8mciayCRR/TpOi7bm2wQBtKxVjWPDzKPUfJQNLv6WzHe8+7IH+eMWnMYZ X-Received: by 2002:a50:9943:: with SMTP id l3-v6mr26406821edb.198.1536649272260; Tue, 11 Sep 2018 00:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649272; cv=none; d=google.com; s=arc-20160816; b=vne9Cnef6IeumF1Cr5XsaDLMpz/KZuVU7bgmeJ0NCWQ8BDzvhKlyej1QJyX54dLz6k 45oCo3o9/YNWHc3z2AJi/5o06aw3BZFCzUZwKT7r011kbfnYZe4zya8Ysnwt1Vz82SbO t9UMTNLoej3V8ANcCYoCPOlGTGsylNbndVF+N+iITwKmw0DZ9mnPh+b7SBTr9dqk9oUA p0VoXHDwY9sW4OEvDKKYs62Vh9dB5z5C6FPXrqaDT2iC95tfkuEJi3B6WzDP3hiLoo5k 5wzS6sdiUxQSk4oyuOS0bHJ/gcr3StkXXyZqz9WZnJvBx6/7m6iMjrKnv064JjrOxhy2 43og== 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; bh=VXxDYRf2UDJuSUK4m4S9fEEL+ihrtraWxS+O6Onn/JY=; b=GEiNPMquLnPDYoYFL6eh5sy2Zar6C3C70bUZ0Y9Xmb2xelmLTkg0sYxX9hlA6tZiwX ebCvyxGZNIvToOpvVx9Kk9snNOTbPnQgKcL933vt93GKXjEckTrdHrQmRrUukoZgdguw gqSArYm5Wmp5tdALm6/EXe4g7SpeBxpPWGWJwnNUOsrRE07QCHwYAT6VqNC4AwIDMlDM sqYFM7YT5NQkbPS3ftYdM+JKrlW++8ktwA7iOZYVRNv7Wv5m7kYXMpTMJvgMuIzFDbTe C3YtTUP1O8RimrhWq4CfNZrUu4Ve607xq7fH9jaCjfkaH1XMRnc4+ekFi6iLt6rK082S xeYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ROv4dzdY; 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 m12-v6si2864168edl.377.2018.09.11.00.01.11; Tue, 11 Sep 2018 00:01:12 -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=ROv4dzdY; 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 746A5C21F0B; Tue, 11 Sep 2018 07:00:27 +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 92EEDC21E1E; Tue, 11 Sep 2018 06:59:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1DFECC21E79; Tue, 11 Sep 2018 06:59:24 +0000 (UTC) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by lists.denx.de (Postfix) with ESMTPS id 0166DC21EB4 for ; Tue, 11 Sep 2018 06:59:18 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id p5-v6so3420530plk.3 for ; Mon, 10 Sep 2018 23:59:18 -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=keiPZSLItt2usdSO0Pcw2aKM3colcSf8l+MbC4bYk7s=; b=ROv4dzdYlBTJlg4qK4jaTHz8kKWwyJHReIGF7uJV9x1F1ozXyxo+xE60SlPDczSBtd M2tR39nDfNQ/JgH8fkDL/iFHNOxIl5Rh8TYcnAzESF3doxjrl1yFikMD25gPFvE+xmgk ReJwBbhbNw0oaECSzn9yDrWGedNSRuXfgpFlQ= 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=keiPZSLItt2usdSO0Pcw2aKM3colcSf8l+MbC4bYk7s=; b=jMLMhrWuXSAVyfuU1K+BLlupsN3X7lW0hIcOtD895VsQQz5ZXirTbxFDwIGgl9jsXm xi1Q5H/j/1c/oIS+ZfZI6kuO+CIyZYVM4eyyMiyVPp9CZinALYG079m+0CONgGMbaL0S qZedh0Wnv7gq5qy0/Yy0BB5sNJBRZGHBYZRHDgwgm0r0uio2Ir6uIBtqxfjRyhWoRDMa g0C1sxh/FyJc6C8eF3JlmtX14veOBZlU92W+E+IV+e8nJUs1/eyVuIs1JrKmcBiYpF2/ ZF5x04VT9WWQbamSYVo/gyfHXXJ9oRE5YBxCiZDepwgsXVXLVDHx4Jn652TAgMq/G0m9 df4A== X-Gm-Message-State: APzg51BI3rvXo+7kHKeFOgeSlJwcOo9hwHdlJDQlXDe/l88wNSqp1FlK 9xJPLAlM3Cf+3uHolDUsVB2JDA== X-Received: by 2002:a17:902:722:: with SMTP id 31-v6mr25417554pli.207.1536649157445; Mon, 10 Sep 2018 23:59:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w12-v6sm27310589pfd.110.2018.09.10.23.59.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:16 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:00 +0900 Message-Id: <20180911065922.19141-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180911065922.19141-1-takahiro.akashi@linaro.org> References: <20180911065922.19141-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH v3 04/26] 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" From: AKASHI Takahiro 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 | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index eaea9300fd7f..afb8b3f9ef1a 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -641,6 +641,7 @@ static int get_fs_info(fsdata *mydata) 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 */ @@ -672,6 +673,7 @@ static 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; @@ -707,9 +709,11 @@ static 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; @@ -727,7 +731,7 @@ static 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); @@ -748,18 +752,19 @@ static 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; } } @@ -775,8 +780,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; @@ -937,6 +945,7 @@ static 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;