From patchwork Fri Jun 8 17:31:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 163827 X-Patchwork-Delegate: wd@denx.de 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 F045AB6FBE for ; Sat, 9 Jun 2012 03:32:29 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 29FBB2815C; Fri, 8 Jun 2012 19:32:25 +0200 (CEST) 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 kfSDakyWvmzp; Fri, 8 Jun 2012 19:32:24 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 600F628234; Fri, 8 Jun 2012 19:32:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BBA1B28234 for ; Fri, 8 Jun 2012 19:32:03 +0200 (CEST) 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 N33AUaRmFpt8 for ; Fri, 8 Jun 2012 19:32:02 +0200 (CEST) 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-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by theia.denx.de (Postfix) with ESMTPS id C210728231 for ; Fri, 8 Jun 2012 19:32:02 +0200 (CEST) Received: from frontend1.mail.m-online.net (unknown [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3W89fV0NTtz4Kh0t; Fri, 8 Jun 2012 19:32:02 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.8.164]) by mail.m-online.net (Postfix) with ESMTP id 3W89fT73Zrz4KK99; Fri, 8 Jun 2012 19:32:01 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from smtp-auth.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.8.164]) (amavisd-new, port 10024) with ESMTP id 1wiag8fgVz8x; Fri, 8 Jun 2012 19:32:01 +0200 (CEST) Received: from mashiro.lan (unknown [195.140.253.167]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA; Fri, 8 Jun 2012 19:32:00 +0200 (CEST) From: Marek Vasut To: u-boot@lists.denx.de Date: Fri, 8 Jun 2012 19:31:47 +0200 Message-Id: <1339176713-13309-3-git-send-email-marex@denx.de> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1339176713-13309-1-git-send-email-marex@denx.de> References: <1339176713-13309-1-git-send-email-marex@denx.de> Cc: Marek Vasut Subject: [U-Boot] [PATCH 2/8] EXT2: Indent cleanup ext2fs.c 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 * Mostly cleanup problems reported by checkpatch.pl -f * Minor tweaks where it simplified the code Signed-off-by: Marek Vasut Cc: Wolfgang Denk --- fs/ext2/ext2fs.c | 264 ++++++++++++++++++++++++++---------------------------- 1 file changed, 128 insertions(+), 136 deletions(-) diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c index a4f3094..f9e9228 100644 --- a/fs/ext2/ext2fs.c +++ b/fs/ext2/ext2fs.c @@ -27,12 +27,11 @@ #include #include #include -#include +#include -extern int ext2fs_devread (int sector, int byte_offset, int byte_len, +extern int ext2fs_devread(int sector, int byte_offset, int byte_len, char *buf); - struct ext2_data *ext2fs_root = NULL; struct ext2fs_node *ext2fs_file; int symlinknest = 0; @@ -65,55 +64,55 @@ static int ext2fs_blockgroup } - -static int ext2fs_read_inode - (struct ext2_data *data, int ino, struct ext2_inode *inode) { +static int ext2fs_read_inode(struct ext2_data *data, int ino, + struct ext2_inode *inode) +{ struct ext2_block_group blkgrp; struct ext2_sblock *sblock = &data->sblock; - int inodes_per_block; - int status; - unsigned int blkno; unsigned int blkoff; + int status; + int inodes_per_block; -#ifdef DEBUG - printf ("ext2fs read inode %d, inode_size %d\n", ino, inode_size); -#endif - /* It is easier to calculate if the first inode is 0. */ + debug("EXT2: read inode %d, inode_size %d\n", ino, inode_size); + + /* It is easier to calculate if the first inode is 0. */ ino--; - status = ext2fs_blockgroup (data, ino / __le32_to_cpu - (sblock->inodes_per_group), &blkgrp); - if (status == 0) { - return (0); - } + status = ext2fs_blockgroup(data, + ino / __le32_to_cpu(sblock->inodes_per_group), + &blkgrp); + if (status == 0) + return 0; inodes_per_block = EXT2_BLOCK_SIZE(data) / inode_size; - blkno = __le32_to_cpu (blkgrp.inode_table_id) + - (ino % __le32_to_cpu (sblock->inodes_per_group)) - / inodes_per_block; + blkno = __le32_to_cpu(blkgrp.inode_table_id) + + (ino % __le32_to_cpu(sblock->inodes_per_group)) / + inodes_per_block; blkoff = (ino % inodes_per_block) * inode_size; -#ifdef DEBUG - printf ("ext2fs read inode blkno %d blkoff %d\n", blkno, blkoff); -#endif - /* Read the inode. */ - status = ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE (data), blkoff, + + debug("EXT2: read inode blkno %d blkoff %d\n", blkno, blkoff); + + /* Read the inode. */ + status = ext2fs_devread(blkno << LOG2_EXT2_BLOCK_SIZE (data), blkoff, sizeof (struct ext2_inode), (char *) inode); - if (status == 0) { - return (0); - } + if (status == 0) + return 0; - return (1); + return 1; } - -void ext2fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot) +static void ext2fs_free_node(struct ext2fs_node *node, + struct ext2fs_node *currroot) { - if ((node != &ext2fs_root->diropen) && (node != currroot)) { - free (node); - } -} + if (node == &ext2fs_root->diropen) + return; + + if (node == currroot) + return; + free(node); +} static int ext2fs_read_block(struct ext2fs_node *node, int fileblock) { @@ -490,7 +489,6 @@ static char *ext2fs_read_symlink(struct ext2fs_node *node) return (symlink); } - int ext2fs_find_file1 (const char *currpath, struct ext2fs_node *currroot, struct ext2fs_node **currfound, int *foundtype) @@ -595,172 +593,166 @@ int ext2fs_find_file1 return (-1); } - -int ext2fs_find_file - (const char *path, struct ext2fs_node *rootnode, - struct ext2fs_node **foundnode, int expecttype) +static int ext2fs_find_file(const char *path, struct ext2fs_node *rootnode, + struct ext2fs_node **foundnode, int expecttype) { int status; int foundtype = FILETYPE_DIRECTORY; - symlinknest = 0; - if (!path) { - return (0); - } + if (!path) + return 0; - status = ext2fs_find_file1 (path, rootnode, foundnode, &foundtype); - if (status == 0) { - return (0); - } - /* Check if the node that was found was of the expected type. */ - if ((expecttype == FILETYPE_REG) && (foundtype != expecttype)) { - return (0); - } else if ((expecttype == FILETYPE_DIRECTORY) - && (foundtype != expecttype)) { - return (0); + status = ext2fs_find_file1(path, rootnode, foundnode, &foundtype); + if (status == 0) + return 0; + + /* Check if the node that was found was of the expected type. */ + if (foundtype != expecttype) { + if (expecttype == FILETYPE_REG) + return 0; + if (expecttype == FILETYPE_DIRECTORY) + return 0; } - return (1); -} + return 1; +} -int ext2fs_ls (const char *dirname) { +int ext2fs_ls(const char *dirname) +{ struct ext2fs_node *dirnode; int status; - if (ext2fs_root == NULL) { - return (0); - } + if (ext2fs_root == NULL) + return 0; - status = ext2fs_find_file (dirname, &ext2fs_root->diropen, &dirnode, - FILETYPE_DIRECTORY); + status = ext2fs_find_file(dirname, &ext2fs_root->diropen, &dirnode, + FILETYPE_DIRECTORY); if (status != 1) { - printf ("** Can not find directory. **\n"); - return (1); + printf("EXT2: Can not find directory!\n"); + return 1; } - ext2fs_iterate_dir (dirnode, NULL, NULL, NULL); - ext2fs_free_node (dirnode, &ext2fs_root->diropen); - return (0); -} + ext2fs_iterate_dir(dirnode, NULL, NULL, NULL); + ext2fs_free_node(dirnode, &ext2fs_root->diropen); + + return 0; +} -int ext2fs_open (const char *filename) { +int ext2fs_open(const char *filename) +{ struct ext2fs_node *fdiro = NULL; int status; - int len; - if (ext2fs_root == NULL) { - return (-1); - } + if (ext2fs_root == NULL) + return -1; + ext2fs_file = NULL; - status = ext2fs_find_file (filename, &ext2fs_root->diropen, &fdiro, - FILETYPE_REG); - if (status == 0) { + status = ext2fs_find_file(filename, &ext2fs_root->diropen, &fdiro, + FILETYPE_REG); + if (status == 0) goto fail; - } + if (!fdiro->inode_read) { - status = ext2fs_read_inode (fdiro->data, fdiro->ino, - &fdiro->inode); - if (status == 0) { + status = ext2fs_read_inode(fdiro->data, fdiro->ino, + &fdiro->inode); + if (status == 0) goto fail; - } } - len = __le32_to_cpu (fdiro->inode.size); + ext2fs_file = fdiro; - return (len); + + return __le32_to_cpu(fdiro->inode.size); fail: - ext2fs_free_node (fdiro, &ext2fs_root->diropen); - return (-1); + ext2fs_free_node(fdiro, &ext2fs_root->diropen); + return -1; } - int ext2fs_close(void) { - if ((ext2fs_file != NULL) && (ext2fs_root != NULL)) { - ext2fs_free_node (ext2fs_file, &ext2fs_root->diropen); - ext2fs_file = NULL; - } if (ext2fs_root != NULL) { - free (ext2fs_root); + if (ext2fs_file != NULL) { + ext2fs_free_node(ext2fs_file, &ext2fs_root->diropen); + ext2fs_file = NULL; + } + + free(ext2fs_root); ext2fs_root = NULL; } + if (indir1_block != NULL) { - free (indir1_block); + free(indir1_block); indir1_block = NULL; indir1_size = 0; indir1_blkno = -1; } + if (indir2_block != NULL) { - free (indir2_block); + free(indir2_block); indir2_block = NULL; indir2_size = 0; indir2_blkno = -1; } - return (0); -} + return 0; +} -int ext2fs_read (char *buf, unsigned len) { - int status; - - if (ext2fs_root == NULL) { - return (0); - } +int ext2fs_read(char *buf, unsigned len) +{ + if (ext2fs_root == NULL) + return 0; - if (ext2fs_file == NULL) { - return (0); - } + if (ext2fs_file == NULL) + return 0; - status = ext2fs_read_file (ext2fs_file, 0, len, buf); - return (status); + return ext2fs_read_file(ext2fs_file, 0, len, buf); } - -int ext2fs_mount (unsigned part_length) { +int ext2fs_mount(unsigned part_length) +{ struct ext2_data *data; int status; - data = malloc (sizeof (struct ext2_data)); - if (!data) { - return (0); - } - /* Read the superblock. */ - status = ext2fs_devread (1 * 2, 0, sizeof (struct ext2_sblock), - (char *) &data->sblock); - if (status == 0) { + data = malloc(sizeof(struct ext2_data)); + if (!data) + return 0; + + /* Read the superblock. */ + status = ext2fs_devread(1 * 2, 0, sizeof(struct ext2_sblock), + (char *)&data->sblock); + + if (status == 0) goto fail; - } - /* Make sure this is an ext2 filesystem. */ - if (__le16_to_cpu (data->sblock.magic) != EXT2_MAGIC) { + + /* Make sure this is an ext2 filesystem. */ + if (__le16_to_cpu(data->sblock.magic) != EXT2_MAGIC) goto fail; - } - if (__le32_to_cpu(data->sblock.revision_level == 0)) { + + if (__le32_to_cpu(data->sblock.revision_level == 0)) inode_size = 128; - } else { + else inode_size = __le16_to_cpu(data->sblock.inode_size); - } -#ifdef DEBUG - printf("EXT2 rev %d, inode_size %d\n", - __le32_to_cpu(data->sblock.revision_level), inode_size); -#endif + + debug("EXT2: rev %d, inode_size %d\n", + __le32_to_cpu(data->sblock.revision_level), inode_size); + data->diropen.data = data; data->diropen.ino = 2; data->diropen.inode_read = 1; data->inode = &data->diropen.inode; - status = ext2fs_read_inode (data, 2, data->inode); - if (status == 0) { + status = ext2fs_read_inode(data, 2, data->inode); + if (status == 0) goto fail; - } ext2fs_root = data; - return (1); - + return 1; fail: - printf ("Failed to mount ext2 filesystem...\n"); - free (data); + printf("EXT2: Failed to mount ext2 filesystem!\n"); + free(data); ext2fs_root = NULL; - return (0); + + return 0; }