inode.c 1.2 KB

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