/src/print_inode_to.cc

http://ext3grep.googlecode.com/ · C++ · 125 lines · 90 code · 3 blank · 32 comment · 20 complexity · 529dc3dbd839778c4a23f95d212e29ec MD5 · raw file

  1. // ext3grep -- An ext3 file system investigation and undelete tool
  2. //
  3. //! @file print_inode_to.cc Definition of the function print_inode_to.
  4. //
  5. // Copyright (C) 2008, by
  6. //
  7. // Carlo Wood, Run on IRC <carlo@alinoe.com>
  8. // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
  9. // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 2 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. #ifndef USE_PCH
  24. #include "sys.h"
  25. #include <iostream>
  26. #include "ext3.h"
  27. #endif
  28. #include "FileMode.h"
  29. #include "globals.h"
  30. #include "print_symlink.h"
  31. void print_inode_to(std::ostream& os, Inode const& inode)
  32. {
  33. os << "Generation Id: " << inode.generation() << '\n';
  34. union {
  35. uid_t uid;
  36. uint16_t uid_word[2];
  37. };
  38. uid_word[0] = inode.uid_low();
  39. uid_word[1] = inode.uid_high();
  40. union {
  41. uid_t gid;
  42. uint16_t gid_word[2];
  43. };
  44. gid_word[0] = inode.gid_low();
  45. gid_word[1] = inode.gid_high();
  46. os << "uid / gid: " << uid << " / " << gid << '\n';
  47. os << "mode: " << FileMode(inode.mode()) << '\n';
  48. os << "size: " << inode.size() << '\n';
  49. os << "num of links: " << inode.links_count() << '\n';
  50. os << "sectors: " << inode.blocks();
  51. // A sector is 512 bytes. Therefore, we are using 'inode.i_blocks * 512 / block_size_' blocks.
  52. // 'inode.i_size / block_size_' blocks are used for the content, thus
  53. // '(inode.i_blocks * 512 - inode.i_size) / block_size_' blocks should
  54. // be used for indirect blocks.
  55. if ((inode.mode() & 0xf000) != 0xa000 || inode.blocks() != 0) // Not an inline symlink?
  56. {
  57. unsigned int number_of_indirect_blocks = (inode.blocks() * 512 - inode.size()) / block_size_;
  58. os << " (--> " << number_of_indirect_blocks << " indirect " << ((number_of_indirect_blocks == 1) ? "block" : "blocks") << ").\n";
  59. }
  60. time_t atime = inode.atime();
  61. os << "\nInode Times:\n";
  62. os << "Accessed: ";
  63. if (atime > 0)
  64. os << atime << " = " << std::ctime(&atime);
  65. else
  66. os << "0\n";
  67. time_t ctime = inode.ctime();
  68. os << "File Modified: ";
  69. if (ctime > 0)
  70. os << ctime << " = " << std::ctime(&ctime);
  71. else
  72. os << "0\n";
  73. time_t mtime = inode.mtime();
  74. os << "Inode Modified: ";
  75. if (mtime > 0)
  76. os << mtime << " = " << std::ctime(&mtime);
  77. else
  78. os << "0\n";
  79. os << "Deletion time: ";
  80. if (inode.has_valid_dtime())
  81. {
  82. time_t dtime = inode.dtime();
  83. os << dtime << " = " << std::ctime(&dtime);
  84. }
  85. else if (inode.is_orphan())
  86. os << "ORPHAN (next inode: " << inode.dtime() << ")\n";
  87. else
  88. os << "0\n";
  89. //os << "File flags: " << inode.flags() << '\n';
  90. if ((inode.mode() & 0xf000) != 0xa000 || inode.blocks() != 0) // Not an inline symlink?
  91. {
  92. os << "\nDirect Blocks:";
  93. long sb = (inode.size() + block_size_ - 1) / block_size_; // Size in blocks.
  94. for (int n = 0; n < EXT3_NDIR_BLOCKS; ++n)
  95. {
  96. os << ' ' << inode.block()[n];
  97. --sb;
  98. if (sb <= 0)
  99. break;
  100. }
  101. os << '\n';
  102. if (sb > 0)
  103. os << "Indirect Block: " << inode.block()[EXT3_IND_BLOCK] << '\n';
  104. sb -= block_size_ >> 2;
  105. if (sb > 0)
  106. os << "Double Indirect Block: " << inode.block()[EXT3_DIND_BLOCK] << '\n';
  107. sb -= (block_size_ >> 2) * (block_size_ >> 2);
  108. if (sb > 0)
  109. os << "Tripple Indirect Block: " << inode.block()[EXT3_TIND_BLOCK] << '\n';
  110. }
  111. else
  112. {
  113. os << "Symbolic link target name: ";
  114. print_symlink(os, inode);
  115. os << '\n';
  116. }
  117. //os << "File ACL: " << inode.file_acl() << '\n';
  118. //os << "Directory ACL: " << inode.dir_acl() << '\n';
  119. //os << "Fragment address: " << inode.faddr() << '\n';
  120. //os << "Fragment number: " << (int)inode.osd2.linux2.l_i_frag << '\n';
  121. //os << "Fragment size: " << (int)inode.osd2.linux2.l_i_fsize << '\n';
  122. }