REFACTOR: Invert 'if' statement to reduce nesting.

This commit is contained in:
2017-12-21 06:06:19 +00:00
parent 9cd1869d1d
commit 4d886dae25
138 changed files with 9447 additions and 9806 deletions

View File

@@ -129,11 +129,10 @@ namespace DiscImageChef.Partitions
Scheme = Name
};
part.Offset = part.Start * (ulong)sector.Length;
if(entry.magic == LINUX_MAGIC || entry.magic == SWAP_MAGIC)
{
partitions.Add(part);
counter++;
}
if(entry.magic != LINUX_MAGIC && entry.magic != SWAP_MAGIC) continue;
partitions.Add(part);
counter++;
}
break;
@@ -160,11 +159,10 @@ namespace DiscImageChef.Partitions
Scheme = Name
};
part.Offset = part.Start * (ulong)sector.Length;
if(entry.length > 0)
{
partitions.Add(part);
counter++;
}
if(entry.length <= 0) continue;
partitions.Add(part);
counter++;
}
break;

View File

@@ -243,101 +243,99 @@ namespace DiscImageChef.Partitions
byte[] tmp = new byte[entry_size];
Array.Copy(entries, i * entry_size, tmp, 0, entry_size);
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
if(entry.signature == APM_MAGIC)
if(entry.signature != APM_MAGIC) continue;
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].signature = 0x{1:X4}", i, entry.signature);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].reserved1 = 0x{1:X4}", i, entry.reserved1);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entries = {1}", i, entry.entries);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].start = {1}", i, entry.start);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].sectors = {1}", i, entry.sectors);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i,
StringHandlers.CToString(entry.name));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i,
StringHandlers.CToString(entry.type));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i,
entry.first_data_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].data_sectors = {1}", i, entry.data_sectors);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i,
(AppleMapFlags)entry.flags);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i,
entry.first_boot_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].boot_size = {1}", i, entry.boot_size);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i,
entry.load_address);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i,
entry.load_address2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i,
entry.entry_point);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i,
entry.entry_point2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i,
StringHandlers.CToString(entry.processor));
AppleMapFlags flags = (AppleMapFlags)entry.flags;
// BeOS doesn't mark its partitions as valid
//if(flags.HasFlag(AppleMapFlags.Valid) &&
if(StringHandlers.CToString(entry.type) == "Apple_partition_map" || entry.sectors <= 0) continue;
StringBuilder sb = new StringBuilder();
CommonTypes.Partition _partition = new CommonTypes.Partition
{
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].signature = 0x{1:X4}", i, entry.signature);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].reserved1 = 0x{1:X4}", i, entry.reserved1);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entries = {1}", i, entry.entries);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].start = {1}", i, entry.start);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].sectors = {1}", i, entry.sectors);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i,
StringHandlers.CToString(entry.name));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i,
StringHandlers.CToString(entry.type));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i,
entry.first_data_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].data_sectors = {1}", i, entry.data_sectors);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i,
(AppleMapFlags)entry.flags);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i,
entry.first_boot_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].boot_size = {1}", i, entry.boot_size);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i,
entry.load_address);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i,
entry.load_address2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i,
entry.entry_point);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i,
entry.entry_point2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i,
StringHandlers.CToString(entry.processor));
Sequence = sequence,
Type = StringHandlers.CToString(entry.type),
Name = StringHandlers.CToString(entry.name),
Offset = entry.start * entry_size,
Size = entry.sectors * entry_size,
Start = entry.start * entry_size / sector_size + sectorOffset,
Length = entry.sectors * entry_size / sector_size,
Scheme = Name
};
sb.AppendLine("Partition flags:");
if(flags.HasFlag(AppleMapFlags.Valid)) sb.AppendLine("Partition is valid.");
if(flags.HasFlag(AppleMapFlags.Allocated)) sb.AppendLine("Partition entry is allocated.");
if(flags.HasFlag(AppleMapFlags.InUse)) sb.AppendLine("Partition is in use.");
if(flags.HasFlag(AppleMapFlags.Bootable)) sb.AppendLine("Partition is bootable.");
if(flags.HasFlag(AppleMapFlags.Readable)) sb.AppendLine("Partition is readable.");
if(flags.HasFlag(AppleMapFlags.Writable)) sb.AppendLine("Partition is writable.");
AppleMapFlags flags = (AppleMapFlags)entry.flags;
if(flags.HasFlag(AppleMapFlags.Bootable))
{
sb.AppendFormat("First boot sector: {0}",
entry.first_boot_block * entry_size / sector_size).AppendLine();
sb.AppendFormat("Boot is {0} bytes.", entry.boot_size).AppendLine();
sb.AppendFormat("Boot load address: 0x{0:X8}", entry.load_address).AppendLine();
sb.AppendFormat("Boot entry point: 0x{0:X8}", entry.entry_point).AppendLine();
sb.AppendFormat("Boot code checksum: 0x{0:X8}", entry.checksum).AppendLine();
sb.AppendFormat("Processor: {0}", StringHandlers.CToString(entry.processor)).AppendLine();
// BeOS doesn't mark its partitions as valid
//if(flags.HasFlag(AppleMapFlags.Valid) &&
if(StringHandlers.CToString(entry.type) != "Apple_partition_map" && entry.sectors > 0)
{
StringBuilder sb = new StringBuilder();
CommonTypes.Partition _partition = new CommonTypes.Partition
{
Sequence = sequence,
Type = StringHandlers.CToString(entry.type),
Name = StringHandlers.CToString(entry.name),
Offset = entry.start * entry_size,
Size = entry.sectors * entry_size,
Start = entry.start * entry_size / sector_size + sectorOffset,
Length = entry.sectors * entry_size / sector_size,
Scheme = Name
};
sb.AppendLine("Partition flags:");
if(flags.HasFlag(AppleMapFlags.Valid)) sb.AppendLine("Partition is valid.");
if(flags.HasFlag(AppleMapFlags.Allocated)) sb.AppendLine("Partition entry is allocated.");
if(flags.HasFlag(AppleMapFlags.InUse)) sb.AppendLine("Partition is in use.");
if(flags.HasFlag(AppleMapFlags.Bootable)) sb.AppendLine("Partition is bootable.");
if(flags.HasFlag(AppleMapFlags.Readable)) sb.AppendLine("Partition is readable.");
if(flags.HasFlag(AppleMapFlags.Writable)) sb.AppendLine("Partition is writable.");
if(flags.HasFlag(AppleMapFlags.Bootable))
{
sb.AppendFormat("First boot sector: {0}",
entry.first_boot_block * entry_size / sector_size).AppendLine();
sb.AppendFormat("Boot is {0} bytes.", entry.boot_size).AppendLine();
sb.AppendFormat("Boot load address: 0x{0:X8}", entry.load_address).AppendLine();
sb.AppendFormat("Boot entry point: 0x{0:X8}", entry.entry_point).AppendLine();
sb.AppendFormat("Boot code checksum: 0x{0:X8}", entry.checksum).AppendLine();
sb.AppendFormat("Processor: {0}", StringHandlers.CToString(entry.processor)).AppendLine();
if(flags.HasFlag(AppleMapFlags.PicCode))
sb.AppendLine("Partition's boot code is position independent.");
}
_partition.Description = sb.ToString();
if(_partition.Start < imagePlugin.ImageInfo.Sectors &&
_partition.End < imagePlugin.ImageInfo.Sectors)
{
partitions.Add(_partition);
sequence++;
}
// Some CD and DVDs end with an Apple_Free that expands beyond the disc size...
else if(_partition.Start < imagePlugin.ImageInfo.Sectors)
{
DicConsole.DebugWriteLine("AppleMap Plugin",
"Cutting last partition end ({0}) to media size ({1})",
_partition.End, imagePlugin.ImageInfo.Sectors - 1);
_partition.Length = imagePlugin.ImageInfo.Sectors - _partition.Start;
partitions.Add(_partition);
sequence++;
}
else
DicConsole.DebugWriteLine("AppleMap Plugin",
"Not adding partition becaus start ({0}) is outside media size ({1})",
_partition.Start, imagePlugin.ImageInfo.Sectors - 1);
}
if(flags.HasFlag(AppleMapFlags.PicCode))
sb.AppendLine("Partition's boot code is position independent.");
}
_partition.Description = sb.ToString();
if(_partition.Start < imagePlugin.ImageInfo.Sectors &&
_partition.End < imagePlugin.ImageInfo.Sectors)
{
partitions.Add(_partition);
sequence++;
}
// Some CD and DVDs end with an Apple_Free that expands beyond the disc size...
else if(_partition.Start < imagePlugin.ImageInfo.Sectors)
{
DicConsole.DebugWriteLine("AppleMap Plugin",
"Cutting last partition end ({0}) to media size ({1})",
_partition.End, imagePlugin.ImageInfo.Sectors - 1);
_partition.Length = imagePlugin.ImageInfo.Sectors - _partition.Start;
partitions.Add(_partition);
sequence++;
}
else
DicConsole.DebugWriteLine("AppleMap Plugin",
"Not adding partition becaus start ({0}) is outside media size ({1})",
_partition.Start, imagePlugin.ImageInfo.Sectors - 1);
}
return partitions.Count > 0;

