1 /*
2 * mmap.c
3 *
4 * Copyright (C) 1995, 1996 by Volker Lendecke
5 * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
6 *
7 */
8
9 #include <linux/stat.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12 #include <linux/mm.h>
13 #include <linux/shm.h>
14 #include <linux/errno.h>
15 #include <linux/mman.h>
16 #include <linux/string.h>
17 #include <linux/malloc.h>
18 #include <linux/fcntl.h>
19 #include <linux/ncp_fs.h>
20
21 #include "ncplib_kernel.h"
22 #include <asm/uaccess.h>
23 #include <asm/system.h>
24
25 static inline int min(int a, int b)
26 {
27 return a < b ? a : b;
28 }
29
30 /*
31 * Fill in the supplied page for mmap
32 */
33 static struct page* ncp_file_mmap_nopage(struct vm_area_struct *area,
34 unsigned long address, int write_access)
35 {
36 struct file *file = area->vm_file;
37 struct dentry *dentry = file->f_dentry;
38 struct inode *inode = dentry->d_inode;
39 struct page* page;
40 char *pg_addr;
41 unsigned int already_read;
42 unsigned int count;
43 int bufsize;
44 int pos;
45
46 page = alloc_page(GFP_HIGHMEM); /* ncpfs has nothing against GFP_HIGHMEM
47 as long as recvmsg and memset works on it */
48 if (!page)
49 return page;
50 pg_addr = kmap(page);
51 address &= PAGE_MASK;
52 pos = address - area->vm_start + (area->vm_pgoff << PAGE_SHIFT);
53
54 count = PAGE_SIZE;
55 if (address + PAGE_SIZE > area->vm_end) {
56 count = area->vm_end - address;
57 }
58 /* what we can read in one go */
59 bufsize = NCP_SERVER(inode)->buffer_size;
60
61 already_read = 0;
62 if (ncp_make_open(inode, O_RDONLY) >= 0) {
63 while (already_read < count) {
64 int read_this_time;
65 int to_read;
66
67 to_read = bufsize - (pos % bufsize);
68
69 to_read = min(to_read, count - already_read);
70
71 if (ncp_read_kernel(NCP_SERVER(inode),
72 NCP_FINFO(inode)->file_handle,
73 pos, to_read,
74 pg_addr + already_read,
75 &read_this_time) != 0) {
76 read_this_time = 0;
77 }
78 pos += read_this_time;
79 already_read += read_this_time;
80
81 if (read_this_time < to_read) {
82 break;
83 }
84 }
85 ncp_inode_close(inode);
86
87 }
88
89 if (already_read < PAGE_SIZE)
90 memset(pg_addr + already_read, 0, PAGE_SIZE - already_read);
91 flush_dcache_page(page);
92 kunmap(page);
93 return page;
94 }
95
96 static struct vm_operations_struct ncp_file_mmap =
97 {
98 nopage: ncp_file_mmap_nopage,
99 };
100
101
102 /* This is used for a general mmap of a ncp file */
103 int ncp_mmap(struct file *file, struct vm_area_struct *vma)
104 {
105 struct inode *inode = file->f_dentry->d_inode;
106
107 DPRINTK("ncp_mmap: called\n");
108
109 if (!ncp_conn_valid(NCP_SERVER(inode))) {
110 return -EIO;
111 }
112 /* only PAGE_COW or read-only supported now */
113 if (vma->vm_flags & VM_SHARED)
114 return -EINVAL;
115 if (!inode->i_sb || !S_ISREG(inode->i_mode))
116 return -EACCES;
117 /* we do not support files bigger than 4GB... We eventually
118 supports just 4GB... */
119 if (((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff
120 > (1U << (32 - PAGE_SHIFT)))
121 return -EFBIG;
122 if (!IS_RDONLY(inode)) {
123 inode->i_atime = CURRENT_TIME;
124 }
125
126 vma->vm_ops = &ncp_file_mmap;
127 return 0;
128 }
129
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.