io.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/fs/befs/io.c
  4. *
  5. * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com
  6. *
  7. * Based on portions of file.c and inode.c
  8. * by Makoto Kato (m_kato@ga2.so-net.ne.jp)
  9. *
  10. * Many thanks to Dominic Giampaolo, author of Practical File System
  11. * Design with the Be File System, for such a helpful book.
  12. *
  13. */
  14. #include <linux/buffer_head.h>
  15. #include "befs.h"
  16. #include "io.h"
  17. /*
  18. * Converts befs notion of disk addr to a disk offset and uses
  19. * linux kernel function sb_bread() to get the buffer containing
  20. * the offset.
  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. }