/src/print_directory.cc

http://ext3grep.googlecode.com/ · C++ · 118 lines · 85 code · 6 blank · 27 comment · 21 complexity · 15e44a16db428b3c00a82423632b8174 MD5 · raw file

  1. // ext3grep -- An ext3 file system investigation and undelete tool
  2. //
  3. //! @file print_directory.cc Implementation of the function print_directory.
  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 <iomanip>
  26. #endif
  27. #include "directories.h"
  28. #include "globals.h"
  29. #include "utils.h"
  30. #include "inode.h"
  31. #include "FileMode.h"
  32. #include "print_symlink.h"
  33. #include "forward_declarations.h"
  34. #include "commandline.h"
  35. #include "print_dir_entry_long_action.h"
  36. //-----------------------------------------------------------------------------
  37. //
  38. // Directory printing
  39. //
  40. void DirEntry::print(void) const
  41. {
  42. if (filtered)
  43. return;
  44. std::cout << std::setfill(' ') << std::setw(4) << index.cur << ' ';
  45. if (index.next)
  46. std::cout << std::setfill(' ') << std::setw(4) << index.next << ' ';
  47. else
  48. std::cout << " end ";
  49. if (feature_incompat_filetype)
  50. std::cout << dir_entry_file_type(M_file_type, true);
  51. else
  52. std::cout << '-';
  53. std::cout << std::setfill(' ') << std::setw(8) << M_inode << " ";
  54. std::cout << (zero_inode ? 'Z' : deleted ? reallocated ? 'R' : 'D' : ' ');
  55. InodePointer inode;
  56. if (!zero_inode)
  57. {
  58. inode = get_inode(M_inode);
  59. if (deleted && !reallocated)
  60. {
  61. time_t dtime = inode->dtime();
  62. std::string dtime_str(ctime(&dtime));
  63. std::cout << ' ' << std::setw(10) << dtime << ' ' << dtime_str.substr(0, dtime_str.length() - 1);
  64. }
  65. }
  66. if (zero_inode && linked)
  67. std::cout << " * LINKED ENTRY WITH ZERO INODE * ";
  68. else if (zero_inode || !deleted || reallocated)
  69. std::cout << std::string(36, ' ');
  70. if (zero_inode || reallocated)
  71. std::cout << " ??????????";
  72. else
  73. std::cout << " " << FileMode(inode->mode());
  74. std::cout << " " << M_name;
  75. if (!(reallocated || zero_inode) && is_symlink(inode))
  76. {
  77. std::cout << " -> ";
  78. print_symlink(std::cout, inode);
  79. }
  80. std::cout << '\n';
  81. }
  82. void DirectoryBlock::print(void) const
  83. {
  84. for (std::vector<DirEntry>::const_iterator iter = M_dir_entry.begin(); iter != M_dir_entry.end(); ++iter)
  85. iter->print();
  86. }
  87. void print_directory(unsigned char* block, int blocknr)
  88. {
  89. depth = 1;
  90. if (commandline_ls)
  91. {
  92. if (feature_incompat_filetype)
  93. std::cout << " .-- File type in dir_entry (r=regular file, d=directory, l=symlink)\n";
  94. std::cout << " | .-- D: Deleted ; R: Reallocated\n";
  95. std::cout << "Indx Next | Inode | Deletion time Mode File name\n";
  96. std::cout << "==========+==========+----------------data-from-inode------+-----------+=========\n";
  97. std::list<DirectoryBlock> db(1);
  98. db.begin()->read_block(blocknr, db.begin());
  99. db.begin()->print();
  100. std::cout << '\n';
  101. }
  102. else
  103. {
  104. #ifdef CPPGRAPH
  105. // Let cppgraph know that we call print_dir_entry_long_action from here.
  106. iterate_over_directory__with__print_dir_entry_long_action();
  107. #endif
  108. ++no_filtering;
  109. iterate_over_directory(block, blocknr, print_dir_entry_long_action, NULL, NULL);
  110. --no_filtering;
  111. }
  112. }