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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  mmap.c
3
 *
4
 *  Copyright (C) 1995, 1996 by Volker Lendecke
5
 *
6
 */
7
 
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
#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/fcntl.h>
24
#include <linux/ncp_fs.h>
25
 
26
#include "ncplib_kernel.h"
27
#include <asm/segment.h>
28
#include <asm/system.h>
29
 
30
#ifndef NO_MM
31
 
32
static inline int min(int a, int b)
33
{
34
        return a<b ? a : b;
35
}
36
 
37
/*
38
 * Fill in the supplied page for mmap
39
 */
40
static unsigned long
41
ncp_file_mmap_nopage(struct vm_area_struct * area,
42
                     unsigned long address, int no_share)
43
{
44
        struct inode * inode = area->vm_inode;
45
        unsigned long page;
46
        unsigned int clear;
47
        unsigned long tmp;
48
        int bufsize;
49
        int pos;
50
        unsigned short fs;
51
 
52
        page = __get_free_page(GFP_KERNEL);
53
        if (!page)
54
                return page;
55
        address &= PAGE_MASK;
56
        pos = address - area->vm_start + area->vm_offset;
57
 
58
        clear = 0;
59
        if (address + PAGE_SIZE > area->vm_end)
60
        {
61
                clear = address + PAGE_SIZE - area->vm_end;
62
        }
63
 
64
        /* what we can read in one go */
65
        bufsize = NCP_SERVER(inode)->buffer_size;
66
 
67
        fs = get_fs();
68
        set_fs(get_ds());
69
 
70
        if (ncp_make_open(inode, O_RDONLY) < 0)
71
        {
72
                clear = PAGE_SIZE;
73
        }
74
        else
75
        {
76
                int already_read = 0;
77
                int count = PAGE_SIZE - clear;
78
                int to_read;
79
 
80
                while (already_read < count)
81
                {
82
                        int read_this_time;
83
 
84
                        if ((pos % bufsize) != 0)
85
                        {
86
                                to_read = bufsize - (pos % bufsize);
87
                        }
88
                        else
89
                        {
90
                                to_read = bufsize;
91
                        }
92
 
93
                        to_read = min(to_read, count - already_read);
94
 
95
                        if (ncp_read(NCP_SERVER(inode),
96
                                     NCP_FINFO(inode)->file_handle,
97
                                     pos, to_read,
98
                                     (char *)(page + already_read),
99
                                     &read_this_time) != 0)
100
                        {
101
                               read_this_time = 0;
102
                        }
103
 
104
                        pos += read_this_time;
105
                        already_read += read_this_time;
106
 
107
                        if (read_this_time < to_read)
108
                        {
109
                                break;
110
                        }
111
                }
112
 
113
        }
114
 
115
        set_fs(fs);
116
 
117
        tmp = page + PAGE_SIZE;
118
        while (clear--) {
119
                *(char *)--tmp = 0;
120
        }
121
        return page;
122
}
123
 
124
struct vm_operations_struct ncp_file_mmap = {
125
        NULL,                   /* open */
126
        NULL,                   /* close */
127
        NULL,                   /* unmap */
128
        NULL,                   /* protect */
129
        NULL,                   /* sync */
130
        NULL,                   /* advise */
131
        ncp_file_mmap_nopage,   /* nopage */
132
        NULL,                   /* wppage */
133
        NULL,                   /* swapout */
134
        NULL,                   /* swapin */
135
};
136
 
137
 
138
/* This is used for a general mmap of a ncp file */
139
int
140
ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
141
{
142
        DPRINTK("ncp_mmap: called\n");
143
 
144
        if (!ncp_conn_valid(NCP_SERVER(inode)))
145
        {
146
                return -EIO;
147
        }
148
 
149
        /* only PAGE_COW or read-only supported now */
150
        if (vma->vm_flags & VM_SHARED)
151
                return -EINVAL;
152
        if (!inode->i_sb || !S_ISREG(inode->i_mode))
153
                return -EACCES;
154
        if (!IS_RDONLY(inode)) {
155
                inode->i_atime = CURRENT_TIME;
156
                inode->i_dirt = 1;
157
        }
158
 
159
        vma->vm_inode = inode;
160
        inode->i_count++;
161
        vma->vm_ops = &ncp_file_mmap;
162
        return 0;
163
}
164
 
165
#else /* !NO_MM */
166
 
167
int
168
ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
169
{
170
        return -ENOSYS;
171
}
172
 
173
#endif /* !NO_MM */

powered by: WebSVN 2.1.0

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