public static AACSLBAExtentsResponse?DecodeAACSLBAExtents(byte[] AACSLBAExtsResponse) { if (AACSLBAExtsResponse == null) { return(null); } AACSLBAExtentsResponse decoded = new AACSLBAExtentsResponse(); BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; decoded.DataLength = BigEndianBitConverter.ToUInt16(AACSLBAExtsResponse, 0); decoded.Reserved = AACSLBAExtsResponse[2]; decoded.MaxLBAExtents = AACSLBAExtsResponse[3]; if ((AACSLBAExtsResponse.Length - 4) % 16 != 0) { return(decoded); } decoded.Extents = new AACSLBAExtent[(AACSLBAExtsResponse.Length - 4) / 16]; for (int i = 0; i < (AACSLBAExtsResponse.Length - 4) / 16; i++) { decoded.Extents[i].Reserved = new byte[8]; Array.Copy(AACSLBAExtsResponse, 0 + i * 16 + 4, decoded.Extents[i].Reserved, 0, 8); decoded.Extents[i].StartLBA = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 8 + i * 16 + 4); decoded.Extents[i].LBACount = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 12 + i * 16 + 4); } return(decoded); }
public static string PrettifyAACSLBAExtents(AACSLBAExtentsResponse?AACSLBAExtsResponse) { if (AACSLBAExtsResponse == null) { return(null); } AACSLBAExtentsResponse response = AACSLBAExtsResponse.Value; StringBuilder sb = new StringBuilder(); if (response.MaxLBAExtents == 0) { sb.AppendLine(response.DataLength > 2 ? "Drive can store 256 LBA Extents" : "Drive cannot store LBA Extents"); } else { sb.AppendFormat("Drive can store {0} LBA Extents", response.MaxLBAExtents).AppendLine(); } for (int i = 0; i < response.Extents.Length; i++) { sb.AppendFormat("LBA Extent {0} starts at LBA {1} and goes for {2} sectors", i, response.Extents[i].StartLBA, response.Extents[i].LBACount); } return(sb.ToString()); }
public static AACSLBAExtentsResponse? DecodeAACSLBAExtents(byte[] AACSLBAExtsResponse) { if(AACSLBAExtsResponse == null) return null; var decoded = new AACSLBAExtentsResponse { DataLength = BigEndianBitConverter.ToUInt16(AACSLBAExtsResponse, 0), Reserved = AACSLBAExtsResponse[2], MaxLBAExtents = AACSLBAExtsResponse[3] }; if((AACSLBAExtsResponse.Length - 4) % 16 != 0) return decoded; decoded.Extents = new AACSLBAExtent[(AACSLBAExtsResponse.Length - 4) / 16]; for(int i = 0; i < (AACSLBAExtsResponse.Length - 4) / 16; i++) { decoded.Extents[i].Reserved = new byte[8]; Array.Copy(AACSLBAExtsResponse, 0 + (i * 16) + 4, decoded.Extents[i].Reserved, 0, 8); decoded.Extents[i].StartLBA = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 8 + (i * 16) + 4); decoded.Extents[i].LBACount = BigEndianBitConverter.ToUInt32(AACSLBAExtsResponse, 12 + (i * 16) + 4); } return decoded; }