io.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <linux/buffer_head.h>
  14. #include "befs.h"
  15. #include "io.h"
  16. /*
  17. * Converts befs notion of disk addr to a disk offset and uses
  18. * linux kernel function sb_bread() to get the buffer containing
  19. * the offset. -Will Dyson
  20. *
  21. */
  22. struct buffer_head *
  23. befs_bread_iaddr(struct super_block *sb, befs_inode_addr iaddr)
  24. {
  25. struct buffer_head *bh = NULL;
  26. befs_blocknr_t block = 0;
  27. befs_sb_info *befs_sb = BEFS_SB(sb);
  28. befs_debug(sb, "---> Enter befs_read_iaddr() "
  29. "[%u, %hu, %hu]",
  30. iaddr.allocation_group, iaddr.start, iaddr.len);
  31. if (iaddr.allocation_group > befs_sb->num_ags) {
  32. befs_error(sb, "BEFS: Invalid allocation group %u, max is %u",
  33. iaddr.allocation_group, befs_sb->num_ags);
  34. goto error;
  35. }
  36. block = iaddr2blockno(sb, &iaddr);
  37. befs_debug(sb, "befs_read_iaddr: offset = %lu", block);
  38. bh = sb_bread(sb, block);
  39. if (bh == NULL) {
  40. befs_error(sb, "Failed to read block %lu", block);
  41. goto error;
  42. }
  43. befs_debug(sb, "<--- befs_read_iaddr()");
  44. return bh;
  45. error:
  46. befs_debug(sb, "<--- befs_read_iaddr() ERROR");
  47. return NULL;
  48. }
  49. struct buffer_head *
  50. befs_bread(struct super_block *sb, befs_blocknr_t block)
  51. {
  52. struct buffer_head *bh = NULL;
  53. befs_debug(sb, "---> Enter befs_read() %Lu", block);
  54. bh = sb_bread(sb, block);
  55. if (bh == NULL) {
  56. befs_error(sb, "Failed to read block %lu", block);
  57. goto error;
  58. }
  59. befs_debug(sb, "<--- befs_read()");
  60. return bh;
  61. error:
  62. befs_debug(sb, "<--- befs_read() ERROR");
  63. return NULL;
  64. }