/// <returns>Capacity in bytes</returns> public ulong ReadCapacity(ushort LUN, out int bytesPerSector) { if (!m_isConnected) { throw new InvalidOperationException("iSCSI client is not connected"); } SCSICommandPDU readCapacity = ClientHelper.GetReadCapacity10Command(m_session, m_connection, LUN); SendPDU(readCapacity); // SCSIResponsePDU with CheckCondition could be returned in case of an error SCSIDataInPDU data = WaitForPDU(readCapacity.InitiatorTaskTag) as SCSIDataInPDU; if (data != null && data.StatusPresent && data.Status == SCSIStatusCodeName.Good) { ReadCapacity10Parameter capacity = new ReadCapacity10Parameter(data.Data); if (capacity.ReturnedLBA != 0xFFFFFFFF) { bytesPerSector = (int)capacity.BlockLengthInBytes; return((capacity.ReturnedLBA + 1) * capacity.BlockLengthInBytes); } readCapacity = ClientHelper.GetReadCapacity16Command(m_session, m_connection, LUN); m_clientSocket.Send(readCapacity.GetBytes()); data = WaitForPDU(readCapacity.InitiatorTaskTag) as SCSIDataInPDU; if (data != null && data.StatusPresent && data.Status == SCSIStatusCodeName.Good) { ReadCapacity16Parameter capacity16 = new ReadCapacity16Parameter(data.Data); bytesPerSector = (int)capacity16.BlockLengthInBytes; return((capacity16.ReturnedLBA + 1) * capacity16.BlockLengthInBytes); } } bytesPerSector = 0; return(0); }
public List <ushort> GetLUNList() { if (!m_isConnected) { throw new InvalidOperationException("iSCSI client is not connected"); } SCSICommandPDU reportLUNs = ClientHelper.GetReportLUNsCommand(m_session, m_connection, ReportLUNsParameter.MinimumAllocationLength); SendPDU(reportLUNs); SCSIDataInPDU data = WaitForPDU(reportLUNs.InitiatorTaskTag) as SCSIDataInPDU; if (data != null && data.StatusPresent && data.Status == SCSIStatusCodeName.Good) { uint requiredAllocationLength = ReportLUNsParameter.GetRequiredAllocationLength(data.Data); if (requiredAllocationLength > ReportLUNsParameter.MinimumAllocationLength) { reportLUNs = ClientHelper.GetReportLUNsCommand(m_session, m_connection, requiredAllocationLength); m_clientSocket.Send(reportLUNs.GetBytes()); data = WaitForPDU(reportLUNs.InitiatorTaskTag) as SCSIDataInPDU; if (data == null || !data.StatusPresent || data.Status != SCSIStatusCodeName.Good) { return(null); } } ReportLUNsParameter parameter = new ReportLUNsParameter(data.Data); List <ushort> result = new List <ushort>(); foreach (LUNStructure lun in parameter.LUNList) { if (lun.IsSingleLevelLUN) { result.Add(lun); } } return(result); } return(null); }