PageRenderTime 36ms CodeModel.GetById 13ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 24#ifndef USE_PCH
 25#include "sys.h"
 26#include <iostream>
 27#include "ext3.h"
 28#endif
 29
 30#include "FileMode.h"
 31#include "globals.h"
 32#include "print_symlink.h"
 33
 34void print_inode_to(std::ostream& os, Inode const& inode)
 35{
 36  os << "Generation Id: " << inode.generation() << '\n';
 37  union {
 38    uid_t uid;
 39    uint16_t uid_word[2];
 40  };
 41  uid_word[0] = inode.uid_low();
 42  uid_word[1] = inode.uid_high();
 43  union {
 44    uid_t gid;
 45    uint16_t gid_word[2];
 46  };
 47  gid_word[0] = inode.gid_low();
 48  gid_word[1] = inode.gid_high();
 49  os << "uid / gid: " << uid << " / " << gid << '\n';
 50  os << "mode: " << FileMode(inode.mode()) << '\n';
 51  os << "size: " << inode.size() << '\n';
 52  os << "num of links: " << inode.links_count() << '\n';
 53  os << "sectors: " << inode.blocks();
 54  // A sector is 512 bytes. Therefore, we are using 'inode.i_blocks * 512 / block_size_' blocks.
 55  // 'inode.i_size / block_size_' blocks are used for the content, thus
 56  // '(inode.i_blocks * 512 - inode.i_size) / block_size_' blocks should
 57  // be used for indirect blocks.
 58  if ((inode.mode() & 0xf000) != 0xa000 || inode.blocks() != 0)		// Not an inline symlink?
 59  {
 60    unsigned int number_of_indirect_blocks = (inode.blocks() * 512 - inode.size()) / block_size_;
 61    os << " (--> " << number_of_indirect_blocks << " indirect " << ((number_of_indirect_blocks == 1) ? "block" : "blocks") << ").\n";
 62  }
 63  time_t atime = inode.atime();
 64  os << "\nInode Times:\n";
 65  os << "Accessed:       ";
 66  if (atime > 0)
 67    os << atime << " = " << std::ctime(&atime);
 68  else
 69    os << "0\n";
 70  time_t ctime = inode.ctime();
 71  os << "File Modified:  ";
 72  if (ctime > 0)
 73    os << ctime << " = " << std::ctime(&ctime);
 74  else
 75    os << "0\n";
 76  time_t mtime = inode.mtime();
 77  os << "Inode Modified: ";
 78  if (mtime > 0)
 79    os << mtime << " = " << std::ctime(&mtime);
 80  else
 81    os << "0\n";
 82  os << "Deletion time:  ";
 83  if (inode.has_valid_dtime())
 84  {
 85    time_t dtime = inode.dtime();
 86    os << dtime << " = " << std::ctime(&dtime);
 87  }
 88  else if (inode.is_orphan())
 89    os << "ORPHAN (next inode: " << inode.dtime() << ")\n";
 90  else
 91    os << "0\n";
 92  //os << "File flags: " << inode.flags() << '\n';
 93  if ((inode.mode() & 0xf000) != 0xa000 || inode.blocks() != 0)		// Not an inline symlink?
 94  {
 95    os << "\nDirect Blocks:";
 96    long sb = (inode.size() + block_size_ - 1) / block_size_;	// Size in blocks.
 97    for (int n = 0; n < EXT3_NDIR_BLOCKS; ++n)
 98    {
 99      os << ' ' << inode.block()[n];
100      --sb;
101      if (sb <= 0)
102	break;
103    }
104    os << '\n';
105    if (sb > 0)
106      os << "Indirect Block: " << inode.block()[EXT3_IND_BLOCK] << '\n';
107    sb -= block_size_ >> 2;
108    if (sb > 0)
109      os << "Double Indirect Block: " << inode.block()[EXT3_DIND_BLOCK] << '\n';
110    sb -= (block_size_ >> 2) * (block_size_ >> 2);
111    if (sb > 0)
112      os << "Tripple Indirect Block: " << inode.block()[EXT3_TIND_BLOCK] << '\n';
113  }
114  else
115  {
116    os << "Symbolic link target name: ";
117    print_symlink(os, inode);
118    os << '\n';
119  }
120  //os << "File ACL: " << inode.file_acl() << '\n';
121  //os << "Directory ACL: " << inode.dir_acl() << '\n';
122  //os << "Fragment address: " << inode.faddr() << '\n';
123  //os << "Fragment number: " << (int)inode.osd2.linux2.l_i_frag << '\n';
124  //os << "Fragment size: " << (int)inode.osd2.linux2.l_i_fsize << '\n';
125}