View File

@@ -140,7 +140,8 @@ namespace DiscImageChef.Partitions
{
uint type = table.entries[i].type & 0x00FFFFFF;
switch(type) {
switch(type)
{
case TypeGEMDOS:
case TypeBigGEMDOS:
case TypeLinux:
@@ -241,97 +242,17 @@ namespace DiscImageChef.Partitions
{
uint extendedType = extendedTable.entries[j].type & 0x00FFFFFF;
if(extendedType == TypeGEMDOS || extendedType == TypeBigGEMDOS || extendedType == TypeLinux ||
extendedType == TypeSwap || extendedType == TypeRAW || extendedType == TypeNetBSD ||
extendedType == TypeNetBSDSwap || extendedType == TypeSysV || extendedType == TypeMac ||
extendedType == TypeMinix || extendedType == TypeMinix2)
{
validTable = true;
if(extendedTable.entries[j].start <= imagePlugin.GetSectors())
{
if(extendedTable.entries[j].start + extendedTable.entries[j].length >
imagePlugin.GetSectors())
DicConsole.DebugWriteLine("Atari partition plugin",
"WARNING: End of partition goes beyond device size");
if(extendedType != TypeGEMDOS && extendedType != TypeBigGEMDOS &&
extendedType != TypeLinux && extendedType != TypeSwap && extendedType != TypeRAW &&
extendedType != TypeNetBSD && extendedType != TypeNetBSDSwap &&
extendedType != TypeSysV && extendedType != TypeMac && extendedType != TypeMinix &&
extendedType != TypeMinix2) continue;
ulong sectorSize = imagePlugin.GetSectorSize();
if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048;
validTable = true;
if(extendedTable.entries[j].start > imagePlugin.GetSectors()) continue;
byte[] partType = new byte[3];
partType[0] = (byte)((extendedType & 0xFF0000) >> 16);
partType[1] = (byte)((extendedType & 0x00FF00) >> 8);
partType[2] = (byte)(extendedType & 0x0000FF);
CommonTypes.Partition part = new CommonTypes.Partition
{
Size = extendedTable.entries[j].length * sectorSize,
Length = extendedTable.entries[j].length,
Sequence = partitionSequence,
Name = "",
Offset = extendedTable.entries[j].start * sectorSize,
Start = extendedTable.entries[j].start,
Type = Encoding.ASCII.GetString(partType),
Scheme = Name
};
switch(extendedType)
{
case TypeGEMDOS:
part.Description = "Atari GEMDOS partition";
break;
case TypeBigGEMDOS:
part.Description = "Atari GEMDOS partition bigger than 32 MiB";
break;
case TypeLinux:
part.Description = "Linux partition";
break;
case TypeSwap:
part.Description = "Swap partition";
break;
case TypeRAW:
part.Description = "RAW partition";
break;
case TypeNetBSD:
part.Description = "NetBSD partition";
break;
case TypeNetBSDSwap:
part.Description = "NetBSD swap partition";
break;
case TypeSysV:
part.Description = "Atari UNIX partition";
break;
case TypeMac:
part.Description = "Macintosh partition";
break;
case TypeMinix:
case TypeMinix2:
part.Description = "MINIX partition";
break;
default:
part.Description = "Unknown partition type";
break;
}
partitions.Add(part);
partitionSequence++;
}
}
}
break;
}
}
if(validTable)
for(int i = 0; i < 8; i++)
{
uint type = table.icdEntries[i].type & 0x00FFFFFF;
if(type == TypeGEMDOS || type == TypeBigGEMDOS || type == TypeLinux || type == TypeSwap ||
type == TypeRAW || type == TypeNetBSD || type == TypeNetBSDSwap || type == TypeSysV ||
type == TypeMac || type == TypeMinix || type == TypeMinix2)
if(table.icdEntries[i].start <= imagePlugin.GetSectors())
{
if(table.icdEntries[i].start + table.icdEntries[i].length > imagePlugin.GetSectors())
if(extendedTable.entries[j].start + extendedTable.entries[j].length >
imagePlugin.GetSectors())
DicConsole.DebugWriteLine("Atari partition plugin",
"WARNING: End of partition goes beyond device size");
@@ -339,22 +260,22 @@ namespace DiscImageChef.Partitions
if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048;
byte[] partType = new byte[3];
partType[0] = (byte)((type & 0xFF0000) >> 16);
partType[1] = (byte)((type & 0x00FF00) >> 8);
partType[2] = (byte)(type & 0x0000FF);
partType[0] = (byte)((extendedType & 0xFF0000) >> 16);
partType[1] = (byte)((extendedType & 0x00FF00) >> 8);
partType[2] = (byte)(extendedType & 0x0000FF);
CommonTypes.Partition part = new CommonTypes.Partition
{
Size = table.icdEntries[i].length * sectorSize,
Length = table.icdEntries[i].length,
Size = extendedTable.entries[j].length * sectorSize,
Length = extendedTable.entries[j].length,
Sequence = partitionSequence,
Name = "",
Offset = table.icdEntries[i].start * sectorSize,
Start = table.icdEntries[i].start,
Offset = extendedTable.entries[j].start * sectorSize,
Start = extendedTable.entries[j].start,
Type = Encoding.ASCII.GetString(partType),
Scheme = Name
};
switch(type)
switch(extendedType)
{
case TypeGEMDOS:
part.Description = "Atari GEMDOS partition";
@@ -395,7 +316,87 @@ namespace DiscImageChef.Partitions
partitions.Add(part);
partitionSequence++;
}
break;
}
}
if(!validTable) return partitions.Count > 0;
for(int i = 0; i < 8; i++)
{
uint type = table.icdEntries[i].type & 0x00FFFFFF;
if(type != TypeGEMDOS && type != TypeBigGEMDOS && type != TypeLinux && type != TypeSwap &&
type != TypeRAW && type != TypeNetBSD && type != TypeNetBSDSwap && type != TypeSysV &&
type != TypeMac && type != TypeMinix && type != TypeMinix2) continue;
if(table.icdEntries[i].start > imagePlugin.GetSectors()) continue;
if(table.icdEntries[i].start + table.icdEntries[i].length > imagePlugin.GetSectors())
DicConsole.DebugWriteLine("Atari partition plugin",
"WARNING: End of partition goes beyond device size");
ulong sectorSize = imagePlugin.GetSectorSize();
if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048;
byte[] partType = new byte[3];
partType[0] = (byte)((type & 0xFF0000) >> 16);
partType[1] = (byte)((type & 0x00FF00) >> 8);
partType[2] = (byte)(type & 0x0000FF);
CommonTypes.Partition part = new CommonTypes.Partition
{
Size = table.icdEntries[i].length * sectorSize,
Length = table.icdEntries[i].length,
Sequence = partitionSequence,
Name = "",
Offset = table.icdEntries[i].start * sectorSize,
Start = table.icdEntries[i].start,
Type = Encoding.ASCII.GetString(partType),
Scheme = Name
};
switch(type)
{
case TypeGEMDOS:
part.Description = "Atari GEMDOS partition";
break;
case TypeBigGEMDOS:
part.Description = "Atari GEMDOS partition bigger than 32 MiB";
break;
case TypeLinux:
part.Description = "Linux partition";
break;
case TypeSwap:
part.Description = "Swap partition";
break;
case TypeRAW:
part.Description = "RAW partition";
break;
case TypeNetBSD:
part.Description = "NetBSD partition";
break;
case TypeNetBSDSwap:
part.Description = "NetBSD swap partition";
break;
case TypeSysV:
part.Description = "Atari UNIX partition";
break;
case TypeMac:
part.Description = "Macintosh partition";
break;
case TypeMinix:
case TypeMinix2:
part.Description = "MINIX partition";
break;
default:
part.Description = "Unknown partition type";
break;
}
partitions.Add(part);
partitionSequence++;
}
return partitions.Count > 0;
}

