1*f0bc043bSIngo Weinhold // SuperBlock.h 2*f0bc043bSIngo Weinhold // 3*f0bc043bSIngo Weinhold // Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de) 4*f0bc043bSIngo Weinhold // 5*f0bc043bSIngo Weinhold // This program is free software; you can redistribute it and/or modify 6*f0bc043bSIngo Weinhold // it under the terms of the GNU General Public License as published by 7*f0bc043bSIngo Weinhold // the Free Software Foundation; either version 2 of the License, or 8*f0bc043bSIngo Weinhold // (at your option) any later version. 9*f0bc043bSIngo Weinhold // 10*f0bc043bSIngo Weinhold // This program is distributed in the hope that it will be useful, 11*f0bc043bSIngo Weinhold // but WITHOUT ANY WARRANTY; without even the implied warranty of 12*f0bc043bSIngo Weinhold // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*f0bc043bSIngo Weinhold // GNU General Public License for more details. 14*f0bc043bSIngo Weinhold // 15*f0bc043bSIngo Weinhold // You should have received a copy of the GNU General Public License 16*f0bc043bSIngo Weinhold // along with this program; if not, write to the Free Software 17*f0bc043bSIngo Weinhold // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18*f0bc043bSIngo Weinhold // 19*f0bc043bSIngo Weinhold // You can alternatively use *this file* under the terms of the the MIT 20*f0bc043bSIngo Weinhold // license included in this package. 21*f0bc043bSIngo Weinhold 22*f0bc043bSIngo Weinhold #ifndef SUPER_BLOCK_H 23*f0bc043bSIngo Weinhold #define SUPER_BLOCK_H 24*f0bc043bSIngo Weinhold 25*f0bc043bSIngo Weinhold #include "endianess.h" 26*f0bc043bSIngo Weinhold #include "reiserfs.h" 27*f0bc043bSIngo Weinhold 28*f0bc043bSIngo Weinhold class SuperBlock { 29*f0bc043bSIngo Weinhold public: 30*f0bc043bSIngo Weinhold SuperBlock(); 31*f0bc043bSIngo Weinhold ~SuperBlock(); 32*f0bc043bSIngo Weinhold 33*f0bc043bSIngo Weinhold status_t Init(int device, off_t offset = 0); 34*f0bc043bSIngo Weinhold 35*f0bc043bSIngo Weinhold uint32 GetFormatVersion() const { return fFormatVersion; } 36*f0bc043bSIngo Weinhold 37*f0bc043bSIngo Weinhold uint16 GetBlockSize() const 38*f0bc043bSIngo Weinhold { 39*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 40*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_blocksize) : le2h(fOldData->s_blocksize)); 41*f0bc043bSIngo Weinhold } 42*f0bc043bSIngo Weinhold 43*f0bc043bSIngo Weinhold uint32 CountBlocks() const 44*f0bc043bSIngo Weinhold { 45*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 46*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_block_count) 47*f0bc043bSIngo Weinhold : le2h(fOldData->s_block_count)); 48*f0bc043bSIngo Weinhold } 49*f0bc043bSIngo Weinhold 50*f0bc043bSIngo Weinhold uint32 CountFreeBlocks() const 51*f0bc043bSIngo Weinhold { 52*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 53*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_free_blocks) 54*f0bc043bSIngo Weinhold : le2h(fOldData->s_free_blocks)); 55*f0bc043bSIngo Weinhold } 56*f0bc043bSIngo Weinhold 57*f0bc043bSIngo Weinhold uint16 GetVersion() const 58*f0bc043bSIngo Weinhold { 59*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 60*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_version) : REISERFS_VERSION_0); 61*f0bc043bSIngo Weinhold } 62*f0bc043bSIngo Weinhold 63*f0bc043bSIngo Weinhold uint32 GetRootBlock() const 64*f0bc043bSIngo Weinhold { 65*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 66*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_root_block) : le2h(fOldData->s_root_block)); 67*f0bc043bSIngo Weinhold } 68*f0bc043bSIngo Weinhold 69*f0bc043bSIngo Weinhold uint16 GetState() const 70*f0bc043bSIngo Weinhold { 71*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 72*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_state) : le2h(fOldData->s_state)); 73*f0bc043bSIngo Weinhold } 74*f0bc043bSIngo Weinhold 75*f0bc043bSIngo Weinhold uint32 GetHashFunctionCode() const 76*f0bc043bSIngo Weinhold { 77*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 78*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_hash_function_code) : UNSET_HASH); 79*f0bc043bSIngo Weinhold } 80*f0bc043bSIngo Weinhold 81*f0bc043bSIngo Weinhold uint16 GetTreeHeight() const 82*f0bc043bSIngo Weinhold { 83*f0bc043bSIngo Weinhold return (GetFormatVersion() == REISERFS_3_6 84*f0bc043bSIngo Weinhold ? le2h(fCurrentData->s_tree_height) 85*f0bc043bSIngo Weinhold : le2h(fOldData->s_tree_height)); 86*f0bc043bSIngo Weinhold } 87*f0bc043bSIngo Weinhold 88*f0bc043bSIngo Weinhold private: 89*f0bc043bSIngo Weinhold uint32 fFormatVersion; 90*f0bc043bSIngo Weinhold union { 91*f0bc043bSIngo Weinhold reiserfs_super_block *fCurrentData; 92*f0bc043bSIngo Weinhold reiserfs_super_block_v1 *fOldData; 93*f0bc043bSIngo Weinhold }; 94*f0bc043bSIngo Weinhold }; 95*f0bc043bSIngo Weinhold 96*f0bc043bSIngo Weinhold #endif // SUPER_BLOCK_H 97