io.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. struct befs_sb_info *befs_sb = BEFS_SB(sb);
  28. befs_debug(sb, "---> Enter %s "
  29. "[%u, %hu, %hu]", __func__, iaddr.allocation_group,
  30. 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, "%s: offset = %lu", __func__, (unsigned long)block);
  38. bh = sb_bread(sb, block);
  39. if (bh == NULL) {
  40. befs_error(sb, "Failed to read block %lu",
  41. (unsigned long)block);
  42. goto error;
  43. }
  44. befs_debug(sb, "<--- %s", __func__);
  45. return bh;
  46. error:
  47. befs_debug(sb, "<--- %s ERROR", __func__);
  48. return NULL;
  49. }
  50. struct buffer_head *
  51. befs_bread(struct super_block *sb, befs_blocknr_t block)
  52. {
  53. struct buffer_head *bh = NULL;
  54. befs_debug(sb, "---> Enter %s %lu", __func__, (unsigned long)block);
  55. bh = sb_bread(sb, block);
  56. if (bh == NULL) {
  57. befs_error(sb, "Failed to read block %lu",
  58. (unsigned long)block);
  59. goto error;
  60. }
  61. befs_debug(sb, "<--- %s", __func__);
  62. return bh;
  63. error:
  64. befs_debug(sb, "<--- %s ERROR", __func__);
  65. return NULL;
  66. }