View File

@@ -80,12 +80,11 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("BSD plugin",
"dl.magic on sector {0} at offset {1} = 0x{2:X8} (expected 0x{3:X8})",
location + sectorOffset, offset, dl.d_magic, DISKMAGIC);
if(dl.d_magic == DISKMAGIC && dl.d_magic2 == DISKMAGIC ||
dl.d_magic == DISKCIGAM && dl.d_magic2 == DISKCIGAM)
{
found = true;
break;
}
if((dl.d_magic != DISKMAGIC || dl.d_magic2 != DISKMAGIC) &&
(dl.d_magic != DISKCIGAM || dl.d_magic2 != DISKCIGAM)) continue;
found = true;
break;
}
if(found) break;
@@ -151,21 +150,19 @@ namespace DiscImageChef.Partitions
Sequence = counter,
Scheme = Name
};
if(dl.d_partitions[i].p_fstype != fsType.Unused)
{
// Crude and dirty way to know if the disklabel is relative to its parent partition...
if(dl.d_partitions[i].p_offset < sectorOffset && !addSectorOffset) addSectorOffset = true;
if(dl.d_partitions[i].p_fstype == fsType.Unused) continue;
// Crude and dirty way to know if the disklabel is relative to its parent partition...
if(dl.d_partitions[i].p_offset < sectorOffset && !addSectorOffset) addSectorOffset = true;
if(addSectorOffset)
{
part.Start += sectorOffset;
part.Offset += sectorOffset * imagePlugin.GetSectorSize();
}
DicConsole.DebugWriteLine("BSD plugin", "part.start = {0}", part.Start);
DicConsole.DebugWriteLine("BSD plugin", "Adding it...");
partitions.Add(part);
counter++;
if(addSectorOffset)
{
part.Start += sectorOffset;
part.Offset += sectorOffset * imagePlugin.GetSectorSize();
}
DicConsole.DebugWriteLine("BSD plugin", "part.start = {0}", part.Start);
DicConsole.DebugWriteLine("BSD plugin", "Adding it...");
partitions.Add(part);
counter++;
}
return partitions.Count > 0;

