#include <linux/device.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/mutex.h>
#include <linux/backing-dev.h>
#include <linux/compat.h>
#include <linux/mount.h>
#include <linux/blkpg.h>
#include <linux/magic.h>
#include <linux/major.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/map.h>
#include <linux/uaccess.h>
#include "mtdcore.h"
struct mtd_file_info { … };
static loff_t mtdchar_lseek(struct file *file, loff_t offset, int orig)
{ … }
static int mtdchar_open(struct inode *inode, struct file *file)
{ … }
static int mtdchar_close(struct inode *inode, struct file *file)
{ … }
static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{ … }
static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t count,
loff_t *ppos)
{ … }
static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
{ … }
static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd,
uint64_t start, uint32_t length, void __user *ptr,
uint32_t __user *retp)
{ … }
static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
uint64_t start, uint32_t length, void __user *ptr,
uint32_t __user *retp)
{ … }
static int shrink_ecclayout(struct mtd_info *mtd,
struct nand_ecclayout_user *to)
{ … }
static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to)
{ … }
static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
struct blkpg_ioctl_arg *arg)
{ … }
static void adjust_oob_length(struct mtd_info *mtd, uint64_t start,
struct mtd_oob_ops *ops)
{ … }
static noinline_for_stack int
mtdchar_write_ioctl(struct mtd_info *mtd, struct mtd_write_req __user *argp)
{ … }
static noinline_for_stack int
mtdchar_read_ioctl(struct mtd_info *mtd, struct mtd_read_req __user *argp)
{ … }
static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
{ … }
static long mtdchar_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
{ … }
#ifdef CONFIG_COMPAT
struct mtd_oob_buf32 { … };
#define MEMWRITEOOB32 …
#define MEMREADOOB32 …
static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{ … }
#endif
#ifndef CONFIG_MMU
static unsigned long mtdchar_get_unmapped_area(struct file *file,
unsigned long addr,
unsigned long len,
unsigned long pgoff,
unsigned long flags)
{
struct mtd_file_info *mfi = file->private_data;
struct mtd_info *mtd = mfi->mtd;
unsigned long offset;
int ret;
if (addr != 0)
return (unsigned long) -EINVAL;
if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
return (unsigned long) -EINVAL;
offset = pgoff << PAGE_SHIFT;
if (offset > mtd->size - len)
return (unsigned long) -EINVAL;
ret = mtd_get_unmapped_area(mtd, len, offset, flags);
return ret == -EOPNOTSUPP ? -ENODEV : ret;
}
static unsigned mtdchar_mmap_capabilities(struct file *file)
{
struct mtd_file_info *mfi = file->private_data;
return mtd_mmap_capabilities(mfi->mtd);
}
#endif
static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
{ … }
static const struct file_operations mtd_fops = …;
int __init init_mtdchar(void)
{ … }
void __exit cleanup_mtdchar(void)
{ … }
MODULE_ALIAS_CHARDEV_MAJOR(…);