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