blob: 523c8af2d770b08473bfa6200d635ae46364b0e2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/befs/io.c
3 *
4 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com
5 *
6 * Based on portions of file.c and inode.c
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
22 * the offset. -Will Dyson
23 *
24 */
25
26struct buffer_head *
27befs_bread_iaddr(struct super_block *sb, befs_inode_addr iaddr)
28{
Salah Triki77169af2016-05-23 16:22:52 -070029 struct buffer_head *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 befs_blocknr_t block = 0;
Fabian Frederick038428f2015-04-16 12:46:20 -070031 struct befs_sb_info *befs_sb = BEFS_SB(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Fabian Frederickdac52fc2014-04-03 14:50:23 -070033 befs_debug(sb, "---> Enter %s "
34 "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
35 iaddr.start, iaddr.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 if (iaddr.allocation_group > befs_sb->num_ags) {
38 befs_error(sb, "BEFS: Invalid allocation group %u, max is %u",
39 iaddr.allocation_group, befs_sb->num_ags);
40 goto error;
41 }
42
43 block = iaddr2blockno(sb, &iaddr);
44
Fabian Frederickdac52fc2014-04-03 14:50:23 -070045 befs_debug(sb, "%s: offset = %lu", __func__, (unsigned long)block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 bh = sb_bread(sb, block);
48
49 if (bh == NULL) {
Fabian Frederickdac52fc2014-04-03 14:50:23 -070050 befs_error(sb, "Failed to read block %lu",
51 (unsigned long)block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 goto error;
53 }
54
Fabian Frederickdac52fc2014-04-03 14:50:23 -070055 befs_debug(sb, "<--- %s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 return bh;
57
58 error:
Fabian Frederickdac52fc2014-04-03 14:50:23 -070059 befs_debug(sb, "<--- %s ERROR", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return NULL;
61}
62
63struct buffer_head *
64befs_bread(struct super_block *sb, befs_blocknr_t block)
65{
Salah Trikia46d8c32016-05-23 16:22:55 -070066 struct buffer_head *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Fabian Frederickdac52fc2014-04-03 14:50:23 -070068 befs_debug(sb, "---> Enter %s %lu", __func__, (unsigned long)block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 bh = sb_bread(sb, block);
71
72 if (bh == NULL) {
Fabian Frederickdac52fc2014-04-03 14:50:23 -070073 befs_error(sb, "Failed to read block %lu",
74 (unsigned long)block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 goto error;
76 }
77
Fabian Frederickdac52fc2014-04-03 14:50:23 -070078 befs_debug(sb, "<--- %s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 return bh;
81
82 error:
Fabian Frederickdac52fc2014-04-03 14:50:23 -070083 befs_debug(sb, "<--- %s ERROR", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return NULL;
85}