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