// ======================================================= void CXfsPart::readSuperBlock() { BEGIN; xfs_superblock sb; int nRes; char szTemp1[4096], szTemp2[4096], szTemp3[4096]; QWORD qwFreeSpace, qwUsedSpace; // init memset(&m_info, 0, sizeof(CInfoXfsHeader)); // 0. go to the beginning of the super block nRes = fseek(m_fDeviceFile, 0, SEEK_SET); if (nRes == -1) THROW(ERR_ERRNO, errno); // 1. read and print important informations nRes = fread(&sb, sizeof(xfs_superblock), 1, m_fDeviceFile); if (nRes != 1) { g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } // 2. check it's an XFS file system if (BeToCpu(sb.sb_magicnum) != XFS_SUPER_MAGIC) { g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } // ---- blocks m_header.qwBlockSize = (QWORD)BeToCpu(sb.sb_blocksize); showDebug(3, "SUPER: sb_blocksize=m_header.qwBlockSize=%llu\n", m_header.qwBlockSize); // check for block size if (m_header.qwBlockSize != ((QWORD)4096)) { showDebug(1, "Only 4096 bytes per block volumes are supported. Current one is %lu bytes/block", (DWORD)m_header.qwBlockSize); //g_interface -> msgBoxError(szTemp); THROW(ERR_BLOCKSIZE, "XFS", (DWORD)m_header.qwBlockSize); } m_header.qwBlocksCount = (QWORD)BeToCpu(sb.sb_dblocks); showDebug(3, "SUPER: sb_dblocks=m_header.qwBlocksCount=%llu\n", m_header.qwBlocksCount); m_header.qwUsedBlocks = m_header.qwBlocksCount - (QWORD)BeToCpu(sb.sb_fdblocks); //swapNb((QWORD)sb.sb_fdblocks); showDebug(3, "SUPER: m_header.qwUsedBlocks=%llu\n", m_header.qwUsedBlocks); m_info.dwAgCount = (DWORD)BeToCpu(sb.sb_agcount); showDebug(3, "SUPER: sb_agcount=m_info.dwAgCount=%lu\n", m_info.dwAgCount); m_info.dwAgBlocksCount = (DWORD)BeToCpu(sb.sb_agblocks); showDebug(3, "SUPER: m_info.dwAgBlocksCount=%lu\n", m_info.dwAgBlocksCount); showDebug(3, "SUPER: Allocation group size: %lu blocks = %s\n", m_info.dwAgBlocksCount, formatSize(m_info.dwAgBlocksCount*m_header.qwBlockSize,szTemp1)); // ---- space informations qwFreeSpace = (m_header.qwBlocksCount - m_header.qwUsedBlocks) * m_header.qwBlockSize; qwUsedSpace = m_header.qwUsedBlocks * m_header.qwBlockSize; showDebug(3, "SUPER: total: %s\nused: %s\nfree: %s\n", formatSize(m_header.qwBlockSize * m_header.qwBlocksCount, szTemp1), formatSize(qwUsedSpace, szTemp2), formatSize(qwFreeSpace, szTemp3)); showDebug(3, "SUPER: sb_rbmblocks=%lu\n",(DWORD)BeToCpu(sb.sb_rbmblocks)); // ---- calculate infos //m_header.qwBlockSize = (QWORD)m_info.dwBlockSize; //m_header.qwUsedBlocks = m_info.qwBlocksCount - m_info.qwFreeBlocksCount; //swapNb((QWORD)sb.sb_fdblocks); //m_header.qwBlocksCount = m_info.qwBlocksCount; m_header.qwBitmapSize = (m_header.qwBlocksCount+7)/8; //sb.s_bmap_nr * m_header.qwBlockSize; memset(m_header.szLabel, 0, 64); setSuperBlockInfos(true, true, qwUsedSpace, qwFreeSpace); RETURN; }
// ======================================================= void CHfsPart::readSuperBlock() { BEGIN; QWORD qwBlocksInRegularAlloc; hfsSuperBlock sb, sb2; int nRes; // read superblock nRes = readData(&sb, 1024, sizeof(sb)); if (nRes == -1) { showDebug(10, "ERROR 1\n"); g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } if (Be16ToCpu(GET_WORD(&sb.drSigWord)) != HFS_SUPER_MAGIC) { showDebug(10, "ERROR 2\n"); g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } // init memset(&m_info, 0, sizeof(CInfoHfsHeader)); m_info.qwAllocCount = BeToCpu(GET_WORD(&sb.drNmAlBlks)); m_info.dwAllocSize = BeToCpu(GET_DWORD(&sb.drAlBlkSize)); m_info.dwBlocksPerAlloc = m_info.dwAllocSize / 512; m_info.qwBitmapSectLocation = (QWORD)BeToCpu(GET_WORD(&sb.drVBMSt)); m_info.qwFirstAllocBlock = (QWORD)BeToCpu(GET_WORD(&sb.drAlBlSt)); m_info.qwFreeAllocs = (QWORD)BeToCpu(GET_WORD(&sb.drFreeBks)); // if not a 512 multiple if ((m_info.dwAllocSize % 512) != 0) THROW(ERR_READING, (DWORD)0, errno); // check the last but one block is a superblock qwBlocksInRegularAlloc = m_info.dwBlocksPerAlloc * m_info.qwAllocCount; nRes = readData(&sb2, (m_info.qwFirstAllocBlock+qwBlocksInRegularAlloc)*512LL, sizeof(sb2)); if (nRes == -1) { showDebug(10, "ERROR 3\n"); g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } if (Be16ToCpu(GET_WORD(&sb.drSigWord)) != HFS_SUPER_MAGIC) { showDebug(10, "ERROR 4\n"); g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_READING, (DWORD)0, errno); } // show infos showDebug(10, "m_info.qwAllocCount=%llu\n", m_info.qwAllocCount); showDebug(10, "m_info.dwAllocSize=%lu=%lu sectors\n", m_info.dwAllocSize, m_info.dwBlocksPerAlloc); showDebug(10, "m_info.qwBitmapSectLocation=%llu\n", m_info.qwBitmapSectLocation); showDebug(10, "m_info.qwFirstAllocBlock=%llu\n", m_info.qwFirstAllocBlock); showDebug(10, "m_info.qwFreeAllocs=%llu\n", m_info.qwFreeAllocs); // label == pascal string memset(m_header.szLabel, 0, 64); memcpy(m_header.szLabel, ((char*)&sb.drVN)+1, my_min(((BYTE*)&sb.drVN)[0], 63)); showDebug(10, "label=[%s]\n", m_header.szLabel); // calculate sectors count m_header.qwBlocksCount = m_info.qwFirstAllocBlock // first reserved (2 boot blocks, 1 superblock, ...) + (m_info.dwBlocksPerAlloc * m_info.qwAllocCount) // allocation blocks + 1 // alternate superblock + 1; // last volume of sector showDebug(10, "m_header.qwBlocksCount = %llu\n", m_header.qwBlocksCount); m_header.qwBlockSize = 512; m_header.qwBitmapSize = (m_header.qwBlocksCount+7)/8; QWORD qwUsedBlocks = m_info.qwFirstAllocBlock + 2 + ((m_info.qwAllocCount-m_info.qwFreeAllocs) * m_info.dwBlocksPerAlloc); QWORD qwFreeBlocks = m_info.qwFreeAllocs * m_info.dwBlocksPerAlloc; setSuperBlockInfos(true, true, qwUsedBlocks*512, qwFreeBlocks*512); RETURN; }
// ======================================================= void CExt2Part::readSuperBlock() { BEGIN; CExt2Super sb; int nRes; // init memset(&m_info, 0, sizeof(CInfoExt2Header)); // 0. go to the beginning of the super block nRes = fseek(m_fDeviceFile, 1024, SEEK_SET); if (nRes == -1) goto error_readSuperBlock; // 1. read and print important informations nRes = fread(&sb, sizeof(sb), 1, m_fDeviceFile); if (nRes != 1) goto error_readSuperBlock; // check partition has an ext2 file system if (sb.s_magic != Le16ToCpu(EXT2_SUPER_MAGIC)) goto error_readSuperBlock; // read and print important informations m_info.dwBlockSize = (EXT2_MIN_BLOCK_SIZE << Le32ToCpu(sb.s_log_block_size)); //sb.s_blocksize; //EXT2_BLOCK_SIZE(m_fs->super); showDebug(1, "blksize=%lu\n", m_info.dwBlockSize); m_info.dwFirstBlock = Le32ToCpu(sb.s_first_data_block); showDebug(1, "first=%lu\n", m_info.dwFirstBlock); m_info.dwTotalBlocksCount = Le32ToCpu(sb.s_blocks_count); showDebug(1, "total blocks=%lu\n", m_info.dwTotalBlocksCount); m_info.dwBlocksPerGroup = Le32ToCpu(sb.s_blocks_per_group); showDebug(1, "BlocksPerGroup=%lu\n", m_info.dwBlocksPerGroup); m_info.dwGroupsCount = (m_info.dwTotalBlocksCount - m_info.dwFirstBlock + m_info.dwBlocksPerGroup - 1) / Le32ToCpu(sb.s_blocks_per_group); showDebug(1, "groups=%lu\n", m_info.dwGroupsCount); m_info.dwLogicalBlocksPerExt2Block = m_info.dwBlockSize / LOGICAL_EXT2_BLKSIZE; showDebug(1, "m_info.dwLogicalBlocksPerExt2Block=%lu\n",m_info.dwLogicalBlocksPerExt2Block); showDebug(1, "logperblok=%lu\n", m_info.dwLogicalBlocksPerExt2Block); m_info.dwDescPerBlock = m_info.dwBlockSize / sizeof(CExt2GroupDesc); m_info.dwDescBlocks = (m_info.dwGroupsCount + m_info.dwDescPerBlock - 1) / m_info.dwDescPerBlock; //debugWin("m_info.dwDescBlocks=%lu",(DWORD)m_info.dwDescBlocks); // virtual blocks used in the abstract CFSBase m_header.qwBlocksCount = m_info.dwTotalBlocksCount * m_info.dwLogicalBlocksPerExt2Block; m_header.qwBlockSize = LOGICAL_EXT2_BLKSIZE; m_header.qwBitmapSize = ((m_header.qwBlocksCount+7) / 8)+16; m_header.qwUsedBlocks = (m_info.dwTotalBlocksCount - Le32ToCpu(sb.s_free_blocks_count)) * m_info.dwLogicalBlocksPerExt2Block; //debugWin("freeblks=%lu", sb.s_free_blocks_count); strncpy(m_header.szLabel, sb.s_volume_name, 64); // features m_info.dwFeatureCompat = Le32ToCpu(sb.s_feature_compat); m_info.dwFeatureIncompat = Le32ToCpu(sb.s_feature_incompat); m_info.dwFeatureRoCompat = Le32ToCpu(sb.s_feature_ro_compat); // misc infos m_info.dwRevLevel = Le32ToCpu(sb.s_rev_level); // Revision level memcpy(m_info.cUuid, sb.s_uuid, 16); // 128-bit uuid for volume //success_readSuperBlock: setSuperBlockInfos(true, true, m_header.qwUsedBlocks*m_header.qwBlockSize, ((QWORD)Le32ToCpu(sb.s_free_blocks_count)) * ((QWORD)m_info.dwBlockSize)); showDebug(1, "end success\n"); RETURN; error_readSuperBlock: g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_WRONG_FS); }
// ======================================================= void CAfsPart::readSuperBlock() { BEGIN; QWORD qwFreeBlocks; CAfsSuper sb; int nRes; // init memset(&m_info, 0, sizeof(CInfoAfsHeader)); // 0. go to the beginning of the super block nRes = readData(&sb, AFS_SUPERBLOCK_OFFSET, sizeof(sb)); if (nRes == -1) goto error_readSuperBlock; if (CpuToLe32(sb.as_nMagic1) != SUPER_BLOCK_MAGIC1) goto error_readSuperBlock; if (CpuToLe32(sb.as_nMagic2) != SUPER_BLOCK_MAGIC2) goto error_readSuperBlock; // take infos from superblock m_info.dwByteOrder = sb.as_nByteOrder; m_info.dwBlockShift = sb.as_nBlockShift; m_info.dwBlockPerGroup = sb.as_nBlockPerGroup; m_info.dwAllocGrpShift = sb.as_nAllocGrpShift; m_info.dwAllocGroupCount = sb.as_nAllocGroupCount; m_info.dwFlags = sb.as_nFlags; m_info.dwBootLoaderSize = sb.as_nBootLoaderSize; // virtual blocks used in the abstract CFSBase m_header.qwBlocksCount = (DWORD)sb.as_nNumBlocks; showDebug(1, "qwBlocksCount=%llu\n", m_header.qwBlocksCount); m_header.qwBlockSize = (DWORD)sb.as_nBlockSize; showDebug(1, "qwBlockSize=%llu\n", m_header.qwBlockSize); m_header.qwBitmapSize = ((m_header.qwBlocksCount+7)/ 8)+1024; m_header.qwUsedBlocks = sb.as_nUsedBlocks; showDebug(1, "qwUsedBlocks%llu\n", m_header.qwUsedBlocks); // get bitmap position /*DWORD a, b, c; a = (m_info.dwBootLoaderSize*m_header.qwBlockSize + AFS_SUPERBLOCK_SIZE + 1024 + m_header.qwBlockSize - 1) / m_header.qwBlockSize; b = (m_info.dwBootLoaderSize*m_header.qwBlockSize + AFS_SUPERBLOCK_SIZE + 1024 + m_header.qwBlockSize) / m_header.qwBlockSize; c = (m_info.dwBootLoaderSize*m_header.qwBlockSize + AFS_SUPERBLOCK_SIZE + 1024 + m_header.qwBlockSize + 1) / m_header.qwBlockSize; showDebug(1, "a=%lu\n", a); showDebug(1, "b=%lu\n", b); showDebug(1, "c=%lu\n", c); */ m_info.qwBitmapStart = (m_info.dwBootLoaderSize*m_header.qwBlockSize + AFS_SUPERBLOCK_SIZE + 1024 + m_header.qwBlockSize - 1) / m_header.qwBlockSize; qwFreeBlocks = m_header.qwBlocksCount-m_header.qwUsedBlocks; setSuperBlockInfos(false, false, m_header.qwUsedBlocks*m_header.qwBlockSize, qwFreeBlocks * m_header.qwBlockSize); showDebug(1, "end success\n"); RETURN; error_readSuperBlock: g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_WRONG_FS); }