File: /usr/src/linux/fs/freevxfs/vxfs_subr.c
1 /*
2 * Copyright (c) 2000-2001 Christoph Hellwig.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 *
14 * Alternatively, this software may be distributed under the terms of the
15 * GNU General Public License ("GPL").
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #ident "$Id: vxfs_subr.c,v 1.5 2001/04/26 22:49:51 hch Exp hch $"
31
32 /*
33 * Veritas filesystem driver - shared subroutines.
34 */
35 #include <linux/fs.h>
36 #include <linux/kernel.h>
37 #include <linux/slab.h>
38 #include <linux/pagemap.h>
39
40 #include "vxfs_extern.h"
41
42
43 static int vxfs_readpage(struct file *, struct page *);
44 static int vxfs_bmap(struct address_space *, long);
45
46 struct address_space_operations vxfs_aops = {
47 .readpage = vxfs_readpage,
48 .bmap = vxfs_bmap
49 };
50
51
52 /**
53 * vxfs_get_page - read a page into memory.
54 * @ip: inode to read from
55 * @n: page number
56 *
57 * Description:
58 * vxfs_get_page reads the @n th page of @ip into the pagecache.
59 *
60 * Returns:
61 * The wanted page on success, else a NULL pointer.
62 */
63 struct page *
64 vxfs_get_page(struct inode *ip, u_long n)
65 {
66 struct address_space * mapping = ip->i_mapping;
67 struct page * pp;
68
69 pp = read_cache_page(mapping, n,
70 (filler_t*)mapping->a_ops->readpage, NULL);
71
72 if (!IS_ERR(pp)) {
73 wait_on_page(pp);
74 kmap(pp);
75 if (!Page_Uptodate(pp))
76 goto fail;
77 /** if (!PageChecked(pp)) **/
78 /** vxfs_check_page(pp); **/
79 if (PageError(pp))
80 goto fail;
81 }
82
83 return (pp);
84
85 fail:
86 vxfs_put_page(pp);
87 return ERR_PTR(-EIO);
88 }
89
90 __inline__ void
91 vxfs_put_page(struct page *pp)
92 {
93 kunmap(pp);
94 page_cache_release(pp);
95 }
96
97 /**
98 * vxfs_bread - read buffer for a give inode,block tuple
99 * @ip: inode
100 * @block: logical block
101 *
102 * Description:
103 * The vxfs_bread function reads block no @block of
104 * @ip into the buffercache.
105 *
106 * Returns:
107 * The resulting &struct buffer_head.
108 */
109 struct buffer_head *
110 vxfs_bread(struct inode *ip, int block)
111 {
112 struct buffer_head *bp;
113 daddr_t pblock;
114
115 pblock = vxfs_bmap1(ip, block);
116 bp = bread(ip->i_dev, pblock, ip->i_sb->s_blocksize);
117
118 return (bp);
119 }
120
121 /**
122 * vxfs_get_block - locate buffer for given inode,block tuple
123 * @ip: inode
124 * @iblock: logical block
125 * @bp: buffer skeleton
126 * @create: %TRUE if blocks may be newly allocated.
127 *
128 * Description:
129 * The vxfs_get_block function fills @bp with the right physical
130 * block and device number to perform a lowlevel read/write on
131 * it.
132 *
133 * Returns:
134 * Zero on success, else a negativ error code (-EIO).
135 */
136 static int
137 vxfs_getblk(struct inode *ip, long iblock,
138 struct buffer_head *bp, int create)
139 {
140 daddr_t pblock;
141
142 pblock = vxfs_bmap1(ip, iblock);
143 if (pblock != 0) {
144 bp->b_dev = ip->i_dev;
145 bp->b_blocknr = pblock;
146 bp->b_state |= (1UL << BH_Mapped);
147
148 return 0;
149 }
150
151 return -EIO;
152 }
153
154 /**
155 * vxfs_readpage - read one page synchronously into the pagecache
156 * @file: file context (unused)
157 * @page: page frame to fill in.
158 *
159 * Description:
160 * The vxfs_readpage routine reads @page synchronously into the
161 * pagecache.
162 *
163 * Returns:
164 * Zero on success, else a negative error code.
165 *
166 * Locking status:
167 * @page is locked and will be unlocked.
168 */
169 static int
170 vxfs_readpage(struct file *file, struct page *page)
171 {
172 return block_read_full_page(page, vxfs_getblk);
173 }
174
175 /**
176 * vxfs_bmap - perform logical to physical block mapping
177 * @mapping: logical to physical mapping to use
178 * @block: logical block (relative to @mapping).
179 *
180 * Description:
181 * Vxfs_bmap find out the corresponding phsical block to the
182 * @mapping, @block pair.
183 *
184 * Returns:
185 * Physical block number on success, else Zero.
186 *
187 * Locking status:
188 * We are under the bkl.
189 */
190 static int
191 vxfs_bmap(struct address_space *mapping, long block)
192 {
193 return generic_block_bmap(mapping, block, vxfs_getblk);
194 }
195