From patchwork Sat Sep 17 00:10:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Br=C3=BCns?= X-Patchwork-Id: 671193 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3sbXcj3GsQz9ssP for ; Sat, 17 Sep 2016 10:11:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 42FDDA7535; Sat, 17 Sep 2016 02:11:05 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fWS04K5-bCc8; Sat, 17 Sep 2016 02:11:05 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6301AA754A; Sat, 17 Sep 2016 02:10:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 410484B6B3 for ; Sat, 17 Sep 2016 02:10:41 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zd8d9q_c958k for ; Sat, 17 Sep 2016 02:10:41 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx-out-2.rwth-aachen.de (mx-out-2.rwth-aachen.de [134.130.5.187]) by theia.denx.de (Postfix) with ESMTPS id 047744B660 for ; Sat, 17 Sep 2016 02:10:38 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.30,347,1470693600"; d="scan'208";a="458562963" Received: from rwthex-w2-b.rwth-ad.de ([134.130.26.159]) by mx-2.rz.rwth-aachen.de with ESMTP; 17 Sep 2016 02:10:34 +0200 Received: from pebbles.fritz.box (77.182.221.0) by rwthex-w2-b.rwth-ad.de (2002:8682:1a9f::8682:1a9f) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sat, 17 Sep 2016 02:11:33 +0200 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= To: Date: Sat, 17 Sep 2016 02:10:08 +0200 X-Mailer: git-send-email 2.10.0 In-Reply-To: <20160917001012.10498-1-stefan.bruens@rwth-aachen.de> References: <20160917001012.10498-1-stefan.bruens@rwth-aachen.de> MIME-Version: 1.0 X-Originating-IP: [77.182.221.0] X-ClientProxiedBy: rwthex-w1-b.rwth-ad.de (2002:8682:1a9d::8682:1a9d) To rwthex-w2-b.rwth-ad.de (2002:8682:1a9f::8682:1a9f) Message-ID: Cc: Stephen Warren , Stefan Roese Subject: [U-Boot] [PATCH 3/7] ext4: Add helper functions for block group descriptor field access X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The helper functions encapsulate access of the block group descriptors, independent of group descriptor size. The helpers also deal with the endianess of the fields, and with split fields like free_blocks/ free_blocks_high. Signed-off-by: Stefan BrĂ¼ns --- fs/ext4/ext4_common.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/ext4_common.h | 12 ++++++++ 2 files changed, 92 insertions(+) diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 416a9db..9e5bca0 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -47,6 +47,12 @@ struct ext2_inode *g_parent_inode; static int symlinknest; #if defined(CONFIG_EXT4_WRITE) +struct ext2_block_group *ext4fs_get_group_descriptor + (const struct ext_filesystem *fs, uint32_t bg_idx) +{ + return (struct ext2_block_group *)(fs->gdtable + (bg_idx * fs->gdsize)); +} + static inline void ext4fs_sb_free_inodes_dec(struct ext2_sblock *sb) { sb->free_inodes = cpu_to_le32(le32_to_cpu(sb->free_inodes) - 1); @@ -72,6 +78,80 @@ static inline void ext4fs_bg_itable_unused_dec(struct ext2_block_group *bg) bg->bg_itable_unused = cpu_to_le16(le16_to_cpu(bg->bg_itable_unused) - 1); } +uint64_t ext4fs_sb_get_free_blocks(const struct ext2_sblock *sb) +{ + uint64_t free_blocks = le32_to_cpu(sb->free_blocks); + free_blocks += (uint64_t)le32_to_cpu(sb->free_blocks_high) << 32; + return free_blocks; +} + +void ext4fs_sb_set_free_blocks(struct ext2_sblock *sb, uint64_t free_blocks) +{ + sb->free_blocks = cpu_to_le32(free_blocks & 0xffffffff); + sb->free_blocks_high = cpu_to_le16(free_blocks >> 32); +} + +uint32_t ext4fs_bg_get_free_blocks(const struct ext2_block_group *bg, + const struct ext_filesystem *fs) +{ + uint32_t free_blocks = le16_to_cpu(bg->free_blocks); + if (fs->gdsize == 64) + free_blocks += le16_to_cpu(bg->free_blocks_high) << 16; + return free_blocks; +} + +static inline +uint32_t ext4fs_bg_get_free_inodes(const struct ext2_block_group *bg, + const struct ext_filesystem *fs) +{ + uint32_t free_inodes = le16_to_cpu(bg->free_inodes); + if (fs->gdsize == 64) + free_inodes += le16_to_cpu(bg->free_inodes_high) << 16; + return free_inodes; +} + +static inline uint16_t ext4fs_bg_get_flags(const struct ext2_block_group *bg) +{ + return le16_to_cpu(bg->bg_flags); +} + +static inline void ext4fs_bg_set_flags(struct ext2_block_group *bg, + uint16_t flags) +{ + bg->bg_flags = cpu_to_le16(flags); +} + +/* Block number of the block bitmap */ +uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg, + const struct ext_filesystem *fs) +{ + uint64_t block_nr = le32_to_cpu(bg->block_id); + if (fs->gdsize == 64) + block_nr += (uint64_t)le32_to_cpu(bg->block_id_high) << 32; + return block_nr; +} + +/* Block number of the inode bitmap */ +uint64_t ext4fs_bg_get_inode_id(const struct ext2_block_group *bg, + const struct ext_filesystem *fs) +{ + uint64_t block_nr = le32_to_cpu(bg->inode_id); + if (fs->gdsize == 64) + block_nr += (uint64_t)le32_to_cpu(bg->inode_id_high) << 32; + return block_nr; +} + +/* Block number of the inode table */ +uint64_t ext4fs_bg_get_inode_table_id(const struct ext2_block_group *bg, + const struct ext_filesystem *fs) +{ + uint64_t block_nr = le32_to_cpu(bg->inode_table_id); + if (fs->gdsize == 64) + block_nr += + (uint64_t)le32_to_cpu(bg->inode_table_id_high) << 32; + return block_nr; +} + uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n) { uint32_t res = size / n; diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h index cc9d0c5..99d49e6 100644 --- a/fs/ext4/ext4_common.h +++ b/fs/ext4/ext4_common.h @@ -74,5 +74,17 @@ void ext4fs_allocate_blocks(struct ext2_inode *file_inode, unsigned int total_remaining_blocks, unsigned int *total_no_of_block); void put_ext4(uint64_t off, void *buf, uint32_t size); +struct ext2_block_group *ext4fs_get_group_descriptor + (const struct ext_filesystem *fs, uint32_t bg_idx); +uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg, + const struct ext_filesystem *fs); +uint64_t ext4fs_bg_get_inode_id(const struct ext2_block_group *bg, + const struct ext_filesystem *fs); +uint64_t ext4fs_bg_get_inode_table_id(const struct ext2_block_group *bg, + const struct ext_filesystem *fs); +uint64_t ext4fs_sb_get_free_blocks(const struct ext2_sblock *sb); +void ext4fs_sb_set_free_blocks(struct ext2_sblock *sb, uint64_t free_blocks); +uint32_t ext4fs_bg_get_free_blocks(const struct ext2_block_group *bg, + const struct ext_filesystem *fs); #endif #endif