1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* NOMMU mmap support for RomFS on MTD devices 3 * 4 * Copyright © 2007 Red Hat, Inc. All Rights 5 * Written by David Howells (dhowells@redhat.c 6 */ 7 8 #include <linux/mm.h> 9 #include <linux/mtd/super.h> 10 #include "internal.h" 11 12 /* 13 * try to determine where a shared mapping can 14 * - only supported for NOMMU at the moment (M 15 * mappings) 16 * - attempts to map through to the underlying 17 */ 18 static unsigned long romfs_get_unmapped_area(s 19 u 20 u 21 u 22 u 23 { 24 struct inode *inode = file->f_mapping- 25 struct mtd_info *mtd = inode->i_sb->s_ 26 unsigned long isize, offset, maxpages, 27 int ret; 28 29 if (!mtd) 30 return (unsigned long) -ENOSYS 31 32 /* the mapping mustn't extend beyond t 33 lpages = (len + PAGE_SIZE - 1) >> PAGE 34 isize = i_size_read(inode); 35 offset = pgoff << PAGE_SHIFT; 36 37 maxpages = (isize + PAGE_SIZE - 1) >> 38 if ((pgoff >= maxpages) || (maxpages - 39 return (unsigned long) -EINVAL 40 41 if (addr != 0) 42 return (unsigned long) -EINVAL 43 44 if (len > mtd->size || pgoff >= (mtd-> 45 return (unsigned long) -EINVAL 46 47 offset += ROMFS_I(inode)->i_dataoffset 48 if (offset >= mtd->size) 49 return (unsigned long) -EINVAL 50 /* the mapping mustn't extend beyond t 51 if ((offset + len) > mtd->size) 52 len = mtd->size - offset; 53 54 ret = mtd_get_unmapped_area(mtd, len, 55 if (ret == -EOPNOTSUPP) 56 ret = -ENOSYS; 57 return (unsigned long) ret; 58 } 59 60 /* 61 * permit a R/O mapping to be made directly th 62 * possible 63 */ 64 static int romfs_mmap(struct file *file, struc 65 { 66 return is_nommu_shared_mapping(vma->vm 67 } 68 69 static unsigned romfs_mmap_capabilities(struct 70 { 71 struct mtd_info *mtd = file_inode(file 72 73 if (!mtd) 74 return NOMMU_MAP_COPY; 75 return mtd_mmap_capabilities(mtd); 76 } 77 78 const struct file_operations romfs_ro_fops = { 79 .llseek = generic_file 80 .read_iter = generic_file 81 .splice_read = filemap_spli 82 .mmap = romfs_mmap, 83 .get_unmapped_area = romfs_get_un 84 .mmap_capabilities = romfs_mmap_c 85 }; 86
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.