This source file includes following definitions.
- min
- ncp_file_mmap_nopage
- ncp_mmap
1
2
3
4
5
6
7
8 #include <linux/stat.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
11 #include <linux/mm.h>
12 #include <linux/shm.h>
13 #include <linux/errno.h>
14 #include <linux/mman.h>
15 #include <linux/string.h>
16 #include <linux/malloc.h>
17 #include <linux/fcntl.h>
18 #include <linux/ncp_fs.h>
19
20 #include "ncplib_kernel.h"
21 #include <asm/segment.h>
22 #include <asm/system.h>
23
24 static inline int min(int a, int b)
25 {
26 return a<b ? a : b;
27 }
28
29
30
31
32 static unsigned long
33 ncp_file_mmap_nopage(struct vm_area_struct * area,
34 unsigned long address, unsigned long page, int no_share)
35 {
36 struct inode * inode = area->vm_inode;
37 unsigned int clear;
38 unsigned long tmp;
39 int bufsize;
40 int pos;
41 unsigned short fs;
42
43 address &= PAGE_MASK;
44 pos = address - area->vm_start + area->vm_offset;
45
46 clear = 0;
47 if (address + PAGE_SIZE > area->vm_end)
48 {
49 clear = address + PAGE_SIZE - area->vm_end;
50 }
51
52
53 bufsize = NCP_SERVER(inode)->buffer_size;
54
55 fs = get_fs();
56 set_fs(get_ds());
57
58 if (ncp_make_open(inode, O_RDONLY) < 0)
59 {
60 clear = PAGE_SIZE;
61 }
62 else
63 {
64 int already_read = 0;
65 int count = PAGE_SIZE - clear;
66 int to_read;
67
68 while (already_read < count)
69 {
70 int read_this_time;
71
72 if ((pos % bufsize) != 0)
73 {
74 to_read = bufsize - (pos % bufsize);
75 }
76 else
77 {
78 to_read = bufsize;
79 }
80
81 to_read = min(to_read, count - already_read);
82
83 if (ncp_read(NCP_SERVER(inode),
84 NCP_FINFO(inode)->file_handle,
85 pos, to_read,
86 (char *)(page + already_read),
87 &read_this_time) != 0)
88 {
89 read_this_time = 0;
90 }
91
92 pos += read_this_time;
93 already_read += read_this_time;
94
95 if (read_this_time < to_read)
96 {
97 break;
98 }
99 }
100
101 }
102
103 set_fs(fs);
104
105 tmp = page + PAGE_SIZE;
106 while (clear--) {
107 *(char *)--tmp = 0;
108 }
109 return page;
110 }
111
112 struct vm_operations_struct ncp_file_mmap = {
113 NULL,
114 NULL,
115 NULL,
116 NULL,
117 NULL,
118 NULL,
119 ncp_file_mmap_nopage,
120 NULL,
121 NULL,
122 NULL,
123 };
124
125
126
127 int
128 ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
129 {
130 DPRINTK("ncp_mmap: called\n");
131
132
133 if (vma->vm_flags & VM_SHARED)
134 return -EINVAL;
135 if (!inode->i_sb || !S_ISREG(inode->i_mode))
136 return -EACCES;
137 if (!IS_RDONLY(inode)) {
138 inode->i_atime = CURRENT_TIME;
139 inode->i_dirt = 1;
140 }
141
142 vma->vm_inode = inode;
143 inode->i_count++;
144 vma->vm_ops = &ncp_file_mmap;
145 return 0;
146 }