View File

@@ -79,11 +79,10 @@ namespace DiscImageChef.Partitions
Sequence = counter,
Scheme = Name
};
if(part.Size > 0)
{
partitions.Add(part);
counter++;
}
if(part.Size <= 0) continue;
partitions.Add(part);
counter++;
}
return true;

View File

@@ -86,11 +86,10 @@ namespace DiscImageChef.Partitions
if((BSD.fsType)entry.p_fstype == BSD.fsType.Other) part.Type = entry.p_type_uuid.ToString();
else part.Type = BSD.fsTypeToString((BSD.fsType)entry.p_fstype);
if(entry.p_bsize > 0 && entry.p_boffset > 0)
{
partitions.Add(part);
counter++;
}
if(entry.p_bsize <= 0 || entry.p_boffset <= 0) continue;
partitions.Add(part);
counter++;
}
return true;

View File

@@ -112,11 +112,10 @@ namespace DiscImageChef.Partitions
};
part.Offset = part.Start * (ulong)sector.Length;
part.Size = part.Length * (ulong)sector.Length;
if(entry.length > 0)
{
partitions.Add(part);
counter++;
}
if(entry.length <= 0) continue;
partitions.Add(part);
counter++;
}
return true;

View File

@@ -222,128 +222,123 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("MBR plugin", "entry.extended = {0}", extended);
if(extended) // Let's extend the fun
if(!extended) continue;
bool processing_extended = true;
ulong chain_start = lba_start;
while(processing_extended)
{
bool processing_extended = true;
ulong chain_start = lba_start;
sector = imagePlugin.ReadSector(lba_start);
while(processing_extended)
handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
ExtendedBootRecord ebr =
(ExtendedBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(ExtendedBootRecord));
handle.Free();
DicConsole.DebugWriteLine("MBR plugin", "ebr.magic == MBR_Magic = {0}", ebr.magic == MBR_Magic);
if(ebr.magic != MBR_Magic) break;
ulong next_start = 0;
foreach(MBRPartitionEntry ebr_entry in ebr.entries)
{
sector = imagePlugin.ReadSector(lba_start);
bool ext_valid = true;
start_sector = (byte)(ebr_entry.start_sector & 0x3F);
start_cylinder = (ushort)(((ebr_entry.start_sector & 0xC0) << 2) | ebr_entry.start_cylinder);
end_sector = (byte)(ebr_entry.end_sector & 0x3F);
end_cylinder = (ushort)(((ebr_entry.end_sector & 0xC0) << 2) | ebr_entry.end_cylinder);
ulong ext_start = ebr_entry.lba_start;
ulong ext_sectors = ebr_entry.lba_sectors;
bool ext_minix = false;
handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
ExtendedBootRecord ebr =
(ExtendedBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(ExtendedBootRecord));
handle.Free();
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.status {0}", ebr_entry.status);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.type {0}", ebr_entry.type);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_start {0}", ebr_entry.lba_start);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_sectors {0}", ebr_entry.lba_sectors);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_cylinder {0}", start_cylinder);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_head {0}", ebr_entry.start_head);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_sector {0}", start_sector);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_cylinder {0}", end_cylinder);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_head {0}", ebr_entry.end_head);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_sector {0}", end_sector);
DicConsole.DebugWriteLine("MBR plugin", "ebr.magic == MBR_Magic = {0}", ebr.magic == MBR_Magic);
if(ebr.magic != MBR_Magic) break;
ulong next_start = 0;
foreach(MBRPartitionEntry ebr_entry in ebr.entries)
// Let's start the fun...
ext_valid &= ebr_entry.status == 0x00 || ebr_entry.status == 0x80;
ext_valid &= ebr_entry.type != 0x00;
ext_valid &= ebr_entry.lba_start != 0 || ebr_entry.lba_sectors != 0 ||
ebr_entry.start_cylinder != 0 || ebr_entry.start_head != 0 ||
ebr_entry.start_sector != 0 || ebr_entry.end_cylinder != 0 ||
ebr_entry.end_head != 0 || ebr_entry.end_sector != 0;
if(ebr_entry.lba_start == 0 && ebr_entry.lba_sectors == 0 && ext_valid)
{
bool ext_valid = true;
start_sector = (byte)(ebr_entry.start_sector & 0x3F);
start_cylinder =
(ushort)(((ebr_entry.start_sector & 0xC0) << 2) | ebr_entry.start_cylinder);
end_sector = (byte)(ebr_entry.end_sector & 0x3F);
end_cylinder = (ushort)(((ebr_entry.end_sector & 0xC0) << 2) | ebr_entry.end_cylinder);
ulong ext_start = ebr_entry.lba_start;
ulong ext_sectors = ebr_entry.lba_sectors;
bool ext_minix = false;
ext_start = Helpers.CHS.ToLBA(start_cylinder, ebr_entry.start_head, start_sector,
imagePlugin.ImageInfo.Heads,
imagePlugin.ImageInfo.SectorsPerTrack);
ext_sectors = Helpers.CHS.ToLBA(end_cylinder, ebr_entry.end_head, ebr_entry.end_sector,
imagePlugin.ImageInfo.Heads,
imagePlugin.ImageInfo.SectorsPerTrack) - ext_start;
}
ext_minix |= ebr_entry.type == 0x81 || ebr_entry.type == 0x80;
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.status {0}", ebr_entry.status);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.type {0}", ebr_entry.type);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_start {0}", ebr_entry.lba_start);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_sectors {0}", ebr_entry.lba_sectors);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_cylinder {0}", start_cylinder);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_head {0}", ebr_entry.start_head);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_sector {0}", start_sector);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_cylinder {0}", end_cylinder);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_head {0}", ebr_entry.end_head);
DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_sector {0}", end_sector);
// For optical media
ext_start /= divider;
ext_sectors /= divider;
// Let's start the fun...
ext_valid &= ebr_entry.status == 0x00 || ebr_entry.status == 0x80;
ext_valid &= ebr_entry.type != 0x00;
ext_valid &= ebr_entry.lba_start != 0 || ebr_entry.lba_sectors != 0 ||
ebr_entry.start_cylinder != 0 || ebr_entry.start_head != 0 ||
ebr_entry.start_sector != 0 || ebr_entry.end_cylinder != 0 ||
ebr_entry.end_head != 0 || ebr_entry.end_sector != 0;
if(ebr_entry.lba_start == 0 && ebr_entry.lba_sectors == 0 && ext_valid)
{
ext_start = Helpers.CHS.ToLBA(start_cylinder, ebr_entry.start_head, start_sector,
imagePlugin.ImageInfo.Heads,
imagePlugin.ImageInfo.SectorsPerTrack);
ext_sectors =
Helpers.CHS.ToLBA(end_cylinder, ebr_entry.end_head, ebr_entry.end_sector,
imagePlugin.ImageInfo.Heads,
imagePlugin.ImageInfo.SectorsPerTrack) - ext_start;
}
ext_minix |= ebr_entry.type == 0x81 || ebr_entry.type == 0x80;
DicConsole.DebugWriteLine("MBR plugin", "ext_start {0}", ext_start);
DicConsole.DebugWriteLine("MBR plugin", "ext_sectors {0}", ext_sectors);
// For optical media
ext_start /= divider;
ext_sectors /= divider;
DicConsole.DebugWriteLine("MBR plugin", "ext_start {0}", ext_start);
DicConsole.DebugWriteLine("MBR plugin", "ext_sectors {0}", ext_sectors);
if(ebr_entry.type == 0x05 || ebr_entry.type == 0x0F || ebr_entry.type == 0x15 ||
ebr_entry.type == 0x1F || ebr_entry.type == 0x85 || ebr_entry.type == 0x91 ||
ebr_entry.type == 0x9B || ebr_entry.type == 0xC5 || ebr_entry.type == 0xCF ||
ebr_entry.type == 0xD5)
{
ext_valid = false;
next_start = chain_start + ext_start;
}
ext_start += lba_start;
ext_valid &= ext_start <= imagePlugin.GetSectors();
// Some buggy implementations do some rounding errors getting a few sectors beyond device size
if(ext_start + ext_sectors > imagePlugin.GetSectors())
ext_sectors = imagePlugin.GetSectors() - ext_start;
if(ext_valid && ext_minix) // Let's mix the fun
if(GetMinix(imagePlugin, lba_start, divider, sectorOffset, sectorSize,
out List<Partition> mnx_parts)) partitions.AddRange(mnx_parts);
else ext_minix = false;
if(ext_valid && !ext_minix)
{
Partition part = new Partition();
if(ext_start > 0 && ext_sectors > 0)
{
part.Start = ext_start + sectorOffset;
part.Length = ext_sectors;
part.Offset = part.Start * sectorSize;
part.Size = part.Length * sectorSize;
}
else ext_valid = false;
if(ext_valid)
{
part.Type = string.Format("0x{0:X2}", ebr_entry.type);
part.Name = DecodeMBRType(ebr_entry.type);
part.Sequence = counter;
part.Description = ebr_entry.status == 0x80 ? "Partition is bootable." : "";
part.Scheme = Name;
counter++;
partitions.Add(part);
}
}
if(ebr_entry.type == 0x05 || ebr_entry.type == 0x0F || ebr_entry.type == 0x15 ||
ebr_entry.type == 0x1F || ebr_entry.type == 0x85 || ebr_entry.type == 0x91 ||
ebr_entry.type == 0x9B || ebr_entry.type == 0xC5 || ebr_entry.type == 0xCF ||
ebr_entry.type == 0xD5)
{
ext_valid = false;
next_start = chain_start + ext_start;
}
DicConsole.DebugWriteLine("MBR plugin", "next_start {0}", next_start);
processing_extended &= next_start != 0;
processing_extended &= next_start <= imagePlugin.GetSectors();
lba_start = next_start;
ext_start += lba_start;
ext_valid &= ext_start <= imagePlugin.GetSectors();
// Some buggy implementations do some rounding errors getting a few sectors beyond device size
if(ext_start + ext_sectors > imagePlugin.GetSectors())
ext_sectors = imagePlugin.GetSectors() - ext_start;
if(ext_valid && ext_minix) // Let's mix the fun
if(GetMinix(imagePlugin, lba_start, divider, sectorOffset, sectorSize,
out List<Partition> mnx_parts)) partitions.AddRange(mnx_parts);
else ext_minix = false;
if(!ext_valid || ext_minix) continue;
Partition part = new Partition();
if(ext_start > 0 && ext_sectors > 0)
{
part.Start = ext_start + sectorOffset;
part.Length = ext_sectors;
part.Offset = part.Start * sectorSize;
part.Size = part.Length * sectorSize;
}
else ext_valid = false;
if(!ext_valid) continue;
part.Type = string.Format("0x{0:X2}", ebr_entry.type);
part.Name = DecodeMBRType(ebr_entry.type);
part.Sequence = counter;
part.Description = ebr_entry.status == 0x80 ? "Partition is bootable." : "";
part.Scheme = Name;
counter++;
partitions.Add(part);
}
DicConsole.DebugWriteLine("MBR plugin", "next_start {0}", next_start);
processing_extended &= next_start != 0;
processing_extended &= next_start <= imagePlugin.GetSectors();
lba_start = next_start;
}
}
@@ -411,29 +406,27 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("MBR plugin", "mnx_start {0}", mnx_start);
DicConsole.DebugWriteLine("MBR plugin", "mnx_sectors {0}", mnx_sectors);
if(mnx_valid)
if(!mnx_valid) continue;
CommonTypes.Partition part = new CommonTypes.Partition();
if(mnx_start > 0 && mnx_sectors > 0)
{
CommonTypes.Partition part = new CommonTypes.Partition();
if(mnx_start > 0 && mnx_sectors > 0)
{
part.Start = mnx_start + sectorOffset;
part.Length = mnx_sectors;
part.Offset = part.Start * sectorSize;
part.Size = part.Length * sectorSize;
}
else mnx_valid = false;
if(mnx_valid)
{
any_mnx = true;
part.Type = "MINIX";
part.Name = "MINIX";
part.Description = mnx_entry.status == 0x80 ? "Partition is bootable." : "";
part.Scheme = "MINIX";
partitions.Add(part);
}
part.Start = mnx_start + sectorOffset;
part.Length = mnx_sectors;
part.Offset = part.Start * sectorSize;
part.Size = part.Length * sectorSize;
}
else mnx_valid = false;
if(!mnx_valid) continue;
any_mnx = true;
part.Type = "MINIX";
part.Name = "MINIX";
part.Description = mnx_entry.status == 0x80 ? "Partition is bootable." : "";
part.Scheme = "MINIX";
partitions.Add(part);
}
return any_mnx;

