Guest User

Untitled

a guest
May 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino,
  2. struct buffer_head **p)
  3. {
  4. struct buffer_head * bh;
  5. unsigned long block_group;
  6. unsigned long block;
  7. unsigned long offset;
  8. struct ext2_group_desc * gdp;
  9.  
  10. *p = NULL;
  11. if ((ino != EXT2_ROOT_INO && ino < EXT2_FIRST_INO(sb)) ||
  12. ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count))
  13. goto Einval;
  14.  
  15. block_group = (ino - 1) / EXT2_INODES_PER_GROUP(sb);
  16. gdp = ext2_get_group_desc(sb, block_group, NULL);
  17. if (!gdp)
  18. goto Egdp;
  19. /*
  20. * Figure out the offset within the block group inode table
  21. */
  22. offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb);
  23. block = le32_to_cpu(gdp->bg_inode_table) +
  24. (offset >> EXT2_BLOCK_SIZE_BITS(sb));
  25. if (!(bh = sb_bread(sb, block)))
  26. goto Eio;
  27.  
  28. *p = bh;
  29. offset &= (EXT2_BLOCK_SIZE(sb) - 1);
  30. return (struct ext2_inode *) (bh->b_data + offset);
  31.  
  32. Einval:
  33. ext2_error(sb, "ext2_get_inode", "bad inode number: %lu",
  34. (unsigned long) ino);
  35. return ERR_PTR(-EINVAL);
  36. Eio:
  37. ext2_error(sb, "ext2_get_inode",
  38. "unable to read inode block - inode=%lu, block=%lu",
  39. (unsigned long) ino, block);
  40. Egdp:
  41. return ERR_PTR(-EIO);
  42. }
Add Comment
Please, Sign In to add comment