root/fs/msdos/mmap.c

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

DEFINITIONS

This source file includes following definitions.
  1. msdos_file_mmap_nopage
  2. msdos_mmap

   1 /*
   2  *      fs/msdos/mmap.c
   3  *
   4  *      Written by Jacques Gelinas (jacques@solucorp.qc.ca)
   5  *      Inspired by fs/nfs/mmap.c (Jon Tombs 15 Aug 1993)
   6  *
   7  *      msdos mmap handling
   8  */
   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/msdos_fs.h>
  20 
  21 #include <asm/segment.h>
  22 #include <asm/system.h>
  23 
  24 /*
  25  * Fill in the supplied page for mmap
  26  */
  27 static unsigned long msdos_file_mmap_nopage(
     /* [previous][next][first][last][top][bottom][index][help] */
  28         struct vm_area_struct * area,
  29         unsigned long address,
  30         unsigned long page,
  31         int error_code)
  32 {
  33         struct inode * inode = area->vm_inode;
  34         unsigned int clear;
  35         int pos;
  36         long gap;       /* distance from eof to pos */
  37 
  38         address &= PAGE_MASK;
  39         pos = address - area->vm_start + area->vm_offset;
  40 
  41         clear = 0;
  42         gap = inode->i_size - pos;
  43         if (gap <= 0){
  44                 /* mmaping beyond end of file */
  45                 clear = PAGE_SIZE;
  46         }else{
  47                 int cur_read;
  48                 int need_read;
  49                 struct file filp;
  50                 if (gap < PAGE_SIZE){
  51                         clear = PAGE_SIZE - gap;
  52                 }
  53                 filp.f_reada = 0;
  54                 filp.f_pos = pos;
  55                 need_read = PAGE_SIZE - clear;
  56                 {
  57                         unsigned long cur_fs = get_fs();
  58                         set_fs (KERNEL_DS);
  59                         cur_read = msdos_file_read (inode,&filp,(char*)page
  60                                 ,need_read);
  61                         set_fs (cur_fs);
  62                 }
  63                 if (cur_read != need_read){
  64                         printk ("MSDOS: Error while reading an mmap file %d <> %d\n"
  65                                 ,cur_read,need_read);
  66                 }
  67         }
  68         if (clear > 0){
  69                 memset ((char*)page+PAGE_SIZE-clear,0,clear);
  70         }
  71         return page;
  72 }
  73 
  74 struct vm_operations_struct msdos_file_mmap = {
  75         NULL,                   /* open */
  76         NULL,                   /* close */
  77         NULL,                   /* unmap */
  78         NULL,                   /* protect */
  79         NULL,                   /* sync */
  80         NULL,                   /* advise */
  81         msdos_file_mmap_nopage, /* nopage */
  82         NULL,                   /* wppage */
  83         NULL,                   /* swapout */
  84         NULL,                   /* swapin */
  85 };
  86 
  87 /*
  88  * This is used for a general mmap of an msdos file
  89  * Returns 0 if ok, or a negative error code if not.
  90  */
  91 int msdos_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93         if (vma->vm_flags & VM_SHARED)  /* only PAGE_COW or read-only supported now */
  94                 return -EINVAL;
  95         if (vma->vm_offset & (inode->i_sb->s_blocksize - 1))
  96                 return -EINVAL;
  97         if (!inode->i_sb || !S_ISREG(inode->i_mode))
  98                 return -EACCES;
  99         if (!IS_RDONLY(inode)) {
 100                 inode->i_atime = CURRENT_TIME;
 101                 inode->i_dirt = 1;
 102         }
 103 
 104         vma->vm_inode = inode;
 105         inode->i_count++;
 106         vma->vm_ops = &msdos_file_mmap;
 107         return 0;
 108 }
 109 
 110 

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