View File

@@ -82,12 +82,11 @@ namespace DiscImageChef.Partitions
label_sector = imagePlugin.ReadSector(i + sectorOffset);
magic = BigEndianBitConverter.ToUInt32(label_sector, 0x00);
if(magic == NEXT_MAGIC1 || magic == NEXT_MAGIC2 || magic == NEXT_MAGIC3)
{
magic_found = true;
label_position = i + sectorOffset;
break;
}
if(magic != NEXT_MAGIC1 && magic != NEXT_MAGIC2 && magic != NEXT_MAGIC3) continue;
magic_found = true;
label_position = i + sectorOffset;
break;
}
if(!magic_found) return false;
@@ -166,52 +165,51 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_type = \"{1}\"", i,
StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type));
if(label.dl_dt.d_partitions[i].p_size > 0 && label.dl_dt.d_partitions[i].p_base >= 0 &&
label.dl_dt.d_partitions[i].p_bsize >= 0)
if(label.dl_dt.d_partitions[i].p_size <= 0 || label.dl_dt.d_partitions[i].p_base < 0 ||
label.dl_dt.d_partitions[i].p_bsize < 0) continue;
StringBuilder sb = new StringBuilder();
CommonTypes.Partition part = new CommonTypes.Partition
{
StringBuilder sb = new StringBuilder();
Size = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize),
Offset =
(ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) * label.dl_dt.d_secsize),
Type = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type),
Sequence = (ulong)i,
Name = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_mountpt),
Length = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize / sector_size),
Start = (ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) *
label.dl_dt.d_secsize / sector_size),
Scheme = Name
};
CommonTypes.Partition part = new CommonTypes.Partition
{
Size = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize),
Offset =
(ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) * label.dl_dt.d_secsize),
Type = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type),
Sequence = (ulong)i,
Name = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_mountpt),
Length = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize / sector_size),
Start = (ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) *
label.dl_dt.d_secsize / sector_size),
Scheme = Name
};
if(part.Start + part.Length > imagePlugin.ImageInfo.Sectors)
{
DicConsole.DebugWriteLine("NeXT Plugin", "Partition bigger than device, reducing...");
part.Length = imagePlugin.ImageInfo.Sectors - part.Start;
part.Size = part.Length * sector_size;
DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_size = {1}", i,
part.Length);
}
sb.AppendFormat("{0} bytes per block", label.dl_dt.d_partitions[i].p_bsize).AppendLine();
sb.AppendFormat("{0} bytes per fragment", label.dl_dt.d_partitions[i].p_fsize).AppendLine();
if(label.dl_dt.d_partitions[i].p_opt == 's') sb.AppendLine("Space optimized");
else if(label.dl_dt.d_partitions[i].p_opt == 't') sb.AppendLine("Time optimized");
else sb.AppendFormat("Unknown optimization {0:X2}", label.dl_dt.d_partitions[i].p_opt).AppendLine();
sb.AppendFormat("{0} cylinders per group", label.dl_dt.d_partitions[i].p_cpg).AppendLine();
sb.AppendFormat("{0} bytes per inode", label.dl_dt.d_partitions[i].p_density).AppendLine();
sb.AppendFormat("{0}% of space must be free at minimum", label.dl_dt.d_partitions[i].p_minfree)
.AppendLine();
if(label.dl_dt.d_partitions[i].p_newfs != 1)
sb.AppendLine("Filesystem should be formatted at start");
if(label.dl_dt.d_partitions[i].p_automnt == 1)
sb.AppendLine("Filesystem should be automatically mounted");
part.Description = sb.ToString();
partitions.Add(part);
if(part.Start + part.Length > imagePlugin.ImageInfo.Sectors)
{
DicConsole.DebugWriteLine("NeXT Plugin", "Partition bigger than device, reducing...");
part.Length = imagePlugin.ImageInfo.Sectors - part.Start;
part.Size = part.Length * sector_size;
DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_size = {1}", i,
part.Length);
}
sb.AppendFormat("{0} bytes per block", label.dl_dt.d_partitions[i].p_bsize).AppendLine();
sb.AppendFormat("{0} bytes per fragment", label.dl_dt.d_partitions[i].p_fsize).AppendLine();
if(label.dl_dt.d_partitions[i].p_opt == 's') sb.AppendLine("Space optimized");
else if(label.dl_dt.d_partitions[i].p_opt == 't') sb.AppendLine("Time optimized");
else sb.AppendFormat("Unknown optimization {0:X2}", label.dl_dt.d_partitions[i].p_opt).AppendLine();
sb.AppendFormat("{0} cylinders per group", label.dl_dt.d_partitions[i].p_cpg).AppendLine();
sb.AppendFormat("{0} bytes per inode", label.dl_dt.d_partitions[i].p_density).AppendLine();
sb.AppendFormat("{0}% of space must be free at minimum", label.dl_dt.d_partitions[i].p_minfree)
.AppendLine();
if(label.dl_dt.d_partitions[i].p_newfs != 1)
sb.AppendLine("Filesystem should be formatted at start");
if(label.dl_dt.d_partitions[i].p_automnt == 1)
sb.AppendLine("Filesystem should be automatically mounted");
part.Description = sb.ToString();
partitions.Add(part);
}
return true;

