From patchwork Wed Jan 7 23:44:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1334 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767829629; bh=LTWPYu3i3seAOK9NjKVqarsyfvAC7Mzkl77A3gmn+RU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=JeIfHACPID12pyU+8Y+0O/txPlcpvVIMJ0MWYnCnURacwBYNG04M2eLHSRxDtj2p7 RIZemt0YBQ3pFd9F+/g6mfqeHxI43IMsdRQA2Y5Q7WL1+pIczDmzFsLyyw8midmW4o NRV4lAQjQ2EY/QUuvLpQCP6pDKyqjKQZG+6oGeSdE3NMkcvDF9cgjoy2GPfEL7dTdx G1673j7n/ji3tqBphCDaZ3kf/qgiXibNtZb64UUU14qwtIKa7Ux2xitM3w8vjv6Nsl 6rW55syd8Yl2fwF3ze5YLWi/vcv0ksf+GSYDGSR1TNn3aWfN/LWvG0lj23WcqbA4hO RyXeLEgKQSpDQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6B91E691A2 for ; Wed, 7 Jan 2026 16:47:09 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ysetT8OwaYMr for ; Wed, 7 Jan 2026 16:47:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767829629; bh=LTWPYu3i3seAOK9NjKVqarsyfvAC7Mzkl77A3gmn+RU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=JeIfHACPID12pyU+8Y+0O/txPlcpvVIMJ0MWYnCnURacwBYNG04M2eLHSRxDtj2p7 RIZemt0YBQ3pFd9F+/g6mfqeHxI43IMsdRQA2Y5Q7WL1+pIczDmzFsLyyw8midmW4o NRV4lAQjQ2EY/QUuvLpQCP6pDKyqjKQZG+6oGeSdE3NMkcvDF9cgjoy2GPfEL7dTdx G1673j7n/ji3tqBphCDaZ3kf/qgiXibNtZb64UUU14qwtIKa7Ux2xitM3w8vjv6Nsl 6rW55syd8Yl2fwF3ze5YLWi/vcv0ksf+GSYDGSR1TNn3aWfN/LWvG0lj23WcqbA4hO RyXeLEgKQSpDQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 46E1469195 for ; Wed, 7 Jan 2026 16:47:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767829626; bh=bWZfDHLbD8Ig1uO2GoAWo2HiWxuSF3yW75NqjJyq0Iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aMbOKRge6u+TFMecIEIY5ZG17k9kxwuwSLE0AT57EcrfBtCUfKSLdpkbxIi3/LLzz IqHWyNxHG6m3TKRggJsPPuzx3y5wPFj7p+5yDsjIt6pm82tXMY0b+oNhq2RmT7KvPl gnVj3DOoxRn9ZtEv0IB+vQhDP/+lea3zGq4eXDUZUlCNIE4qI7UtaGQ9FFsov7um3E vJ5KNySM56qqTL1YWK5yp1DsG3D5lMeYGHFT8VeU8Bi2/olk4sAxtvXPu5EqpSmM4R B7fu08tBFZ38L43MyySUljaiXFAPjTS+vRaS4pO1wUNser+PMiIBk1KKYA4bDlXXRi 16ul5JBYUKyfg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0D33D69187; Wed, 7 Jan 2026 16:47:06 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 78MLeIXAT7-g; Wed, 7 Jan 2026 16:47:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767829621; bh=/5FLomm/fridi9QJPSM6BVscZRyc/JCxMl+sQ6Fp89o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tATteQdVyGX2l6d8Q78XGJ+OHV8VQWSL5VGHWnJfUZweGnNVudK8pGRB4KuqJ1HaX 8RB3ANvmeu/KBg+odr62G4Y8idSdc8J+HWVq1sCOKMwI/QWfZbMGzw4HowIN08VHoY Ev15yihHvebpfrOegs2ho3WwOdIYbDHkUiUnSzXKwiHJyHAAp3/9i9hNQzQN05tYoM 8pRrS+kYY3zBByJtt1ZRb2mcD1QLMRv2cdMT7NU5HUmZixHNhl+WdGaEtcWT7imekh QlQ5KfE0edP8G5nhJBwGdLpN7fqnvGQU0inzIAk9m8a7yrBndXr/t9dTlRfRoxukhu KUQwCIytwRUzA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 98B1669146; Wed, 7 Jan 2026 16:47:01 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 7 Jan 2026 16:44:12 -0700 Message-ID: <20260107234426.3508161-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260107234426.3508161-1-sjg@u-boot.org> References: <20260107234426.3508161-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5MFKDNM35VKMX4SHG3JZ4WYV2CUQNABH X-Message-ID-Hash: 5MFKDNM35VKMX4SHG3JZ4WYV2CUQNABH X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 2/9] fs: ext4l: Add block conversion macros and use them List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add EXT4_LBLK_TO_B(), EXT4_LBLK_TO_PG() and EXT4_PG_TO_LBLK() macros to ext4.h to match the Linux kernel API. These convert between logical block numbers, byte offsets and page indices. Update inode.c to use these macros instead of inline shift operations, aligning the code with the Linux kernel source. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4.h | 8 ++++++++ fs/ext4l/inode.c | 15 +++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/ext4l/ext4.h b/fs/ext4l/ext4.h index a1c80dd7cdf..47054daffc2 100644 --- a/fs/ext4l/ext4.h +++ b/fs/ext4l/ext4.h @@ -342,6 +342,14 @@ struct ext4_io_submit { blkbits)) #define EXT4_B_TO_LBLK(inode, offset) \ (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits) +#define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits) + +/* Translate a block number to a page index */ +#define EXT4_LBLK_TO_PG(inode, lblk) (EXT4_LBLK_TO_B((inode), (lblk)) >> \ + PAGE_SHIFT) +/* Translate a page index to a block number */ +#define EXT4_PG_TO_LBLK(inode, pnum) (((loff_t)(pnum) << PAGE_SHIFT) >> \ + (inode)->i_blkbits) /* Translate a block number to a cluster number */ #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) diff --git a/fs/ext4l/inode.c b/fs/ext4l/inode.c index 415c9f7f62f..7001c7299cd 100644 --- a/fs/ext4l/inode.c +++ b/fs/ext4l/inode.c @@ -803,9 +803,8 @@ found: !(flags & EXT4_GET_BLOCKS_ZERO) && !ext4_is_quota_file(inode) && ext4_should_order_data(inode)) { - loff_t start_byte = - (loff_t)map->m_lblk << inode->i_blkbits; - loff_t length = (loff_t)map->m_len << inode->i_blkbits; + loff_t start_byte = EXT4_LBLK_TO_B(inode, map->m_lblk); + loff_t length = EXT4_LBLK_TO_B(inode, map->m_len); if (flags & EXT4_GET_BLOCKS_IO_SUBMIT) ret = ext4_jbd2_inode_add_wait(handle, inode, @@ -2384,7 +2383,7 @@ static int mpage_submit_partial_folio(struct mpage_da_data *mpd) * The mapped position should be within the current processing folio * but must not be the folio start position. */ - pos = ((loff_t)mpd->map.m_lblk) << inode->i_blkbits; + pos = EXT4_LBLK_TO_B(inode, mpd->map.m_lblk); if (WARN_ON_ONCE((folio_pos(folio) == pos) || !folio_contains(folio, pos >> PAGE_SHIFT))) return -EINVAL; @@ -2441,7 +2440,7 @@ static int mpage_map_and_submit_extent(handle_t *handle, io_end_vec = ext4_alloc_io_end_vec(io_end); if (IS_ERR(io_end_vec)) return PTR_ERR(io_end_vec); - io_end_vec->offset = ((loff_t)map->m_lblk) << inode->i_blkbits; + io_end_vec->offset = EXT4_LBLK_TO_B(inode, map->m_lblk); do { err = mpage_map_one_extent(handle, mpd); if (err < 0) { @@ -3481,8 +3480,8 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev; else iomap->bdev = inode->i_sb->s_bdev; - iomap->offset = (u64) map->m_lblk << blkbits; - iomap->length = (u64) map->m_len << blkbits; + iomap->offset = EXT4_LBLK_TO_B(inode, map->m_lblk); + iomap->length = EXT4_LBLK_TO_B(inode, map->m_len); if ((map->m_flags & EXT4_MAP_MAPPED) && !ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) @@ -3715,7 +3714,7 @@ retry: * i_disksize out to i_size. This could be beyond where direct I/O is * happening and thus expose allocated blocks to direct I/O reads. */ - else if (((loff_t)map->m_lblk << blkbits) >= i_size_read(inode)) + else if (EXT4_LBLK_TO_B(inode, map->m_lblk) >= i_size_read(inode)) m_flags = EXT4_GET_BLOCKS_CREATE; else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) m_flags = EXT4_GET_BLOCKS_IO_CREATE_EXT;