ref: 3d5b848c46403c569051dfb3654086e34bde6366
parent: 1887221f942c128553730946025d1a9c419f56cb
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Sat Jan 23 23:24:03 EST 2016
Add type cast to eliminate compiler warning messages.
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -1647,10 +1647,11 @@
f->fsize = ext4_inode_get_size(sb, ref.inode);
block_size = ext4_sb_get_block_size(sb);
- size = size > (f->fsize - f->fpos) ? (f->fsize - f->fpos) : size;
+ size = ((uint64_t)size > (f->fsize - f->fpos))
+ ? ((size_t)(f->fsize - f->fpos)) : size;
- iblock_idx = (f->fpos) / block_size;
- iblock_last = (f->fpos + size) / block_size;
+ iblock_idx = (uint32_t)((f->fpos) / block_size);
+ iblock_last = (uint32_t)((f->fpos + size) / block_size);
unalg = (f->fpos) % block_size;
/*If the size of symlink is smaller than 60 bytes*/
@@ -1662,8 +1663,8 @@
char *content = (char *)ref.inode->blocks;
if (f->fpos < f->fsize) {
size_t len = size;
- if (unalg + size > f->fsize)
- len = f->fsize - unalg;
+ if (unalg + size > (uint32_t)f->fsize)
+ len = (uint32_t)f->fsize - unalg;
memcpy(buf, content + unalg, len);
if (rcnt)
*rcnt = len;
@@ -1808,9 +1809,9 @@
f->fsize = ext4_inode_get_size(sb, ref.inode);
block_size = ext4_sb_get_block_size(sb);
- iblock_last = (f->fpos + size) / block_size;
- iblk_idx = (f->fpos) / block_size;
- ifile_blocks = (f->fsize + block_size - 1) / block_size;
+ iblock_last = (uint32_t)((f->fpos + size) / block_size);
+ iblk_idx = (uint32_t)(f->fpos / block_size);
+ ifile_blocks = (uint32_t)((f->fsize + block_size - 1) / block_size);
unalg = (f->fpos) % block_size;
--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -58,7 +58,7 @@
if (ext4_get32(s, first_data_block) && baddr)
baddr--;
- return baddr / ext4_get32(s, blocks_per_group);
+ return (uint32_t)(baddr / ext4_get32(s, blocks_per_group));
}
/**@brief Compute the starting block address of a block group
--- a/lwext4/ext4_block_group.h
+++ b/lwext4/ext4_block_group.h
@@ -79,7 +79,7 @@
struct ext4_sblock *s, uint64_t blk)
{
- bg->block_bitmap_lo = to_le32(blk);
+ bg->block_bitmap_lo = to_le32((uint32_t)blk);
if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
bg->block_bitmap_hi = to_le32(blk >> 32);
@@ -111,7 +111,7 @@
static inline void ext4_bg_set_inode_bitmap(struct ext4_bgroup *bg,
struct ext4_sblock *s, uint64_t blk)
{
- bg->inode_bitmap_lo = to_le32(blk);
+ bg->inode_bitmap_lo = to_le32((uint32_t)blk);
if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
bg->inode_bitmap_hi = to_le32(blk >> 32);
@@ -145,7 +145,7 @@
ext4_bg_set_inode_table_first_block(struct ext4_bgroup *bg,
struct ext4_sblock *s, uint64_t blk)
{
- bg->inode_table_first_block_lo = to_le32(blk);
+ bg->inode_table_first_block_lo = to_le32((uint32_t)blk);
if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
bg->inode_table_first_block_hi = to_le32(blk >> 32);
}
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -217,7 +217,7 @@
/* Compute next block address */
uint32_t block_size = ext4_sb_get_block_size(sb);
uint64_t current_blk_idx = it->curr_off / block_size;
- uint32_t next_blk_idx = pos / block_size;
+ uint32_t next_blk_idx = (uint32_t)(pos / block_size);
/*
* If we don't have a block or are moving across block boundary,
@@ -316,7 +316,7 @@
/* Set basic attributes */
ext4_dir_en_set_inode(en, child->index);
ext4_dir_en_set_entry_len(en, entry_len);
- ext4_dir_en_set_name_len(sb, en, name_len);
+ ext4_dir_en_set_name_len(sb, en, (uint16_t)name_len);
/* Write name */
memcpy(en->name, name, name_len);
@@ -353,8 +353,8 @@
uint32_t iblock = 0;
ext4_fsblk_t fblock = 0;
uint32_t block_size = ext4_sb_get_block_size(sb);
- uint32_t inode_size = ext4_inode_get_size(sb, parent->inode);
- uint32_t total_blocks = inode_size / block_size;
+ uint64_t inode_size = ext4_inode_get_size(sb, parent->inode);
+ uint32_t total_blocks = (uint32_t)(inode_size / block_size);
/* Find block, where is space for new entry and try to add */
bool success = false;
@@ -462,8 +462,8 @@
uint32_t iblock;
ext4_fsblk_t fblock;
uint32_t block_size = ext4_sb_get_block_size(sb);
- uint32_t inode_size = ext4_inode_get_size(sb, parent->inode);
- uint32_t total_blocks = inode_size / block_size;
+ uint64_t inode_size = ext4_inode_get_size(sb, parent->inode);
+ uint32_t total_blocks = (uint32_t)(inode_size / block_size);
/* Walk through all data blocks */
for (iblock = 0; iblock < total_blocks; ++iblock) {
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -962,7 +962,7 @@
while ((void *)de < (void *)(old_data_block->data + block_size)) {
/* Read only valid entries */
if (ext4_dir_en_get_inode(de) && de->name_len) {
- uint8_t len = ext4_dir_en_get_name_len(sb, de);
+ uint16_t len = ext4_dir_en_get_name_len(sb, de);
rc = ext4_dir_dx_hash_string(&hinfo_tmp, len,
(char *)de->name);
if (rc != EOK) {
--- a/lwext4/ext4_extent.c
+++ b/lwext4/ext4_extent.c
@@ -170,9 +170,9 @@
ext4_balloc_free_blocks(inode_ref, block, count);
}
-static size_t ext4_ext_space_block(struct ext4_inode_ref *inode_ref)
+static uint16_t ext4_ext_space_block(struct ext4_inode_ref *inode_ref)
{
- size_t size;
+ uint16_t size;
uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
size = (block_size - sizeof(struct ext4_extent_header)) /
@@ -184,9 +184,9 @@
return size;
}
-static size_t ext4_ext_space_block_idx(struct ext4_inode_ref *inode_ref)
+static uint16_t ext4_ext_space_block_idx(struct ext4_inode_ref *inode_ref)
{
- size_t size;
+ uint16_t size;
uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
size = (block_size - sizeof(struct ext4_extent_header)) /
@@ -198,9 +198,9 @@
return size;
}
-static size_t ext4_ext_space_root(struct ext4_inode_ref *inode_ref)
+static uint16_t ext4_ext_space_root(struct ext4_inode_ref *inode_ref)
{
- size_t size;
+ uint16_t size;
size = sizeof(inode_ref->inode->blocks);
size -= sizeof(struct ext4_extent_header);
@@ -212,9 +212,9 @@
return size;
}
-static size_t ext4_ext_space_root_idx(struct ext4_inode_ref *inode_ref)
+static uint16_t ext4_ext_space_root_idx(struct ext4_inode_ref *inode_ref)
{
- size_t size;
+ uint16_t size;
size = sizeof(inode_ref->inode->blocks);
size -= sizeof(struct ext4_extent_header);
@@ -226,10 +226,10 @@
return size;
}
-static size_t ext4_ext_max_entries(struct ext4_inode_ref *inode_ref,
+static uint16_t ext4_ext_max_entries(struct ext4_inode_ref *inode_ref,
uint32_t depth)
{
- size_t max;
+ uint16_t max;
if (depth == ext_depth(inode_ref->inode)) {
if (depth == 0)
@@ -1730,7 +1730,7 @@
return err;
}
-int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock,
+int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_lblk_t iblock,
uint32_t max_blocks, ext4_fsblk_t *result, bool create,
uint32_t *blocks_count)
{
@@ -1740,7 +1740,8 @@
int err = EOK;
int32_t depth;
uint32_t allocated = 0;
- ext4_fsblk_t next, newblock;
+ ext4_lblk_t next;
+ ext4_fsblk_t newblock;
if (result)
*result = 0;
--- a/lwext4/ext4_extent.h
+++ b/lwext4/ext4_extent.h
@@ -265,7 +265,7 @@
/**TODO: */
-int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock,
+int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_lblk_t iblock,
uint32_t max_blocks, ext4_fsblk_t *result, bool create,
uint32_t *blocks_count);
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -328,10 +328,10 @@
* to make sure we calculate the right free blocks
*/
- group_blocks = ext4_sb_get_blocks_cnt(sb);
- group_blocks -= ext4_get32(sb, first_data_block);
- group_blocks -= ext4_get32(sb, blocks_per_group) *
- (ext4_block_group_cnt(sb) - 1);
+ group_blocks = (uint32_t)(ext4_sb_get_blocks_cnt(sb) -
+ ext4_get32(sb, first_data_block) -
+ ext4_get32(sb, blocks_per_group) *
+ (ext4_block_group_cnt(sb) - 1));
} else {
group_blocks = ext4_get32(sb, blocks_per_group);
}
@@ -339,16 +339,19 @@
bool in_bg;
in_bg = ext4_block_in_group(sb, bmp_blk, bg_ref->index);
if (!flex_bg || in_bg)
- ext4_bmap_bit_set(block_bitmap.data, bmp_blk - first_bg);
+ ext4_bmap_bit_set(block_bitmap.data,
+ (uint32_t)(bmp_blk - first_bg));
in_bg = ext4_block_in_group(sb, bmp_inode, bg_ref->index);
if (!flex_bg || in_bg)
- ext4_bmap_bit_set(block_bitmap.data, bmp_inode - first_bg);
+ ext4_bmap_bit_set(block_bitmap.data,
+ (uint32_t)(bmp_inode - first_bg));
for (i = inode_table; i < inode_table + inode_table_bcnt; i++) {
in_bg = ext4_block_in_group(sb, i, bg_ref->index);
if (!flex_bg || in_bg)
- ext4_bmap_bit_set(block_bitmap.data, i - first_bg);
+ ext4_bmap_bit_set(block_bitmap.data,
+ (uint32_t)(i - first_bg));
}
/*
* Also if the number of blocks within the group is
@@ -727,7 +730,7 @@
}
/* Load block address, where i-node table is located */
- uint32_t inode_table_start =
+ ext4_fsblk_t inode_table_start =
ext4_bg_get_inode_table_first_block(bg_ref.block_group, &fs->sb);
/* Put back block group reference (not needed more) */
@@ -1089,7 +1092,7 @@
return EIO;
/* Compute offsets for the topmost level */
- uint64_t block_offset_in_level =
+ uint32_t block_offset_in_level =
iblock - fs->inode_block_limits[level - 1];
ext4_fsblk_t current_block =
ext4_inode_get_indirect_block(inode, level - 1);
@@ -1172,7 +1175,8 @@
if (v && old_size < sizeof(inode_ref->inode->blocks) &&
!ext4_inode_get_blocks_count(sb, inode_ref->inode)) {
char *content = (char *)inode_ref->inode->blocks + new_size;
- memset(content , 0, sizeof(inode_ref->inode->blocks) - new_size);
+ memset(content, 0,
+ sizeof(inode_ref->inode->blocks) - (uint32_t)new_size);
ext4_inode_set_size(inode_ref->inode, new_size);
inode_ref->dirty = true;
@@ -1181,8 +1185,8 @@
/* Compute how many blocks will be released */
uint32_t block_size = ext4_sb_get_block_size(sb);
- uint32_t new_blocks_cnt = (new_size + block_size - 1) / block_size;
- uint32_t old_blocks_cnt = (old_size + block_size - 1) / block_size;
+ uint32_t new_blocks_cnt = (uint32_t)((new_size + block_size - 1) / block_size);
+ uint32_t old_blocks_cnt = (uint32_t)((old_size + block_size - 1) / block_size);
uint32_t diff_blocks_cnt = old_blocks_cnt - new_blocks_cnt;
#if CONFIG_EXTENT_ENABLE
if ((ext4_sb_feature_incom(sb, EXT4_FINCOM_EXTENTS)) &&
@@ -1242,7 +1246,7 @@
uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode);
uint32_t block_size = ext4_sb_get_block_size(sb);
- uint32_t iblock_cnt = inode_size / block_size;
+ uint32_t iblock_cnt = (uint32_t)(inode_size / block_size);
if (inode_size % block_size != 0)
iblock_cnt++;
@@ -1362,7 +1366,7 @@
return EIO;
/* Compute offsets for the topmost level */
- uint64_t blk_off_in_lvl = iblock - fs->inode_block_limits[l - 1];
+ uint32_t blk_off_in_lvl = iblock - fs->inode_block_limits[l - 1];
current_block = ext4_inode_get_indirect_block(inode, l - 1);
uint32_t off_in_blk = blk_off_in_lvl / fs->inode_blocks_per_level[l - 1];
@@ -1434,7 +1438,7 @@
}
static int ext4_fs_set_inode_data_block_index(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, ext4_fsblk_t fblock)
+ uint32_t iblock, ext4_fsblk_t fblock)
{
struct ext4_fs *fs = inode_ref->fs;
@@ -1472,7 +1476,7 @@
uint32_t block_size = ext4_sb_get_block_size(&fs->sb);
/* Compute offsets for the topmost level */
- uint64_t blk_off_in_lvl = iblock - fs->inode_block_limits[l - 1];
+ uint32_t blk_off_in_lvl = iblock - fs->inode_block_limits[l - 1];
ext4_fsblk_t current_block =
ext4_inode_get_indirect_block(inode_ref->inode, l - 1);
uint32_t off_in_blk = blk_off_in_lvl / fs->inode_blocks_per_level[l - 1];
@@ -1495,7 +1499,8 @@
return rc;
/* Update i-node */
- ext4_inode_set_indirect_block(inode_ref->inode, l - 1, new_blk);
+ ext4_inode_set_indirect_block(inode_ref->inode, l - 1,
+ (uint32_t)new_blk);
inode_ref->dirty = true;
/* Load newly allocated block */
@@ -1610,7 +1615,7 @@
struct ext4_sblock *sb = &inode_ref->fs->sb;
uint64_t inode_size = ext4_inode_get_size(sb, inode_ref->inode);
uint32_t block_size = ext4_sb_get_block_size(sb);
- *iblock = (inode_size + block_size - 1) / block_size;
+ *iblock = (uint32_t)((inode_size + block_size - 1) / block_size);
rc = ext4_extent_get_blocks(inode_ref, *iblock, 1,
¤t_fsblk, true, NULL);
@@ -1636,7 +1641,7 @@
inode_size += block_size - (inode_size % block_size);
/* Logical blocks are numbered from 0 */
- uint32_t new_block_idx = inode_size / block_size;
+ uint32_t new_block_idx = (uint32_t)(inode_size / block_size);
/* Allocate new physical block */
ext4_fsblk_t goal, phys_block;
--- a/lwext4/ext4_inode.c
+++ b/lwext4/ext4_inode.c
@@ -216,7 +216,7 @@
max = ~max >> 32;
if (count <= max) {
- inode->blocks_count_lo = to_le32(count);
+ inode->blocks_count_lo = to_le32((uint32_t)count);
inode->osd2.linux2.blocks_high = 0;
ext4_inode_clear_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);
@@ -232,8 +232,8 @@
max = ~max >> 16;
if (count <= max) {
- inode->blocks_count_lo = to_le32(count);
- inode->osd2.linux2.blocks_high = to_le16(count >> 32);
+ inode->blocks_count_lo = to_le32((uint32_t)count);
+ inode->osd2.linux2.blocks_high = to_le16((uint16_t)(count >> 32));
ext4_inode_clear_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);
} else {
uint32_t block_count = ext4_sb_get_block_size(sb);
@@ -241,8 +241,8 @@
ext4_inode_set_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);
count = count >> (block_bits - 9);
- inode->blocks_count_lo = to_le32(count);
- inode->osd2.linux2.blocks_high = to_le16(count >> 32);
+ inode->blocks_count_lo = to_le32((uint32_t)count);
+ inode->osd2.linux2.blocks_high = to_le16((uint16_t)(count >> 32));
}
return EOK;
@@ -293,7 +293,7 @@
inode->file_acl_lo = to_le32((acl << 32) >> 32);
if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_LINUX)
- inode->osd2.linux2.file_acl_high = to_le16(acl >> 32);
+ inode->osd2.linux2.file_acl_high = to_le16((uint16_t)(acl >> 32));
}
uint32_t ext4_inode_get_direct_block(struct ext4_inode *inode, uint32_t idx)
--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -701,7 +701,7 @@
JBD_FEATURE_INCOMPAT_CSUM_V3)) {
struct jbd_block_tag3 *tag = __tag;
memset(tag, 0, sizeof(struct jbd_block_tag3));
- jbd_set32(tag, blocknr, tag_info->block);
+ jbd_set32(tag, blocknr, (uint32_t)tag_info->block);
if (JBD_HAS_INCOMPAT_FEATURE(&jbd_fs->sb,
JBD_FEATURE_INCOMPAT_64BIT))
jbd_set32(tag, blocknr_high, tag_info->block >> 32);
@@ -727,7 +727,7 @@
} else {
struct jbd_block_tag *tag = __tag;
memset(tag, 0, sizeof(struct jbd_block_tag));
- jbd_set32(tag, blocknr, tag_info->block);
+ jbd_set32(tag, blocknr, (uint32_t)tag_info->block);
if (JBD_HAS_INCOMPAT_FEATURE(&jbd_fs->sb,
JBD_FEATURE_INCOMPAT_64BIT))
jbd_set32(tag, blocknr_high, tag_info->block >> 32);
@@ -1997,7 +1997,7 @@
} else {
uint32_t *blocks =
(uint32_t *)blocks_entry;
- *blocks = to_be32(rec->lba);
+ *blocks = to_be32((uint32_t)rec->lba);
}
blocks_entry += record_len;
tag_tbl_size -= record_len;
--- a/lwext4/ext4_mkfs.c
+++ b/lwext4/ext4_mkfs.c
@@ -105,12 +105,12 @@
static uint32_t compute_inodes(struct ext4_mkfs_info *info)
{
- return DIV_ROUND_UP(info->len, info->block_size) / 4;
+ return (uint32_t)DIV_ROUND_UP(info->len, info->block_size) / 4;
}
static uint32_t compute_inodes_per_group(struct ext4_mkfs_info *info)
{
- uint32_t blocks = DIV_ROUND_UP(info->len, info->block_size);
+ uint32_t blocks = (uint32_t)DIV_ROUND_UP(info->len, info->block_size);
uint32_t block_groups = DIV_ROUND_UP(blocks, info->blocks_per_group);
uint32_t inodes = DIV_ROUND_UP(info->inodes, block_groups);
inodes = EXT4_ALIGN(inodes, (info->block_size / info->inode_size));
@@ -126,7 +126,8 @@
static uint32_t compute_journal_blocks(struct ext4_mkfs_info *info)
{
- uint32_t journal_blocks = DIV_ROUND_UP(info->len, info->block_size) / 64;
+ uint32_t journal_blocks = (uint32_t)DIV_ROUND_UP(info->len,
+ info->block_size) / 64;
if (journal_blocks < 1024)
journal_blocks = 1024;
if (journal_blocks > 32768)
@@ -149,7 +150,7 @@
aux_info->len_blocks = info->len / info->block_size;
aux_info->inode_table_blocks = DIV_ROUND_UP(info->inodes_per_group *
info->inode_size, info->block_size);
- aux_info->groups = DIV_ROUND_UP(aux_info->len_blocks -
+ aux_info->groups = (uint32_t)DIV_ROUND_UP(aux_info->len_blocks -
aux_info->first_data_block, info->blocks_per_group);
aux_info->blocks_per_ind = info->block_size / sizeof(uint32_t);
aux_info->blocks_per_dind =
@@ -297,7 +298,7 @@
{
uint32_t i;
- uint64_t bg_free_blk = 0;
+ uint32_t bg_free_blk = 0;
uint64_t sb_free_blk = 0;
for (i = 0; i < aux_info->groups; i++) {
--- a/lwext4/ext4_super.c
+++ b/lwext4/ext4_super.c
@@ -48,7 +48,7 @@
uint64_t blocks_count = ext4_sb_get_blocks_cnt(s);
uint32_t blocks_per_group = ext4_get32(s, blocks_per_group);
- uint32_t block_groups_count = blocks_count / blocks_per_group;
+ uint32_t block_groups_count = (uint32_t)(blocks_count / blocks_per_group);
if (blocks_count % blocks_per_group)
block_groups_count++;
@@ -65,7 +65,7 @@
if (bgid < block_group_count - 1)
return blocks_per_group;
- return (total_blocks - ((block_group_count - 1) * blocks_per_group));
+ return (uint32_t)(total_blocks - ((block_group_count - 1) * blocks_per_group));
}
uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid)
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -590,7 +590,7 @@
struct ext4_xattr_ibody_header *ibody_header,
struct ext4_xattr_entry *entry, void *ibody_data_ptr)
{
- entry->e_name_len = to_le32(item->name_len);
+ entry->e_name_len = (uint8_t)item->name_len;
entry->e_name_index = item->name_index;
entry->e_value_offs =
(char *)ibody_data_ptr - (char *)EXT4_XATTR_IFIRST(ibody_header);
@@ -603,7 +603,7 @@
struct ext4_xattr_entry *block_entry,
void *block_data_ptr)
{
- block_entry->e_name_len = to_le32(item->name_len);
+ block_entry->e_name_len = (uint8_t)item->name_len;
block_entry->e_name_index = item->name_index;
block_entry->e_value_offs =
(char *)block_data_ptr - (char *)block_header;