OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [fat/] [mmap.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *      linux/fs/fat/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
 *      mmap handling for fat-based filesystems
8
 *
9
 * uClinux revisions for NO_MM
10
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
11
 *                     The Silver Hammer Group, Ltd.
12
 */
13
 
14
#define ASC_LINUX_VERSION(V, P, S)      (((V) * 65536) + ((P) * 256) + (S))
15
#include <linux/version.h>
16
 
17
#include <linux/stat.h>
18
#include <linux/sched.h>
19
#include <linux/kernel.h>
20
#include <linux/mm.h>
21
#include <linux/shm.h>
22
#include <linux/errno.h>
23
#include <linux/mman.h>
24
#include <linux/string.h>
25
#include <linux/malloc.h>
26
#include <linux/msdos_fs.h>
27
 
28
#if LINUX_VERSION_CODE >= ASC_LINUX_VERSION(2,1,0)
29
#include <asm/uaccess.h>
30
#else
31
#include <asm/segment.h>
32
#endif
33
#include <asm/system.h>
34
 
35
#ifndef NO_MM
36
 
37
/*
38
 * Fill in the supplied page for mmap
39
 */
40
static unsigned long fat_file_mmap_nopage(
41
        struct vm_area_struct * area,
42
        unsigned long address,
43
        int error_code)
44
{
45
        struct inode * inode = area->vm_inode;
46
        unsigned long page;
47
        unsigned int clear;
48
        int pos;
49
        long gap;       /* distance from eof to pos */
50
 
51
        page = __get_free_page(GFP_KERNEL);
52
        if (!page)
53
                return page;
54
        address &= PAGE_MASK;
55
        pos = address - area->vm_start + area->vm_offset;
56
 
57
        clear = 0;
58
        gap = inode->i_size - pos;
59
        if (gap <= 0){
60
                /* mmaping beyond end of file */
61
                clear = PAGE_SIZE;
62
        }else{
63
                int cur_read;
64
                int need_read;
65
                struct file filp;
66
                if (gap < PAGE_SIZE){
67
                        clear = PAGE_SIZE - gap;
68
                }
69
                filp.f_reada = 0;
70
                filp.f_pos = pos;
71
                need_read = PAGE_SIZE - clear;
72
                {
73
                        unsigned long cur_fs = get_fs();
74
                        set_fs (KERNEL_DS);
75
                        cur_read = fat_file_read (inode,&filp,(char*)page
76
                                ,need_read);
77
                        set_fs (cur_fs);
78
                }
79
                if (cur_read != need_read){
80
                        printk ("MSDOS: Error while reading an mmap file %d <> %d\n"
81
                                ,cur_read,need_read);
82
                }
83
        }
84
        if (clear > 0){
85
                memset ((char*)page+PAGE_SIZE-clear,0,clear);
86
        }
87
        return page;
88
}
89
 
90
struct vm_operations_struct fat_file_mmap = {
91
        NULL,                   /* open */
92
        NULL,                   /* close */
93
        NULL,                   /* unmap */
94
        NULL,                   /* protect */
95
        NULL,                   /* sync */
96
        NULL,                   /* advise */
97
        fat_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 an msdos file
105
 * Returns 0 if ok, or a negative error code if not.
106
 */
107
int fat_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
108
{
109
        if (vma->vm_flags & VM_SHARED)  /* only PAGE_COW or read-only supported now */
110
                return -EINVAL;
111
        if (vma->vm_offset & (inode->i_sb->s_blocksize - 1))
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 = &fat_file_mmap;
123
        return 0;
124
}
125
 
126
#else /* NO_MM */
127
 
128
int fat_mmap()
129
{
130
        return -ENOSYS;
131
}
132
 
133
#endif /* NO_MM */
134
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.