RFC: mmap(PROT_READ, MAP_SHARED) fails if !writepage.

David Woodhouse (dwmw2@infradead.org)
Fri, 08 Nov 2002 22:49:02 +0000


Why does a _readonly_ mapping fail if the file system has no writepage
method?

do_mmap_pgoff() sets VM_MAYWRITE on the vma and then generic_file_mmap()
refuses to allow it.

Suggested patch below.... or should I just hack fsx-linux to use
MAP_PRIVATE for its readonly mappings and ignore it?

--- 1.157/mm/filemap.c Sun Nov 3 02:55:27 2002
+++ edited/mm/filemap.c Fri Nov 8 22:08:22 2002
@@ -1311,9 +1311,12 @@
struct address_space *mapping = file->f_dentry->d_inode->i_mapping;
struct inode *inode = mapping->host;

- if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) {
- if (!mapping->a_ops->writepage)
+ if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE) &&
+ !mapping->a_ops->writepage) {
+ if (vma->vm_flags & VM_WRITE)
return -EINVAL;
+ else
+ vma->vm_flags &= ~VM_MAYWRITE;
}
if (!mapping->a_ops->readpage)
return -ENOEXEC;

--
dwmw2

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/