From 81180819b842602f29f325298ee3e522beda3e0a Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Thu, 23 Aug 2012 11:31:46 +0000 Subject: cmd_extX: use common get_device_and_partition function Convert ext2/4 load, ls, and write functions to use common device and partition parsing function. With the common function "dev:part" can come from the environment and a '-' can be used in that case. Signed-off-by: Rob Herring --- fs/ext4/dev.c | 32 +++++++++++++------------------- fs/ext4/ext4_common.h | 1 - fs/ext4/ext4fs.c | 1 - 3 files changed, 13 insertions(+), 21 deletions(-) (limited to 'fs') diff --git a/fs/ext4/dev.c b/fs/ext4/dev.c index 9e85228eda..1596a92b9a 100644 --- a/fs/ext4/dev.c +++ b/fs/ext4/dev.c @@ -38,26 +38,20 @@ #include #include +#include #include +unsigned long part_offset; + static block_dev_desc_t *ext4fs_block_dev_desc; -static disk_partition_t part_info; +static disk_partition_t *part_info; -int ext4fs_set_blk_dev(block_dev_desc_t *rbdd, int part) +void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info) { ext4fs_block_dev_desc = rbdd; - - if (part == 0) { - /* disk doesn't use partition table */ - part_info.start = 0; - part_info.size = rbdd->lba; - part_info.blksz = rbdd->blksz; - } else { - if (get_partition_info(ext4fs_block_dev_desc, - part, &part_info)) - return 0; - } - return part_info.size; + part_info = info; + part_offset = info->start; + get_fs()->total_sect = (info->size * info->blksz) / SECTOR_SIZE; } int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) @@ -68,7 +62,7 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) /* Check partition boundaries */ if ((sector < 0) || ((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >= - part_info.size)) { + part_info->size)) { printf("%s read outside partition %d\n", __func__, sector); return 0; } @@ -88,7 +82,7 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) /* read first part which isn't aligned with start of sector */ if (ext4fs_block_dev_desc-> block_read(ext4fs_block_dev_desc->dev, - part_info.start + sector, 1, + part_info->start + sector, 1, (unsigned long *) sec_buf) != 1) { printf(" ** ext2fs_devread() read error **\n"); return 0; @@ -111,14 +105,14 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) block_len = SECTOR_SIZE; ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev, - part_info.start + sector, + part_info->start + sector, 1, (unsigned long *)p); memcpy(buf, p, byte_len); return 1; } if (ext4fs_block_dev_desc->block_read(ext4fs_block_dev_desc->dev, - part_info.start + sector, + part_info->start + sector, block_len / SECTOR_SIZE, (unsigned long *) buf) != block_len / SECTOR_SIZE) { @@ -134,7 +128,7 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) /* read rest of data which are not in whole sector */ if (ext4fs_block_dev_desc-> block_read(ext4fs_block_dev_desc->dev, - part_info.start + sector, 1, + part_info->start + sector, 1, (unsigned long *) sec_buf) != 1) { printf("* %s read error - last part\n", __func__); return 0; diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h index 0af625db2b..f728134186 100644 --- a/fs/ext4/ext4_common.h +++ b/fs/ext4/ext4_common.h @@ -62,7 +62,6 @@ static inline void *zalloc(size_t size) return p; } -extern unsigned long part_offset; int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode); int ext4fs_read_file(struct ext2fs_node *node, int pos, diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index c366e6f099..93dcb7e8fa 100644 --- a/fs/ext4/ext4fs.c +++ b/fs/ext4/ext4fs.c @@ -43,7 +43,6 @@ #include "ext4_common.h" int ext4fs_symlinknest; -block_dev_desc_t *ext4_dev_desc; struct ext_filesystem ext_fs; struct ext_filesystem *get_fs(void) -- cgit v1.2.1