View File

@@ -86,43 +86,41 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("PC98 plugin", "entry.dp_name = \"{0}\"",
StringHandlers.CToString(entry.dp_name, Encoding.GetEncoding(932)));
if(entry.dp_scyl != entry.dp_ecyl && entry.dp_ecyl > 0 &&
entry.dp_scyl <= imagePlugin.ImageInfo.Cylinders &&
entry.dp_ecyl <= imagePlugin.ImageInfo.Cylinders && entry.dp_shd <= imagePlugin.ImageInfo.Heads &&
entry.dp_ehd <= imagePlugin.ImageInfo.Heads &&
entry.dp_ssect <= imagePlugin.ImageInfo.SectorsPerTrack &&
entry.dp_esect <= imagePlugin.ImageInfo.SectorsPerTrack)
if(entry.dp_scyl == entry.dp_ecyl || entry.dp_ecyl <= 0 ||
entry.dp_scyl > imagePlugin.ImageInfo.Cylinders || entry.dp_ecyl > imagePlugin.ImageInfo.Cylinders ||
entry.dp_shd > imagePlugin.ImageInfo.Heads || entry.dp_ehd > imagePlugin.ImageInfo.Heads ||
entry.dp_ssect > imagePlugin.ImageInfo.SectorsPerTrack ||
entry.dp_esect > imagePlugin.ImageInfo.SectorsPerTrack) continue;
Partition part = new Partition
{
Partition part = new Partition
{
Start = Helpers.CHS.ToLBA(entry.dp_scyl, entry.dp_shd, (uint)(entry.dp_ssect + 1),
imagePlugin.ImageInfo.Heads, imagePlugin.ImageInfo.SectorsPerTrack),
Type = DecodePC98Sid(entry.dp_sid),
Name = StringHandlers.CToString(entry.dp_name, Encoding.GetEncoding(932)).Trim(),
Sequence = counter,
Scheme = Name
};
part.Offset = part.Start * imagePlugin.GetSectorSize();
part.Length = Helpers.CHS.ToLBA(entry.dp_ecyl, entry.dp_ehd, (uint)(entry.dp_esect + 1),
imagePlugin.ImageInfo.Heads,
imagePlugin.ImageInfo.SectorsPerTrack) - part.Start;
part.Size = part.Length * imagePlugin.GetSectorSize();
Start = Helpers.CHS.ToLBA(entry.dp_scyl, entry.dp_shd, (uint)(entry.dp_ssect + 1),
imagePlugin.ImageInfo.Heads, imagePlugin.ImageInfo.SectorsPerTrack),
Type = DecodePC98Sid(entry.dp_sid),
Name = StringHandlers.CToString(entry.dp_name, Encoding.GetEncoding(932)).Trim(),
Sequence = counter,
Scheme = Name
};
part.Offset = part.Start * imagePlugin.GetSectorSize();
part.Length = Helpers.CHS.ToLBA(entry.dp_ecyl, entry.dp_ehd, (uint)(entry.dp_esect + 1),
imagePlugin.ImageInfo.Heads,
imagePlugin.ImageInfo.SectorsPerTrack) - part.Start;
part.Size = part.Length * imagePlugin.GetSectorSize();
DicConsole.DebugWriteLine("PC98 plugin", "part.Start = {0}", part.Start);
DicConsole.DebugWriteLine("PC98 plugin", "part.Type = {0}", part.Type);
DicConsole.DebugWriteLine("PC98 plugin", "part.Name = {0}", part.Name);
DicConsole.DebugWriteLine("PC98 plugin", "part.Sequence = {0}", part.Sequence);
DicConsole.DebugWriteLine("PC98 plugin", "part.Offset = {0}", part.Offset);
DicConsole.DebugWriteLine("PC98 plugin", "part.Length = {0}", part.Length);
DicConsole.DebugWriteLine("PC98 plugin", "part.Size = {0}", part.Size);
DicConsole.DebugWriteLine("PC98 plugin", "part.Start = {0}", part.Start);
DicConsole.DebugWriteLine("PC98 plugin", "part.Type = {0}", part.Type);
DicConsole.DebugWriteLine("PC98 plugin", "part.Name = {0}", part.Name);
DicConsole.DebugWriteLine("PC98 plugin", "part.Sequence = {0}", part.Sequence);
DicConsole.DebugWriteLine("PC98 plugin", "part.Offset = {0}", part.Offset);
DicConsole.DebugWriteLine("PC98 plugin", "part.Length = {0}", part.Length);
DicConsole.DebugWriteLine("PC98 plugin", "part.Size = {0}", part.Size);
if(((entry.dp_mid & 0x20) == 0x20 || (entry.dp_mid & 0x44) == 0x44) &&
part.Start < imagePlugin.ImageInfo.Sectors && part.End <= imagePlugin.ImageInfo.Sectors)
{
partitions.Add(part);
counter++;
}
}
if(((entry.dp_mid & 0x20) != 0x20 && (entry.dp_mid & 0x44) != 0x44) ||
part.Start >= imagePlugin.ImageInfo.Sectors ||
part.End > imagePlugin.ImageInfo.Sectors) continue;
partitions.Add(part);
counter++;
}
return partitions.Count > 0;

