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  * Fill in the supplied page for mmap
  29  */
  30 static unsigned long nfs_file_mmap_nopage(struct vm_area_struct * area,
     /* [previous][next][first][last][top][bottom][index][help] */
  31         unsigned long address, unsigned long page, int no_share)
  32 {
  33         struct inode * inode = area->vm_inode;
  34         unsigned int clear;
  35         unsigned long tmp;
  36         int n;
  37         int i;
  38         int pos;
  39         struct nfs_fattr fattr;
  40 
  41         address &= PAGE_MASK;
  42         pos = address - area->vm_start + area->vm_offset;
  43 
  44         clear = 0;
  45         if (address + PAGE_SIZE > area->vm_end) {
  46                 clear = address + PAGE_SIZE - area->vm_end;
  47         }
  48 
  49         n = NFS_SERVER(inode)->rsize; /* what we can read in one go */
  50 
  51         for (i = 0; i < (PAGE_SIZE - clear); i += n) {
  52                 int hunk, result;
  53 
  54                 hunk = PAGE_SIZE - i;
  55                 if (hunk > n)
  56                         hunk = n;
  57                 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode),
  58                         pos, hunk, (char *) (page + i), &fattr, 0);
  59                 if (result < 0)
  60                         break;
  61                 pos += result;
  62                 if (result < n) {
  63                         i += result;
  64                         break;
  65                 }
  66         }
  67 
  68 #ifdef doweneedthishere
  69         nfs_refresh_inode(inode, &fattr);
  70 #endif
  71 
  72         tmp = page + PAGE_SIZE;
  73         if (clear > 0){
  74                 memset ((char*)(tmp-clear),0,clear);
  75         }
  76 
  77         return page;
  78 }
  79 
  80 struct vm_operations_struct nfs_file_mmap = {
  81         NULL,                   /* open */
  82         NULL,                   /* close */
  83         NULL,                   /* unmap */
  84         NULL,                   /* protect */
  85         NULL,                   /* sync */
  86         NULL,                   /* advise */
  87         nfs_file_mmap_nopage,   /* nopage */
  88         NULL,                   /* wppage */
  89         NULL,                   /* swapout */
  90         NULL,                   /* swapin */
  91 };
  92 
  93 
  94 /* This is used for a general mmap of a nfs file */
  95 int nfs_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97         if (vma->vm_flags & VM_SHARED)  /* only PAGE_COW or read-only supported now */
  98                 return -EINVAL;
  99         if (!inode->i_sb || !S_ISREG(inode->i_mode))
 100                 return -EACCES;
 101         if (!IS_RDONLY(inode)) {
 102                 inode->i_atime = CURRENT_TIME;
 103                 inode->i_dirt = 1;
 104         }
 105 
 106         vma->vm_inode = inode;
 107         inode->i_count++;
 108         vma->vm_ops = &nfs_file_mmap;
 109         return 0;
 110 }

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