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