root/fs/nfs/mmap.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nfs_file_mmap_nopage
  2. nfs_mmap

   1 /*
   2  *      fs/nfs/mmap.c   by Jon Tombs 15 Aug 1993
   3  *
   4  * This code is from
   5  *      linux/mm/mmap.c which was written by obz, Linus and Eric
   6  * and
   7  *      linux/mm/memory.c  by Linus Torvalds and others
   8  *
   9  *      Copyright (C) 1993
  10  *
  11  */
  12 
  13 #include <linux/stat.h>
  14 #include <linux/sched.h>
  15 #include <linux/kernel.h>
  16 #include <linux/mm.h>
  17 #include <linux/shm.h>
  18 #include <linux/errno.h>
  19 #include <linux/mman.h>
  20 #include <linux/string.h>
  21 #include <linux/malloc.h>
  22 #include <linux/nfs_fs.h>
  23 
  24 #include <asm/segment.h>
  25 #include <asm/system.h>
  26 
  27 /*
  28  * Return a page for mmap. We need to start using the page cache,
  29  * because otherwise we can't share pages between processes..
  30  */
  31 static unsigned long nfs_file_mmap_nopage(struct vm_area_struct * area,
     /* [previous][next][first][last][top][bottom][index][help] */
  32         unsigned long address, int no_share)
  33 {
  34         struct inode * inode = area->vm_inode;
  35         unsigned long page;
  36         unsigned int clear;
  37         unsigned long tmp;
  38         int n;
  39         int i;
  40         int pos;
  41         struct nfs_fattr fattr;
  42 
  43         page = __get_free_page(GFP_KERNEL);
  44         if (!page)
  45                 return page;
  46         address &= PAGE_MASK;
  47         pos = address - area->vm_start + area->vm_offset;
  48 
  49         clear = 0;
  50         if (address + PAGE_SIZE > area->vm_end) {
  51                 clear = address + PAGE_SIZE - area->vm_end;
  52         }
  53 
  54         n = NFS_SERVER(inode)->rsize; /* what we can read in one go */
  55 
  56         for (i = 0; i < (PAGE_SIZE - clear); i += n) {
  57                 int hunk, result;
  58 
  59                 hunk = PAGE_SIZE - i;
  60                 if (hunk > n)
  61                         hunk = n;
  62                 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode),
  63                         pos, hunk, (char *) (page + i), &fattr, 0);
  64                 if (result < 0)
  65                         break;
  66                 pos += result;
  67                 if (result < n) {
  68                         i += result;
  69                         break;
  70                 }
  71         }
  72 
  73 #ifdef doweneedthishere
  74         nfs_refresh_inode(inode, &fattr);
  75 #endif
  76 
  77         tmp = page + PAGE_SIZE;
  78         if (clear > 0){
  79                 memset ((char*)(tmp-clear),0,clear);
  80         }
  81 
  82         return page;
  83 }
  84 
  85 struct vm_operations_struct nfs_file_mmap = {
  86         NULL,                   /* open */
  87         NULL,                   /* close */
  88         NULL,                   /* unmap */
  89         NULL,                   /* protect */
  90         NULL,                   /* sync */
  91         NULL,                   /* advise */
  92         nfs_file_mmap_nopage,   /* nopage */
  93         NULL,                   /* wppage */
  94         NULL,                   /* swapout */
  95         NULL,                   /* swapin */
  96 };
  97 
  98 
  99 /* This is used for a general mmap of a nfs file */
 100 int nfs_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         if (vma->vm_flags & VM_SHARED)  /* only PAGE_COW or read-only supported now */
 103                 return -EINVAL;
 104         if (!inode->i_sb || !S_ISREG(inode->i_mode))
 105                 return -EACCES;
 106         if (!IS_RDONLY(inode)) {
 107                 inode->i_atime = CURRENT_TIME;
 108                 inode->i_dirt = 1;
 109         }
 110 
 111         vma->vm_inode = inode;
 112         inode->i_count++;
 113         vma->vm_ops = &nfs_file_mmap;
 114         return 0;
 115 }

/* [previous][next][first][last][top][bottom][index][help] */