GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / fs / ncpfs / mmap.c
bloba5eea42575d2887ecdead9385d512042180bb4ac
1 /*
2 * mmap.c
4 * Copyright (C) 1995, 1996 by Volker Lendecke
5 * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
7 */
9 #include <linux/stat.h>
10 #include <linux/time.h>
11 #include <linux/kernel.h>
12 #include <linux/gfp.h>
13 #include <linux/mm.h>
14 #include <linux/shm.h>
15 #include <linux/errno.h>
16 #include <linux/mman.h>
17 #include <linux/string.h>
18 #include <linux/fcntl.h>
19 #include <linux/ncp_fs.h>
21 #include "ncplib_kernel.h"
22 #include <asm/uaccess.h>
23 #include <asm/system.h>
25 static int ncp_file_mmap_fault(struct vm_area_struct *area,
26 struct vm_fault *vmf)
28 struct file *file = area->vm_file;
29 struct dentry *dentry = file->f_path.dentry;
30 struct inode *inode = dentry->d_inode;
31 char *pg_addr;
32 unsigned int already_read;
33 unsigned int count;
34 int bufsize;
35 int pos;
38 * ncpfs has nothing against high pages as long
39 * as recvmsg and memset works on it
41 vmf->page = alloc_page(GFP_HIGHUSER);
42 if (!vmf->page)
43 return VM_FAULT_OOM;
44 pg_addr = kmap(vmf->page);
45 pos = vmf->pgoff << PAGE_SHIFT;
47 count = PAGE_SIZE;
48 /* what we can read in one go */
49 bufsize = NCP_SERVER(inode)->buffer_size;
51 already_read = 0;
52 if (ncp_make_open(inode, O_RDONLY) >= 0) {
53 while (already_read < count) {
54 int read_this_time;
55 int to_read;
57 to_read = bufsize - (pos % bufsize);
59 to_read = min_t(unsigned int, to_read, count - already_read);
61 if (ncp_read_kernel(NCP_SERVER(inode),
62 NCP_FINFO(inode)->file_handle,
63 pos, to_read,
64 pg_addr + already_read,
65 &read_this_time) != 0) {
66 read_this_time = 0;
68 pos += read_this_time;
69 already_read += read_this_time;
71 if (read_this_time < to_read) {
72 break;
75 ncp_inode_close(inode);
79 if (already_read < PAGE_SIZE)
80 memset(pg_addr + already_read, 0, PAGE_SIZE - already_read);
81 flush_dcache_page(vmf->page);
82 kunmap(vmf->page);
85 * If I understand ncp_read_kernel() properly, the above always
86 * fetches from the network, here the analogue of disk.
87 * -- wli
89 count_vm_event(PGMAJFAULT);
90 return VM_FAULT_MAJOR;
93 static const struct vm_operations_struct ncp_file_mmap =
95 .fault = ncp_file_mmap_fault,
99 /* This is used for a general mmap of a ncp file */
100 int ncp_mmap(struct file *file, struct vm_area_struct *vma)
102 struct inode *inode = file->f_path.dentry->d_inode;
104 DPRINTK("ncp_mmap: called\n");
106 if (!ncp_conn_valid(NCP_SERVER(inode)))
107 return -EIO;
109 /* only PAGE_COW or read-only supported now */
110 if (vma->vm_flags & VM_SHARED)
111 return -EINVAL;
112 /* we do not support files bigger than 4GB... We eventually
113 supports just 4GB... */
114 if (((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff
115 > (1U << (32 - PAGE_SHIFT)))
116 return -EFBIG;
118 vma->vm_ops = &ncp_file_mmap;
119 file_accessed(file);
120 return 0;