valid_blk.c 1.3 KB

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