View File

@@ -40,8 +40,8 @@ namespace DiscImageChef.Partitions
{
public class RioKarma : PartitionPlugin
{
const ushort KarmaMagic = 0xAB56;
const byte EntryMagic = 0x4D;
const ushort KARMA_MAGIC = 0xAB56;
const byte ENTRY_MAGIC = 0x4D;
public RioKarma()
{
@@ -62,7 +62,7 @@ namespace DiscImageChef.Partitions
table = (RioKarmaTable)Marshal.PtrToStructure(tablePtr, typeof(RioKarmaTable));
Marshal.FreeHGlobal(tablePtr);
if(table.magic != KarmaMagic) return false;
if(table.magic != KARMA_MAGIC) return false;
ulong counter = 0;
@@ -78,11 +78,10 @@ namespace DiscImageChef.Partitions
Sequence = counter,
Scheme = Name
};
if(entry.type == EntryMagic)
{
partitions.Add(part);
counter++;
}
if(entry.type != ENTRY_MAGIC) continue;
partitions.Add(part);
counter++;
}
return true;

View File

@@ -126,12 +126,11 @@ namespace DiscImageChef.Partitions
Sequence = counter,
Scheme = Name
};
if(part.Size > 0 && dvh.partitions[i].type != SGIType.Header && dvh.partitions[i].type != SGIType.Volume
)
{
partitions.Add(part);
counter++;
}
if(part.Size <= 0 || dvh.partitions[i].type == SGIType.Header ||
dvh.partitions[i].type == SGIType.Volume) continue;
partitions.Add(part);
counter++;
}
return true;

View File

@@ -72,12 +72,11 @@ namespace DiscImageChef.Partitions
magic = BitConverter.ToUInt32(pdsector, 4);
DicConsole.DebugWriteLine("VTOC plugin", "sanity at {0} is 0x{1:X8} (should be 0x{2:X8} or 0x{3:X8})",
i + sectorOffset, magic, PD_MAGIC, PD_CIGAM);
if(magic == PD_MAGIC || magic == PD_CIGAM)
{
magic_found = true;
pdloc = i;
break;
}
if(magic != PD_MAGIC && magic != PD_CIGAM) continue;
magic_found = true;
pdloc = i;
break;
}
if(!magic_found) return false;

View File

