root/fs/smbfs/mmap.c

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

DEFINITIONS

This source file includes following definitions.
  1. smb_file_mmap_nopage
  2. smb_mmap

   1 /*
   2  *  mmap.c
   3  *
   4  *  Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
   5  *
   6  */
   7 
   8 #include <linux/module.h>
   9 
  10 #include <linux/stat.h>
  11 #include <linux/sched.h>
  12 #include <linux/kernel.h>
  13 #include <linux/mm.h>
  14 #include <linux/shm.h>
  15 #include <linux/errno.h>
  16 #include <linux/mman.h>
  17 #include <linux/string.h>
  18 #include <linux/malloc.h>
  19 #include <linux/smb_fs.h>
  20 #include <linux/fcntl.h>
  21 
  22 #include <asm/segment.h>
  23 #include <asm/system.h>
  24 
  25 /*
  26  * Fill in the supplied page for mmap
  27  */
  28 static unsigned long 
  29 smb_file_mmap_nopage(struct vm_area_struct * area,
     /* [previous][next][first][last][top][bottom][index][help] */
  30                      unsigned long address, unsigned long page, int no_share)
  31 {
  32         struct inode * inode = area->vm_inode;
  33         unsigned int clear;
  34         unsigned long tmp;
  35         int n;
  36         int i;
  37         int pos;
  38 
  39         address &= PAGE_MASK;
  40         pos = address - area->vm_start + area->vm_offset;
  41 
  42         clear = 0;
  43         if (address + PAGE_SIZE > area->vm_end) {
  44                 clear = address + PAGE_SIZE - area->vm_end;
  45         }
  46 
  47         /* what we can read in one go */
  48         n = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 3 - 10;
  49 
  50         if (smb_make_open(inode, O_RDONLY) < 0) {
  51                 clear = PAGE_SIZE;
  52         }
  53         else
  54         {
  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 
  63                         DDPRINTK("smb_file_mmap_nopage: reading\n");
  64                         DDPRINTK("smb_file_mmap_nopage: pos = %d\n", pos);
  65                         result = smb_proc_read(SMB_SERVER(inode),
  66                                                SMB_FINFO(inode), pos, hunk,
  67                                                (char *) (page + i), 0);
  68                         DDPRINTK("smb_file_mmap_nopage: result= %d\n", result);
  69                         if (result < 0)
  70                                 break;
  71                         pos += result;
  72                         if (result < n) {
  73                                 i += result;
  74                                 break;
  75                         }
  76                 }
  77         }
  78 
  79         tmp = page + PAGE_SIZE;
  80         while (clear--) {
  81                 *(char *)--tmp = 0;
  82         }
  83         return page;
  84 }
  85 
  86 struct vm_operations_struct smb_file_mmap = {
  87         NULL,                   /* open */
  88         NULL,                   /* close */
  89         NULL,                   /* unmap */
  90         NULL,                   /* protect */
  91         NULL,                   /* sync */
  92         NULL,                   /* advise */
  93         smb_file_mmap_nopage,   /* nopage */
  94         NULL,                   /* wppage */
  95         NULL,                   /* swapout */
  96         NULL,                   /* swapin */
  97 };
  98 
  99 
 100 /* This is used for a general mmap of a smb file */
 101 int
 102 smb_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104         DPRINTK("smb_mmap: called\n");
 105 
 106         /* only PAGE_COW or read-only supported now */
 107         if (vma->vm_flags & VM_SHARED)  
 108                 return -EINVAL;
 109         if (!inode->i_sb || !S_ISREG(inode->i_mode))
 110                 return -EACCES;
 111         if (!IS_RDONLY(inode)) {
 112                 inode->i_atime = CURRENT_TIME;
 113                 inode->i_dirt = 1;
 114         }
 115 
 116         vma->vm_inode = inode;
 117         inode->i_count++;
 118         vma->vm_ops = &smb_file_mmap;
 119         return 0;
 120 }
 121 
 122 /*
 123  * Overrides for Emacs so that we follow Linus's tabbing style.
 124  * Emacs will notice this stuff at the end of the file and automatically
 125  * adjust the settings for this buffer only.  This must remain at the end
 126  * of the file.
 127  * ---------------------------------------------------------------------------
 128  * Local variables:
 129  * c-indent-level: 8
 130  * c-brace-imaginary-offset: 0
 131  * c-brace-offset: -8
 132  * c-argdecl-indent: 8
 133  * c-label-offset: -8
 134  * c-continued-statement-offset: 8
 135  * c-continued-brace-offset: 0
 136  * End:
 137  */

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