Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * linux/fs/befs/io.c
0004  *
0005  * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com
0006  *
0007  * Based on portions of file.c and inode.c
0008  * by Makoto Kato (m_kato@ga2.so-net.ne.jp)
0009  *
0010  * Many thanks to Dominic Giampaolo, author of Practical File System
0011  * Design with the Be File System, for such a helpful book.
0012  *
0013  */
0014 
0015 #include <linux/buffer_head.h>
0016 
0017 #include "befs.h"
0018 #include "io.h"
0019 
0020 /*
0021  * Converts befs notion of disk addr to a disk offset and uses
0022  * linux kernel function sb_bread() to get the buffer containing
0023  * the offset.
0024  */
0025 
0026 struct buffer_head *
0027 befs_bread_iaddr(struct super_block *sb, befs_inode_addr iaddr)
0028 {
0029     struct buffer_head *bh;
0030     befs_blocknr_t block;
0031     struct befs_sb_info *befs_sb = BEFS_SB(sb);
0032 
0033     befs_debug(sb, "---> Enter %s "
0034            "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
0035            iaddr.start, iaddr.len);
0036 
0037     if (iaddr.allocation_group > befs_sb->num_ags) {
0038         befs_error(sb, "BEFS: Invalid allocation group %u, max is %u",
0039                iaddr.allocation_group, befs_sb->num_ags);
0040         goto error;
0041     }
0042 
0043     block = iaddr2blockno(sb, &iaddr);
0044 
0045     befs_debug(sb, "%s: offset = %lu", __func__, (unsigned long)block);
0046 
0047     bh = sb_bread(sb, block);
0048 
0049     if (bh == NULL) {
0050         befs_error(sb, "Failed to read block %lu",
0051                (unsigned long)block);
0052         goto error;
0053     }
0054 
0055     befs_debug(sb, "<--- %s", __func__);
0056     return bh;
0057 
0058 error:
0059     befs_debug(sb, "<--- %s ERROR", __func__);
0060     return NULL;
0061 }