root/fs/sysv/mmap.c

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

DEFINITIONS

This source file includes following definitions.
  1. sysv_file_mmap_nopage
  2. sysv_mmap

   1 /*
   2  *  linux/fs/sysv/mmap.c
   3  *
   4  *  mm/memory.c, mm/mmap.c
   5  *  Copyright (C) 1991, 1992, 1993  Linus Torvalds
   6  *
   7  *  nfs/mmap.c
   8  *  Copyright (C) 1993  Jon Tombs
   9  *
  10  *  fs/msdos/mmap.c
  11  *  Copyright (C) 1994  Jacques Gelinas
  12  *
  13  *  fs/sysv/mmap.c
  14  *  Copyright (C) 1994  Bruno Haible
  15  *
  16  *  SystemV/Coherent mmap handling
  17  */
  18 
  19 #include <asm/segment.h>
  20 
  21 #include <linux/fs.h>
  22 #include <linux/sysv_fs.h>
  23 #include <linux/mm.h>
  24 #include <linux/string.h>
  25 #include <linux/stat.h>
  26 #include <linux/sched.h>
  27 #include <linux/errno.h>
  28 #include <linux/malloc.h>
  29 
  30 /*
  31  * Fill in the supplied page for mmap
  32  */
  33 static unsigned long sysv_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         int remaining, count, old_fs;
  37         struct file filp;
  38 
  39         address &= PAGE_MASK;
  40         /* prepare a file pointer */
  41         filp.f_pos = address - area->vm_start + area->vm_offset;
  42         filp.f_reada = 0;
  43         remaining = area->vm_end - address;
  44         if (remaining > PAGE_SIZE)
  45                 remaining = PAGE_SIZE;
  46         /* read from the file. page is in kernel space, not user space. */
  47         old_fs = get_fs(); set_fs(get_ds());
  48         count = sysv_file_read (area->vm_inode, &filp, (char *)page, remaining);
  49         set_fs(old_fs);
  50         if (count < 0)
  51                 count = 0;      /* do nothing on I/O error ?? */
  52         else
  53                 remaining -= count;
  54         if (remaining > 0)
  55                 memset((char *)page + count, 0, remaining);
  56         return page;
  57 }
  58 
  59 static struct vm_operations_struct sysv_file_mmap = {
  60         NULL,                   /* open */
  61         NULL,                   /* close */
  62         sysv_file_mmap_nopage,  /* nopage */
  63         NULL,                   /* wppage */
  64         NULL,                   /* share */
  65         NULL,                   /* unmap */
  66 };
  67 
  68 int sysv_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70         if (vma->vm_page_prot & PAGE_RW)        /* only PAGE_COW or read-only supported right now */
  71                 return -EINVAL;
  72         if (vma->vm_offset & (inode->i_sb->s_blocksize - 1))
  73                 return -EINVAL;
  74         if (!inode->i_sb || !S_ISREG(inode->i_mode))
  75                 return -EACCES;
  76         if (!IS_RDONLY(inode)) {
  77                 inode->i_atime = CURRENT_TIME;
  78                 inode->i_dirt = 1;
  79         }
  80 
  81         vma->vm_inode = inode;
  82         inode->i_count++;
  83         vma->vm_ops = &sysv_file_mmap;
  84         return 0;
  85 }

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