PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/src/is_blockdetection.h

http://ext3grep.googlecode.com/
C++ Header | 108 lines | 60 code | 16 blank | 32 comment | 3 complexity | 298833ef82f908e74557f62687857cc6 MD5 | raw file
  1// ext3grep -- An ext3 file system investigation and undelete tool
  2//
  3//! @file is_blockdetection.h Various is_* test functions.
  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 IS_BLOCKDETECTION_H
 25#define IS_BLOCKDETECTION_H
 26
 27#ifndef USE_PCH
 28#include <stdint.h>	// Needed for uint32_t
 29#include <iosfwd>	// Needed for std::ostream
 30#endif
 31
 32#include "inode.h"	// Needed for InodePointer
 33
 34// Return type of is_directory.
 35enum is_directory_type {
 36  isdir_no = 0,         // Block is not a directory.
 37  isdir_start,          // Block is a directory containing "." and "..".
 38  isdir_extended        // Block is a directory not containing "." and "..".
 39};
 40
 41class DirectoryBlockStats {
 42  private:
 43    int M_number_of_entries;			// Number of entries in chain to the end.
 44    __u8 M_unlikely_character_count[256];	// Character count of filenames.
 45  public:
 46    DirectoryBlockStats(void) { std::memset(this, 0, sizeof(DirectoryBlockStats)); }
 47
 48    int number_of_entries(void) const { return M_number_of_entries; }
 49    void increment_number_of_entries(void) { ++M_number_of_entries; }
 50    void increment_unlikely_character_count(__u8 c) { ++M_unlikely_character_count[c]; }
 51};
 52
 53// Return true if this inode is a directory.
 54inline bool is_directory(Inode const& inode)
 55{
 56  return (inode.mode() & 0xf000) == 0x4000;
 57}
 58
 59// Same for an InodePointer.
 60inline bool is_directory(InodePointer const& inoderef)
 61{
 62  // We can dereference inoderef here because it is known that is_directory does not keep a pointer or reference to the inode.
 63  return is_directory(*inoderef);
 64}
 65
 66// Return true if this inode is a symlink.
 67inline bool is_symlink(Inode const& inode)
 68{
 69  return (inode.mode() & 0xf000) == 0xa000;
 70}
 71
 72// Same for an InodePointer.
 73inline bool is_symlink(InodePointer const& inoderef)
 74{
 75  // We can dereference inoderef here because it is known that is_symlink does not keep a pointer or reference to the inode.
 76  return is_symlink(*inoderef);
 77}
 78
 79// Return true if this inode is a regular file.
 80inline bool is_regular_file(Inode const& inode)
 81{
 82  return (inode.mode() & 0xf000) == 0x8000;
 83}
 84
 85// Same for an InodePointer.
 86inline bool is_regular_file(InodePointer const& inoderef)
 87{
 88  // We can dereference inoderef here because it is known that is_regular_file does not keep a pointer or reference to the inode.
 89  return is_regular_file(*inoderef);
 90}
 91
 92inline bool is_block_number(uint32_t block_number)
 93{
 94  return block_number < block_count_;
 95}
 96
 97inline bool is_data_block_number(uint32_t block_number)
 98{
 99  return block_number < block_count_;	// FIXME: not all blocks contain data (ie, skip at least the inode tables).
100}
101
102int block_to_inode(int block);
103bool is_inode(int block);
104bool is_allocated(int inode);
105int inode_to_block(ext3_super_block const& super_block, int inode);
106void print_buf_to(std::ostream& os, char const* buf, int len);
107
108#endif // IS_BLOCKDETECTION_H