[U-Boot] [PATCH 2/8] EXT2: Indent cleanup ext2fs.c

Jason Cooper u-boot at lakedaemon.net
Thu Jun 28 21:48:33 CEST 2012


On Fri, Jun 08, 2012 at 07:31:47PM +0200, Marek Vasut wrote:
> * Mostly cleanup problems reported by checkpatch.pl -f
> * Minor tweaks where it simplified the code
> 
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Wolfgang Denk <wd at denx.de>
> ---
>  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 <ext2fs.h>
>  #include <ext_common.h>
>  #include <malloc.h>
> -#include <asm/byteorder.h>
> +#include <linux/byteorder/generic.h>
>  
> -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);
>  
> -

This is not applying to origin/master.  It has:

/* Magic value used to identify an ext2 filesystem.  */
#define EXT2_MAGIC              0xEF53
/* Amount of indirect blocks in an inode.  */
#define INDIRECT_BLOCKS         12
/* Maximum lenght of a pathname.  */
#define EXT2_PATH_MAX           4096
/* Maximum nesting of symlinks, used to prevent a loop.  */
#define EXT2_MAX_SYMLINKCNT     8

at line 33, 32 after.  a git blame for these lines shows only 2b918712
which is from 2004.  What is this based on?  a4f3094 isn't in my tree...

thx,

Jason.

>  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;
>  }
> -- 
> 1.7.10
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot


More information about the U-Boot mailing list