From patchwork Sun Sep 10 11:21:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812107 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="fgh/Dzbn"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqplp0s7vz9sDB for ; Sun, 10 Sep 2017 21:31:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id AEF2CC21E54; Sun, 10 Sep 2017 11:25:13 +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 083A3C21F21; Sun, 10 Sep 2017 11:23:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2F5ABC21F21; Sun, 10 Sep 2017 11:22:44 +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 40243C21DEB for ; Sun, 10 Sep 2017 11:22:40 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id 7so4090843qtz.3 for ; Sun, 10 Sep 2017 04:22:40 -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=JQFBMriCF8kpLl5pw7gQ935N+34SJvcfPBpLESISXgc=; b=fgh/DzbnJRn3z2AWZOgGekexVuAXJvUXr5F5clKnz+egijEIa40JWXFVQZ73ok7gxe pnR2JVpR53ZRLbonnAa5AKPBy9KsncvB7Z+dDfhechrqJy7/WCYUUqZPFDbH3mIuqIJi CDiuH+LMK2GOS1a1PPjb0/TwPIcDQqLOJrIl/3EHlYS79iU1QV/PkrwcA3MMmpkSJ04m IWbq/iVR4TjKSAGjlUe0FNapFCkhntoLJ7ZB+/ZGsEhND9WXiru0zkyqLHbYJcySIRpr vJCuh+93efX5mU5dptws0wXRG0zMcB5wJMwJPZNa2i597lZZhjVrw+W0GsyXkO+ilXB5 wddg== 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=JQFBMriCF8kpLl5pw7gQ935N+34SJvcfPBpLESISXgc=; b=cpbXb1ducWu3KFsuo6Otam6SblbJ/H+TUmNmEpe9x1ab3GgrU+nQVAXMhG3Se9MMUZ dRT2DWRhOu86ttq1OgTz74a5RWr6bgxQ3WMrwYPdJWmmkjJ3oh8TwJD8IabXr8xr3NfV T1eZ4aq3TEYDE0S8nnKM2HttPWZCcHXh8kj7mF4/Q2mYMK0PxRuMB/n403e+2EmQ54B1 MAbsIWO2E/R5FsLbjGoVHlsk7+xfU5nqPG0mLk+56TwcHviFyt6g8fae/V4mFLA1P3TM qxtg7jUjomDWVcCoAbmpAfdDaLVkMgvIW99RSSBkWpsD+MCmg3XK3trUBk3t5GWxxSsp B4dw== X-Gm-Message-State: AHPjjUidSByAzrA1npTI677KBuTVDf/UpNd2xhB927BUdkyU8cwdoa9z CfVS9cnUKTPJhWXlHUk= X-Google-Smtp-Source: AOwi7QAN/zTZCDQEFapwT0hJe9f0VKTyYMBINyIavuOv/W3dDz5mIBbef8p5pt5XB7/lnL+xIYNY4w== X-Received: by 10.200.34.251 with SMTP id g56mr2849278qta.160.1505042558979; Sun, 10 Sep 2017 04:22:38 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id f20sm4476487qta.86.2017.09.10.04.22.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 04:22:37 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 07:21:27 -0400 Message-Id: <20170910112149.21358-11-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 Subject: [U-Boot] [PATCH v3 5/9] fs/fat: implement opendir/readdir/closedir 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" Implement the readdir interface using the directory iterators. Signed-off-by: Rob Clark Reviewed-by: Ɓukasz Majewski --- fs/fat/fat.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index bbba7947ee..82ddb7eab1 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1146,6 +1147,66 @@ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, return ret; } +typedef struct { + struct fs_dir_stream parent; + struct fs_dirent dirent; + fsdata fsdata; + fat_itr itr; +} fat_dir; + +int fat_opendir(const char *filename, struct fs_dir_stream **dirsp) +{ + fat_dir *dir = malloc(sizeof(*dir)); + int ret; + + if (!dir) + return -ENOMEM; + + ret = fat_itr_root(&dir->itr, &dir->fsdata); + if (ret) + goto fail; + + ret = fat_itr_resolve(&dir->itr, filename, TYPE_DIR); + if (ret) + goto fail; + + *dirsp = (struct fs_dir_stream *)dir; + return 0; + +fail: + free(dir); + return ret; +} + +int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp) +{ + fat_dir *dir = (fat_dir *)dirs; + struct fs_dirent *dent = &dir->dirent; + + if (!fat_itr_next(&dir->itr)) + return -ENOENT; + + memset(dent, 0, sizeof(*dent)); + strcpy(dent->name, dir->itr.name); + + if (fat_itr_isdir(&dir->itr)) { + dent->type = FS_DT_DIR; + } else { + dent->type = FS_DT_REG; + dent->size = FAT2CPU32(dir->itr.dent->size); + } + + *dentp = dent; + + return 0; +} + +void fat_closedir(struct fs_dir_stream *dirs) +{ + fat_dir *dir = (fat_dir *)dirs; + free(dir); +} + void fat_close(void) { }