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

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