diff options
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r-- | drivers/mtd/mtdchar.c | 79 |
1 files changed, 29 insertions, 50 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 50c6a1e7f675..58fc65f5c817 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -31,15 +31,14 @@ #include <linux/compat.h> #include <linux/mount.h> #include <linux/blkpg.h> +#include <linux/magic.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #include <linux/mtd/map.h> #include <asm/uaccess.h> -#define MTD_INODE_FS_MAGIC 0x11307854 static DEFINE_MUTEX(mtd_mutex); -static struct vfsmount *mtd_inode_mnt __read_mostly; /* * 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) return -EINVAL; } - +static int count; +static struct vfsmount *mnt; +static struct file_system_type mtd_inodefs_type; static int mtdchar_open(struct inode *inode, struct file *file) { @@ -92,6 +93,10 @@ static int mtdchar_open(struct inode *inode, struct file *file) if ((file->f_mode & FMODE_WRITE) && (minor & 1)) return -EACCES; + ret = simple_pin_fs(&mtd_inodefs_type, &mnt, &count); + if (ret) + return ret; + mutex_lock(&mtd_mutex); mtd = get_mtd_device(NULL, devnum); @@ -101,16 +106,14 @@ static int mtdchar_open(struct inode *inode, struct file *file) } if (mtd->type == MTD_ABSENT) { - put_mtd_device(mtd); ret = -ENODEV; - goto out; + goto out1; } - mtd_ino = iget_locked(mtd_inode_mnt->mnt_sb, devnum); + mtd_ino = iget_locked(mnt->mnt_sb, devnum); if (!mtd_ino) { - put_mtd_device(mtd); ret = -ENOMEM; - goto out; + goto out1; } if (mtd_ino->i_state & I_NEW) { mtd_ino->i_private = mtd; @@ -122,25 +125,28 @@ static int mtdchar_open(struct inode *inode, struct file *file) /* You can't open it RW if it's not a writeable device */ if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { - iput(mtd_ino); - put_mtd_device(mtd); ret = -EACCES; - goto out; + goto out2; } mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); if (!mfi) { - iput(mtd_ino); - put_mtd_device(mtd); ret = -ENOMEM; - goto out; + goto out2; } mfi->ino = mtd_ino; mfi->mtd = mtd; file->private_data = mfi; + mutex_unlock(&mtd_mutex); + return 0; +out2: + iput(mtd_ino); +out1: + put_mtd_device(mtd); out: mutex_unlock(&mtd_mutex); + simple_release_fs(&mnt, &count); return ret; } /* mtdchar_open */ @@ -162,6 +168,7 @@ static int mtdchar_close(struct inode *inode, struct file *file) put_mtd_device(mtd); file->private_data = NULL; kfree(mfi); + simple_release_fs(&mnt, &count); return 0; } /* mtdchar_close */ @@ -405,7 +412,7 @@ static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd, if (length > 4096) return -EINVAL; - if (!mtd->write_oob) + if (!mtd->_write_oob) ret = -EOPNOTSUPP; else ret = access_ok(VERIFY_READ, ptr, length) ? 0 : -EFAULT; @@ -576,7 +583,7 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd, !access_ok(VERIFY_READ, req.usr_data, req.len) || !access_ok(VERIFY_READ, req.usr_oob, req.ooblen)) return -EFAULT; - if (!mtd->write_oob) + if (!mtd->_write_oob) return -EOPNOTSUPP; ops.mode = req.mode; @@ -1175,10 +1182,15 @@ static const struct file_operations mtd_fops = { #endif }; +static const struct super_operations mtd_ops = { + .drop_inode = generic_delete_inode, + .statfs = simple_statfs, +}; + static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { - return mount_pseudo(fs_type, "mtd_inode:", NULL, NULL, MTD_INODE_FS_MAGIC); + return mount_pseudo(fs_type, "mtd_inode:", &mtd_ops, NULL, MTD_INODE_FS_MAGIC); } static struct file_system_type mtd_inodefs_type = { @@ -1187,26 +1199,6 @@ static struct file_system_type mtd_inodefs_type = { .kill_sb = kill_anon_super, }; -static void mtdchar_notify_add(struct mtd_info *mtd) -{ -} - -static void mtdchar_notify_remove(struct mtd_info *mtd) -{ - struct inode *mtd_ino = ilookup(mtd_inode_mnt->mnt_sb, mtd->index); - - if (mtd_ino) { - /* Destroy the inode if it exists */ - clear_nlink(mtd_ino); - iput(mtd_ino); - } -} - -static struct mtd_notifier mtdchar_notifier = { - .add = mtdchar_notify_add, - .remove = mtdchar_notify_remove, -}; - static int __init init_mtdchar(void) { int ret; @@ -1224,19 +1216,8 @@ static int __init init_mtdchar(void) pr_notice("Can't register mtd_inodefs filesystem: %d\n", ret); goto err_unregister_chdev; } - - mtd_inode_mnt = kern_mount(&mtd_inodefs_type); - if (IS_ERR(mtd_inode_mnt)) { - ret = PTR_ERR(mtd_inode_mnt); - pr_notice("Error mounting mtd_inodefs filesystem: %d\n", ret); - goto err_unregister_filesystem; - } - register_mtd_user(&mtdchar_notifier); - return ret; -err_unregister_filesystem: - unregister_filesystem(&mtd_inodefs_type); err_unregister_chdev: __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); return ret; @@ -1244,8 +1225,6 @@ err_unregister_chdev: static void __exit cleanup_mtdchar(void) { - unregister_mtd_user(&mtdchar_notifier); - kern_unmount(mtd_inode_mnt); unregister_filesystem(&mtd_inodefs_type); __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); } |