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

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