@@ -75,25 +75,24 @@ namespace DiscImageChef.Partitions
{
DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p[{0}].p_off = {1}", i, xnxtbl.p[i].p_off);
DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p[{0}].p_size = {1}", i, xnxtbl.p[i].p_size);
if(xnxtbl.p[i].p_size > 0)
{
Partition part = new Partition
{
Start =
(ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) / imagePlugin.GetSectorSize() +
sectorOffset,
Length = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE) / imagePlugin.GetSectorSize(),
Offset =
(ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) +
imagePlugin.GetSectorSize() * sectorOffset,
Size = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE),
Sequence = (ulong)i,
Type = "XENIX",
Scheme = Name
};
if(xnxtbl.p[i].p_size <= 0) continue;
if(part.End < imagePlugin.GetSectors()) partitions.Add(part);
}
Partition part = new Partition
{
Start =
(ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) / imagePlugin.GetSectorSize() +
sectorOffset,
Length = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE) / imagePlugin.GetSectorSize(),
Offset =
(ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) +
imagePlugin.GetSectorSize() * sectorOffset,
Size = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE),
Sequence = (ulong)i,
Type = "XENIX",
Scheme = Name
};
if(part.End < imagePlugin.GetSectors()) partitions.Add(part);
}
return partitions.Count > 0;

View File

@@ -161,103 +161,102 @@ namespace DiscImageChef.Partitions
}
}
if(imagePlugin.ImageInfo.Sectors > (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize))
if(imagePlugin.ImageInfo.Sectors <= (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize))
return false;
{
sector = imagePlugin.ReadSector((ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize));
temp = BitConverter.ToUInt32(sector, 0);
if(temp == XboxCigam)
if(temp != XboxCigam) return false;
Partition securityPart = new Partition
{
Partition securityPart = new Partition
{
Description = "Security sectors",
Size = Xbox360SecuritySectorLen,
Length = (ulong)(Xbox360SecuritySectorLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 1,
Offset = Xbox360SecuritySectorOff,
Start = (ulong)(Xbox360SecuritySectorOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Description = "Security sectors",
Size = Xbox360SecuritySectorLen,
Length = (ulong)(Xbox360SecuritySectorLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 1,
Offset = Xbox360SecuritySectorOff,
Start = (ulong)(Xbox360SecuritySectorOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition sysCachePart = new Partition
{
Description = "System cache",
Size = Xbox360SystemCacheLen,
Length = (ulong)(Xbox360SystemCacheLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 2,
Offset = Xbox360SystemCacheOff,
Start = (ulong)(Xbox360SystemCacheOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition sysCachePart = new Partition
{
Description = "System cache",
Size = Xbox360SystemCacheLen,
Length = (ulong)(Xbox360SystemCacheLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 2,
Offset = Xbox360SystemCacheOff,
Start = (ulong)(Xbox360SystemCacheOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition gameCachePart = new Partition
{
Description = "Game cache",
Size = Xbox360GameCacheLen,
Length = (ulong)(Xbox360GameCacheLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 3,
Offset = Xbox360GameCacheOff,
Start = (ulong)(Xbox360GameCacheOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition gameCachePart = new Partition
{
Description = "Game cache",
Size = Xbox360GameCacheLen,
Length = (ulong)(Xbox360GameCacheLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 3,
Offset = Xbox360GameCacheOff,
Start = (ulong)(Xbox360GameCacheOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition sysExtPart = new Partition
{
Description = "System volume",
Size = Xbox368SysExtLen,
Length = (ulong)(Xbox368SysExtLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 4,
Offset = Xbox368SysExtOff,
Start = (ulong)(Xbox368SysExtOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition sysExtPart = new Partition
{
Description = "System volume",
Size = Xbox368SysExtLen,
Length = (ulong)(Xbox368SysExtLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 4,
Offset = Xbox368SysExtOff,
Start = (ulong)(Xbox368SysExtOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition sysExt2Part = new Partition
{
Description = "System volume 2",
Size = Xbox360SysExt2Len,
Length = (ulong)(Xbox360SysExt2Len / imagePlugin.ImageInfo.SectorSize),
Sequence = 5,
Offset = Xbox360SysExt2Off,
Start = (ulong)(Xbox360SysExt2Off / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition sysExt2Part = new Partition
{
Description = "System volume 2",
Size = Xbox360SysExt2Len,
Length = (ulong)(Xbox360SysExt2Len / imagePlugin.ImageInfo.SectorSize),
Sequence = 5,
Offset = Xbox360SysExt2Off,
Start = (ulong)(Xbox360SysExt2Off / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition xbox1Part = new Partition
{
Description = "Xbox backwards compatibility",
Size = Xbox360CompatLen,
Length = (ulong)(Xbox360CompatLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 6,
Offset = Xbox360CompatOff,
Start = (ulong)(Xbox360CompatOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition xbox1Part = new Partition
{
Description = "Xbox backwards compatibility",
Size = Xbox360CompatLen,
Length = (ulong)(Xbox360CompatLen / imagePlugin.ImageInfo.SectorSize),
Sequence = 6,
Offset = Xbox360CompatOff,
Start = (ulong)(Xbox360CompatOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
Partition dataPart = new Partition
{
Description = "Data volume",
Sequence = 7,
Offset = Xbox360DataOff,
Start = (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
dataPart.Length = imagePlugin.ImageInfo.Sectors - dataPart.Start;
dataPart.Size = dataPart.Length * imagePlugin.ImageInfo.SectorSize;
Partition dataPart = new Partition
{
Description = "Data volume",
Sequence = 7,
Offset = Xbox360DataOff,
Start = (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize),
Scheme = Name
};
dataPart.Length = imagePlugin.ImageInfo.Sectors - dataPart.Start;
dataPart.Size = dataPart.Length * imagePlugin.ImageInfo.SectorSize;
partitions.Add(securityPart);
partitions.Add(sysCachePart);
partitions.Add(gameCachePart);
partitions.Add(sysExtPart);
partitions.Add(sysExt2Part);
partitions.Add(xbox1Part);
partitions.Add(dataPart);
partitions.Add(securityPart);
partitions.Add(sysCachePart);
partitions.Add(gameCachePart);
partitions.Add(sysExtPart);
partitions.Add(sysExt2Part);
partitions.Add(xbox1Part);
partitions.Add(dataPart);
return true;
}
return true;
}
return false;
}
}
}