Skip to contentSkip to conversation

Abstract MTD mounting from JFFS2 and add super_block::s_mtd

RFC PATCH New David Howells 1 participant 1 message Sep 20, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Abstract MTD mounting from JFFS2 and add super_block::s_mtd

Abstract MTD mounting from JFFS2 so that it can be used by other filesystems (such as ROMFS for MTD which is being developed).

This patch:

(1) Creates get_sb_mtd() and kill_mtd_super() functions as analogues of the blockdev ones. These functions live in the MTD core module rather than in fs/super.c because they require access to MTD facilities, and in any case only MTD-dependent code may use them.

A new header file <linux/mtd/super.h> is provided for access to them.

(2) Adds s_mtd to struct super_block as an analogue of s_bdev. This is used to hold a pointer to the MTD device structure used by a superblock instead of a blockdev pointer. It is also used to compare superblocks during mounting, as for blockdevs.

This change shouldn't add all that much overhead since it adds a single pointer to the super_block struct, and there shouldn't be all that many of those in a system.

(3) Removes the corresponding code from JFFS2 and has JFFS2 use the new facility instead.

I've considered putting s_bdev and s_mtd in an anonymous union together. For the most part this wouldn't be a problem as no filesystems use both and most of the generic code follows suit. However, there are a couple of places where s_bdev is used if non-NULL without checking that it's a blockdev, and I'm not sure how I'd deal with those as I'm not sure how else to check that a filesystem is blockdev based (FS_REQUIRES_DEV maybe?).

I've also considered adding an analogue to FS_REQUIRES_DEV, but I'm not sure of what use it would be, since it seems the only place it is used it get_filesystem_list(). I could mark filesystems such as JFFS2 as being "mtd" in /proc/filesystems, I suppose.

Thoughts anyone?

David

---
 drivers/mtd/Makefile      |    2 
 drivers/mtd/mtdsuper.c    |  231 +++++++++++++++++++++++++++++++++++++++++
 fs/jffs2/super.c          |  197 ++++-------------------------------
 include/linux/fs.h        |    1 
 include/linux/mtd/super.h |   30 +++++
drivers/mtd/Makefile +1 -1
index 9282d4a..aca6b10 100644
@@ -4,7 +4,7 @@ #
 # $Id: Makefile.common,v 1.7 2005/07/11 10:39:27 gleixner Exp $
 
 # Core functionality.
-mtd-y				:= mtdcore.o
+mtd-y				:= mtdcore.o mtdsuper.o
 mtd-$(CONFIG_MTD_PARTITIONS)	+= mtdpart.o
 obj-$(CONFIG_MTD)		+= $(mtd-y)
 
drivers/mtd/mtdsuper.c new file +231 -0

231 lines not on this page · raw message

fs/jffs2/super.c +20 -177

238 lines not on this page · raw message

include/linux/fs.h +1 -0
index 555bc19..a36dc28 100644
@@ -888,6 +888,7 @@ struct super_block {
 	struct list_head	s_files;
 
 	struct block_device	*s_bdev;
+	struct mtd_info		*s_mtd;
 	struct list_head	s_instances;
 	struct quota_info	s_dquot;	/* Diskquota specific options */
 
include/linux/mtd/super.h new file +30 -0
new file mode 100644
index 0000000..8fcdbdf
@@ -0,0 +1,30 @@
+/* MTD-based superblock handling
+ *
+ * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef __MTD_SUPER_H__
+#define __MTD_SUPER_H__
+
+#ifdef __KERNEL__
+
+#include <linux/mtd/mtd.h>
+#include <linux/fs.h>
+#include <linux/mount.h>
+
+extern int get_sb_mtd(struct file_system_type *fs_type, int flags,
+		      const char *dev_name, void *data,
+		      int (*fill_super)(struct super_block *, void *, int),
+		      struct vfsmount *mnt);
+extern void kill_mtd_super(struct super_block *sb);
+
+
+#endif /* __KERNEL__ */
+
+#endif /* __MTD_SUPER_H__ */