linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: support mtd:<name> syntax for block devices
@ 2025-05-16  6:51 Joakim Tjernlund
  2025-05-16  7:14 ` Christoph Hellwig
  0 siblings, 1 reply; 14+ messages in thread
From: Joakim Tjernlund @ 2025-05-16  6:51 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Joakim Tjernlund

This is the same name scheme JFFS2 and UBI uses.

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
---
 fs/super.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 97a17f9d9023..e603236b3ad8 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -37,6 +37,7 @@
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
 #include <uapi/linux/mount.h>
+#include <linux/mtd/mtd.h>
 #include "internal.h"
 
 static int thaw_super_locked(struct super_block *sb, enum freeze_holder who);
@@ -1612,6 +1613,26 @@ int get_tree_bdev_flags(struct fs_context *fc,
 	if (!fc->source)
 		return invalf(fc, "No source specified");
 
+#ifdef CONFIG_MTD_BLOCK
+	if (!strncmp(fc->source, "mtd:", 4)) {
+		struct mtd_info *mtd;
+		char *blk_source;
+
+		/* mount by MTD device name */
+		pr_debug("Block SB: name \"%s\"\n", fc->source);
+
+		mtd = get_mtd_device_nm(fc->source + 4);
+		if (IS_ERR(mtd))
+			return -EINVAL;
+		blk_source = kmalloc(20, GFP_KERNEL);
+		if (!blk_source)
+			return -ENOMEM;
+		sprintf(blk_source, "/dev/mtdblock%d", mtd->index);
+		kfree(fc->source);
+		fc->source = blk_source;
+		pr_debug("MTD device:%s found\n", fc->source);
+	}
+#endif
 	error = lookup_bdev(fc->source, &dev);
 	if (error) {
 		if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-06-14 12:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-16  6:51 [PATCH] block: support mtd:<name> syntax for block devices Joakim Tjernlund
2025-05-16  7:14 ` Christoph Hellwig
2025-05-16  7:37   ` Joakim Tjernlund (Nokia)
2025-05-16  7:47     ` [PATCH v2] " Joakim Tjernlund
2025-05-19  8:12       ` Johannes Thumshirn
2025-05-19 13:11         ` [PATCH v3] " Joakim Tjernlund
2025-05-19 14:37           ` Johannes Thumshirn
2025-05-19 14:39             ` Joakim Tjernlund (Nokia)
2025-05-19 15:03             ` [PATCH v4] " Joakim Tjernlund
2025-05-27 15:10               ` [PATCH v5] " Joakim Tjernlund
2025-05-28 13:09                 ` kernel test robot
2025-06-02  7:50                   ` [PATCH v6] " Joakim Tjernlund
2025-06-14 12:43                     ` Joakim Tjernlund (Nokia)
2025-05-27 15:12               ` [PATCH v4] " Joakim Tjernlund (Nokia)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).