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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [smbfs/] [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 Paal-Kr. Engstad and 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/smb_fs.h>
24
#include <linux/fcntl.h>
25
 
26
#include <asm/segment.h>
27
#include <asm/system.h>
28
 
29
#ifndef NO_MM
30
 
31
/*
32
 * Fill in the supplied page for mmap
33
 */
34
static unsigned long
35
smb_file_mmap_nopage(struct vm_area_struct *area,
36
                     unsigned long address, int no_share)
37
{
38
        struct inode *inode = area->vm_inode;
39
        unsigned long page;
40
        unsigned int clear;
41
        unsigned long tmp;
42
        int n;
43
        int i;
44
        int pos;
45
 
46
        page = __get_free_page(GFP_KERNEL);
47
        if (!page)
48
                return 0;
49
        address &= PAGE_MASK;
50
        pos = address - area->vm_start + area->vm_offset;
51
 
52
        clear = 0;
53
        if (address + PAGE_SIZE > area->vm_end)
54
        {
55
                clear = address + PAGE_SIZE - area->vm_end;
56
        }
57
        /* what we can read in one go */
58
        n = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 3 - 10;
59
 
60
        if (smb_make_open(inode, O_RDONLY) < 0)
61
        {
62
                clear = PAGE_SIZE;
63
        } else
64
        {
65
 
66
                for (i = 0; i < (PAGE_SIZE - clear); i += n)
67
                {
68
                        int hunk, result;
69
 
70
                        hunk = PAGE_SIZE - i;
71
                        if (hunk > n)
72
                                hunk = n;
73
 
74
                        DDPRINTK("smb_file_mmap_nopage: reading\n");
75
                        DDPRINTK("smb_file_mmap_nopage: pos = %d\n", pos);
76
                        result = smb_proc_read(SMB_SERVER(inode),
77
                                               SMB_FINFO(inode), pos, hunk,
78
                                               (char *) (page + i), 0);
79
                        DDPRINTK("smb_file_mmap_nopage: result= %d\n", result);
80
                        if (result < 0)
81
                                break;
82
                        pos += result;
83
                        if (result < n)
84
                        {
85
                                i += result;
86
                                break;
87
                        }
88
                }
89
        }
90
 
91
        tmp = page + PAGE_SIZE;
92
        while (clear--)
93
        {
94
                *(char *) --tmp = 0;
95
        }
96
        return page;
97
}
98
 
99
struct vm_operations_struct smb_file_mmap =
100
{
101
        NULL,                   /* open */
102
        NULL,                   /* close */
103
        NULL,                   /* unmap */
104
        NULL,                   /* protect */
105
        NULL,                   /* sync */
106
        NULL,                   /* advise */
107
        smb_file_mmap_nopage,   /* nopage */
108
        NULL,                   /* wppage */
109
        NULL,                   /* swapout */
110
        NULL,                   /* swapin */
111
};
112
 
113
 
114
/* This is used for a general mmap of a smb file */
115
int
116
smb_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)
117
{
118
        DPRINTK("smb_mmap: called\n");
119
 
120
        /* only PAGE_COW or read-only supported now */
121
        if (vma->vm_flags & VM_SHARED)
122
                return -EINVAL;
123
        if (!inode->i_sb || !S_ISREG(inode->i_mode))
124
                return -EACCES;
125
        if (!IS_RDONLY(inode))
126
        {
127
                inode->i_atime = CURRENT_TIME;
128
                inode->i_dirt = 1;
129
        }
130
        vma->vm_inode = inode;
131
        inode->i_count++;
132
        vma->vm_ops = &smb_file_mmap;
133
        return 0;
134
}
135
 
136
#else /* NO_MM */
137
 
138
int
139
smb_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)\
140
{
141
        return -ENOSYS;
142
}
143
 
144
#endif /* NO_MM */

powered by: WebSVN 2.1.0

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