PageRenderTime 35ms CodeModel.GetById 8ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

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