void PartitionHandle::CheckEBR(u8 PartNum, sec_t ebr_lba) { EXTENDED_BOOT_RECORD *ebr = (EXTENDED_BOOT_RECORD*)MEM2_alloc(MAX_BYTES_PER_SECTOR); if(ebr == NULL) return; sec_t next_erb_lba = 0; do { // Read and validate the extended boot record if(!interface->readSectors(ebr_lba + next_erb_lba, 1, ebr)) { MEM2_free(ebr); return; } if(ebr->signature != EBR_SIGNATURE && ebr->signature != EBR_SIGNATURE_MOD) { MEM2_free(ebr); return; } if(le32(ebr->partition.block_count) > 0 && !IsExisting(ebr_lba + next_erb_lba + le32(ebr->partition.lba_start))) { AddPartition(PartFromType(ebr->partition.type), ebr_lba + next_erb_lba + le32(ebr->partition.lba_start), le32(ebr->partition.block_count), (ebr->partition.status == PARTITION_BOOTABLE), ebr->partition.type, PartNum); } // Get the start sector of the current partition // and the next extended boot record in the chain next_erb_lba = le32(ebr->next_ebr.lba_start); } while(next_erb_lba > 0); MEM2_free(ebr); }
// リスト BOOL CPpcMainWnd::AddFile(LPTSTR pszFile, LPTSTR pszTitle) { if (!m_hMap) return FALSE; // 存在チェック if (IsExisting(pszFile)) return FALSE; // 有効性チェック if (!IsValidStream(pszFile)) return FALSE; // リストに追加 FILEINFO* pInfo = new FILEINFO; if (pszTitle) _tcscpy(pInfo->szDisplayName, pszTitle); else MAP_GetId3TagFile(m_hMap, pszFile, &pInfo->tag); _tcscpy(pInfo->szPath, pszFile); m_pListFile->Add((DWORD)pInfo); // リストビューに追加 TCHAR szTitle[MAX_PATH]; GetTitle(m_pListFile->GetCount() - 1, szTitle); LVITEM lvi = {0}; lvi.mask = LVIF_TEXT; lvi.iItem = ListView_GetItemCount(m_hwndLV); lvi.pszText = szTitle; ListView_InsertItem(m_hwndLV, &lvi); // 開いていない場合は開く OpenFirstFile(); return TRUE; }
s8 PartitionHandle::CheckGPT(u8 PartNum) { GPT_HEADER *gpt_header = (GPT_HEADER*)MEM2_alloc(MAX_BYTES_PER_SECTOR); if(gpt_header == NULL) return -1; // Read and validate the extended boot record if(!interface->readSectors(1, 1, gpt_header)) { MEM2_free(gpt_header); return -1; } if(strncmp(gpt_header->magic, "EFI PART", 8) != 0) { MEM2_free(gpt_header); return -1; } gpt_header->part_table_lba = le64(gpt_header->part_table_lba); gpt_header->part_entries = le32(gpt_header->part_entries); gpt_header->part_entry_size = le32(gpt_header->part_entry_size); gpt_header->part_entry_checksum = le32(gpt_header->part_entry_checksum); u8 *sector_buf = (u8*)MEM2_alloc(MAX_BYTES_PER_SECTOR); if(sector_buf == NULL) { MEM2_free(gpt_header); return -1; } u64 next_lba = gpt_header->part_table_lba; for(u32 i = 0; i < gpt_header->part_entries; ++i) { if(!interface->readSectors(next_lba, 1, sector_buf)) break; for(u32 n = 0; n < BYTES_PER_SECTOR/gpt_header->part_entry_size; ++n, ++i) { GUID_PART_ENTRY *part_entry = (GUID_PART_ENTRY*)(sector_buf+gpt_header->part_entry_size*n); if(memcmp(part_entry->part_type_guid, TYPE_UNUSED, 16) == 0) continue; if(IsExisting(le64(part_entry->part_first_lba))) continue; bool bootable = (memcmp(part_entry->part_type_guid, TYPE_BIOS, 16) == 0); AddPartition("GUID-Entry", le64(part_entry->part_first_lba), le64(part_entry->part_last_lba), bootable, PARTITION_TYPE_GPT, PartNum); } next_lba++; } MEM2_free(sector_buf); MEM2_free(gpt_header); return 0; }
s8 PartitionHandle::FindPartitions() { MASTER_BOOT_RECORD *mbr = (MASTER_BOOT_RECORD*)MEM2_alloc(MAX_BYTES_PER_SECTOR); if(mbr == NULL) return -1; // Read the first sector on the device if(!interface->readSectors(0, 1, mbr)) { MEM2_free(mbr); return -1; } // If this is the devices master boot record if(mbr->signature != MBR_SIGNATURE && mbr->signature != MBR_SIGNATURE_MOD) { MEM2_free(mbr); return -1; } for(u8 i = 0; i < 4; i++) { PARTITION_RECORD *partition = (PARTITION_RECORD *)&mbr->partitions[i]; if(partition->type == PARTITION_TYPE_GPT) { s8 ret = CheckGPT(i); if(ret == 0) // if it's a GPT we don't need to go on looking through the mbr anymore return ret; } if(partition->type == PARTITION_TYPE_DOS33_EXTENDED || partition->type == PARTITION_TYPE_WIN95_EXTENDED) { CheckEBR(i, le32(partition->lba_start)); continue; } if(le32(partition->block_count) > 0 && !IsExisting(le32(partition->lba_start))) { AddPartition(PartFromType(partition->type), le32(partition->lba_start), le32(partition->block_count), (partition->status == PARTITION_BOOTABLE), partition->type, i); } } MEM2_free(mbr); return 0; }
void PartitionHandle::AddPartition(const char * name, u64 lba_start, u64 sec_count, bool bootable, u8 part_type, u8 part_num, u32 EBR_Sector) { if(IsExisting(lba_start)) return; u8 *buffer = new u8[MAX_SECTOR_SIZE]; if (!interface->readSectors(lba_start, 1, buffer)) { delete [] buffer; return; } //! Partition typ can be missleading the correct partition format. Stupid lazy ass Partition Editors. if((memcmp(buffer + 0x36, "FAT", 3) == 0 || memcmp(buffer + 0x52, "FAT", 3) == 0) && strncmp(PartFromType(part_type), "FAT", 3) != 0) { name = "FAT32"; part_type = 0x0c; } if (memcmp(buffer + 0x03, "NTFS", 4) == 0) { name = "NTFS"; part_type = 0x07; } int part = PartitionList.size(); PartitionList.resize(part+1); PartitionList[part].FSName = name; PartitionList[part].LBA_Start = lba_start; PartitionList[part].SecCount = sec_count; PartitionList[part].Bootable = bootable; PartitionList[part].PartitionType = part_type; PartitionList[part].PartitionNum = part_num; PartitionList[part].EBR_Sector = EBR_Sector; delete [] buffer; }
bool SSoundEntity::IsActive() { // is everything required initialized and loaded? return IsExisting() && pSound->IsInitialized() && pSound->IsLoaded(); }