3939#include <asm/uaccess.h>
4040
4141static DEFINE_MUTEX (mtd_mutex );
42- static struct vfsmount * mtd_inode_mnt __read_mostly ;
4342
4443/*
4544 * Data structure to hold the pointer to the mtd device as well
@@ -75,7 +74,9 @@ static loff_t mtdchar_lseek(struct file *file, loff_t offset, int orig)
7574 return - EINVAL ;
7675}
7776
78-
77+ static int count ;
78+ static struct vfsmount * mnt ;
79+ static struct file_system_type mtd_inodefs_type ;
7980
8081static int mtdchar_open (struct inode * inode , struct file * file )
8182{
@@ -92,6 +93,10 @@ static int mtdchar_open(struct inode *inode, struct file *file)
9293 if ((file -> f_mode & FMODE_WRITE ) && (minor & 1 ))
9394 return - EACCES ;
9495
96+ ret = simple_pin_fs (& mtd_inodefs_type , & mnt , & count );
97+ if (ret )
98+ return ret ;
99+
95100 mutex_lock (& mtd_mutex );
96101 mtd = get_mtd_device (NULL , devnum );
97102
@@ -106,7 +111,7 @@ static int mtdchar_open(struct inode *inode, struct file *file)
106111 goto out ;
107112 }
108113
109- mtd_ino = iget_locked (mtd_inode_mnt -> mnt_sb , devnum );
114+ mtd_ino = iget_locked (mnt -> mnt_sb , devnum );
110115 if (!mtd_ino ) {
111116 put_mtd_device (mtd );
112117 ret = - ENOMEM ;
@@ -141,6 +146,7 @@ static int mtdchar_open(struct inode *inode, struct file *file)
141146
142147out :
143148 mutex_unlock (& mtd_mutex );
149+ simple_release_fs (& mnt , & count );
144150 return ret ;
145151} /* mtdchar_open */
146152
@@ -162,6 +168,7 @@ static int mtdchar_close(struct inode *inode, struct file *file)
162168 put_mtd_device (mtd );
163169 file -> private_data = NULL ;
164170 kfree (mfi );
171+ simple_release_fs (& mnt , & count );
165172
166173 return 0 ;
167174} /* mtdchar_close */
@@ -1175,10 +1182,15 @@ static const struct file_operations mtd_fops = {
11751182#endif
11761183};
11771184
1185+ static const struct super_operations mtd_ops = {
1186+ .drop_inode = generic_delete_inode ,
1187+ .statfs = simple_statfs ,
1188+ };
1189+
11781190static struct dentry * mtd_inodefs_mount (struct file_system_type * fs_type ,
11791191 int flags , const char * dev_name , void * data )
11801192{
1181- return mount_pseudo (fs_type , "mtd_inode:" , NULL , NULL , MTD_INODE_FS_MAGIC );
1193+ return mount_pseudo (fs_type , "mtd_inode:" , & mtd_ops , NULL , MTD_INODE_FS_MAGIC );
11821194}
11831195
11841196static struct file_system_type mtd_inodefs_type = {
@@ -1187,26 +1199,6 @@ static struct file_system_type mtd_inodefs_type = {
11871199 .kill_sb = kill_anon_super ,
11881200};
11891201
1190- static void mtdchar_notify_add (struct mtd_info * mtd )
1191- {
1192- }
1193-
1194- static void mtdchar_notify_remove (struct mtd_info * mtd )
1195- {
1196- struct inode * mtd_ino = ilookup (mtd_inode_mnt -> mnt_sb , mtd -> index );
1197-
1198- if (mtd_ino ) {
1199- /* Destroy the inode if it exists */
1200- clear_nlink (mtd_ino );
1201- iput (mtd_ino );
1202- }
1203- }
1204-
1205- static struct mtd_notifier mtdchar_notifier = {
1206- .add = mtdchar_notify_add ,
1207- .remove = mtdchar_notify_remove ,
1208- };
1209-
12101202static int __init init_mtdchar (void )
12111203{
12121204 int ret ;
@@ -1224,28 +1216,15 @@ static int __init init_mtdchar(void)
12241216 pr_notice ("Can't register mtd_inodefs filesystem: %d\n" , ret );
12251217 goto err_unregister_chdev ;
12261218 }
1227-
1228- mtd_inode_mnt = kern_mount (& mtd_inodefs_type );
1229- if (IS_ERR (mtd_inode_mnt )) {
1230- ret = PTR_ERR (mtd_inode_mnt );
1231- pr_notice ("Error mounting mtd_inodefs filesystem: %d\n" , ret );
1232- goto err_unregister_filesystem ;
1233- }
1234- register_mtd_user (& mtdchar_notifier );
1235-
12361219 return ret ;
12371220
1238- err_unregister_filesystem :
1239- unregister_filesystem (& mtd_inodefs_type );
12401221err_unregister_chdev :
12411222 __unregister_chrdev (MTD_CHAR_MAJOR , 0 , 1 << MINORBITS , "mtd" );
12421223 return ret ;
12431224}
12441225
12451226static void __exit cleanup_mtdchar (void )
12461227{
1247- unregister_mtd_user (& mtdchar_notifier );
1248- kern_unmount (mtd_inode_mnt );
12491228 unregister_filesystem (& mtd_inodefs_type );
12501229 __unregister_chrdev (MTD_CHAR_MAJOR , 0 , 1 << MINORBITS , "mtd" );
12511230}
0 commit comments