inode.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "endian.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", 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",
  34. inode, 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", inode);
  42. return BEFS_BAD_INODE;
  43. }
  44. return BEFS_OK;
  45. }