3
0

valid_blk.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * valid_blk.c --- does the inode have valid blocks?
  4. *
  5. * Copyright 1997 by Theodore Ts'o
  6. *
  7. * %Begin-Header%
  8. * This file may be redistributed under the terms of the GNU Public
  9. * License.
  10. * %End-Header%
  11. *
  12. */
  13. #include <stdio.h>
  14. #if HAVE_UNISTD_H
  15. #include <unistd.h>
  16. #endif
  17. #include <string.h>
  18. #include <time.h>
  19. #include "ext2_fs.h"
  20. #include "ext2fs.h"
  21. /*
  22. * This function returns 1 if the inode's block entries actually
  23. * contain block entries.
  24. */
  25. int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode)
  26. {
  27. /*
  28. * Only directories, regular files, and some symbolic links
  29. * have valid block entries.
  30. */
  31. if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) &&
  32. !LINUX_S_ISLNK(inode->i_mode))
  33. return 0;
  34. /*
  35. * If the symbolic link is a "fast symlink", then the symlink
  36. * target is stored in the block entries.
  37. */
  38. if (LINUX_S_ISLNK (inode->i_mode)) {
  39. if (inode->i_file_acl == 0) {
  40. /* With no EA block, we can rely on i_blocks */
  41. if (inode->i_blocks == 0)
  42. return 0;
  43. } else {
  44. /* With an EA block, life gets more tricky */
  45. if (inode->i_size >= EXT2_N_BLOCKS*4)
  46. return 1; /* definitely using i_block[] */
  47. if (inode->i_size > 4 && inode->i_block[1] == 0)
  48. return 1; /* definitely using i_block[] */
  49. return 0; /* Probably a fast symlink */
  50. }
  51. }
  52. return 1;
  53. }