From patchwork Wed Dec 31 22:29:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1156 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=1767220304; bh=NpdfDkEw/grtyabkYE9Auw2Tn13ZYbrM2ddRWdc6jEA=; 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=pFuKesDAlFI2AlbOSiUlwXe4CwFKuVEHO8FWZCWVL3zc55ncD6dhR56UcXOqCZbo/ C+jcyv4GjbDTDA3NIfkjdX8G0RjfFUI2+A5NLdv4DmLkq+DIQy4VouUyPvoES63p5b Hw2f8+tDQezTX4VGfFXfb4aiqNOjKeY8v0Eh+vj0yKrgg0AfSWpPzWaKX0ydjdFVWF iMTi+4BSupIP/1xYlkXrAS5A4+pKItSCG+fkO2790QKf9/+YgYVOwsYEe2O4wzG2xC /6vuf5nPXXti0V2y5h78D9fFgAtX08XL0509O11AMG5LJEsvCXcTTHSoc1YPhCaqv8 klkYkzeurTIcQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D760368FE9 for ; Wed, 31 Dec 2025 15:31:44 -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 ieugnH6GABZy for ; Wed, 31 Dec 2025 15:31:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220302; bh=NpdfDkEw/grtyabkYE9Auw2Tn13ZYbrM2ddRWdc6jEA=; 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=hM0ceN/0XN5fdJD896cVBRzqXP5cC2wpJ5w1RioSyvy9/P3EouRbHVrcERbBiYa7L IJVWHVvilKToIrVBgakVIYqgZgyOrepEwd1Fetbfqa1sM55HSxEf0Miu3i2Cx21syO wRTZYMWBBvl2IPhxIoz/gzShWhMkhb8RaV1HdRZYfCus2oJktmFyQNmdGh7CI0pos4 S063f3eIOgE4xuLOlmTy8zt39l1BD3prqynTMzc/+jdNFxMfhe7s1CQnJaP4xyMcEB AIW/Bq1H48UvATfMDJgZOMCsjyOxHFH3+4i4X+bW5HX3smJe8N3S7GjtXwPMQgTzO1 tPR8TjNWF8XaQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D1B1268FE3 for ; Wed, 31 Dec 2025 15:31:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220301; bh=1sJfDaF46I6M3in63PXT9NP5pQXeuX+aQqAoIv+w7W0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxmhxBilJ3b43znqXy2s8zE1/N1JmhuOeGrJXI4RpD+E95lNAzQKzW0ehuqiCHJp9 dvIEeoTyv9dEdkg04ckBMczf/GKfM7vKgRihFd0KpdGG9Fwl13ixXiv9KpA8c7tLUy 4HfEmWPsyqHqjYhGxxNFVTFyM069chf9NITK8UGrQV4c66jXkxZB8tFz/eep361zqo KYmAAJ8MV3/3oLcN3K/Te4Nf8sYgkWtdAtxT7CqaLEmDPKkupvgvYgsfanDe7fDaGU EgZJvc5/nyXCuiPc7lqCdeBDVNSL02ogSzLniwjx/FsSoka9WxaWAOOdBwpz8YoIGV 8HOWpvFkl57Iw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0BE5C68FCB; Wed, 31 Dec 2025 15:31:41 -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 UUM9G_rGy0xT; Wed, 31 Dec 2025 15:31:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220300; bh=9IkpGkEaYnzDYbZ2SLmiqa50hXyLmr/gU6u3WOQ5RTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyYH7dnIo40NZ5iYAdgO3/MR+YE6FC+UUy0O/ujir5rdBP9pLBJH62P4sklpWmOqD DNbZf03VT7yBk2oL9BrstZynojxr+oWaka5XtqPXiw7hrBmO3TEkkg/hOc1RC+oR1q M19+pCmqN7RWqKIALNnfjng/u+ekUNcfydAsl3BpuO7r2/H/YPaWZ4dXiE1ZUljeDh 760sp9ODkrvBay02d9+mt8TH6IqzRvs83nWj5j1I6RhiyOMQBwW1gcAlCKMtglof5+ aJfZak8UQjUVXRwjXEWT21P+qjp6Ukm5GvsEb0znV7IJB/9Qd5X+PN8Y8EQ8dke7l+ XTtysgNADfMsQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 62DF468F65; Wed, 31 Dec 2025 15:31:40 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:51 -0700 Message-ID: <20251231223008.3251711-19-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: AEG6VDAEHJS7O4IMUKILSPGTDNJJDB2L X-Message-ID-Hash: AEG6VDAEHJS7O4IMUKILSPGTDNJJDB2L 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 18/26] 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 --- 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 00419fe834e..da59956eee8 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) @@ -687,10 +687,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 */