From patchwork Wed Dec 26 19:53:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 208205 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A2D1E2C007A for ; Thu, 27 Dec 2012 06:54:31 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0316A4A098; Wed, 26 Dec 2012 20:54:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HPLMIG06oc9X; Wed, 26 Dec 2012 20:54:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D2EA64A0A6; Wed, 26 Dec 2012 20:54:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C52124A09B for ; Wed, 26 Dec 2012 20:54:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7TYxpg9bOc+S for ; Wed, 26 Dec 2012 20:54:20 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yh0-f73.google.com (mail-yh0-f73.google.com [209.85.213.73]) by theia.denx.de (Postfix) with ESMTPS id 695BF4A09D for ; Wed, 26 Dec 2012 20:54:14 +0100 (CET) Received: by mail-yh0-f73.google.com with SMTP id 47so931383yhr.2 for ; Wed, 26 Dec 2012 11:54:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=yxq3wf2ntc+EG68ZbQDMV4WF92b8lPGyYr/X9mzbpa0=; b=d1NGXsbNZzWHElZqW7IR8LxL0350C7q6byOcWLlY+yZ9lIwt+R88fl5XnHsOAFFURy 12IC6OAq7WXp05+f/Z5JXNeGw5ghxgR/XwA5az3Nmsbm/eD5QVxN4IYz1PoW2R3C7WJo WkrqhqkECVMv9pmWbrHnKonn3W72AtDEysAy8PNBckP5nObSQLhgKLDCx4bU7SzyU8iO jOZ/HODQZoNss5acyCj7QnEVbNtIi63aZRyA/VYHF8RjheeLngjKsOUT67Vna1jbkhTE azLaxR1vGrgpKghrmqDCYg4ozpq6ZWfF9tJUqDnr9Xf2sHPDH5W03TMYr0LG9Oagr4i0 +w0w== X-Received: by 10.236.126.173 with SMTP id b33mr12453442yhi.16.1356551653176; Wed, 26 Dec 2012 11:54:13 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id j11si1209583ank.2.2012.12.26.11.54.13 (version=TLSv1/SSLv3 cipher=AES128-SHA); Wed, 26 Dec 2012 11:54:13 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 0B7E182004A; Wed, 26 Dec 2012 11:54:13 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id B1C4A160D8C; Wed, 26 Dec 2012 11:54:12 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Wed, 26 Dec 2012 11:53:29 -0800 Message-Id: <1356551618-8280-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1356551618-8280-1-git-send-email-sjg@chromium.org> References: <1356551618-8280-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQmhYhvL0eTCtNpN43fgr0q8ZlKpPgcKzRHdOsonNh9vsbpKDAsQn38M7rFDgC6v1hu91P3VNVntegpb81rTgSJcL+rR/AXv57iznp3OuREYlsElLgbfQI/NWrfYNbBZpIxdoFC+4TCm44JktDkifglWrBMp06qp2EtY2BWB2w19GDIDDOcCAgLra5eXu98/9t/gTaBi Cc: Tom Rini Subject: [U-Boot] [PATCH 02/11] fs: Fully populate the filesystem method struct X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de There is a structure in fs.c with just a probe method. By adding methods for other operations, we can avoid lots of #ifdefs and switch()s. As a first step, create the structure ready for use. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- fs/fs.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 47 insertions(+), 9 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 2c9f2c5..66835e2 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -27,6 +27,12 @@ static block_dev_desc_t *fs_dev_desc; static disk_partition_t fs_partition; static int fs_type = FS_TYPE_ANY; +static inline int fs_probe_unsupported(void) +{ + printf("** Unrecognized filesystem type **\n"); + return -1; +} + static inline int fs_ls_unsupported(const char *dirname) { printf("** Unrecognized filesystem type **\n"); @@ -40,6 +46,10 @@ static inline int fs_read_unsupported(const char *filename, ulong addr, return -1; } +static inline void fs_close_unsupported(void) +{ +} + #ifdef CONFIG_FS_FAT static int fs_probe_fat(void) { @@ -143,29 +153,57 @@ static inline void fs_close_ext(void) #define fs_read_ext fs_read_unsupported #endif -static struct { +struct fstype_info { int fstype; int (*probe)(void); -} fstypes[] = { + int (*ls)(const char *dirname); + int (*read)(const char *filename, ulong addr, int offset, int len); + void (*close)(void); +}; + +static struct fstype_info fstypes[] = { +#ifdef CONFIG_FS_FAT { .fstype = FS_TYPE_FAT, .probe = fs_probe_fat, + .close = fs_close_fat, + .ls = file_fat_ls, + .read = fs_read_fat, }, +#endif +#ifdef CONFIG_FS_EXT4 { .fstype = FS_TYPE_EXT, .probe = fs_probe_ext, + .close = fs_close_ext, + .ls = ext4fs_ls, + .read = fs_read_ext, + }, +#endif + { + .fstype = FS_TYPE_ANY, + .probe = fs_probe_unsupported, + .close = fs_close_unsupported, + .ls = fs_ls_unsupported, + .read = fs_read_unsupported, }, }; int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) { + struct fstype_info *info; int part, i; #ifdef CONFIG_NEEDS_MANUAL_RELOC static int relocated; if (!relocated) { - for (i = 0; i < ARRAY_SIZE(fstypes); i++) - fstypes[i].probe += gd->reloc_off; + for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); + i++, info++) { + info->probe += gd->reloc_off; + info->close += gd->reloc_off; + info->ls += gd->reloc_off; + info->read += gd->reloc_off; + } relocated = 1; } #endif @@ -175,17 +213,17 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) if (part < 0) return -1; - for (i = 0; i < ARRAY_SIZE(fstypes); i++) { - if ((fstype != FS_TYPE_ANY) && (fstype != fstypes[i].fstype)) + for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { + if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY && + fstype != info->fstype) continue; - if (!fstypes[i].probe()) { - fs_type = fstypes[i].fstype; + if (!info->probe()) { + fs_type = info->fstype; return 0; } } - printf("** Unrecognized filesystem type **\n"); return -1; }