1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * file.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (c) 1999 Al Smith
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds #include <linux/buffer_head.h>
1145254b4fSChristoph Hellwig #include "efs.h"
121da177e4SLinus Torvalds
efs_get_block(struct inode * inode,sector_t iblock,struct buffer_head * bh_result,int create)131da177e4SLinus Torvalds int efs_get_block(struct inode *inode, sector_t iblock,
141da177e4SLinus Torvalds struct buffer_head *bh_result, int create)
151da177e4SLinus Torvalds {
161da177e4SLinus Torvalds int error = -EROFS;
171da177e4SLinus Torvalds long phys;
181da177e4SLinus Torvalds
191da177e4SLinus Torvalds if (create)
201da177e4SLinus Torvalds return error;
211da177e4SLinus Torvalds if (iblock >= inode->i_blocks) {
221da177e4SLinus Torvalds #ifdef DEBUG
231da177e4SLinus Torvalds /*
241da177e4SLinus Torvalds * i have no idea why this happens as often as it does
251da177e4SLinus Torvalds */
26f403d1dbSFabian Frederick pr_warn("%s(): block %d >= %ld (filesize %ld)\n",
27f403d1dbSFabian Frederick __func__, block, inode->i_blocks, inode->i_size);
281da177e4SLinus Torvalds #endif
291da177e4SLinus Torvalds return 0;
301da177e4SLinus Torvalds }
311da177e4SLinus Torvalds phys = efs_map_block(inode, iblock);
321da177e4SLinus Torvalds if (phys)
331da177e4SLinus Torvalds map_bh(bh_result, inode->i_sb, phys);
341da177e4SLinus Torvalds return 0;
351da177e4SLinus Torvalds }
361da177e4SLinus Torvalds
efs_bmap(struct inode * inode,efs_block_t block)371da177e4SLinus Torvalds int efs_bmap(struct inode *inode, efs_block_t block) {
381da177e4SLinus Torvalds
391da177e4SLinus Torvalds if (block < 0) {
40f403d1dbSFabian Frederick pr_warn("%s(): block < 0\n", __func__);
411da177e4SLinus Torvalds return 0;
421da177e4SLinus Torvalds }
431da177e4SLinus Torvalds
441da177e4SLinus Torvalds /* are we about to read past the end of a file ? */
451da177e4SLinus Torvalds if (!(block < inode->i_blocks)) {
461da177e4SLinus Torvalds #ifdef DEBUG
471da177e4SLinus Torvalds /*
481da177e4SLinus Torvalds * i have no idea why this happens as often as it does
491da177e4SLinus Torvalds */
50f403d1dbSFabian Frederick pr_warn("%s(): block %d >= %ld (filesize %ld)\n",
51f403d1dbSFabian Frederick __func__, block, inode->i_blocks, inode->i_size);
521da177e4SLinus Torvalds #endif
531da177e4SLinus Torvalds return 0;
541da177e4SLinus Torvalds }
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds return efs_map_block(inode, block);
571da177e4SLinus Torvalds }
58