From patchwork Tue Sep 4 07:49:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145856 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3364305ljw; Tue, 4 Sep 2018 00:52:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdasTTnHN0rKg9OwT6hBFp7zawjaOIQpbuIwlIItusJ/tZQ8s5ftOyAWGR2Xn2nucWr3ypcb X-Received: by 2002:a50:fa8b:: with SMTP id w11-v6mr12615855edr.59.1536047559692; Tue, 04 Sep 2018 00:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047559; cv=none; d=google.com; s=arc-20160816; b=pqZ/jUI2xDHM1YMxZf1U7txJPST/tfF/2FKfDDHoSBwXjEaN2OTbT9JNneXuAPo1em 1BmbIOjpMLOVe5d7Z8D8zn8Y8cqMKSid6ZTrZGsO/kM7K54GX9VAjWm9vPZl2L51NLhY HQEV7iFwZKhjGtOIHFSjxP9qjfVcA4+eLmHND1SDAcoQs6gMnj6bfXgIVbKV+ezCGrPS WRQeTe8mFjiIC3HRq/on6s+kiz/YQGp70VxEXLjm1IdtI83FusNKNpZwktmBe7Hkd2dz yR0CJb7lFZmhc4E9knLjhkaE+zuf3Ktk77HNy8EPDKksT37nS+ybAXBRpcVyhqk39Yra jHPQ== 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=aeUZj2qFpGLokdMQ7HoNP6FVhVHlXXIow2McIlMRznI=; b=FSq6kMCffmgXYGZpiZQUbL0K8Qu3y7CuYITh+yYX/K8Xp/YrE+S2wbdu1A5S5T/ZjS 567nxx1uvOzZwroiTf9xnBsOYhaJNrMoSqGv6jeX1Qetu7fuiBerE5nAPMJmhhVUYvaH HzIgWSwRt+bb58g1l6CZtWVlaQ1nOP5OPmohBfX80prVfnGs5LqFwDDuUntqfuut4pEi exZCuyPLDAi5wxLrmxDcSlcVESgtobbFg34/uDf9Iqf+eDChbIWXc0kg4SKwNN0Wr9V7 mPVP5hhvqlhIvCyuQ0MwY97bYhQ3ykLOlPCYYaaiXhWoNijfZ1naEKuUOesp00pJXX7x VCfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="RCAV+lB/"; 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 b16-v6si2611151edh.182.2018.09.04.00.52.39; Tue, 04 Sep 2018 00:52:39 -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="RCAV+lB/"; 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 44D33C21EFC; Tue, 4 Sep 2018 07:51:14 +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=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 EAD63C21F2A; Tue, 4 Sep 2018 07:51:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BD9D6C21EFB; Tue, 4 Sep 2018 07:50:44 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 45C39C21F2A for ; Tue, 4 Sep 2018 07:50:41 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id 2-v6so1255178pgo.4 for ; Tue, 04 Sep 2018 00:50:41 -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=GIeh8lLNlwEqZbN/Ylkl4kDPmqfsSWqu/sQpxn0xOso=; b=RCAV+lB/gxhlupUspNaF/ZZtytY+N7bFi6vrzlQkbKXp6eIwD/yk2O9gkucLJLY4co 6xZ+GGx6Fgx/KBGJh0sEVlqr/ayQDBllAXD8LsDPoDMyelkmhnJJnZqUS5QrT179GxmM JxT0/LKLyQ5OL4e6gAr3zGuU5SOTEco9eP/Hw= 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=GIeh8lLNlwEqZbN/Ylkl4kDPmqfsSWqu/sQpxn0xOso=; b=I1HO6RI1HkTFsW90n1UkkW3iPRXyhONobnheFDWzec+OMm3dMcVsNxEAyoU/kRByVR TYObLpqN/uKy19cByX1Wby1sP3RgXBexrv1XpH1CqjZND/A78Yj9hxzsiN4GFgMuzoS0 +28SzL8Lx/bKQL9CKWOgXn97TbwIvY5kk6Db/0f1v+YzZl/BE35IZN/S8mXyj9A9+e3V GxmhAqxWDgbxa65NVepd1XFSBAhhw1d2AtWFQq7fS+kXqKRoSYd7dt8Im5uN7o8hAo9O za+t9D24DCE5xOyFRyVdsqMAHfTaP+Hea9GK0N67xnk6DX9LJ3F1OUOCpmZ8p8IyMpHe FbMg== X-Gm-Message-State: APzg51C0QteixZw9J1cY3wGE6i9Q/BqNL7KrVgAYpFyyPzauEYIyT25L yxSlrYqzUq/Jv1DuPIOpWOUrfQ== X-Received: by 2002:a63:7557:: with SMTP id f23-v6mr15304301pgn.135.1536047439953; Tue, 04 Sep 2018 00:50:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s75-v6sm37103921pfd.108.2018.09.04.00.50.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:39 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:29 +0900 Message-Id: <20180904074948.18146-5-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 04/23] fs: fat: make directory iterator global for write use 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" Directory iterator was introduced in major re-work of read operation by Rob. We want to use it for write operation extensively as well. This patch makes relevant functions, as well as iterator definition, visible outside of fat.c. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 39 ++++++--------------------------------- include/fat.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index eaea9300fd7f..0574af0c0011 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -638,25 +638,6 @@ static int get_fs_info(fsdata *mydata) * For more complete example, see fat_itr_resolve() */ -typedef struct { - fsdata *fsdata; /* filesystem parameters */ - unsigned clust; /* current cluster */ - 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; - -static int fat_itr_isdir(fat_itr *itr); - /** * fat_itr_root() - initialize an iterator to start at the root * directory @@ -665,7 +646,7 @@ static int fat_itr_isdir(fat_itr *itr); * @fsdata: filesystem data for the partition * @return 0 on success, else -errno */ -static int fat_itr_root(fat_itr *itr, fsdata *fsdata) +int fat_itr_root(fat_itr *itr, fsdata *fsdata) { if (get_fs_info(fsdata)) return -ENXIO; @@ -697,7 +678,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) * @parent: the iterator pointing at a directory entry in the * parent directory of the directory to iterate */ -static void fat_itr_child(fat_itr *itr, fat_itr *parent) +void fat_itr_child(fat_itr *itr, fat_itr *parent) { fsdata *mydata = parent->fsdata; /* for silly macros */ unsigned clustnum = START(parent->dent); @@ -717,7 +698,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->last_cluster = 0; } -static void *next_cluster(fat_itr *itr) +void *next_cluster(fat_itr *itr) { fsdata *mydata = itr->fsdata; /* for silly macros */ int ret; @@ -838,7 +819,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr) * @return boolean, 1 if success or 0 if no more entries in the * current directory */ -static int fat_itr_next(fat_itr *itr) +int fat_itr_next(fat_itr *itr) { dir_entry *dent; @@ -883,19 +864,11 @@ static int fat_itr_next(fat_itr *itr) * @itr: the iterator * @return true if cursor is at a directory */ -static int fat_itr_isdir(fat_itr *itr) +int fat_itr_isdir(fat_itr *itr) { return !!(itr->dent->attr & ATTR_DIR); } -/* - * Helpers: - */ - -#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) - /** * fat_itr_resolve() - traverse directory structure to resolve the * requested path. @@ -911,7 +884,7 @@ static int fat_itr_isdir(fat_itr *itr) * @type: bitmask of allowable file types * @return 0 on success or -errno */ -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) { const char *next; diff --git a/include/fat.h b/include/fat.h index 127e6622a9b0..d86eb5a11576 100644 --- a/include/fat.h +++ b/include/fat.h @@ -189,6 +189,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) return (sect - fsdata->data_begin) / fsdata->clust_size; } +/* + * Directory iterator + */ + +#define TYPE_FILE 0x1 +#define TYPE_DIR 0x2 +#define TYPE_ANY (TYPE_FILE | TYPE_DIR) + +typedef struct { + fsdata *fsdata; /* filesystem parameters */ + unsigned clust; /* current cluster */ + 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; + +int fat_itr_root(fat_itr *itr, fsdata *fsdata); +void fat_itr_child(fat_itr *itr, fat_itr *parent); +void *next_cluster(fat_itr *itr); +int fat_itr_next(fat_itr *itr); +int fat_itr_isdir(fat_itr *itr); +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type); + int file_fat_detectfs(void); int fat_exists(const char *filename); int fat_size(const char *filename, loff_t *size);