提交 04735e9c 编写于 作者: F Frederic Leroy 提交者: Tom Rini

Fix ext2/ext4 filesystem accesses beyond 2TiB

With CONFIG_SYS_64BIT_LBA, lbaint_t gets defined as a 64-bit type,
which is required to represent block numbers for storage devices that
exceed 2TiB (the block size usually is 512B), e.g. recent hard drives

We now use lbaint_t for partition offset to reflect the lbaint_t change,
and access partitions beyond or crossing the 2.1TiB limit.
This required changes to signature of ext4fs_devread(), and type of all
variables relatives to block sector.

ext2/ext4 fs uses logical block represented by a 32 bit value. Logical
block is a multiple of device block sector. To avoid overflow problem
when calling ext4fs_devread(), we need to cast the sector parameter.
Signed-off-by: NFrédéric Leroy <fredo@starox.org>
上级 0eb33ad2
...@@ -67,7 +67,8 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, ...@@ -67,7 +67,8 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
"Name: %.32s Type: %.32s\n", intf, dev, part, info.name, "Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
info.type); info.type);
debug("First Block: %ld, # of blocks: %ld, Block Size: %ld\n", debug("First Block: " LBAFU ", # of blocks: " LBAFU
", Block Size: %ld\n",
info.start, info.size, info.blksz); info.start, info.size, info.blksz);
if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) { if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) {
......
...@@ -200,8 +200,8 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part, ...@@ -200,8 +200,8 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
uuid_string(gpt_pte[part - 1].unique_partition_guid.b, info->uuid); uuid_string(gpt_pte[part - 1].unique_partition_guid.b, info->uuid);
#endif #endif
debug("%s: start 0x%lX, size 0x%lX, name %s", __func__, debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s", __func__,
info->start, info->size, info->name); info->start, info->size, info->name);
/* Remember to free pte */ /* Remember to free pte */
free(gpt_pte); free(gpt_pte);
...@@ -431,7 +431,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e, ...@@ -431,7 +431,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
gpt_e[i].partition_name[k] = gpt_e[i].partition_name[k] =
(efi_char16_t)(partitions[i].name[k]); (efi_char16_t)(partitions[i].name[k]);
debug("%s: name: %s offset[%d]: 0x%x size[%d]: 0x%lx\n", debug("%s: name: %s offset[%d]: 0x%x size[%d]: 0x" LBAF "\n",
__func__, partitions[i].name, i, __func__, partitions[i].name, i,
offset, i, partitions[i].size); offset, i, partitions[i].size);
} }
......
...@@ -249,8 +249,8 @@ void print_part_iso(block_dev_desc_t * dev_desc) ...@@ -249,8 +249,8 @@ void print_part_iso(block_dev_desc_t * dev_desc)
printf("Part Start Sect x Size Type\n"); printf("Part Start Sect x Size Type\n");
i=0; i=0;
do { do {
printf (" %2d %8ld %8ld %6ld %.32s\n", printf(" %2d " LBAFU " " LBAFU " %6ld %.32s\n",
i, info.start, info.size, info.blksz, info.type); i, info.start, info.size, info.blksz, info.type);
i++; i++;
} while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1); } while (get_partition_info_iso_verb(dev_desc,i,&info,0)!=-1);
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include <ext_common.h> #include <ext_common.h>
#include "ext4_common.h" #include "ext4_common.h"
unsigned long part_offset; lbaint_t part_offset;
static block_dev_desc_t *ext4fs_block_dev_desc; static block_dev_desc_t *ext4fs_block_dev_desc;
static disk_partition_t *part_info; static disk_partition_t *part_info;
...@@ -58,7 +58,7 @@ void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info) ...@@ -58,7 +58,7 @@ void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info)
get_fs()->dev_desc->log2blksz; get_fs()->dev_desc->log2blksz;
} }
int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf)
{ {
unsigned block_len; unsigned block_len;
int log2blksz = ext4fs_block_dev_desc->log2blksz; int log2blksz = ext4fs_block_dev_desc->log2blksz;
...@@ -74,7 +74,8 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) ...@@ -74,7 +74,8 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
if ((sector < 0) || if ((sector < 0) ||
((sector + ((byte_offset + byte_len - 1) >> log2blksz)) ((sector + ((byte_offset + byte_len - 1) >> log2blksz))
>= part_info->size)) { >= part_info->size)) {
printf("%s read outside partition %d\n", __func__, sector); printf("%s read outside partition " LBAFU "\n", __func__,
sector);
return 0; return 0;
} }
...@@ -82,7 +83,7 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf) ...@@ -82,7 +83,7 @@ int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf)
sector += byte_offset >> log2blksz; sector += byte_offset >> log2blksz;
byte_offset &= ext4fs_block_dev_desc->blksz - 1; byte_offset &= ext4fs_block_dev_desc->blksz - 1;
debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len); debug(" <" LBAFU ", %d, %d>\n", sector, byte_offset, byte_len);
if (byte_offset != 0) { if (byte_offset != 0) {
/* read first part which isn't aligned with start of sector */ /* read first part which isn't aligned with start of sector */
......
...@@ -84,7 +84,7 @@ void put_ext4(uint64_t off, void *buf, uint32_t size) ...@@ -84,7 +84,7 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
if ((startblock + (size >> log2blksz)) > if ((startblock + (size >> log2blksz)) >
(part_offset + fs->total_sect)) { (part_offset + fs->total_sect)) {
printf("part_offset is %lu\n", part_offset); printf("part_offset is " LBAFU "\n", part_offset);
printf("total_sector is %llu\n", fs->total_sect); printf("total_sector is %llu\n", fs->total_sect);
printf("error: overflow occurs\n"); printf("error: overflow occurs\n");
return; return;
...@@ -405,7 +405,7 @@ restart: ...@@ -405,7 +405,7 @@ restart:
previous_blknr = root_blknr; previous_blknr = root_blknr;
} }
status = ext4fs_devread(first_block_no_of_root status = ext4fs_devread((lbaint_t)first_block_no_of_root
* fs->sect_perblk, * fs->sect_perblk,
0, fs->blksz, root_first_block_buffer); 0, fs->blksz, root_first_block_buffer);
if (status == 0) if (status == 0)
...@@ -545,7 +545,7 @@ static int search_dir(struct ext2_inode *parent_inode, char *dirname) ...@@ -545,7 +545,7 @@ static int search_dir(struct ext2_inode *parent_inode, char *dirname)
if (!block_buffer) if (!block_buffer)
goto fail; goto fail;
status = ext4fs_devread(blknr * fs->sect_perblk, status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk,
0, fs->blksz, (char *)block_buffer); 0, fs->blksz, (char *)block_buffer);
if (status == 0) if (status == 0)
goto fail; goto fail;
...@@ -783,7 +783,7 @@ static int check_filename(char *filename, unsigned int blknr) ...@@ -783,7 +783,7 @@ static int check_filename(char *filename, unsigned int blknr)
if (!root_first_block_buffer) if (!root_first_block_buffer)
return -ENOMEM; return -ENOMEM;
root_first_block_addr = root_first_block_buffer; root_first_block_addr = root_first_block_buffer;
status = ext4fs_devread(first_block_no_of_root * status = ext4fs_devread((lbaint_t)first_block_no_of_root *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, root_first_block_buffer); fs->blksz, root_first_block_buffer);
if (status == 0) if (status == 0)
...@@ -895,7 +895,8 @@ long int ext4fs_get_new_blk_no(void) ...@@ -895,7 +895,8 @@ long int ext4fs_get_new_blk_no(void)
fs->first_pass_bbmap++; fs->first_pass_bbmap++;
bgd[i].free_blocks--; bgd[i].free_blocks--;
fs->sb->free_blocks--; fs->sb->free_blocks--;
status = ext4fs_devread(bgd[i].block_id * status = ext4fs_devread((lbaint_t)
bgd[i].block_id *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, fs->blksz,
journal_buffer); journal_buffer);
...@@ -957,7 +958,7 @@ restart: ...@@ -957,7 +958,7 @@ restart:
/* journal backup */ /* journal backup */
if (prev_bg_bitmap_index != bg_idx) { if (prev_bg_bitmap_index != bg_idx) {
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = ext4fs_devread(bgd[bg_idx].block_id status = ext4fs_devread((lbaint_t)bgd[bg_idx].block_id
* fs->sect_perblk, * fs->sect_perblk,
0, fs->blksz, journal_buffer); 0, fs->blksz, journal_buffer);
if (status == 0) if (status == 0)
...@@ -1026,7 +1027,8 @@ int ext4fs_get_new_inode_no(void) ...@@ -1026,7 +1027,8 @@ int ext4fs_get_new_inode_no(void)
bgd[i].free_inodes--; bgd[i].free_inodes--;
bgd[i].bg_itable_unused--; bgd[i].bg_itable_unused--;
fs->sb->free_inodes--; fs->sb->free_inodes--;
status = ext4fs_devread(bgd[i].inode_id * status = ext4fs_devread((lbaint_t)
bgd[i].inode_id *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, fs->blksz,
journal_buffer); journal_buffer);
...@@ -1067,7 +1069,8 @@ restart: ...@@ -1067,7 +1069,8 @@ restart:
/* journal backup */ /* journal backup */
if (prev_inode_bitmap_index != ibmap_idx) { if (prev_inode_bitmap_index != ibmap_idx) {
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = ext4fs_devread(bgd[ibmap_idx].inode_id status = ext4fs_devread((lbaint_t)
bgd[ibmap_idx].inode_id
* fs->sect_perblk, * fs->sect_perblk,
0, fs->blksz, journal_buffer); 0, fs->blksz, journal_buffer);
if (status == 0) if (status == 0)
...@@ -1129,7 +1132,7 @@ static void alloc_single_indirect_block(struct ext2_inode *file_inode, ...@@ -1129,7 +1132,7 @@ static void alloc_single_indirect_block(struct ext2_inode *file_inode,
(*no_blks_reqd)++; (*no_blks_reqd)++;
debug("SIPB %ld: %u\n", si_blockno, *total_remaining_blocks); debug("SIPB %ld: %u\n", si_blockno, *total_remaining_blocks);
status = ext4fs_devread(si_blockno * fs->sect_perblk, status = ext4fs_devread((lbaint_t)si_blockno * fs->sect_perblk,
0, fs->blksz, (char *)si_buffer); 0, fs->blksz, (char *)si_buffer);
memset(si_buffer, '\0', fs->blksz); memset(si_buffer, '\0', fs->blksz);
if (status == 0) if (status == 0)
...@@ -1193,7 +1196,7 @@ static void alloc_double_indirect_block(struct ext2_inode *file_inode, ...@@ -1193,7 +1196,7 @@ static void alloc_double_indirect_block(struct ext2_inode *file_inode,
debug("DIPB %ld: %u\n", di_blockno_parent, debug("DIPB %ld: %u\n", di_blockno_parent,
*total_remaining_blocks); *total_remaining_blocks);
status = ext4fs_devread(di_blockno_parent * status = ext4fs_devread((lbaint_t)di_blockno_parent *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, (char *)di_parent_buffer); fs->blksz, (char *)di_parent_buffer);
...@@ -1224,7 +1227,7 @@ static void alloc_double_indirect_block(struct ext2_inode *file_inode, ...@@ -1224,7 +1227,7 @@ static void alloc_double_indirect_block(struct ext2_inode *file_inode,
debug("DICB %ld: %u\n", di_blockno_child, debug("DICB %ld: %u\n", di_blockno_child,
*total_remaining_blocks); *total_remaining_blocks);
status = ext4fs_devread(di_blockno_child * status = ext4fs_devread((lbaint_t)di_blockno_child *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, fs->blksz,
(char *)di_child_buff); (char *)di_child_buff);
...@@ -1447,7 +1450,8 @@ static struct ext4_extent_header *ext4fs_get_extent_block ...@@ -1447,7 +1450,8 @@ static struct ext4_extent_header *ext4fs_get_extent_block
block = le32_to_cpu(index[i].ei_leaf_hi); block = le32_to_cpu(index[i].ei_leaf_hi);
block = (block << 32) + le32_to_cpu(index[i].ei_leaf_lo); block = (block << 32) + le32_to_cpu(index[i].ei_leaf_lo);
if (ext4fs_devread(block << log2_blksz, 0, fs->blksz, buf)) if (ext4fs_devread((lbaint_t)block << log2_blksz, 0, fs->blksz,
buf))
ext_block = (struct ext4_extent_header *)buf; ext_block = (struct ext4_extent_header *)buf;
else else
return 0; return 0;
...@@ -1470,7 +1474,8 @@ static int ext4fs_blockgroup ...@@ -1470,7 +1474,8 @@ static int ext4fs_blockgroup
debug("ext4fs read %d group descriptor (blkno %ld blkoff %u)\n", debug("ext4fs read %d group descriptor (blkno %ld blkoff %u)\n",
group, blkno, blkoff); group, blkno, blkoff);
return ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - log2blksz), return ext4fs_devread((lbaint_t)blkno <<
(LOG2_BLOCK_SIZE(data) - log2blksz),
blkoff, sizeof(struct ext2_block_group), blkoff, sizeof(struct ext2_block_group),
(char *)blkgrp); (char *)blkgrp);
} }
...@@ -1497,8 +1502,8 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode) ...@@ -1497,8 +1502,8 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
(ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block; (ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
blkoff = (ino % inodes_per_block) * fs->inodesz; blkoff = (ino % inodes_per_block) * fs->inodesz;
/* Read the inode. */ /* Read the inode. */
status = ext4fs_devread(blkno << (LOG2_BLOCK_SIZE(data) - log2blksz), status = ext4fs_devread((lbaint_t)blkno << (LOG2_BLOCK_SIZE(data) -
blkoff, log2blksz), blkoff,
sizeof(struct ext2_inode), (char *)inode); sizeof(struct ext2_inode), (char *)inode);
if (status == 0) if (status == 0)
return 0; return 0;
...@@ -1597,7 +1602,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock) ...@@ -1597,7 +1602,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
if ((__le32_to_cpu(inode->b.blocks.indir_block) << if ((__le32_to_cpu(inode->b.blocks.indir_block) <<
log2_blksz) != ext4fs_indir1_blkno) { log2_blksz) != ext4fs_indir1_blkno) {
status = status =
ext4fs_devread(__le32_to_cpu ext4fs_devread((lbaint_t)__le32_to_cpu
(inode->b.blocks. (inode->b.blocks.
indir_block) << log2_blksz, 0, indir_block) << log2_blksz, 0,
blksz, (char *)ext4fs_indir1_block); blksz, (char *)ext4fs_indir1_block);
...@@ -1646,7 +1651,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock) ...@@ -1646,7 +1651,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
if ((__le32_to_cpu(inode->b.blocks.double_indir_block) << if ((__le32_to_cpu(inode->b.blocks.double_indir_block) <<
log2_blksz) != ext4fs_indir1_blkno) { log2_blksz) != ext4fs_indir1_blkno) {
status = status =
ext4fs_devread(__le32_to_cpu ext4fs_devread((lbaint_t)__le32_to_cpu
(inode->b.blocks. (inode->b.blocks.
double_indir_block) << log2_blksz, double_indir_block) << log2_blksz,
0, blksz, 0, blksz,
...@@ -1686,7 +1691,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock) ...@@ -1686,7 +1691,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
} }
if ((__le32_to_cpu(ext4fs_indir1_block[rblock / perblock]) << if ((__le32_to_cpu(ext4fs_indir1_block[rblock / perblock]) <<
log2_blksz) != ext4fs_indir2_blkno) { log2_blksz) != ext4fs_indir2_blkno) {
status = ext4fs_devread(__le32_to_cpu status = ext4fs_devread((lbaint_t)__le32_to_cpu
(ext4fs_indir1_block (ext4fs_indir1_block
[rblock / [rblock /
perblock]) << log2_blksz, 0, perblock]) << log2_blksz, 0,
...@@ -1738,7 +1743,8 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock) ...@@ -1738,7 +1743,8 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
if ((__le32_to_cpu(inode->b.blocks.triple_indir_block) << if ((__le32_to_cpu(inode->b.blocks.triple_indir_block) <<
log2_blksz) != ext4fs_indir1_blkno) { log2_blksz) != ext4fs_indir1_blkno) {
status = ext4fs_devread status = ext4fs_devread
(__le32_to_cpu(inode->b.blocks.triple_indir_block) ((lbaint_t)
__le32_to_cpu(inode->b.blocks.triple_indir_block)
<< log2_blksz, 0, blksz, << log2_blksz, 0, blksz,
(char *)ext4fs_indir1_block); (char *)ext4fs_indir1_block);
if (status == 0) { if (status == 0) {
...@@ -1778,7 +1784,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock) ...@@ -1778,7 +1784,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
perblock_parent]) << perblock_parent]) <<
log2_blksz) log2_blksz)
!= ext4fs_indir2_blkno) { != ext4fs_indir2_blkno) {
status = ext4fs_devread(__le32_to_cpu status = ext4fs_devread((lbaint_t)__le32_to_cpu
(ext4fs_indir1_block (ext4fs_indir1_block
[rblock / [rblock /
perblock_parent]) << perblock_parent]) <<
...@@ -1823,7 +1829,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock) ...@@ -1823,7 +1829,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
perblock_child]) << perblock_child]) <<
log2_blksz) != ext4fs_indir3_blkno) { log2_blksz) != ext4fs_indir3_blkno) {
status = status =
ext4fs_devread(__le32_to_cpu ext4fs_devread((lbaint_t)__le32_to_cpu
(ext4fs_indir2_block (ext4fs_indir2_block
[(rblock / perblock_child) [(rblock / perblock_child)
% (blksz / 4)]) << log2_blksz, 0, % (blksz / 4)]) << log2_blksz, 0,
......
...@@ -360,7 +360,8 @@ void recover_transaction(int prev_desc_logical_no) ...@@ -360,7 +360,8 @@ void recover_transaction(int prev_desc_logical_no)
(struct ext2_inode *)&inode_journal); (struct ext2_inode *)&inode_journal);
blknr = read_allocated_block((struct ext2_inode *) blknr = read_allocated_block((struct ext2_inode *)
&inode_journal, i); &inode_journal, i);
ext4fs_devread(blknr * fs->sect_perblk, 0, fs->blksz, temp_buff); ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0, fs->blksz,
temp_buff);
p_jdb = (char *)temp_buff; p_jdb = (char *)temp_buff;
jdb = (struct journal_header_t *) temp_buff; jdb = (struct journal_header_t *) temp_buff;
ofs = sizeof(struct journal_header_t); ofs = sizeof(struct journal_header_t);
...@@ -384,7 +385,7 @@ void recover_transaction(int prev_desc_logical_no) ...@@ -384,7 +385,7 @@ void recover_transaction(int prev_desc_logical_no)
continue; continue;
} }
blknr = read_allocated_block(&inode_journal, i); blknr = read_allocated_block(&inode_journal, i);
ext4fs_devread(blknr * fs->sect_perblk, 0, ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0,
fs->blksz, metadata_buff); fs->blksz, metadata_buff);
put_ext4((uint64_t)(be32_to_cpu(tag->block) * fs->blksz), put_ext4((uint64_t)(be32_to_cpu(tag->block) * fs->blksz),
metadata_buff, (uint32_t) fs->blksz); metadata_buff, (uint32_t) fs->blksz);
...@@ -431,7 +432,8 @@ int ext4fs_check_journal_state(int recovery_flag) ...@@ -431,7 +432,8 @@ int ext4fs_check_journal_state(int recovery_flag)
ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal); ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal);
blknr = read_allocated_block(&inode_journal, EXT2_JOURNAL_SUPERBLOCK); blknr = read_allocated_block(&inode_journal, EXT2_JOURNAL_SUPERBLOCK);
ext4fs_devread(blknr * fs->sect_perblk, 0, fs->blksz, temp_buff); ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0, fs->blksz,
temp_buff);
jsb = (struct journal_superblock_t *) temp_buff; jsb = (struct journal_superblock_t *) temp_buff;
if (fs->sb->feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) { if (fs->sb->feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) {
...@@ -455,7 +457,7 @@ int ext4fs_check_journal_state(int recovery_flag) ...@@ -455,7 +457,7 @@ int ext4fs_check_journal_state(int recovery_flag)
while (1) { while (1) {
blknr = read_allocated_block(&inode_journal, i); blknr = read_allocated_block(&inode_journal, i);
memset(temp_buff1, '\0', fs->blksz); memset(temp_buff1, '\0', fs->blksz);
ext4fs_devread(blknr * fs->sect_perblk, ext4fs_devread((lbaint_t)blknr * fs->sect_perblk,
0, fs->blksz, temp_buff1); 0, fs->blksz, temp_buff1);
jdb = (struct journal_header_t *) temp_buff1; jdb = (struct journal_header_t *) temp_buff1;
...@@ -574,7 +576,8 @@ static void update_descriptor_block(long int blknr) ...@@ -574,7 +576,8 @@ static void update_descriptor_block(long int blknr)
ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal); ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal);
jsb_blknr = read_allocated_block(&inode_journal, jsb_blknr = read_allocated_block(&inode_journal,
EXT2_JOURNAL_SUPERBLOCK); EXT2_JOURNAL_SUPERBLOCK);
ext4fs_devread(jsb_blknr * fs->sect_perblk, 0, fs->blksz, temp_buff); ext4fs_devread((lbaint_t)jsb_blknr * fs->sect_perblk, 0, fs->blksz,
temp_buff);
jsb = (struct journal_superblock_t *) temp_buff; jsb = (struct journal_superblock_t *) temp_buff;
jdb.h_blocktype = cpu_to_be32(EXT3_JOURNAL_DESCRIPTOR_BLOCK); jdb.h_blocktype = cpu_to_be32(EXT3_JOURNAL_DESCRIPTOR_BLOCK);
...@@ -621,10 +624,12 @@ static void update_commit_block(long int blknr) ...@@ -621,10 +624,12 @@ static void update_commit_block(long int blknr)
if (!temp_buff) if (!temp_buff)
return; return;
ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal); ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO,
&inode_journal);
jsb_blknr = read_allocated_block(&inode_journal, jsb_blknr = read_allocated_block(&inode_journal,
EXT2_JOURNAL_SUPERBLOCK); EXT2_JOURNAL_SUPERBLOCK);
ext4fs_devread(jsb_blknr * fs->sect_perblk, 0, fs->blksz, temp_buff); ext4fs_devread((lbaint_t)jsb_blknr * fs->sect_perblk, 0, fs->blksz,
temp_buff);
jsb = (struct journal_superblock_t *) temp_buff; jsb = (struct journal_superblock_t *) temp_buff;
jdb.h_blocktype = cpu_to_be32(EXT3_JOURNAL_COMMIT_BLOCK); jdb.h_blocktype = cpu_to_be32(EXT3_JOURNAL_COMMIT_BLOCK);
......
...@@ -88,8 +88,8 @@ int ext4fs_get_bgdtable(void) ...@@ -88,8 +88,8 @@ int ext4fs_get_bgdtable(void)
if (!fs->gdtable) if (!fs->gdtable)
return -ENOMEM; return -ENOMEM;
/* read the group descriptor table */ /* read the group descriptor table */
status = ext4fs_devread(fs->gdtable_blkno * fs->sect_perblk, 0, status = ext4fs_devread((lbaint_t)fs->gdtable_blkno * fs->sect_perblk,
fs->blksz * fs->no_blk_pergdt, fs->gdtable); 0, fs->blksz * fs->no_blk_pergdt, fs->gdtable);
if (status == 0) if (status == 0)
goto fail; goto fail;
...@@ -142,7 +142,7 @@ static void delete_single_indirect_block(struct ext2_inode *inode) ...@@ -142,7 +142,7 @@ static void delete_single_indirect_block(struct ext2_inode *inode)
/* journal backup */ /* journal backup */
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
status = status =
ext4fs_devread(bgd[bg_idx].block_id * ext4fs_devread((lbaint_t)bgd[bg_idx].block_id *
fs->sect_perblk, 0, fs->blksz, fs->sect_perblk, 0, fs->blksz,
journal_buffer); journal_buffer);
if (status == 0) if (status == 0)
...@@ -186,8 +186,8 @@ static void delete_double_indirect_block(struct ext2_inode *inode) ...@@ -186,8 +186,8 @@ static void delete_double_indirect_block(struct ext2_inode *inode)
} }
DIB_start_addr = (unsigned int *)di_buffer; DIB_start_addr = (unsigned int *)di_buffer;
blknr = inode->b.blocks.double_indir_block; blknr = inode->b.blocks.double_indir_block;
status = ext4fs_devread(blknr * fs->sect_perblk, 0, fs->blksz, status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0,
(char *)di_buffer); fs->blksz, (char *)di_buffer);
for (i = 0; i < fs->blksz / sizeof(int); i++) { for (i = 0; i < fs->blksz / sizeof(int); i++) {
if (*di_buffer == 0) if (*di_buffer == 0)
break; break;
...@@ -208,7 +208,8 @@ static void delete_double_indirect_block(struct ext2_inode *inode) ...@@ -208,7 +208,8 @@ static void delete_double_indirect_block(struct ext2_inode *inode)
fs->sb->free_blocks++; fs->sb->free_blocks++;
/* journal backup */ /* journal backup */
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
status = ext4fs_devread(bgd[bg_idx].block_id status = ext4fs_devread((lbaint_t)
bgd[bg_idx].block_id
* fs->sect_perblk, 0, * fs->sect_perblk, 0,
fs->blksz, fs->blksz,
journal_buffer); journal_buffer);
...@@ -238,7 +239,7 @@ static void delete_double_indirect_block(struct ext2_inode *inode) ...@@ -238,7 +239,7 @@ static void delete_double_indirect_block(struct ext2_inode *inode)
/* journal backup */ /* journal backup */
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = ext4fs_devread(bgd[bg_idx].block_id * status = ext4fs_devread((lbaint_t)bgd[bg_idx].block_id *
fs->sect_perblk, 0, fs->blksz, fs->sect_perblk, 0, fs->blksz,
journal_buffer); journal_buffer);
if (status == 0) if (status == 0)
...@@ -287,8 +288,8 @@ static void delete_triple_indirect_block(struct ext2_inode *inode) ...@@ -287,8 +288,8 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
} }
tib_start_addr = (unsigned int *)tigp_buffer; tib_start_addr = (unsigned int *)tigp_buffer;
blknr = inode->b.blocks.triple_indir_block; blknr = inode->b.blocks.triple_indir_block;
status = ext4fs_devread(blknr * fs->sect_perblk, 0, fs->blksz, status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0,
(char *)tigp_buffer); fs->blksz, (char *)tigp_buffer);
for (i = 0; i < fs->blksz / sizeof(int); i++) { for (i = 0; i < fs->blksz / sizeof(int); i++) {
if (*tigp_buffer == 0) if (*tigp_buffer == 0)
break; break;
...@@ -298,7 +299,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode) ...@@ -298,7 +299,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
if (!tip_buffer) if (!tip_buffer)
goto fail; goto fail;
tipb_start_addr = (unsigned int *)tip_buffer; tipb_start_addr = (unsigned int *)tip_buffer;
status = ext4fs_devread((*tigp_buffer) * status = ext4fs_devread((lbaint_t)(*tigp_buffer) *
fs->sect_perblk, 0, fs->blksz, fs->sect_perblk, 0, fs->blksz,
(char *)tip_buffer); (char *)tip_buffer);
for (j = 0; j < fs->blksz / sizeof(int); j++) { for (j = 0; j < fs->blksz / sizeof(int); j++) {
...@@ -325,6 +326,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode) ...@@ -325,6 +326,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
status = status =
ext4fs_devread( ext4fs_devread(
(lbaint_t)
bgd[bg_idx].block_id * bgd[bg_idx].block_id *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, fs->blksz,
...@@ -365,7 +367,8 @@ static void delete_triple_indirect_block(struct ext2_inode *inode) ...@@ -365,7 +367,8 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = status =
ext4fs_devread(bgd[bg_idx].block_id * ext4fs_devread((lbaint_t)
bgd[bg_idx].block_id *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, journal_buffer); fs->blksz, journal_buffer);
if (status == 0) if (status == 0)
...@@ -394,7 +397,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode) ...@@ -394,7 +397,7 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
/* journal backup */ /* journal backup */
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = ext4fs_devread(bgd[bg_idx].block_id * status = ext4fs_devread((lbaint_t)bgd[bg_idx].block_id *
fs->sect_perblk, 0, fs->blksz, fs->sect_perblk, 0, fs->blksz,
journal_buffer); journal_buffer);
if (status == 0) if (status == 0)
...@@ -480,7 +483,8 @@ static int ext4fs_delete_file(int inodeno) ...@@ -480,7 +483,8 @@ static int ext4fs_delete_file(int inodeno)
/* journal backup */ /* journal backup */
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
status = status =
ext4fs_devread(bgd[bg_idx].block_id * ext4fs_devread((lbaint_t)
bgd[bg_idx].block_id *
fs->sect_perblk, 0, fs->sect_perblk, 0,
fs->blksz, journal_buffer); fs->blksz, journal_buffer);
if (status == 0) if (status == 0)
...@@ -524,7 +528,8 @@ static int ext4fs_delete_file(int inodeno) ...@@ -524,7 +528,8 @@ static int ext4fs_delete_file(int inodeno)
/* journal backup */ /* journal backup */
if (prev_bg_bmap_idx != bg_idx) { if (prev_bg_bmap_idx != bg_idx) {
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = ext4fs_devread(bgd[bg_idx].block_id status = ext4fs_devread((lbaint_t)
bgd[bg_idx].block_id
* fs->sect_perblk, * fs->sect_perblk,
0, fs->blksz, 0, fs->blksz,
journal_buffer); journal_buffer);
...@@ -555,7 +560,7 @@ static int ext4fs_delete_file(int inodeno) ...@@ -555,7 +560,7 @@ static int ext4fs_delete_file(int inodeno)
if (!read_buffer) if (!read_buffer)
goto fail; goto fail;
start_block_address = read_buffer; start_block_address = read_buffer;
status = ext4fs_devread(blkno * fs->sect_perblk, status = ext4fs_devread((lbaint_t)blkno * fs->sect_perblk,
0, fs->blksz, read_buffer); 0, fs->blksz, read_buffer);
if (status == 0) if (status == 0)
goto fail; goto fail;
...@@ -578,7 +583,7 @@ static int ext4fs_delete_file(int inodeno) ...@@ -578,7 +583,7 @@ static int ext4fs_delete_file(int inodeno)
fs->sb->free_inodes++; fs->sb->free_inodes++;
/* journal backup */ /* journal backup */
memset(journal_buffer, '\0', fs->blksz); memset(journal_buffer, '\0', fs->blksz);
status = ext4fs_devread(bgd[ibmap_idx].inode_id * status = ext4fs_devread((lbaint_t)bgd[ibmap_idx].inode_id *
fs->sect_perblk, 0, fs->blksz, journal_buffer); fs->sect_perblk, 0, fs->blksz, journal_buffer);
if (status == 0) if (status == 0)
goto fail; goto fail;
...@@ -653,7 +658,8 @@ int ext4fs_init(void) ...@@ -653,7 +658,8 @@ int ext4fs_init(void)
for (i = 0; i < fs->no_blkgrp; i++) { for (i = 0; i < fs->no_blkgrp; i++) {
status = status =
ext4fs_devread(fs->bgd[i].block_id * fs->sect_perblk, 0, ext4fs_devread((lbaint_t)fs->bgd[i].block_id *
fs->sect_perblk, 0,
fs->blksz, (char *)fs->blk_bmaps[i]); fs->blksz, (char *)fs->blk_bmaps[i]);
if (status == 0) if (status == 0)
goto fail; goto fail;
...@@ -670,7 +676,8 @@ int ext4fs_init(void) ...@@ -670,7 +676,8 @@ int ext4fs_init(void)
} }
for (i = 0; i < fs->no_blkgrp; i++) { for (i = 0; i < fs->no_blkgrp; i++) {
status = ext4fs_devread(fs->bgd[i].inode_id * fs->sect_perblk, status = ext4fs_devread((lbaint_t)fs->bgd[i].inode_id *
fs->sect_perblk,
0, fs->blksz, 0, fs->blksz,
(char *)fs->inode_bmaps[i]); (char *)fs->inode_bmaps[i]);
if (status == 0) if (status == 0)
...@@ -710,7 +717,7 @@ void ext4fs_deinit(void) ...@@ -710,7 +717,7 @@ void ext4fs_deinit(void)
&inode_journal); &inode_journal);
blknr = read_allocated_block(&inode_journal, blknr = read_allocated_block(&inode_journal,
EXT2_JOURNAL_SUPERBLOCK); EXT2_JOURNAL_SUPERBLOCK);
ext4fs_devread(blknr * fs->sect_perblk, 0, fs->blksz, ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0, fs->blksz,
temp_buff); temp_buff);
jsb = (struct journal_superblock_t *)temp_buff; jsb = (struct journal_superblock_t *)temp_buff;
jsb->s_start = cpu_to_be32(0); jsb->s_start = cpu_to_be32(0);
...@@ -934,7 +941,8 @@ int ext4fs_write(const char *fname, unsigned char *buffer, ...@@ -934,7 +941,8 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
(inodeno % __le32_to_cpu(sblock->inodes_per_group)) / (inodeno % __le32_to_cpu(sblock->inodes_per_group)) /
inodes_per_block; inodes_per_block;
blkoff = (inodeno % inodes_per_block) * fs->inodesz; blkoff = (inodeno % inodes_per_block) * fs->inodesz;
ext4fs_devread(itable_blkno * fs->sect_perblk, 0, fs->blksz, temp_ptr); ext4fs_devread((lbaint_t)itable_blkno * fs->sect_perblk, 0, fs->blksz,
temp_ptr);
if (ext4fs_log_journal(temp_ptr, itable_blkno)) if (ext4fs_log_journal(temp_ptr, itable_blkno))
goto fail; goto fail;
...@@ -954,7 +962,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer, ...@@ -954,7 +962,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer,
blkoff = (parent_inodeno % inodes_per_block) * fs->inodesz; blkoff = (parent_inodeno % inodes_per_block) * fs->inodesz;
if (parent_itable_blkno != itable_blkno) { if (parent_itable_blkno != itable_blkno) {
memset(temp_ptr, '\0', fs->blksz); memset(temp_ptr, '\0', fs->blksz);
ext4fs_devread(parent_itable_blkno * fs->sect_perblk, ext4fs_devread((lbaint_t)parent_itable_blkno * fs->sect_perblk,
0, fs->blksz, temp_ptr); 0, fs->blksz, temp_ptr);
if (ext4fs_log_journal(temp_ptr, parent_itable_blkno)) if (ext4fs_log_journal(temp_ptr, parent_itable_blkno))
goto fail; goto fail;
......
...@@ -62,16 +62,16 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, ...@@ -62,16 +62,16 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
{ {
struct ext_filesystem *fs = get_fs(); struct ext_filesystem *fs = get_fs();
int i; int i;
int blockcnt; lbaint_t blockcnt;
int log2blksz = fs->dev_desc->log2blksz; int log2blksz = fs->dev_desc->log2blksz;
int log2_fs_blocksize = LOG2_BLOCK_SIZE(node->data) - log2blksz; int log2_fs_blocksize = LOG2_BLOCK_SIZE(node->data) - log2blksz;
int blocksize = (1 << (log2_fs_blocksize + log2blksz)); int blocksize = (1 << (log2_fs_blocksize + log2blksz));
unsigned int filesize = __le32_to_cpu(node->inode.size); unsigned int filesize = __le32_to_cpu(node->inode.size);
int previous_block_number = -1; lbaint_t previous_block_number = -1;
int delayed_start = 0; lbaint_t delayed_start = 0;
int delayed_extent = 0; lbaint_t delayed_extent = 0;
int delayed_skipfirst = 0; lbaint_t delayed_skipfirst = 0;
int delayed_next = 0; lbaint_t delayed_next = 0;
char *delayed_buf = NULL; char *delayed_buf = NULL;
short status; short status;
...@@ -82,7 +82,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, ...@@ -82,7 +82,7 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos,
blockcnt = ((len + pos) + blocksize - 1) / blocksize; blockcnt = ((len + pos) + blocksize - 1) / blocksize;
for (i = pos / blocksize; i < blockcnt; i++) { for (i = pos / blocksize; i < blockcnt; i++) {
int blknr; lbaint_t blknr;
int blockoff = pos % blocksize; int blockoff = pos % blocksize;
int blockend = blocksize; int blockend = blocksize;
int skipfirst = 0; int skipfirst = 0;
......
...@@ -135,7 +135,7 @@ int ext4fs_mount(unsigned part_length); ...@@ -135,7 +135,7 @@ int ext4fs_mount(unsigned part_length);
void ext4fs_close(void); void ext4fs_close(void);
int ext4fs_ls(const char *dirname); int ext4fs_ls(const char *dirname);
void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot);
int ext4fs_devread(int sector, int byte_offset, int byte_len, char *buf); int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf);
void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
long int read_allocated_block(struct ext2_inode *inode, int fileblock); long int read_allocated_block(struct ext2_inode *inode, int fileblock);
int ext4fs_probe(block_dev_desc_t *fs_dev_desc, int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
......
...@@ -180,7 +180,7 @@ struct ext2_data { ...@@ -180,7 +180,7 @@ struct ext2_data {
struct ext2fs_node diropen; struct ext2fs_node diropen;
}; };
extern unsigned long part_offset; extern lbaint_t part_offset;
int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
......
...@@ -44,9 +44,11 @@ extern ulong ide_bus_offset[]; ...@@ -44,9 +44,11 @@ extern ulong ide_bus_offset[];
#ifdef CONFIG_SYS_64BIT_LBA #ifdef CONFIG_SYS_64BIT_LBA
typedef uint64_t lbaint_t; typedef uint64_t lbaint_t;
#define LBAF "%llx" #define LBAF "%llx"
#define LBAFU "%llu"
#else #else
typedef ulong lbaint_t; typedef ulong lbaint_t;
#define LBAF "%lx" #define LBAF "%lx"
#define LBAFU "%lu"
#endif #endif
/* /*
......
...@@ -97,8 +97,8 @@ typedef struct block_dev_desc { ...@@ -97,8 +97,8 @@ typedef struct block_dev_desc {
#define DEV_TYPE_OPDISK 0x07 /* optical disk */ #define DEV_TYPE_OPDISK 0x07 /* optical disk */
typedef struct disk_partition { typedef struct disk_partition {
ulong start; /* # of first block in partition */ lbaint_t start; /* # of first block in partition */
ulong size; /* number of blocks in partition */ lbaint_t size; /* number of blocks in partition */
ulong blksz; /* block size in bytes */ ulong blksz; /* block size in bytes */
uchar name[32]; /* partition name */ uchar name[32]; /* partition name */
uchar type[32]; /* string type description */ uchar type[32]; /* string type description */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册