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

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