^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/befs/io.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on portions of file.c and inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * by Makoto Kato (m_kato@ga2.so-net.ne.jp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Many thanks to Dominic Giampaolo, author of Practical File System
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Design with the Be File System, for such a helpful book.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "befs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Converts befs notion of disk addr to a disk offset and uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * linux kernel function sb_bread() to get the buffer containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * the offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct buffer_head *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) befs_bread_iaddr(struct super_block *sb, befs_inode_addr iaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) befs_blocknr_t block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct befs_sb_info *befs_sb = BEFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) befs_debug(sb, "---> Enter %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) iaddr.start, iaddr.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (iaddr.allocation_group > befs_sb->num_ags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) befs_error(sb, "BEFS: Invalid allocation group %u, max is %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) iaddr.allocation_group, befs_sb->num_ags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) block = iaddr2blockno(sb, &iaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) befs_debug(sb, "%s: offset = %lu", __func__, (unsigned long)block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) bh = sb_bread(sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (bh == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) befs_error(sb, "Failed to read block %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) (unsigned long)block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) befs_debug(sb, "<--- %s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) befs_debug(sb, "<--- %s ERROR", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }