xref: /openbmc/linux/fs/9p/vfs_addr.c (revision e868d61272caa648214046a096e5a6bfc068dc8c)
1 /*
2  *  linux/fs/9p/vfs_addr.c
3  *
4  * This file contians vfs address (mmap) ops for 9P2000.
5  *
6  *  Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
7  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License version 2
11  *  as published by the Free Software Foundation.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to:
20  *  Free Software Foundation
21  *  51 Franklin Street, Fifth Floor
22  *  Boston, MA  02111-1301  USA
23  *
24  */
25 
26 #include <linux/module.h>
27 #include <linux/errno.h>
28 #include <linux/fs.h>
29 #include <linux/file.h>
30 #include <linux/stat.h>
31 #include <linux/string.h>
32 #include <linux/inet.h>
33 #include <linux/pagemap.h>
34 #include <linux/idr.h>
35 
36 #include "debug.h"
37 #include "v9fs.h"
38 #include "9p.h"
39 #include "v9fs_vfs.h"
40 #include "fid.h"
41 
42 /**
43  * v9fs_vfs_readpage - read an entire page in from 9P
44  *
45  * @file: file being read
46  * @page: structure to page
47  *
48  */
49 
50 static int v9fs_vfs_readpage(struct file *filp, struct page *page)
51 {
52 	char *buffer = NULL;
53 	int retval = -EIO;
54 	loff_t offset = page_offset(page);
55 	int count = PAGE_CACHE_SIZE;
56 	struct inode *inode = filp->f_path.dentry->d_inode;
57 	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
58 	int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
59 	struct v9fs_fid *v9f = filp->private_data;
60 	struct v9fs_fcall *fcall = NULL;
61 	int fid = v9f->fid;
62 	int total = 0;
63 	int result = 0;
64 
65 	dprintk(DEBUG_VFS, "\n");
66 
67 	buffer = kmap(page);
68 	do {
69 		if (count < rsize)
70 			rsize = count;
71 
72 		result = v9fs_t_read(v9ses, fid, offset, rsize, &fcall);
73 
74 		if (result < 0) {
75 			printk(KERN_ERR "v9fs_t_read returned %d\n",
76 			       result);
77 
78 			kfree(fcall);
79 			goto UnmapAndUnlock;
80 		} else
81 			offset += result;
82 
83 		memcpy(buffer, fcall->params.rread.data, result);
84 
85 		count -= result;
86 		buffer += result;
87 		total += result;
88 
89 		kfree(fcall);
90 
91 		if (result < rsize)
92 			break;
93 	} while (count);
94 
95 	memset(buffer, 0, count);
96 	flush_dcache_page(page);
97 	SetPageUptodate(page);
98 	retval = 0;
99 
100 UnmapAndUnlock:
101 	kunmap(page);
102 	unlock_page(page);
103 	return retval;
104 }
105 
106 const struct address_space_operations v9fs_addr_operations = {
107       .readpage = v9fs_vfs_readpage,
108 };
109