From patchwork Sun Sep 10 11:21:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812112 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PFCYgjlz"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqps81KTkz9sDB for ; Sun, 10 Sep 2017 21:35:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F264FC21F5B; Sun, 10 Sep 2017 11:24:56 +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=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 C7AC0C21F36; Sun, 10 Sep 2017 11:23:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 08485C21E41; Sun, 10 Sep 2017 11:23:00 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by lists.denx.de (Postfix) with ESMTPS id A4BB4C21DDA for ; Sun, 10 Sep 2017 11:22:54 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id k2so4080338qte.5 for ; Sun, 10 Sep 2017 04:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UGWkoFliRrSUA/JZSO1m2p6u+Wt51fM3gKGKCoQ5dpU=; b=PFCYgjlzPSLfxl7QLvzd2loVmlZhJNK2L6VQerffM3z1eNQXsau58hG1gGRPAxa7aK 78XGGMLToFqAjKWBwusjnOOCQi8CZsqb9BAoJPn2x6mXWbC0Z7y2ozNHPWu7H4gFuFZv f0s8bGBjEX0wEqMrBaI1tlje7VuX2+j02o3pBnsKtKrblWC1AqRVC1zuGnzW4mmcj92J zlzTKJ3/NIh9e7XZsmuor/f7SAY6jvMzvoxj8vPwmkz7Btnrvn4xAjYd6FEtjSfvGvoc gG32wbZ8shal9nm/xdfPFpgIkEuf1WJoGnvNb3HDGAFqKrk4hykayvKRYWZt2w9li7qm yjmQ== 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:mime-version:content-transfer-encoding; bh=UGWkoFliRrSUA/JZSO1m2p6u+Wt51fM3gKGKCoQ5dpU=; b=dFReZf3nQSO54wh9OwRYGXv6ip1zJsWL904xY4n4XEpsHahyY0CzgkKogTASZBckFC smy4c03ADo1Tqr8ImM8qrVZ/+d9By7k0wNCZEdidfXFMAdrx8iXqxmG8d8q21lnbIvA+ xz4eNCzqTyA+YKtA3oRTmjvL86gcSPpbrJ7KNNQdpNXvi5Tn0oD8xl9LT0z1seTzc+iu ZVSonPa7LL9Oz/OmwBQgBn57CXvU68AqtAGE/8DYNqFzWT+d6m1fhX76NoWf9yOvfL6i 5cDgRwpoqAmw6NSZeWqjKLUF2URLSijEbYiXouLBnBHJGUptvEU/IArA3AR/t0sBgDtq 2SJA== X-Gm-Message-State: AHPjjUiKJt3RhtwtblYyn7kEtIV4i3tMIvnFaGcSRQXTqV1RbmS5XEOc PYt9E41Suh+meuAvWxs= X-Google-Smtp-Source: AOwi7QBtghyl1WdIGBSwuFjaXRzzuelSQVQaNReFn1FSlSmtoe0gYL8KqaLiwiEz8kGAItLWwcvGLw== X-Received: by 10.200.52.118 with SMTP id v51mr11201565qtb.252.1505042573379; Sun, 10 Sep 2017 04:22:53 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id x1sm4279973qti.69.2017.09.10.04.22.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 04:22:52 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 07:21:31 -0400 Message-Id: <20170910112149.21358-15-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910112149.21358-1-robdclark@gmail.com> References: <20170910112149.21358-1-robdclark@gmail.com> MIME-Version: 1.0 Cc: Heinrich Schuchardt , Tien Fong Chee Subject: [U-Boot] [PATCH v3 7/9] fat/fs: move ls to generic implementation 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a generic implementation of 'ls' using opendir/readdir/closedir, and replace fat's custom implementation. Other filesystems should move to the generic implementation after they add opendir/readdir/closedir support. Signed-off-by: Rob Clark Reviewed-by: Ɓukasz Majewski Reviewed-by: Simon Glass --- fs/fat/fat.c | 32 -------------------------------- fs/fs.c | 35 +++++++++++++++++++++++++++++++++-- include/fat.h | 5 ++++- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 82ddb7eab1..c951d84f57 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -1029,38 +1029,6 @@ int file_fat_detectfs(void) return 0; } -int file_fat_ls(const char *dir) -{ - fsdata fsdata; - fat_itr itrblock, *itr = &itrblock; - int files = 0, dirs = 0; - int ret; - - ret = fat_itr_root(itr, &fsdata); - if (ret) - return ret; - - ret = fat_itr_resolve(itr, dir, TYPE_DIR); - if (ret) - return ret; - - while (fat_itr_next(itr)) { - if (fat_itr_isdir(itr)) { - printf(" %s/\n", itr->name); - dirs++; - } else { - printf(" %8u %s\n", - FAT2CPU32(itr->dent->size), - itr->name); - files++; - } - } - - printf("\n%d file(s), %d dir(s)\n\n", files, dirs); - - return 0; -} - int fat_exists(const char *filename) { fsdata fsdata; diff --git a/fs/fs.c b/fs/fs.c index fc0c953fcb..3481229aa6 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -37,6 +37,35 @@ static inline int fs_ls_unsupported(const char *dirname) return -1; } +/* generic implementation of ls in terms of opendir/readdir/closedir */ +__maybe_unused +static int fs_ls_generic(const char *dirname) +{ + struct fs_dir_stream *dirs; + struct fs_dirent *dent; + int nfiles = 0, ndirs = 0; + + dirs = fs_opendir(dirname); + if (!dirs) + return -errno; + + while ((dent = fs_readdir(dirs))) { + if (dent->type == FS_DT_DIR) { + printf(" %s/\n", dent->name); + ndirs++; + } else { + printf(" %8lld %s\n", dent->size, dent->name); + nfiles++; + } + } + + fs_closedir(dirs); + + printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs); + + return 0; +} + static inline int fs_exists_unsupported(const char *filename) { return 0; @@ -123,7 +152,7 @@ static struct fstype_info fstypes[] = { .null_dev_desc_ok = false, .probe = fat_set_blk_dev, .close = fat_close, - .ls = file_fat_ls, + .ls = fs_ls_generic, .exists = fat_exists, .size = fat_size, .read = fat_read_file, @@ -133,7 +162,9 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, #endif .uuid = fs_uuid_unsupported, - .opendir = fs_opendir_unsupported, + .opendir = fat_opendir, + .readdir = fat_readdir, + .closedir = fat_closedir, }, #endif #ifdef CONFIG_FS_EXT4 diff --git a/include/fat.h b/include/fat.h index b255ce5337..83cd90017e 100644 --- a/include/fat.h +++ b/include/fat.h @@ -11,6 +11,7 @@ #define _FAT_H_ #include +#include #define CONFIG_SUPPORT_VFAT /* Maximum Long File Name length supported here is 128 UTF-16 code units */ @@ -179,7 +180,6 @@ static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) } int file_fat_detectfs(void); -int file_fat_ls(const char *dir); int fat_exists(const char *filename); int fat_size(const char *filename, loff_t *size); int file_fat_read_at(const char *filename, loff_t pos, void *buffer, @@ -192,5 +192,8 @@ int file_fat_write(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actwrite); int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); +int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); +int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); +void fat_closedir(struct fs_dir_stream *dirs); void fat_close(void); #endif /* _FAT_H_ */