From patchwork Fri Jan 2 00:50:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1186 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=1767315162; bh=2cDDP2brL4IYfQFv4iQmyR7T10hloeT0GvdceTGblCQ=; 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=giv/CdPYSW3A9b1myY/VhktmaA1T2H0rbJ+ye5PDk7fHReFZF2/JkUQdBZI6of4Wz z7zL6bKrID47mKsXzwsQhlQdNoYAT9cB8u4bVrL09LpSmj9RdGFenQazkp9MGnBUwX rKhuCGlSNBH4qlfuayXp+1CMz78L5b1GQtXLyDhyyrf4MNDJhm1qFq0YFl2j+UXkr7 Udhtqa9GFhupv6sKcH75OxQvPtcBCwhOmv0OVilc9IjDICnf93g/pI6xj77NfYKFBk gvN84lqTCc79bFQtymMotg5sJxRWpuKTMJJlMFzgbcVp6zpN6wMxVoL+mqKHdvQrNn TTV3PXWKm8qLA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C2E6568313 for ; Thu, 1 Jan 2026 17:52:42 -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 VN41m7EgDE7V for ; Thu, 1 Jan 2026 17:52:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315162; bh=2cDDP2brL4IYfQFv4iQmyR7T10hloeT0GvdceTGblCQ=; 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=giv/CdPYSW3A9b1myY/VhktmaA1T2H0rbJ+ye5PDk7fHReFZF2/JkUQdBZI6of4Wz z7zL6bKrID47mKsXzwsQhlQdNoYAT9cB8u4bVrL09LpSmj9RdGFenQazkp9MGnBUwX rKhuCGlSNBH4qlfuayXp+1CMz78L5b1GQtXLyDhyyrf4MNDJhm1qFq0YFl2j+UXkr7 Udhtqa9GFhupv6sKcH75OxQvPtcBCwhOmv0OVilc9IjDICnf93g/pI6xj77NfYKFBk gvN84lqTCc79bFQtymMotg5sJxRWpuKTMJJlMFzgbcVp6zpN6wMxVoL+mqKHdvQrNn TTV3PXWKm8qLA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AFB5868F53 for ; Thu, 1 Jan 2026 17:52:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315160; bh=MZXot1Z45o4hEVgXBAeWYuj6J1fAfe70RiH1rfnb1u4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwwtC9xrQk6srXEyxjOcJxwzYbWZOgc85ZqJZNlbkMKDl9BBAJ98nsPyzJxNDMyfV f9BnWCyLzb1VCgbRZ58mUx1sx8ECyZmnDca1cuYsWFUeDz00cVFYZQ6Lt2Ou5twkGt Nk6/fTI7RlilK8AzzhVvAJ97fbdiKikKRWmGS1KPtcHYlJUkejpdu2bDayXVsi4+lk Tc6hjbKqDYDsOh8FcAHxGE2u371rM6r+gVSyNWcSkbPv039N/GrLwpEQM2Je+2t5JI i4KWbdP+IHPFsZ+P3M4kaaHricAi3i8gp8CHrcoM4Vd9NeY3NFn+x277x6YfYJCnOC NEUp24nr/BRXA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 98EEF68F53; Thu, 1 Jan 2026 17:52:40 -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 7DxvDO7dCD6V; Thu, 1 Jan 2026 17:52:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767315156; bh=6PHYCKdYUFB9h4N5JRD6dKyjXvmVJ7WcneCs72Th9hQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8abCmMssRCAUJ/qskb/4GCU7RoeAAw0gzOVxqyYEoa/dTN+Ofb7N8Pw3tvu329zN AztXgx06/EJf7jZFgTSqp8hMPGEj6lDYF5Q9qQE8lvqnx+2jakAD6JWpPPxrO6aAWr PVz8DLweBuYHgA4xntuzNH/IoUtGhz6PlW4wu9va37jL0MhQFKwGyvpsOFencY9Uxs 2DpZp2BN3qoog/ArAw1bYuxtyEMeDNlIeogScHnuMY7eBtyrKn+MUUx9okkd2QjOhq 8l9ve1q6LQsuMZDMVD+P7i89Is4BfZq1I/cnl8otKB30z63OLSLnHWUL4LAqv2tXTn 8a8KS0SFFIVpQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2C0E768313; Thu, 1 Jan 2026 17:52:36 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Thu, 1 Jan 2026 17:50:52 -0700 Message-ID: <20260102005112.552256-23-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260102005112.552256-1-sjg@u-boot.org> References: <20260102005112.552256-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: X6B4HSBU6QGEZAH7OALG45AXSGJ74UPC X-Message-ID-Hash: X6B4HSBU6QGEZAH7OALG45AXSGJ74UPC 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 22/30] ext4l: Add support for read-only devices 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 Some block devices, such as LUKS-encrypted volumes mounted via blkmap_crypt, only support read access. When ext4l attempts to write the superblock during mount, the write fails and causes mount to fail. Add a way to detect this read-only device detection: - Test writes during mount by writing back the superblock data; if the write fails, mark the device as read-only - Update bdev_read_only() to return the actual read_only status - Update sb_rdonly() to check the SB_RDONLY flag This allows ext4l to successfully mount read-only devices like LUKS volumes for read access. We could perhaps have a read-only flag in the block device, but that is left for another day. Co-developed-by: Claude Signed-off-by: Simon Glass --- (no changes since v1) fs/ext4l/ext4_uboot.h | 8 ++++---- fs/ext4l/interface.c | 14 ++++++++++++-- include/linux/fs.h | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index a5c0eba6f15..c29f582b1e0 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -315,8 +315,8 @@ extern struct user_namespace init_user_ns; /* might_sleep - stub */ #define might_sleep() do { } while (0) -/* sb_rdonly - U-Boot mounts filesystems read-write */ -#define sb_rdonly(sb) 0 +/* sb_rdonly - check if filesystem is mounted read-only */ +#define sb_rdonly(sb) ((sb)->s_flags & SB_RDONLY) /* Trace stubs */ #define trace_ext4_journal_start_inode(...) do { } while (0) @@ -696,10 +696,10 @@ struct super_block { struct list_head s_inodes; }; -/* Block device read-only check - stub */ +/* Block device read-only check */ static inline int bdev_read_only(struct block_device *bdev) { - return 0; + return bdev ? bdev->read_only : 0; } /* kuid_t and kgid_t - from linux/cred.h */ diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 301e28af3b8..c60ea7db684 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -401,8 +401,6 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, goto err_free_buf; } - free(buf); - /* Save device info for later operations */ ext4l_dev_desc = fs_dev_desc; if (fs_partition) @@ -411,6 +409,18 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, /* Set block device for buffer I/O */ ext4l_set_blk_dev(fs_dev_desc, fs_partition); + /* + * Test if device supports writes by writing back the same data. + * If write returns 0, the device is read-only (e.g. LUKS/blkmap_crypt) + */ + if (blk_dwrite(fs_dev_desc, + (part_offset + BLOCK_SIZE) / fs_dev_desc->blksz, + 2, buf) != 2) { + sb->s_bdev->read_only = true; + sb->s_flags |= SB_RDONLY; + } + free(buf); + /* Mount the filesystem */ ret = ext4_fill_super(sb, fc); if (ret) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 0bf0d3b0379..54c0148ee72 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -76,6 +76,7 @@ struct block_device { void *bd_disk; struct super_block *bd_super; dev_t bd_dev; + bool read_only; }; /* errseq functions - stubs */