From patchwork Sun Nov 29 02:02:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407772 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=eKjixKQU; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBVV1Cfhz9s0b for ; Sun, 29 Nov 2020 13:03:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A24CC82777; Sun, 29 Nov 2020 03:03:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="eKjixKQU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ABCF882745; Sun, 29 Nov 2020 03:02:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E91DC82749 for ; Sun, 29 Nov 2020 03:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615351; bh=B5puKpH3ZvT5QGyREjKOV6nnMxF95Q7welVpHWemkZA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=eKjixKQUy9CC/iqT6+qMKbmi6Ns5mz+zFUiNxjQZFQRIIshTIllKLpNuzj4xE0Noj Xbbem0ZmHLlsoyvkJ5x9NQaoq9JiKQ0gSlwJ/fJiXeXp4+mbBtGBrKlwnyufNtKnU8 mp/JdFMAyynnINKFEGJIeUv1whDgW4rlbEEGMSLE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M26rD-1kl7r542TR-002Yaq; Sun, 29 Nov 2020 03:02:31 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 05/18] fs: fat: export fat_next_cluster() Date: Sun, 29 Nov 2020 03:02:03 +0100 Message-Id: <20201129020216.4865-6-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9gWRCbcQy2wUsney9PpKMLZN6pxDeSLwBd+52mFxoQ9m3vEOcWz a4m9a03GO8CIZX5EkIwKfqvBNNvF/B/n4mrw0BsIcFHs/qkhmYe/NxYXLgsz4wLlGYnRpjw INyp83Ty4YGKmtXOkJK7VWzySpkxMocXxFAOnXhc6R+5r7VzNTPFfc/2vCQAQ8qnKQdonf6 xYHfVJ8cEkWc0aGoxIz7Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:JW1KjfSad7Y=:yCvir5sdbhWeF+grSXABC5 aBOKf/Sv/5FQ94OTmy8ZJixSQZ6omOfUwHHm6dDzIcg4NN7+guefDtqvDFQrJXGtpBDqI8DMt pkLyrcNyMXwZTPczUAA0Ka+etmTwg3PgR1c0aphAZPcrCkV3xmVzacPZ9R88tebCfQl5ezaQS 5vw9yoccrQ76iBPGFDpla1miLM5LiqTWG1P8ByzhqMHObWwHOYrKaRxw9oB9sDeK4LwUwSDFh LfulE/vHIqaLIKWGgLYHZwtfTq7pv+VU37yBIkiNSqqe1DWp98yIQJlLswK8F974j636ZzU+L ckbguQrvBFymsLGNMuN2g3bhJCjdXzaTnMvtEhapLtNKlrrDGh4zz/oX6uAh6jWCCN2XCy3yZ ySn/MLNGK8NjrNxmkTvzMvl+Kj5s8Tq3vkmInUR1fUqzY3YxJynzIUsVlqFoHLBqKt0zLUm2I 7pOJ1R5wlU88silHcWjhhEE8E60h+gyIPj3G58sHAnyRVvc6TKWmGH8Kw5rRcWIPrVcrzFmB2 sJELY+2wGsWNBZaV07Uvqn8G9l3dJYh5zNqkXOe6XGkZ7kw2Fj8++7VRksFcpFR18Csb/kRfR 0ooQreJ0dgjwsyXYbyw0kIRRHlTVBheqcZbEvnDNOeQ3M7t75zpBsFosYIZf4xXyTjAmpS8sU Nac0Ow12cYRuAJXucHVUnfnZwv9KT1AMyjOZ3edRK/YvRlN9C4X3YKYhFrDB1B9coJlonbYHD 1YWrzet9QZBvQT/H7fuIHjkz3cdlyxsvdMb37NanrurgvBxcaXKD+pAPIFwr8LV/qwPO278O4 TMMgJBfsVDisftcDsckrJx3TlCPj51gvIo4Y0Qtiooxbrh7iflPIjl/Qq0bG8kcBJGqrPqPRW DwdzY/0YdvsQjf4MJ09g== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Rename function next_cluster() to fat_next_cluster() and export it. When creating a new directory entries we should reuse deleted entries. This requires re-scanning the directory. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat.c | 106 +++++++++++++++++++++++++++++++++++--------------- include/fat.h | 7 +++- 2 files changed, 80 insertions(+), 33 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat.c b/fs/fat/fat.c index fb6ba89466..674236d68a 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -621,7 +621,7 @@ static int get_fs_info(fsdata *mydata) /* * The root directory is not cluster-aligned and may be on a * "negative" cluster, this will be handled specially in - * next_cluster(). + * fat_next_cluster(). */ mydata->root_cluster = 0; } @@ -647,44 +647,76 @@ static int get_fs_info(fsdata *mydata) return 0; } - -/* - * Directory iterator, to simplify filesystem traversal +/** + * struct fat_itr - directory iterator, to simplify filesystem traversal * * Implements an iterator pattern to traverse directory tables, * transparently handling directory tables split across multiple * clusters, and the difference between FAT12/FAT16 root directory * (contiguous) and subdirectories + FAT32 root (chained). * - * Rough usage: + * Rough usage * - * for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) { - * // to traverse down to a subdirectory pointed to by - * // current iterator position: - * fat_itr_child(&itr, &itr); - * } + * .. code-block:: c * - * For more complete example, see fat_itr_resolve() + * for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) { + * // to traverse down to a subdirectory pointed to by + * // current iterator position: + * fat_itr_child(&itr, &itr); + * } + * + * For a more complete example, see fat_itr_resolve(). */ - -typedef struct { - fsdata *fsdata; /* filesystem parameters */ - unsigned start_clust; /* first cluster */ - 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 */ - - /* current iterator position values: */ - dir_entry *dent; /* current directory entry */ - char l_name[VFAT_MAXLEN_BYTES]; /* long (vfat) name */ - char s_name[14]; /* short 8.3 name */ - char *name; /* l_name if there is one, else s_name */ - - /* storage for current cluster in memory: */ - u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); -} fat_itr; +struct fat_itr { + /** + * @fsdata: filesystem parameters + */ + fsdata *fsdata; + /** + * @start_clust: first cluster + */ + unsigned int start_clust; + /** + * @clust: current cluster + */ + unsigned int clust; + /** + * @next_clust: next cluster if remaining == 0 + */ + unsigned int next_clust; + /** + * @last_cluster: set if last cluster of directory reached + */ + int last_cluster; + /** + * @is_root: is iterator at root directory + */ + int is_root; + /** + * @remaining: remaining directory entries in current cluster + */ + int remaining; + /** + * @dent: current directory entry + */ + dir_entry *dent; + /** + * @l_name: long name of current directory entry + */ + char l_name[VFAT_MAXLEN_BYTES]; + /** + * @s_name: short 8.3 name of current directory entry + */ + char s_name[14]; + /** + * @name: l_name if there is one, else s_name + */ + char *name; + /** + * @block: buffer for current cluster + */ + u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); +}; static int fat_itr_isdir(fat_itr *itr); @@ -753,7 +785,17 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->last_cluster = 0; } -static void *next_cluster(fat_itr *itr, unsigned *nbytes) +/** + * fat_next_cluster() - load next FAT cluster + * + * The function is used when iterating through directories. It loads the + * next cluster with directory entries + * + * @itr: directory iterator + * @nbytes: number of bytes read, 0 on error + * Return: first directory entry, NULL on error + */ +void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes) { fsdata *mydata = itr->fsdata; /* for silly macros */ int ret; @@ -825,7 +867,7 @@ static dir_entry *next_dent(fat_itr *itr) { if (itr->remaining == 0) { unsigned nbytes; - struct dir_entry *dent = next_cluster(itr, &nbytes); + struct dir_entry *dent = fat_next_cluster(itr, &nbytes); /* have we reached the last cluster? */ if (!dent) { diff --git a/include/fat.h b/include/fat.h index 02742f92a5..3c29a4484d 100644 --- a/include/fat.h +++ b/include/fat.h @@ -9,8 +9,9 @@ #ifndef _FAT_H_ #define _FAT_H_ -#include #include +#include +#include struct disk_partition; @@ -179,6 +180,9 @@ typedef struct { int fats; /* Number of FATs */ } fsdata; +struct fat_itr; +typedef struct fat_itr fat_itr; + static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) { return fsdata->data_begin + clust * fsdata->clust_size; @@ -208,4 +212,5 @@ void fat_closedir(struct fs_dir_stream *dirs); int fat_unlink(const char *filename); int fat_mkdir(const char *dirname); void fat_close(void); +void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes); #endif /* _FAT_H_ */