~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/romfs/mmap-nommu.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/romfs/mmap-nommu.c (Version linux-6.11.5) and /fs/romfs/mmap-nommu.c (Version linux-3.10.108)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php