xref: /OK3568_Linux_fs/kernel/fs/freevxfs/vxfs_immed.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2000-2001 Christoph Hellwig.
3*4882a593Smuzhiyun  * All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
6*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
7*4882a593Smuzhiyun  * are met:
8*4882a593Smuzhiyun  * 1. Redistributions of source code must retain the above copyright
9*4882a593Smuzhiyun  *    notice, this list of conditions, and the following disclaimer,
10*4882a593Smuzhiyun  *    without modification.
11*4882a593Smuzhiyun  * 2. The name of the author may not be used to endorse or promote products
12*4882a593Smuzhiyun  *    derived from this software without specific prior written permission.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * Alternatively, this software may be distributed under the terms of the
15*4882a593Smuzhiyun  * GNU General Public License ("GPL").
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*4882a593Smuzhiyun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4882a593Smuzhiyun  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21*4882a593Smuzhiyun  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*4882a593Smuzhiyun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*4882a593Smuzhiyun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*4882a593Smuzhiyun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*4882a593Smuzhiyun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*4882a593Smuzhiyun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*4882a593Smuzhiyun  * SUCH DAMAGE.
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * Veritas filesystem driver - support for 'immed' inodes.
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun #include <linux/fs.h>
34*4882a593Smuzhiyun #include <linux/pagemap.h>
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #include "vxfs.h"
37*4882a593Smuzhiyun #include "vxfs_extern.h"
38*4882a593Smuzhiyun #include "vxfs_inode.h"
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun static int	vxfs_immed_readpage(struct file *, struct page *);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun  * Address space operations for immed files and directories.
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun const struct address_space_operations vxfs_immed_aops = {
47*4882a593Smuzhiyun 	.readpage =		vxfs_immed_readpage,
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /**
51*4882a593Smuzhiyun  * vxfs_immed_readpage - read part of an immed inode into pagecache
52*4882a593Smuzhiyun  * @file:	file context (unused)
53*4882a593Smuzhiyun  * @page:	page frame to fill in.
54*4882a593Smuzhiyun  *
55*4882a593Smuzhiyun  * Description:
56*4882a593Smuzhiyun  *   vxfs_immed_readpage reads a part of the immed area of the
57*4882a593Smuzhiyun  *   file that hosts @pp into the pagecache.
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  * Returns:
60*4882a593Smuzhiyun  *   Zero on success, else a negative error code.
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * Locking status:
63*4882a593Smuzhiyun  *   @page is locked and will be unlocked.
64*4882a593Smuzhiyun  */
65*4882a593Smuzhiyun static int
vxfs_immed_readpage(struct file * fp,struct page * pp)66*4882a593Smuzhiyun vxfs_immed_readpage(struct file *fp, struct page *pp)
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun 	struct vxfs_inode_info	*vip = VXFS_INO(pp->mapping->host);
69*4882a593Smuzhiyun 	u_int64_t	offset = (u_int64_t)pp->index << PAGE_SHIFT;
70*4882a593Smuzhiyun 	caddr_t		kaddr;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	kaddr = kmap(pp);
73*4882a593Smuzhiyun 	memcpy(kaddr, vip->vii_immed.vi_immed + offset, PAGE_SIZE);
74*4882a593Smuzhiyun 	kunmap(pp);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	flush_dcache_page(pp);
77*4882a593Smuzhiyun 	SetPageUptodate(pp);
78*4882a593Smuzhiyun         unlock_page(pp);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	return 0;
81*4882a593Smuzhiyun }
82