Blame view
fs/romfs/mmap-nommu.c
2.2 KB
da4458bda NOMMU: Make it po... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* NOMMU mmap support for RomFS on MTD devices * * Copyright © 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/mm.h> #include <linux/mtd/super.h> #include "internal.h" /* * 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) * - attempts to map through to the underlying MTD device */ static unsigned long romfs_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct inode *inode = file->f_mapping->host; struct mtd_info *mtd = inode->i_sb->s_mtd; |
2b4b2482e romfs: fix romfs_... |
30 |
unsigned long isize, offset, maxpages, lpages; |
4991e7251 romfs: do not use... |
31 |
int ret; |
da4458bda NOMMU: Make it po... |
32 33 |
if (!mtd) |
4991e7251 romfs: do not use... |
34 |
return (unsigned long) -ENOSYS; |
da4458bda NOMMU: Make it po... |
35 |
|
2b4b2482e romfs: fix romfs_... |
36 37 |
/* the mapping mustn't extend beyond the EOF */ lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT; |
da4458bda NOMMU: Make it po... |
38 39 |
isize = i_size_read(inode); offset = pgoff << PAGE_SHIFT; |
2b4b2482e romfs: fix romfs_... |
40 41 42 |
maxpages = (isize + PAGE_SIZE - 1) >> PAGE_SHIFT; if ((pgoff >= maxpages) || (maxpages - pgoff < lpages)) |
da4458bda NOMMU: Make it po... |
43 |
return (unsigned long) -EINVAL; |
4991e7251 romfs: do not use... |
44 45 |
if (addr != 0) return (unsigned long) -EINVAL; |
da4458bda NOMMU: Make it po... |
46 |
|
4991e7251 romfs: do not use... |
47 48 |
if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT)) return (unsigned long) -EINVAL; |
da4458bda NOMMU: Make it po... |
49 |
|
4991e7251 romfs: do not use... |
50 51 52 |
offset += ROMFS_I(inode)->i_dataoffset; if (offset > mtd->size - len) return (unsigned long) -EINVAL; |
da4458bda NOMMU: Make it po... |
53 |
|
4991e7251 romfs: do not use... |
54 55 56 57 |
ret = mtd_get_unmapped_area(mtd, len, offset, flags); if (ret == -EOPNOTSUPP) ret = -ENOSYS; return (unsigned long) ret; |
da4458bda NOMMU: Make it po... |
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
} /* * permit a R/O mapping to be made directly through onto an MTD device if * possible */ static int romfs_mmap(struct file *file, struct vm_area_struct *vma) { return vma->vm_flags & (VM_SHARED | VM_MAYSHARE) ? 0 : -ENOSYS; } const struct file_operations romfs_ro_fops = { .llseek = generic_file_llseek, .read = do_sync_read, .aio_read = generic_file_aio_read, .splice_read = generic_file_splice_read, .mmap = romfs_mmap, .get_unmapped_area = romfs_get_unmapped_area, }; |