public static string PrettifyModePage_12_13_14(ModePage_12_13_14?modePage) { if (!modePage.HasValue) { return(null); } ModePage_12_13_14 page = modePage.Value; StringBuilder sb = new StringBuilder(); sb.AppendLine("SCSI medium partition page (extra):"); if (page.PS) { sb.AppendLine("\tParameters can be saved"); } sb.AppendFormat("\tMedium has defined {0} partitions", page.PartitionSizes.Length).AppendLine(); for (int i = 0; i < page.PartitionSizes.Length; i++) { sb.AppendFormat("\tPartition {0} is {1} units long", i, page.PartitionSizes[i]).AppendLine(); } return(sb.ToString()); }
public static ModePage_12_13_14?DecodeModePage_12_13_14(byte[] pageResponse) { if (pageResponse == null) { return(null); } if ((pageResponse[0] & 0x40) == 0x40) { return(null); } if ((pageResponse[0] & 0x3F) != 0x12 && (pageResponse[0] & 0x3F) != 0x13 && (pageResponse[0] & 0x3F) != 0x14) { return(null); } if (pageResponse[1] + 2 != pageResponse.Length) { return(null); } if (pageResponse.Length < 2) { return(null); } var decoded = new ModePage_12_13_14(); decoded.PS |= (pageResponse[0] & 0x80) == 0x80; decoded.PartitionSizes = new ushort[(pageResponse.Length - 2) / 2]; for (int i = 2; i < pageResponse.Length; i += 2) { decoded.PartitionSizes[(i - 2) / 2] = (ushort)(pageResponse[i] << 8); decoded.PartitionSizes[(i - 2) / 2] += pageResponse[i + 1]; } return(decoded); }