Ejemplo n.º 1
0
        private void InterceptReadCapacity16(LogicalUnit logicalUnit, byte[] commandBytes, byte[] response)
        {
            ReadCapacity16Parameter parameter = new ReadCapacity16Parameter(response);

            logicalUnit.BlockSize = parameter.BlockLengthInBytes;
            Log(Severity.Verbose, "LUN: {0}, BlockSize updated to {1}", logicalUnit.AssociatedLun, logicalUnit.BlockSize);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        public SCSIStatusCodeName ReadCapacity16(LUNStructure lun, uint allocationLength, out byte[] response)
        {
            if (lun >= m_disks.Count)
            {
                response = FormatSenseData(SenseDataParameter.GetIllegalRequestInvalidLUNSenseData());
                return(SCSIStatusCodeName.CheckCondition);
            }

            ReadCapacity16Parameter parameter = new ReadCapacity16Parameter(m_disks[lun].Size, (uint)m_disks[lun].BytesPerSector);

            response = parameter.GetBytes();
            // we must not return more bytes than ReadCapacity16.AllocationLength
            if (response.Length > allocationLength)
            {
                response = ByteReader.ReadBytes(response, 0, (int)allocationLength);
            }
            return(SCSIStatusCodeName.Good);
        }