| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* | 
|  | 31 | * Veritas filesystem driver - shared subroutines. | 
|  | 32 | */ | 
|  | 33 | #include <linux/fs.h> | 
|  | 34 | #include <linux/buffer_head.h> | 
|  | 35 | #include <linux/kernel.h> | 
|  | 36 | #include <linux/slab.h> | 
|  | 37 | #include <linux/pagemap.h> | 
|  | 38 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "vxfs_extern.h" | 
|  | 40 |  | 
|  | 41 |  | 
|  | 42 | static int		vxfs_readpage(struct file *, struct page *); | 
|  | 43 | static sector_t		vxfs_bmap(struct address_space *, sector_t); | 
|  | 44 |  | 
| Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 45 | const struct address_space_operations vxfs_aops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | .readpage =		vxfs_readpage, | 
|  | 47 | .bmap =			vxfs_bmap, | 
|  | 48 | .sync_page =		block_sync_page, | 
|  | 49 | }; | 
|  | 50 |  | 
|  | 51 | inline void | 
|  | 52 | vxfs_put_page(struct page *pp) | 
|  | 53 | { | 
|  | 54 | kunmap(pp); | 
|  | 55 | page_cache_release(pp); | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | /** | 
|  | 59 | * vxfs_get_page - read a page into memory. | 
|  | 60 | * @ip:		inode to read from | 
|  | 61 | * @n:		page number | 
|  | 62 | * | 
|  | 63 | * Description: | 
|  | 64 | *   vxfs_get_page reads the @n th page of @ip into the pagecache. | 
|  | 65 | * | 
|  | 66 | * Returns: | 
|  | 67 | *   The wanted page on success, else a NULL pointer. | 
|  | 68 | */ | 
|  | 69 | struct page * | 
|  | 70 | vxfs_get_page(struct address_space *mapping, u_long n) | 
|  | 71 | { | 
|  | 72 | struct page *			pp; | 
|  | 73 |  | 
| Pekka Enberg | 090d2b1 | 2006-06-23 02:05:08 -0700 | [diff] [blame] | 74 | pp = read_mapping_page(mapping, n, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 |  | 
|  | 76 | if (!IS_ERR(pp)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | kmap(pp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /** if (!PageChecked(pp)) **/ | 
|  | 79 | /** vxfs_check_page(pp); **/ | 
|  | 80 | if (PageError(pp)) | 
|  | 81 | goto fail; | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | return (pp); | 
|  | 85 |  | 
|  | 86 | fail: | 
|  | 87 | vxfs_put_page(pp); | 
|  | 88 | return ERR_PTR(-EIO); | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | /** | 
|  | 92 | * vxfs_bread - read buffer for a give inode,block tuple | 
|  | 93 | * @ip:		inode | 
|  | 94 | * @block:	logical block | 
|  | 95 | * | 
|  | 96 | * Description: | 
|  | 97 | *   The vxfs_bread function reads block no @block  of | 
|  | 98 | *   @ip into the buffercache. | 
|  | 99 | * | 
|  | 100 | * Returns: | 
|  | 101 | *   The resulting &struct buffer_head. | 
|  | 102 | */ | 
|  | 103 | struct buffer_head * | 
|  | 104 | vxfs_bread(struct inode *ip, int block) | 
|  | 105 | { | 
|  | 106 | struct buffer_head	*bp; | 
|  | 107 | daddr_t			pblock; | 
|  | 108 |  | 
|  | 109 | pblock = vxfs_bmap1(ip, block); | 
|  | 110 | bp = sb_bread(ip->i_sb, pblock); | 
|  | 111 |  | 
|  | 112 | return (bp); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | /** | 
|  | 116 | * vxfs_get_block - locate buffer for given inode,block tuple | 
|  | 117 | * @ip:		inode | 
|  | 118 | * @iblock:	logical block | 
|  | 119 | * @bp:		buffer skeleton | 
|  | 120 | * @create:	%TRUE if blocks may be newly allocated. | 
|  | 121 | * | 
|  | 122 | * Description: | 
|  | 123 | *   The vxfs_get_block function fills @bp with the right physical | 
|  | 124 | *   block and device number to perform a lowlevel read/write on | 
|  | 125 | *   it. | 
|  | 126 | * | 
|  | 127 | * Returns: | 
|  | 128 | *   Zero on success, else a negativ error code (-EIO). | 
|  | 129 | */ | 
|  | 130 | static int | 
|  | 131 | vxfs_getblk(struct inode *ip, sector_t iblock, | 
|  | 132 | struct buffer_head *bp, int create) | 
|  | 133 | { | 
|  | 134 | daddr_t			pblock; | 
|  | 135 |  | 
|  | 136 | pblock = vxfs_bmap1(ip, iblock); | 
|  | 137 | if (pblock != 0) { | 
|  | 138 | map_bh(bp, ip->i_sb, pblock); | 
|  | 139 | return 0; | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | return -EIO; | 
|  | 143 | } | 
|  | 144 |  | 
|  | 145 | /** | 
|  | 146 | * vxfs_readpage - read one page synchronously into the pagecache | 
|  | 147 | * @file:	file context (unused) | 
|  | 148 | * @page:	page frame to fill in. | 
|  | 149 | * | 
|  | 150 | * Description: | 
|  | 151 | *   The vxfs_readpage routine reads @page synchronously into the | 
|  | 152 | *   pagecache. | 
|  | 153 | * | 
|  | 154 | * Returns: | 
|  | 155 | *   Zero on success, else a negative error code. | 
|  | 156 | * | 
|  | 157 | * Locking status: | 
|  | 158 | *   @page is locked and will be unlocked. | 
|  | 159 | */ | 
|  | 160 | static int | 
|  | 161 | vxfs_readpage(struct file *file, struct page *page) | 
|  | 162 | { | 
|  | 163 | return block_read_full_page(page, vxfs_getblk); | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | /** | 
|  | 167 | * vxfs_bmap - perform logical to physical block mapping | 
|  | 168 | * @mapping:	logical to physical mapping to use | 
|  | 169 | * @block:	logical block (relative to @mapping). | 
|  | 170 | * | 
|  | 171 | * Description: | 
|  | 172 | *   Vxfs_bmap find out the corresponding phsical block to the | 
|  | 173 | *   @mapping, @block pair. | 
|  | 174 | * | 
|  | 175 | * Returns: | 
|  | 176 | *   Physical block number on success, else Zero. | 
|  | 177 | * | 
|  | 178 | * Locking status: | 
|  | 179 | *   We are under the bkl. | 
|  | 180 | */ | 
|  | 181 | static sector_t | 
|  | 182 | vxfs_bmap(struct address_space *mapping, sector_t block) | 
|  | 183 | { | 
|  | 184 | return generic_block_bmap(mapping, block, vxfs_getblk); | 
|  | 185 | } |