From patchwork Tue Dec 23 01:16:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1062 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=1766452611; bh=fv0WcbVAYZ4ZiJsmNNPFPUKS9rbqTLoqDaobvKC+Aow=; 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=JdJmdNuL4vmXmSuBVrjTnd/ohpiq8N35mcLMv5IZamCgoPjCljAlD0rYtAc7G+SyY cpLKoN99KGgG1YVkXxkM5hDQGniErphVYeN4JQScMBONkvcDaSkObcv+UBGQUgqLF0 5gJRnZR1Kp15jJZiAZUnRaUfc6BT5s+u+LdR9ddVqy02BdVUewi5XxsK0Se3YoO/7P gRPHx0+oBZK+qtuG3vaSkf8BnUSmwn5tiQdl6EitrOse389k+G93SME+SQ2LfK06+W /e4JqWQDdKfrah3nYXXdxie1HfxquvR6EqeU8HsEZockGpyI94pv6Z5WhqR/+6r/gq 8FSA18YmffmSw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6431664C17 for ; Mon, 22 Dec 2025 18:16:51 -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 B9NO3Dd0oV1s for ; Mon, 22 Dec 2025 18:16:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766452610; bh=fv0WcbVAYZ4ZiJsmNNPFPUKS9rbqTLoqDaobvKC+Aow=; 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=PWM0NKIc0+A59+0uobfBn+nOiSTjdHKs0M+vJsP+z6D4mEdTjZbFlxQx8gnFAetsp t4uCiJocBQDDVu5M6xzsXn4JknMFL4hJ4zVESnZNOB8MUKEix+oGucMbhRo4RGYYuv xsKw4JZVVv/r1kUtEGcdbyi60t1QPe597kjOw3kXyNKenlXhmRBIz2dbBe125+vvMJ ARjsNjccEHJBUdtWjX4wgcrSqQDT+S1Uf1zUREMm1BaTapcm1F6Hx1jsRv7n3vG5LA xdSopTU1KFzYV1X+aa2CdeUOcagXstwJ9xH/uBXpKIXTzMwQIBCC9g+VADKbMj0/qK SZCFu96GF+1Uw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5DC4264DA8 for ; Mon, 22 Dec 2025 18:16:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766452608; bh=YG+Khfr4T7OmnAmzcJrVxGQQnhSn9GesK5o6/BIhsyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+oefkc4nmbvu0fIByMj4uwnGfB6m3+I32ZpIOKUe1OD/fZsboO4Dytlu1PG4Nhx8 lD1RRiHF4usP9B4Pgb8Z5ivG6WdDmQCpLb66i9W82QrZSh6xRqd9P/WS3elaLHU6Ax p62i4AVk2bWLu/GWrjd3IhtAqaIKxnG54iiZ2OywII/tmgnHId5jKb9qoMb7nmeVGq 1OQtnOpzPu3CM2QuG4pZNcgOCx7wMRQ/Hnm7G7j0HturcTUVnrkvGPDMJ8/NFmiSm5 Wq7l7l4zGxuzN6rASSbdx9d2WQvuMGH9r7wfUcFczHyzcPpmwN3V8Jt5eny8Qlx3ON gdQYrKw7s26fw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6038964DBC; Mon, 22 Dec 2025 18:16:48 -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 o64XWwBsgrZA; Mon, 22 Dec 2025 18:16:48 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766452606; bh=ZDWs5zeSfL97vavAvRkxqjEOzSHk4J0uL8nsbtoXt34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lrfd1xibjrJ4L+xw7bGPurIC0SfEguaiP67CZwZwU3mp0ofH75nfOE9QDne42O3nx 594gm8TPmUmWYxkampje3PUsrZe2o+uhyqron4AaPBSIwcZx1OwBFZyU9R6DCDQzew G3fviNiVr4vBwQEX28hwsXFWvHoH5CvgsCBryPZYtMYycno5gRNpTchVvwkP0CeBEW XtOk3YdaP3NZ8gXPCedTFUe4vhKoPvpx3SGtADNx2iXhB91wqFa/2mOkdfD88yh199 T2wHdDLA2KaGBIIRGm8L50dRRR02O2YvNwLQw871cpswsfw5D/HpM8Npp/GxVgd3JW 6qaAYcD+E/8PQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 61DC164DA9; Mon, 22 Dec 2025 18:16:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 22 Dec 2025 18:16:18 -0700 Message-ID: <20251223011632.380026-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251223011632.380026-1-sjg@u-boot.org> References: <20251223011632.380026-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: HOPFH3KSJGXXBA7Z6V45XIZT7Y7D2IUN X-Message-ID-Hash: HOPFH3KSJGXXBA7Z6V45XIZT7Y7D2IUN 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: Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/12] ext4l: Add write support and buffer mapping for mount 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 ext4l_write_block() to enable writing blocks to disk, which is needed for ext4_commit_super() during read-write mounts. Also update submit_bh() to call the write function and return proper error codes. Set the BH_Mapped flag in sb_getblk() and bdev_getblk() since ext4 checks this flag in ext4_commit_super() to verify the buffer is valid. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 2 +- fs/ext4l/support.c | 55 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 4dd03494586..6dd498c8f52 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2150,7 +2150,7 @@ struct blockgroup_lock { }; /* Buffer submission stubs - declarations for stub.c implementations */ -void submit_bh(int op_flags, struct buffer_head *bh); +int submit_bh(int op_flags, struct buffer_head *bh); struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block, unsigned int size, gfp_t gfp); int trylock_buffer(struct buffer_head *bh); diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 9e93426b565..05efa8d067c 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -352,6 +352,40 @@ int ext4l_read_block(sector_t block, size_t size, void *buffer) return 0; } +/** + * ext4l_write_block() - Write a block to the block device + * @block: Block number (filesystem block, not sector) + * @size: Block size in bytes + * @buffer: Source buffer + * Return: 0 on success, negative on error + */ +int ext4l_write_block(sector_t block, size_t size, void *buffer) +{ + struct blk_desc *blk_dev; + struct disk_partition *part; + lbaint_t sector; + lbaint_t sector_count; + unsigned long n; + + blk_dev = ext4l_get_blk_dev(); + part = ext4l_get_partition(); + if (!blk_dev) + return -EIO; + + /* Convert block to sector */ + sector = (block * size) / blk_dev->blksz + part->start; + sector_count = size / blk_dev->blksz; + + if (sector_count == 0) + sector_count = 1; + + n = blk_dwrite(blk_dev, sector, sector_count, buffer); + if (n != sector_count) + return -EIO; + + return 0; +} + /** * sb_getblk() - Get a buffer, using cache if available * @sb: Super block @@ -379,6 +413,9 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block) bh->b_bdev = sb->s_bdev; bh->b_size = sb->s_blocksize; + /* Mark buffer as having a valid disk mapping */ + set_buffer_mapped(bh); + /* Don't read - just allocate with zeroed data */ memset(bh->b_data, '\0', bh->b_size); @@ -474,6 +511,9 @@ struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block, bh->b_bdev = bdev; bh->b_size = size; + /* Mark buffer as having a valid disk mapping */ + set_buffer_mapped(bh); + /* Don't read - just allocate with zeroed data */ memset(bh->b_data, 0, bh->b_size); @@ -520,8 +560,9 @@ struct buffer_head *__bread(struct block_device *bdev, sector_t block, * submit_bh() - Submit a buffer_head for I/O * @op: Operation (REQ_OP_READ, REQ_OP_WRITE, etc.) * @bh: Buffer head to submit + * Return: 0 on success, negative on error */ -void submit_bh(int op, struct buffer_head *bh) +int submit_bh(int op, struct buffer_head *bh) { int ret; int op_type = op & 0xff; /* Mask out flags, keep operation type */ @@ -530,13 +571,19 @@ void submit_bh(int op, struct buffer_head *bh) ret = ext4l_read_block(bh->b_blocknr, bh->b_size, bh->b_data); if (ret) { clear_buffer_uptodate(bh); - return; + return ret; } set_buffer_uptodate(bh); } else if (op_type == REQ_OP_WRITE) { - /* Write support not implemented yet */ - clear_buffer_uptodate(bh); + ret = ext4l_write_block(bh->b_blocknr, bh->b_size, bh->b_data); + if (ret) { + clear_buffer_uptodate(bh); + return ret; + } + /* Mark buffer as clean (not dirty) after write */ } + + return 0; } /**