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         while (clear--) {
  77                 *(char *)--tmp = 0;
  78         }
  79         return page;
  80 }
  81 
  82 struct vm_operations_struct nfs_file_mmap = {
  83         NULL,                   /* open */
  84         NULL,                   /* close */
  85         NULL,                   /* unmap */
  86         NULL,                   /* protect */
  87         NULL,                   /* sync */
  88         NULL,                   /* advise */
  89         nfs_file_mmap_nopage,   /* nopage */
  90         NULL,                   /* wppage */
  91         NULL,                   /* swapout */
  92         NULL,                   /* swapin */
  93 };
  94 
  95 
  96 /* This is used for a general mmap of a nfs file */
  97 int nfs_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
  98 {
  99         if (vma->vm_flags & VM_SHARED)  /* only PAGE_COW or read-only supported now */
 100                 return -EINVAL;
 101         if (!inode->i_sb || !S_ISREG(inode->i_mode))
 102                 return -EACCES;
 103         if (!IS_RDONLY(inode)) {
 104                 inode->i_atime = CURRENT_TIME;
 105                 inode->i_dirt = 1;
 106         }
 107 
 108         vma->vm_inode = inode;
 109         inode->i_count++;
 110         vma->vm_ops = &nfs_file_mmap;
 111         return 0;
 112 }

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