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: 965803 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="eB9wubb8"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 424JwZ1c2bz9rvt for ; Tue, 4 Sep 2018 17:53:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B8EBBC21E44; Tue, 4 Sep 2018 07:52:03 +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-Google-Smtp-Source: ANB0VdbL8yYZWexxpbBUmE18CfhRBlU/T/03gNckbbwEP/FuF1aTijU0mZUfQNsjIrOO2FKn5DsDqA== 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 */