BOOL IsDiskFat32(PSZ pszDisk) { strupr(pszDisk); if (!stricmp(GetFSName(pszDisk), "FAT32")) { return TRUE; } return FALSE; }
void PartitionHandle::UnMount(int pos) { if(!interface || (pos >= (int)MountNameList.size()) || (MountNameList[pos].size() == 0)) return; WBFS_Close(); char DeviceSyn[10]; memcpy(DeviceSyn, MountName(pos), 8); strcat(DeviceSyn, ":"); DeviceSyn[9] = '\0'; if(strncmp(GetFSName(pos), "WBFS", 4) == 0) { wbfs_t *wbfshandle = GetWbfsHandle(pos); if(wbfshandle) wbfs_close(wbfshandle); gprintf("WBFS Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "FAT", 3) == 0) { fatUnmount(DeviceSyn); gprintf("FAT Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "NTFS", 4) == 0) { ntfsUnmount(DeviceSyn, true); gprintf("NTFS Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "LINUX", 5) == 0) { ext2Unmount(DeviceSyn); gprintf("EXT Partition at %s unmounted.\n", DeviceSyn); } /* Remove name from list */ MountNameList[pos].clear(); SetWbfsHandle(pos, NULL); }
int DeviceHandler::GetFSType(int dev) { const char *FSName = GetFSName(dev); if(!FSName) return -1; if(strncmp(FSName, "WBFS", 4) == 0) return PART_FS_WBFS; else if(strncmp(FSName, "FAT", 3) == 0) return PART_FS_FAT; else if(strncmp(FSName, "NTFS", 4) == 0) return PART_FS_NTFS; else if(strncmp(FSName, "LINUX", 4) == 0) return PART_FS_EXT; return -1; }
bool PartitionHandle::Mount(int pos, const char * name) { if(!valid(pos)) return false; if(!name) return false; UnMount(pos); if(pos >= (int) MountNameList.size()) MountNameList.resize(GetPartitionCount()); MountNameList[pos] = name; if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0) { if (fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS)) { if(strcmp(GetFSName(pos), "GUID-Entry") == 0) PartitionList[pos].FSName = "FAT"; return true; } } if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0) { if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER)) { PartitionList[pos].FSName = "NTFS"; return true; } } if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0) { if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT)) { PartitionList[pos].FSName = "LINUX"; return true; } } MountNameList[pos].clear(); return false; }
int DeviceHandler::GetFilesystemType(int part) { PartitionHandle* handle = GetHandleFromPartition(part); if(handle == NULL) return-1; const char* fsName = GetFSName(part); if(!fsName) return -1; if(strncmp(fsName, "WBFS", 4) == 0) return PART_FS_WBFS; else if(strncmp(fsName, "FAT", 3) == 0) return PART_FS_FAT; else if(strncmp(fsName, "NTFS", 4) == 0) return PART_FS_NTFS; else if(strncmp(fsName, "LINUX", 4) == 0) return PART_FS_EXT; return -1; }
static const char * PathToFSName(const char * path) { return GetFSName(PathToDriveType(path)); };
bool PartitionHandle::Mount(int pos, const char *name, bool forceFAT) { if(valid(pos)) UnMount(pos); if(!name) return false; if(pos >= (int)MountNameList.size()) MountNameList.resize(pos + 1); MountNameList[pos] = name; char DeviceSyn[10]; memcpy(DeviceSyn, name, 8); strcat(DeviceSyn, ":"); DeviceSyn[9] = '\0'; //! Some stupid partition manager think they don't need to edit the freaken MBR. //! So we need to check the first 64 sectors and see if some partition is there. //! libfat does that by default so let's use it. if(forceFAT && (strlen(GetFSName(pos)) == 0 || strcmp(GetFSName(pos), "Unknown") == 0)) { if(fatMount(MountNameList[pos].c_str(), interface, 0, CACHE, SECTORS)) { sec_t FAT_startSector = FindFirstValidPartition(interface); AddPartition("FAT", FAT_startSector, 0xdeadbeaf, true, 0x0c, 0); gprintf("FAT Partition at %s (forceFAT) mounted.\n", DeviceSyn); SetWbfsHandle(pos, NULL); return true; } } if(!valid(pos)) return false; SetWbfsHandle(pos, NULL); if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0) { if(fatMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS)) { gprintf("FAT Partition at %s mounted.\n", DeviceSyn); PartitionList[pos].FSName = "FAT"; return true; } } else if(strncmp(GetFSName(pos), "NTFS", 4) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0) { if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER)) { gprintf("NTFS Partition at %s mounted.\n", DeviceSyn); PartitionList[pos].FSName = "NTFS"; return true; } } else if(strncmp(GetFSName(pos), "LINUX", 5) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0) { if(ext2Mount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, EXT2_FLAG_DEFAULT)) { gprintf("EXT Partition at %s mounted.\n", DeviceSyn); PartitionList[pos].FSName = "LINUX"; return true; } } else if(strncmp(GetFSName(pos), "WBFS", 4) == 0) { if(interface == &__io_usbstorage2_port0 || interface == &__io_usbstorage2_port1) SetWbfsHandle(pos, wbfs_open_partition(__WBFS_ReadUSB, __WBFS_WriteUSB, NULL, USBStorage2_GetSectorSize(), GetSecCount(pos), GetLBAStart(pos), 0)); else if(interface == &__io_sdhc) SetWbfsHandle(pos, wbfs_open_partition(__WBFS_ReadSDHC, __WBFS_WriteSDHC, NULL, 512, GetSecCount(pos), GetLBAStart(pos), 0)); if(GetWbfsHandle(pos)) { gprintf("WBFS Partition at %s mounted.\n", DeviceSyn); PartitionList[pos].FSName = "WBFS"; return true; } } /* FAIL */ MountNameList[pos].clear(); return false; }
const char* DeviceHandler::GetFSName(const char* path) { int part = GetPartitionNumber(path); if(part < 0) return ""; return GetFSName(part); }