1 /*
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/fs.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 bread() to get the buffer containing
22 * the offset. -Will Dyson
23 *
24 */
25
26 struct buffer_head *
befs_bread_iaddr(struct super_block * sb,befs_inode_addr iaddr)27 befs_bread_iaddr(struct super_block *sb, befs_inode_addr iaddr)
28 {
29 struct buffer_head *bh = NULL;
30 befs_blocknr_t block = 0;
31 vfs_blocknr_t vfs_block = 0;
32 befs_sb_info *befs_sb = BEFS_SB(sb);
33
34 befs_debug(sb, "---> Enter befs_read_iaddr() "
35 "[%u, %hu, %hu]",
36 iaddr.allocation_group, iaddr.start, iaddr.len);
37
38 if (iaddr.allocation_group > befs_sb->num_ags) {
39 befs_error(sb, "BEFS: Invalid allocation group %u, max is %u",
40 iaddr.allocation_group, befs_sb->num_ags);
41 goto error;
42 }
43
44 block = iaddr2blockno(sb, &iaddr);
45 vfs_block = (vfs_blocknr_t) block;
46
47 if (vfs_block != block) {
48 befs_error(sb, "Error converting to host blocknr_t. %Lu "
49 "is larger than the host can use", block);
50 goto error;
51 }
52
53 befs_debug(sb, "befs_read_iaddr: offset = %lu", block);
54
55 bh = bread(sb->s_dev, vfs_block, befs_sb->block_size);
56
57 if (bh == NULL) {
58 befs_error(sb, "Failed to read block %lu", block);
59 goto error;
60 }
61
62 befs_debug(sb, "<--- befs_read_iaddr()");
63 return bh;
64
65 error:
66 befs_debug(sb, "<--- befs_read_iaddr() ERROR");
67 return NULL;
68 }
69
70 struct buffer_head *
befs_bread(struct super_block * sb,befs_blocknr_t block)71 befs_bread(struct super_block *sb, befs_blocknr_t block)
72 {
73 struct buffer_head *bh = NULL;
74 befs_sb_info *befs_sb = BEFS_SB(sb);
75 vfs_blocknr_t vfs_block = (vfs_blocknr_t) block;
76
77 befs_debug(sb, "---> Enter befs_read() %Lu", block);
78
79 if (vfs_block != block) {
80 befs_error(sb, "Error converting to host blocknr_t. %Lu "
81 "is larger than the host can use", block);
82 goto error;
83 }
84
85 bh = bread(sb->s_dev, vfs_block, befs_sb->block_size);
86
87 if (bh == NULL) {
88 befs_error(sb, "Failed to read block %lu", vfs_block);
89 goto error;
90 }
91
92 befs_debug(sb, "<--- befs_read()");
93
94 return bh;
95
96 error:
97 befs_debug(sb, "<--- befs_read() ERROR");
98 return NULL;
99 }
100