public static DeviceGeometryTuple DecodeDeviceGeometryTuple(byte[] data) { if ((data?.Length - 2) % 6 != 0) { return(null); } DeviceGeometryTuple tuple = new DeviceGeometryTuple(); List <DeviceGeometry> geometries = new List <DeviceGeometry>(); for (int position = 2; position < data.Length; position += 6) { DeviceGeometry geometry = new DeviceGeometry { CardInterface = data[position], EraseBlockSize = data[position + 1], ReadBlockSize = data[position + 2], WriteBlockSize = data[position + 3], Partitions = data[position + 4], Interleaving = data[position + 5] }; geometries.Add(geometry); } tuple.Code = (TupleCodes)data[0]; tuple.Link = data[1]; tuple.Geometries = geometries.ToArray(); return(tuple); }
public static string PrettifyDeviceGeometryTuple(DeviceGeometryTuple tuple) { if (tuple == null) { return(null); } if (tuple.Code != TupleCodes.CISTPL_DEVICEGEO && tuple.Code != TupleCodes.CISTPL_DEVICEGEO_A) { return(null); } StringBuilder sb = new StringBuilder(); sb.AppendLine("PCMCIA Device Geometry Tuples:"); foreach (DeviceGeometry geometry in tuple.Geometries) { sb.AppendLine("\tGeometry:"); sb.AppendFormat("\t\tDevice width: {0} bits", (1 << (geometry.CardInterface - 1)) * 8).AppendLine(); sb.AppendFormat("\t\tErase block = {0} bytes", (1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1))).AppendLine(); sb.AppendFormat("\t\tRead block = {0} bytes", (1 << (geometry.ReadBlockSize - 1)) * (1 << (geometry.Interleaving - 1))).AppendLine(); sb.AppendFormat("\t\tWrite block = {0} bytes", (1 << (geometry.WriteBlockSize - 1)) * (1 << (geometry.Interleaving - 1))).AppendLine(); sb.AppendFormat("\t\tPartition alignment = {0} bytes", (1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1)) * (1 << (geometry.Partitions - 1))).AppendLine(); } return(sb.ToString()); }