X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=fs%2Fext4%2Fext4_journal.c;h=148593da7fefacc79fb6ce2510e47a807e0c3e4d;hb=809e0e398a91db7bf8b4d6259d9bfc6fbd6bce83;hp=8a252d66c336d813d6d13ddaee0f2d56877d8cbf;hpb=5675b509165b67465a20e5cf71e07f40b449ef0c;p=u-boot diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c index 8a252d66c3..148593da7f 100644 --- a/fs/ext4/ext4_journal.c +++ b/fs/ext4/ext4_journal.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2011 - 2012 Samsung Electronics * EXT4 filesystem implementation in Uboot by @@ -10,23 +11,6 @@ * Written by Stephen C. Tweedie * * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved - * This file is part of the Linux kernel and is made available under - * the terms of the GNU General Public License, version 2, or at your - * option, any later version, incorporated herein by reference. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include @@ -37,7 +21,7 @@ static struct revoke_blk_list *revk_blk_list; static struct revoke_blk_list *prev_node; -static int first_node = TRUE; +static int first_node = true; int gindex; int gd_index; @@ -167,7 +151,7 @@ int ext4fs_log_gdt(char *gd_table) * journal_buffer -- Buffer containing meta data * blknr -- Block number on disk of the meta data buffer */ -int ext4fs_log_journal(char *journal_buffer, long int blknr) +int ext4fs_log_journal(char *journal_buffer, uint32_t blknr) { struct ext_filesystem *fs = get_fs(); short i; @@ -199,14 +183,18 @@ int ext4fs_log_journal(char *journal_buffer, long int blknr) * metadata_buffer -- Buffer containing meta data * blknr -- Block number on disk of the meta data buffer */ -int ext4fs_put_metadata(char *metadata_buffer, long int blknr) +int ext4fs_put_metadata(char *metadata_buffer, uint32_t blknr) { struct ext_filesystem *fs = get_fs(); if (!metadata_buffer) { printf("Invalid input arguments %s\n", __func__); return -EINVAL; } - dirty_block_ptr[gd_index]->buf = zalloc(fs->blksz); + if (dirty_block_ptr[gd_index]->buf) + assert(dirty_block_ptr[gd_index]->blknr == blknr); + else + dirty_block_ptr[gd_index]->buf = zalloc(fs->blksz); + if (!dirty_block_ptr[gd_index]->buf) return -ENOMEM; memcpy(dirty_block_ptr[gd_index]->buf, metadata_buffer, fs->blksz); @@ -231,7 +219,7 @@ void print_revoke_blks(char *revk_blk) printf("total bytes %d\n", max); while (offset < max) { - blocknr = be32_to_cpu(*((long int *)(revk_blk + offset))); + blocknr = be32_to_cpu(*((__be32 *)(revk_blk + offset))); printf("revoke blknr is %ld\n", blocknr); offset += 4; } @@ -268,10 +256,10 @@ void ext4fs_push_revoke_blk(char *buffer) return; memcpy(node->content, buffer, fs->blksz); - if (first_node == TRUE) { + if (first_node == true) { revk_blk_list = node; prev_node = node; - first_node = FALSE; + first_node = false; } else { prev_node->next = node; prev_node = node; @@ -298,7 +286,7 @@ void ext4fs_free_revoke_blks(void) revk_blk_list = NULL; prev_node = NULL; - first_node = TRUE; + first_node = true; } int check_blknr_for_revoke(long int blknr, int sequence_no) @@ -318,7 +306,7 @@ int check_blknr_for_revoke(long int blknr, int sequence_no) max = be32_to_cpu(header->r_count); while (offset < max) { - blocknr = be32_to_cpu(*((long int *) + blocknr = be32_to_cpu(*((__be32 *) (revk_blk + offset))); if (blocknr == blknr) goto found; @@ -360,13 +348,14 @@ void recover_transaction(int prev_desc_logical_no) (struct ext2_inode *)&inode_journal); blknr = read_allocated_block((struct ext2_inode *) &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; jdb = (struct journal_header_t *) temp_buff; ofs = sizeof(struct journal_header_t); do { - tag = (struct ext3_journal_block_tag *)&p_jdb[ofs]; + tag = (struct ext3_journal_block_tag *)(p_jdb + ofs); ofs += sizeof(struct ext3_journal_block_tag); if (ofs > fs->blksz) @@ -384,9 +373,9 @@ void recover_transaction(int prev_desc_logical_no) continue; } 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); - put_ext4((uint64_t)(be32_to_cpu(tag->block) * fs->blksz), + put_ext4((uint64_t)((uint64_t)be32_to_cpu(tag->block) * (uint64_t)fs->blksz), metadata_buff, (uint32_t) fs->blksz); } while (!(flags & EXT3_JOURNAL_FLAG_LAST_TAG)); fail: @@ -410,7 +399,7 @@ int ext4fs_check_journal_state(int recovery_flag) int transaction_state = TRANSACTION_COMPLETE; int prev_desc_logical_no = 0; int curr_desc_logical_no = 0; - int ofs, flags, block; + int ofs, flags; struct ext2_inode inode_journal; struct journal_superblock_t *jsb = NULL; struct journal_header_t *jdb = NULL; @@ -431,10 +420,11 @@ int ext4fs_check_journal_state(int recovery_flag) ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal); 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; - if (fs->sb->feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) { + if (le32_to_cpu(fs->sb->feature_incompat) & EXT3_FEATURE_INCOMPAT_RECOVER) { if (recovery_flag == RECOVER) printf("Recovery required\n"); } else { @@ -453,10 +443,9 @@ int ext4fs_check_journal_state(int recovery_flag) i = be32_to_cpu(jsb->s_first); while (1) { - block = be32_to_cpu(jsb->s_first); blknr = read_allocated_block(&inode_journal, i); 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); jdb = (struct journal_header_t *) temp_buff1; @@ -477,7 +466,7 @@ int ext4fs_check_journal_state(int recovery_flag) ofs = sizeof(struct journal_header_t); do { tag = (struct ext3_journal_block_tag *) - &p_jdb[ofs]; + (p_jdb + ofs); ofs += sizeof(struct ext3_journal_block_tag); if (ofs > fs->blksz) break; @@ -532,23 +521,24 @@ int ext4fs_check_journal_state(int recovery_flag) end: if (recovery_flag == RECOVER) { + uint32_t new_feature_incompat; jsb->s_start = cpu_to_be32(1); jsb->s_sequence = cpu_to_be32(be32_to_cpu(jsb->s_sequence) + 1); /* get the superblock */ - ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE, - (char *)fs->sb); - fs->sb->feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER; + ext4_read_superblock((char *)fs->sb); + new_feature_incompat = le32_to_cpu(fs->sb->feature_incompat); + new_feature_incompat |= EXT3_FEATURE_INCOMPAT_RECOVER; + fs->sb->feature_incompat = cpu_to_le32(new_feature_incompat); /* Update the super block */ put_ext4((uint64_t) (SUPERBLOCK_SIZE), (struct ext2_sblock *)fs->sb, (uint32_t) SUPERBLOCK_SIZE); - ext4fs_devread(SUPERBLOCK_SECTOR, 0, SUPERBLOCK_SIZE, - (char *)fs->sb); + ext4_read_superblock((char *)fs->sb); blknr = read_allocated_block(&inode_journal, EXT2_JOURNAL_SUPERBLOCK); - put_ext4((uint64_t) (blknr * fs->blksz), + put_ext4((uint64_t) ((uint64_t)blknr * (uint64_t)fs->blksz), (struct journal_superblock_t *)temp_buff, (uint32_t) fs->blksz); ext4fs_free_revoke_blks(); @@ -577,7 +567,8 @@ static void update_descriptor_block(long int blknr) ext4fs_read_inode(ext4fs_root, EXT2_JOURNAL_INO, &inode_journal); jsb_blknr = read_allocated_block(&inode_journal, 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; jdb.h_blocktype = cpu_to_be32(EXT3_JOURNAL_DESCRIPTOR_BLOCK); @@ -606,7 +597,7 @@ static void update_descriptor_block(long int blknr) tag.flags = cpu_to_be32(EXT3_JOURNAL_FLAG_LAST_TAG); memcpy(temp - sizeof(struct ext3_journal_block_tag), &tag, sizeof(struct ext3_journal_block_tag)); - put_ext4((uint64_t) (blknr * fs->blksz), buf, (uint32_t) fs->blksz); + put_ext4((uint64_t) ((uint64_t)blknr * (uint64_t)fs->blksz), buf, (uint32_t) fs->blksz); free(temp_buff); free(buf); @@ -624,10 +615,12 @@ static void update_commit_block(long int blknr) if (!temp_buff) 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, 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; jdb.h_blocktype = cpu_to_be32(EXT3_JOURNAL_COMMIT_BLOCK); @@ -639,7 +632,7 @@ static void update_commit_block(long int blknr) return; } memcpy(buf, &jdb, sizeof(struct journal_header_t)); - put_ext4((uint64_t) (blknr * fs->blksz), buf, (uint32_t) fs->blksz); + put_ext4((uint64_t) ((uint64_t)blknr * (uint64_t)fs->blksz), buf, (uint32_t) fs->blksz); free(temp_buff); free(buf);