18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2000-2001 Christoph Hellwig. 38c2ecf20Sopenharmony_ci * All rights reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 68c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 78c2ecf20Sopenharmony_ci * are met: 88c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 98c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 108c2ecf20Sopenharmony_ci * without modification. 118c2ecf20Sopenharmony_ci * 2. The name of the author may not be used to endorse or promote products 128c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 158c2ecf20Sopenharmony_ci * GNU General Public License ("GPL"). 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 188c2ecf20Sopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 198c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 208c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 218c2ecf20Sopenharmony_ci * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 228c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 238c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 248c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 258c2ecf20Sopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 268c2ecf20Sopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 278c2ecf20Sopenharmony_ci * SUCH DAMAGE. 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Veritas filesystem driver - shared subroutines. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci#include <linux/fs.h> 348c2ecf20Sopenharmony_ci#include <linux/buffer_head.h> 358c2ecf20Sopenharmony_ci#include <linux/kernel.h> 368c2ecf20Sopenharmony_ci#include <linux/pagemap.h> 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include "vxfs_extern.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic int vxfs_readpage(struct file *, struct page *); 428c2ecf20Sopenharmony_cistatic sector_t vxfs_bmap(struct address_space *, sector_t); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciconst struct address_space_operations vxfs_aops = { 458c2ecf20Sopenharmony_ci .readpage = vxfs_readpage, 468c2ecf20Sopenharmony_ci .bmap = vxfs_bmap, 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciinline void 508c2ecf20Sopenharmony_civxfs_put_page(struct page *pp) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci kunmap(pp); 538c2ecf20Sopenharmony_ci put_page(pp); 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/** 578c2ecf20Sopenharmony_ci * vxfs_get_page - read a page into memory. 588c2ecf20Sopenharmony_ci * @ip: inode to read from 598c2ecf20Sopenharmony_ci * @n: page number 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * Description: 628c2ecf20Sopenharmony_ci * vxfs_get_page reads the @n th page of @ip into the pagecache. 638c2ecf20Sopenharmony_ci * 648c2ecf20Sopenharmony_ci * Returns: 658c2ecf20Sopenharmony_ci * The wanted page on success, else a NULL pointer. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_cistruct page * 688c2ecf20Sopenharmony_civxfs_get_page(struct address_space *mapping, u_long n) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci struct page * pp; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci pp = read_mapping_page(mapping, n, NULL); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci if (!IS_ERR(pp)) { 758c2ecf20Sopenharmony_ci kmap(pp); 768c2ecf20Sopenharmony_ci /** if (!PageChecked(pp)) **/ 778c2ecf20Sopenharmony_ci /** vxfs_check_page(pp); **/ 788c2ecf20Sopenharmony_ci if (PageError(pp)) 798c2ecf20Sopenharmony_ci goto fail; 808c2ecf20Sopenharmony_ci } 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci return (pp); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cifail: 858c2ecf20Sopenharmony_ci vxfs_put_page(pp); 868c2ecf20Sopenharmony_ci return ERR_PTR(-EIO); 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/** 908c2ecf20Sopenharmony_ci * vxfs_bread - read buffer for a give inode,block tuple 918c2ecf20Sopenharmony_ci * @ip: inode 928c2ecf20Sopenharmony_ci * @block: logical block 938c2ecf20Sopenharmony_ci * 948c2ecf20Sopenharmony_ci * Description: 958c2ecf20Sopenharmony_ci * The vxfs_bread function reads block no @block of 968c2ecf20Sopenharmony_ci * @ip into the buffercache. 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * Returns: 998c2ecf20Sopenharmony_ci * The resulting &struct buffer_head. 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_cistruct buffer_head * 1028c2ecf20Sopenharmony_civxfs_bread(struct inode *ip, int block) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci struct buffer_head *bp; 1058c2ecf20Sopenharmony_ci daddr_t pblock; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci pblock = vxfs_bmap1(ip, block); 1088c2ecf20Sopenharmony_ci bp = sb_bread(ip->i_sb, pblock); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci return (bp); 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/** 1148c2ecf20Sopenharmony_ci * vxfs_get_block - locate buffer for given inode,block tuple 1158c2ecf20Sopenharmony_ci * @ip: inode 1168c2ecf20Sopenharmony_ci * @iblock: logical block 1178c2ecf20Sopenharmony_ci * @bp: buffer skeleton 1188c2ecf20Sopenharmony_ci * @create: %TRUE if blocks may be newly allocated. 1198c2ecf20Sopenharmony_ci * 1208c2ecf20Sopenharmony_ci * Description: 1218c2ecf20Sopenharmony_ci * The vxfs_get_block function fills @bp with the right physical 1228c2ecf20Sopenharmony_ci * block and device number to perform a lowlevel read/write on 1238c2ecf20Sopenharmony_ci * it. 1248c2ecf20Sopenharmony_ci * 1258c2ecf20Sopenharmony_ci * Returns: 1268c2ecf20Sopenharmony_ci * Zero on success, else a negativ error code (-EIO). 1278c2ecf20Sopenharmony_ci */ 1288c2ecf20Sopenharmony_cistatic int 1298c2ecf20Sopenharmony_civxfs_getblk(struct inode *ip, sector_t iblock, 1308c2ecf20Sopenharmony_ci struct buffer_head *bp, int create) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci daddr_t pblock; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci pblock = vxfs_bmap1(ip, iblock); 1358c2ecf20Sopenharmony_ci if (pblock != 0) { 1368c2ecf20Sopenharmony_ci map_bh(bp, ip->i_sb, pblock); 1378c2ecf20Sopenharmony_ci return 0; 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci return -EIO; 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/** 1448c2ecf20Sopenharmony_ci * vxfs_readpage - read one page synchronously into the pagecache 1458c2ecf20Sopenharmony_ci * @file: file context (unused) 1468c2ecf20Sopenharmony_ci * @page: page frame to fill in. 1478c2ecf20Sopenharmony_ci * 1488c2ecf20Sopenharmony_ci * Description: 1498c2ecf20Sopenharmony_ci * The vxfs_readpage routine reads @page synchronously into the 1508c2ecf20Sopenharmony_ci * pagecache. 1518c2ecf20Sopenharmony_ci * 1528c2ecf20Sopenharmony_ci * Returns: 1538c2ecf20Sopenharmony_ci * Zero on success, else a negative error code. 1548c2ecf20Sopenharmony_ci * 1558c2ecf20Sopenharmony_ci * Locking status: 1568c2ecf20Sopenharmony_ci * @page is locked and will be unlocked. 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_cistatic int 1598c2ecf20Sopenharmony_civxfs_readpage(struct file *file, struct page *page) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci return block_read_full_page(page, vxfs_getblk); 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/** 1658c2ecf20Sopenharmony_ci * vxfs_bmap - perform logical to physical block mapping 1668c2ecf20Sopenharmony_ci * @mapping: logical to physical mapping to use 1678c2ecf20Sopenharmony_ci * @block: logical block (relative to @mapping). 1688c2ecf20Sopenharmony_ci * 1698c2ecf20Sopenharmony_ci * Description: 1708c2ecf20Sopenharmony_ci * Vxfs_bmap find out the corresponding phsical block to the 1718c2ecf20Sopenharmony_ci * @mapping, @block pair. 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * Returns: 1748c2ecf20Sopenharmony_ci * Physical block number on success, else Zero. 1758c2ecf20Sopenharmony_ci * 1768c2ecf20Sopenharmony_ci * Locking status: 1778c2ecf20Sopenharmony_ci * We are under the bkl. 1788c2ecf20Sopenharmony_ci */ 1798c2ecf20Sopenharmony_cistatic sector_t 1808c2ecf20Sopenharmony_civxfs_bmap(struct address_space *mapping, sector_t block) 1818c2ecf20Sopenharmony_ci{ 1828c2ecf20Sopenharmony_ci return generic_block_bmap(mapping, block, vxfs_getblk); 1838c2ecf20Sopenharmony_ci} 184