[PATCH] Make MTD chardev mmap available under some circumstances
Josh Boyer
jwboyer at gmail.com
Tue Sep 5 21:00:06 EDT 2006
On 9/5/06, David Howells <dhowells at redhat.com> wrote:
>
> Make it possible to mmap MTD chardevs directly or by copy on a NOMMU system.
Why would you want to do this? I'm just curious.
> +/*
> + * Allow NOMMU mmap() to directly map the device (if not NULL)
> + * - return the address to which the offset maps
> + * - return -ENOSYS to indicate refusal to do the mapping
Where do you actually do the -ENOSYS part? I think that comment
belongs to the actual mtd_get_unmapped_area call in mtdchar.c, no?
> +/*
> + * try to determine where a shared mapping can be made
> + * - only supported for NOMMU at the moment (MMU can't doesn't copy private
> + * mappings)
> + */
> +#ifndef CONFIG_MMU
> +static unsigned long mtd_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;
> +
> + if (mtd->get_unmapped_area) {
> + unsigned long offset;
> +
> + 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;
> +
> + return mtd->get_unmapped_area(mtd, len, offset, flags);
> + }
> +
> + /* can't map directly */
> + return (unsigned long) -ENOSYS;
> +}
> +#endif
Could we do something like:
#else
#define mtd_get_unmapped_area (NULL);
which would prevent the ugly ifdef in the mtd_fops structure?
> static struct file_operations mtd_fops = {
> .owner = THIS_MODULE,
> .llseek = mtd_lseek,
> @@ -771,6 +864,10 @@ static struct file_operations mtd_fops =
> .ioctl = mtd_ioctl,
> .open = mtd_open,
> .release = mtd_close,
> + .mmap = mtd_mmap,
> +#ifndef CONFIG_MMU
> + .get_unmapped_area = mtd_get_unmapped_area,
> +#endif
See above.
josh
More information about the linux-mtd
mailing list