1 /* NOMMU mmap support for RomFS on MTD devices
3 * Copyright © 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 #include <linux/mtd/super.h>
17 * try to determine where a shared mapping can be made
18 * - only supported for NOMMU at the moment (MMU can't doesn't copy private
20 * - attempts to map through to the underlying MTD device
22 static unsigned long romfs_get_unmapped_area(struct file
*file
,
28 struct inode
*inode
= file
->f_mapping
->host
;
29 struct mtd_info
*mtd
= inode
->i_sb
->s_mtd
;
30 unsigned long isize
, offset
;
33 goto cant_map_directly
;
35 isize
= i_size_read(inode
);
36 offset
= pgoff
<< PAGE_SHIFT
;
37 if (offset
> isize
|| len
> isize
|| offset
> isize
- len
)
38 return (unsigned long) -EINVAL
;
40 /* we need to call down to the MTD layer to do the actual mapping */
41 if (mtd
->get_unmapped_area
) {
43 return (unsigned long) -EINVAL
;
45 if (len
> mtd
->size
|| pgoff
>= (mtd
->size
>> PAGE_SHIFT
))
46 return (unsigned long) -EINVAL
;
48 offset
+= ROMFS_I(inode
)->i_dataoffset
;
49 if (offset
> mtd
->size
- len
)
50 return (unsigned long) -EINVAL
;
52 return mtd
->get_unmapped_area(mtd
, len
, offset
, flags
);
56 return (unsigned long) -ENOSYS
;
60 * permit a R/O mapping to be made directly through onto an MTD device if
63 static int romfs_mmap(struct file
*file
, struct vm_area_struct
*vma
)
65 return vma
->vm_flags
& (VM_SHARED
| VM_MAYSHARE
) ? 0 : -ENOSYS
;
68 const struct file_operations romfs_ro_fops
= {
69 .llseek
= generic_file_llseek
,
71 .aio_read
= generic_file_aio_read
,
72 .splice_read
= generic_file_splice_read
,
74 .get_unmapped_area
= romfs_get_unmapped_area
,