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