Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (c) 2000-2001 Christoph Hellwig.
0004  */
0005 
0006 /*
0007  * Veritas filesystem driver - shared subroutines.
0008  */
0009 #include <linux/fs.h>
0010 #include <linux/buffer_head.h>
0011 #include <linux/kernel.h>
0012 #include <linux/pagemap.h>
0013 
0014 #include "vxfs_extern.h"
0015 
0016 
0017 static int      vxfs_read_folio(struct file *, struct folio *);
0018 static sector_t     vxfs_bmap(struct address_space *, sector_t);
0019 
0020 const struct address_space_operations vxfs_aops = {
0021     .read_folio =       vxfs_read_folio,
0022     .bmap =         vxfs_bmap,
0023 };
0024 
0025 inline void
0026 vxfs_put_page(struct page *pp)
0027 {
0028     kunmap(pp);
0029     put_page(pp);
0030 }
0031 
0032 /**
0033  * vxfs_get_page - read a page into memory.
0034  * @ip:     inode to read from
0035  * @n:      page number
0036  *
0037  * Description:
0038  *   vxfs_get_page reads the @n th page of @ip into the pagecache.
0039  *
0040  * Returns:
0041  *   The wanted page on success, else a NULL pointer.
0042  */
0043 struct page *
0044 vxfs_get_page(struct address_space *mapping, u_long n)
0045 {
0046     struct page *           pp;
0047 
0048     pp = read_mapping_page(mapping, n, NULL);
0049 
0050     if (!IS_ERR(pp)) {
0051         kmap(pp);
0052         /** if (!PageChecked(pp)) **/
0053             /** vxfs_check_page(pp); **/
0054     }
0055     
0056     return (pp);
0057 }
0058 
0059 /**
0060  * vxfs_bread - read buffer for a give inode,block tuple
0061  * @ip:     inode
0062  * @block:  logical block
0063  *
0064  * Description:
0065  *   The vxfs_bread function reads block no @block  of
0066  *   @ip into the buffercache.
0067  *
0068  * Returns:
0069  *   The resulting &struct buffer_head.
0070  */
0071 struct buffer_head *
0072 vxfs_bread(struct inode *ip, int block)
0073 {
0074     struct buffer_head  *bp;
0075     daddr_t         pblock;
0076 
0077     pblock = vxfs_bmap1(ip, block);
0078     bp = sb_bread(ip->i_sb, pblock);
0079 
0080     return (bp);
0081 }
0082 
0083 /**
0084  * vxfs_get_block - locate buffer for given inode,block tuple 
0085  * @ip:     inode
0086  * @iblock: logical block
0087  * @bp:     buffer skeleton
0088  * @create: %TRUE if blocks may be newly allocated.
0089  *
0090  * Description:
0091  *   The vxfs_get_block function fills @bp with the right physical
0092  *   block and device number to perform a lowlevel read/write on
0093  *   it.
0094  *
0095  * Returns:
0096  *   Zero on success, else a negativ error code (-EIO).
0097  */
0098 static int
0099 vxfs_getblk(struct inode *ip, sector_t iblock,
0100         struct buffer_head *bp, int create)
0101 {
0102     daddr_t         pblock;
0103 
0104     pblock = vxfs_bmap1(ip, iblock);
0105     if (pblock != 0) {
0106         map_bh(bp, ip->i_sb, pblock);
0107         return 0;
0108     }
0109 
0110     return -EIO;
0111 }
0112 
0113 /**
0114  * vxfs_read_folio - read one page synchronously into the pagecache
0115  * @file:   file context (unused)
0116  * @folio:  folio to fill in.
0117  *
0118  * Description:
0119  *   The vxfs_read_folio routine reads @folio synchronously into the
0120  *   pagecache.
0121  *
0122  * Returns:
0123  *   Zero on success, else a negative error code.
0124  *
0125  * Locking status:
0126  *   @folio is locked and will be unlocked.
0127  */
0128 static int vxfs_read_folio(struct file *file, struct folio *folio)
0129 {
0130     return block_read_full_folio(folio, vxfs_getblk);
0131 }
0132  
0133 /**
0134  * vxfs_bmap - perform logical to physical block mapping
0135  * @mapping:    logical to physical mapping to use
0136  * @block:  logical block (relative to @mapping).
0137  *
0138  * Description:
0139  *   Vxfs_bmap find out the corresponding phsical block to the
0140  *   @mapping, @block pair.
0141  *
0142  * Returns:
0143  *   Physical block number on success, else Zero.
0144  *
0145  * Locking status:
0146  *   We are under the bkl.
0147  */
0148 static sector_t
0149 vxfs_bmap(struct address_space *mapping, sector_t block)
0150 {
0151     return generic_block_bmap(mapping, block, vxfs_getblk);
0152 }