inode.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * inode.c
  4. *
  5. * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
  6. */
  7. #include <linux/fs.h>
  8. #include "befs.h"
  9. #include "inode.h"
  10. /*
  11. * Validates the correctness of the befs inode
  12. * Returns BEFS_OK if the inode should be used, otherwise
  13. * returns BEFS_BAD_INODE
  14. */
  15. int
  16. befs_check_inode(struct super_block *sb, befs_inode *raw_inode,
  17. befs_blocknr_t inode)
  18. {
  19. u32 magic1 = fs32_to_cpu(sb, raw_inode->magic1);
  20. befs_inode_addr ino_num = fsrun_to_cpu(sb, raw_inode->inode_num);
  21. u32 flags = fs32_to_cpu(sb, raw_inode->flags);
  22. /* check magic header. */
  23. if (magic1 != BEFS_INODE_MAGIC1) {
  24. befs_error(sb,
  25. "Inode has a bad magic header - inode = %lu",
  26. (unsigned long)inode);
  27. return BEFS_BAD_INODE;
  28. }
  29. /*
  30. * Sanity check2: inodes store their own block address. Check it.
  31. */
  32. if (inode != iaddr2blockno(sb, &ino_num)) {
  33. befs_error(sb, "inode blocknr field disagrees with vfs "
  34. "VFS: %lu, Inode %lu", (unsigned long)
  35. inode, (unsigned long)iaddr2blockno(sb, &ino_num));
  36. return BEFS_BAD_INODE;
  37. }
  38. /*
  39. * check flag
  40. */
  41. if (!(flags & BEFS_INODE_IN_USE)) {
  42. befs_error(sb, "inode is not used - inode = %lu",
  43. (unsigned long)inode);
  44. return BEFS_BAD_INODE;
  45. }
  46. return BEFS_OK;
  47. }