From patchwork Tue Sep 4 07:49:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145855 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3363967ljw; Tue, 4 Sep 2018 00:52:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbleeJxqfQ9pRkY8q188UhKrtfl2sZeFHnpK7USC7fZ3EiI65molkft2DGFNbuuB0F6Aegh X-Received: by 2002:a50:8ee4:: with SMTP id x33-v6mr35020546edx.252.1536047531694; Tue, 04 Sep 2018 00:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047531; cv=none; d=google.com; s=arc-20160816; b=Ra73YXud9ZUPSKdVpKOYaSFa0VfR+EnBf2AgJOKhyEh1S8K9mkSiWXYEhzLLRuW1a2 UFlcd7qBdd3FXr3wxelvLLz1mq1OLciLe4Sb5meBEtjnLSUSQPRnwRWhy1Ht1oW+irww whZpmMrS4ppWRd5Dg/481cUs6NE7L74uTxZ+9DhSkRi4BS1m/oDxf4nq1RwwnVRKAwZn RPJdp1XRNeiYzRhRLRRDAHYcc3qHVNsTwgIARYtJwJT+Bptkp3pyfOrG1jzrw24dWK7q dsTNGD/O+UbOJoFB1dagSrx7H/1LCT2DGj4fbdGJBGqM57ImOLpzdFKZM+MZaetWXYTE sreA== 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=4Ndd58saM4ybxdzbhBBjwH9xfcn/g9JkWoVmgORTFTE=; b=rSJb+/kB3lly9QuVN92NO4F8TdYo0c+mzfuX2U5aBuqyqcCFrqLusnFGRvXnxcw/tE MQ2KJkuDQOTjRINkGOuFPLEuj5WFgPWKDLjnFsc83PBlg66GBC5T87TJFpI0wpZBrsX6 GDH7PNbiBHTPKlir+MmLU44nRVMCzreVm66Fal9N9k2v0runyKIBdC1R3Jh06uEqYVz1 BArRVBATktbzIr2EiscjW2u1cjRe24D7oJIVp0y9UtxoaxyNANL5VdKiEeFyO9pPD3qy 5hMOa6u7L11VbhAAdG4uGkpYuc6pqBw+0w+78MOpnuFoA6Oxy22pbda+uPg90MKvvu9U dukQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eB9wubb8; 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 g13-v6si994417edf.328.2018.09.04.00.52.11; Tue, 04 Sep 2018 00:52:11 -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=eB9wubb8; 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 3CC19C21EE8; Tue, 4 Sep 2018 07:52:04 +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 7CD96C21EBB; Tue, 4 Sep 2018 07:52:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 20BC5C21DEC; Tue, 4 Sep 2018 07:50:56 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by lists.denx.de (Postfix) with ESMTPS id 37515C21D8E for ; Tue, 4 Sep 2018 07:50:51 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id d1-v6so1261064pgo.3 for ; Tue, 04 Sep 2018 00:50:51 -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=ys6XheIq6x/pFLbbYfjyJ6g4Zalor9R2KdEMPx6Or+I=; b=eB9wubb8q1K53TRBS8o2wJ5+DFyNiMMcXNtNnwX2u/hQ2arDrYTnzOUKleUmc5ErlC xv3kRQUxrhtex1VZEqYuX6FJtBAOVqgth+k56UBIS+Mk+eo3Sm6w9xA2wVXhq8I7Ah4B /N0bTp4JrN7ELl+pN/PxuM1/R4c46QTnqeKPM= 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=ys6XheIq6x/pFLbbYfjyJ6g4Zalor9R2KdEMPx6Or+I=; b=X768Wkic488Htl5zQVVik8nMhAr5T7h/rzMNyPZi8Ps5ZN9QwB53xyd+TI+s4Px4Lu 4JLLPJ4l/iZu8PSJDIiMUd4heT/8VWBMQoDOUuSuDD1ABQffUFJDkf5e+rBZVo9i40UB xH44wuGpH10dxwjM1kwtVjqxS6UnjGuyuEHD4gRIxa8p+CN6+Vp9QajEtaB9cEW5RmS6 gnHrazGcA+gmJE/UIkbDj02Uo/JzmY8wUdVvYBL5hvfOKTuJ0Y5SX0J1yXnkoukJsQo/ PNKn5LXN0VrURuqqEZ5U+zZTsQHH5Ahn8xhCU4R2UueSDpZYDX2bPKFLAC6W/j0JmwK8 63vg== X-Gm-Message-State: APzg51A5L9PPJHgnJlV74G1FdsMgn9z34VAEB7gTYcLombnJp9wlzyIH JbXp2FpZhQO8mQoS3cF+He/P/g== X-Received: by 2002:a63:e756:: with SMTP id j22-v6mr30225561pgk.185.1536047449903; Tue, 04 Sep 2018 00:50:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v140-v6sm37403148pgb.45.2018.09.04.00.50.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:49 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:30 +0900 Message-Id: <20180904074948.18146-6-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 05/23] 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 0574af0c0011..1e414380d527 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -653,6 +653,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; @@ -688,9 +689,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; @@ -708,7 +711,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); @@ -729,18 +732,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; } } @@ -756,8 +760,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; @@ -910,6 +917,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 d86eb5a11576..9b114e3cbda4 100644 --- a/include/fat.h +++ b/include/fat.h @@ -200,6 +200,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 */