io.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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;
  26. befs_blocknr_t block;
  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. }