mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: Reformat code.
This commit is contained in:
@@ -51,14 +51,14 @@ namespace DiscImageChef.Devices.Linux
|
||||
/// <param name="direction">SCSI command transfer direction</param>
|
||||
/// <param name="duration">Time it took to execute the command in milliseconds</param>
|
||||
/// <param name="sense"><c>True</c> if SCSI error returned non-OK status and <paramref name="senseBuffer"/> contains SCSI sense</param>
|
||||
internal static int SendScsiCommand(int fd, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer, uint timeout, ScsiIoctlDirection direction, out double duration, out bool sense)
|
||||
internal static int SendScsiCommand(int fd, byte[] cdb, ref byte[] buffer, out byte[] senseBuffer, uint timeout,
|
||||
ScsiIoctlDirection direction, out double duration, out bool sense)
|
||||
{
|
||||
senseBuffer = null;
|
||||
duration = 0;
|
||||
sense = false;
|
||||
|
||||
if(buffer == null)
|
||||
return -1;
|
||||
if(buffer == null) return -1;
|
||||
|
||||
sg_io_hdr_t io_hdr = new sg_io_hdr_t();
|
||||
|
||||
@@ -82,8 +82,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
int error = Extern.ioctlSg(fd, LinuxIoctl.SG_IO, ref io_hdr);
|
||||
DateTime end = DateTime.UtcNow;
|
||||
|
||||
if(error < 0)
|
||||
error = Marshal.GetLastWin32Error();
|
||||
if(error < 0) error = Marshal.GetLastWin32Error();
|
||||
|
||||
Marshal.Copy(io_hdr.dxferp, buffer, 0, buffer.Length);
|
||||
Marshal.Copy(io_hdr.cmdp, cdb, 0, cdb.Length);
|
||||
@@ -91,10 +90,8 @@ namespace DiscImageChef.Devices.Linux
|
||||
|
||||
sense |= (io_hdr.info & SgInfo.OkMask) != SgInfo.Ok;
|
||||
|
||||
if(io_hdr.duration > 0)
|
||||
duration = io_hdr.duration;
|
||||
else
|
||||
duration = (end - start).TotalMilliseconds;
|
||||
if(io_hdr.duration > 0) duration = io_hdr.duration;
|
||||
else duration = (end - start).TotalMilliseconds;
|
||||
|
||||
Marshal.FreeHGlobal(io_hdr.dxferp);
|
||||
Marshal.FreeHGlobal(io_hdr.cmdp);
|
||||
@@ -112,36 +109,30 @@ namespace DiscImageChef.Devices.Linux
|
||||
case AtaProtocol.HardReset:
|
||||
case AtaProtocol.NonData:
|
||||
case AtaProtocol.SoftReset:
|
||||
case AtaProtocol.ReturnResponse:
|
||||
return ScsiIoctlDirection.None;
|
||||
case AtaProtocol.ReturnResponse: return ScsiIoctlDirection.None;
|
||||
case AtaProtocol.PioIn:
|
||||
case AtaProtocol.UDmaIn:
|
||||
return ScsiIoctlDirection.In;
|
||||
case AtaProtocol.UDmaIn: return ScsiIoctlDirection.In;
|
||||
case AtaProtocol.PioOut:
|
||||
case AtaProtocol.UDmaOut:
|
||||
return ScsiIoctlDirection.Out;
|
||||
default:
|
||||
return ScsiIoctlDirection.Unspecified;
|
||||
case AtaProtocol.UDmaOut: return ScsiIoctlDirection.Out;
|
||||
default: return ScsiIoctlDirection.Unspecified;
|
||||
}
|
||||
}
|
||||
|
||||
internal static int SendAtaCommand(int fd, AtaRegistersCHS registers,
|
||||
out AtaErrorRegistersCHS errorRegisters, AtaProtocol protocol,
|
||||
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
||||
bool transferBlocks, out double duration, out bool sense)
|
||||
internal static int SendAtaCommand(int fd, AtaRegistersCHS registers, out AtaErrorRegistersCHS errorRegisters,
|
||||
AtaProtocol protocol, AtaTransferRegister transferRegister,
|
||||
ref byte[] buffer, uint timeout, bool transferBlocks, out double duration,
|
||||
out bool sense)
|
||||
{
|
||||
duration = 0;
|
||||
sense = false;
|
||||
errorRegisters = new AtaErrorRegistersCHS();
|
||||
|
||||
if(buffer == null)
|
||||
return -1;
|
||||
if(buffer == null) return -1;
|
||||
|
||||
byte[] cdb = new byte[16];
|
||||
cdb[0] = (byte)ScsiCommands.AtaPassThrough16;
|
||||
cdb[1] = (byte)(((byte)protocol << 1) & 0x1E);
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer &&
|
||||
protocol != AtaProtocol.NonData)
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer && protocol != AtaProtocol.NonData)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -154,8 +145,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
break;
|
||||
}
|
||||
|
||||
if(transferBlocks)
|
||||
cdb[2] |= 0x04;
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
|
||||
cdb[2] |= (byte)((int)transferRegister & 0x03);
|
||||
}
|
||||
@@ -171,10 +161,10 @@ namespace DiscImageChef.Devices.Linux
|
||||
cdb[14] = registers.command;
|
||||
|
||||
byte[] senseBuffer;
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout, AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout,
|
||||
AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
|
||||
if(senseBuffer.Length < 22 || (senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C))
|
||||
return error;
|
||||
if(senseBuffer.Length < 22 || (senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C)) return error;
|
||||
|
||||
errorRegisters.error = senseBuffer[11];
|
||||
|
||||
@@ -191,22 +181,20 @@ namespace DiscImageChef.Devices.Linux
|
||||
}
|
||||
|
||||
internal static int SendAtaCommand(int fd, AtaRegistersLBA28 registers,
|
||||
out AtaErrorRegistersLBA28 errorRegisters, AtaProtocol protocol,
|
||||
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
||||
bool transferBlocks, out double duration, out bool sense)
|
||||
out AtaErrorRegistersLBA28 errorRegisters, AtaProtocol protocol,
|
||||
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
||||
bool transferBlocks, out double duration, out bool sense)
|
||||
{
|
||||
duration = 0;
|
||||
sense = false;
|
||||
errorRegisters = new AtaErrorRegistersLBA28();
|
||||
|
||||
if(buffer == null)
|
||||
return -1;
|
||||
if(buffer == null) return -1;
|
||||
|
||||
byte[] cdb = new byte[16];
|
||||
cdb[0] = (byte)ScsiCommands.AtaPassThrough16;
|
||||
cdb[1] = (byte)(((byte)protocol << 1) & 0x1E);
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer &&
|
||||
protocol != AtaProtocol.NonData)
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer && protocol != AtaProtocol.NonData)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -219,8 +207,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
break;
|
||||
}
|
||||
|
||||
if(transferBlocks)
|
||||
cdb[2] |= 0x04;
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
|
||||
cdb[2] |= (byte)((int)transferRegister & 0x03);
|
||||
}
|
||||
@@ -236,10 +223,10 @@ namespace DiscImageChef.Devices.Linux
|
||||
cdb[14] = registers.command;
|
||||
|
||||
byte[] senseBuffer;
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout, AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout,
|
||||
AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
|
||||
if(senseBuffer.Length < 22 || (senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C))
|
||||
return error;
|
||||
if(senseBuffer.Length < 22 || (senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C)) return error;
|
||||
|
||||
errorRegisters.error = senseBuffer[11];
|
||||
|
||||
@@ -256,23 +243,21 @@ namespace DiscImageChef.Devices.Linux
|
||||
}
|
||||
|
||||
internal static int SendAtaCommand(int fd, AtaRegistersLBA48 registers,
|
||||
out AtaErrorRegistersLBA48 errorRegisters, AtaProtocol protocol,
|
||||
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
||||
bool transferBlocks, out double duration, out bool sense)
|
||||
out AtaErrorRegistersLBA48 errorRegisters, AtaProtocol protocol,
|
||||
AtaTransferRegister transferRegister, ref byte[] buffer, uint timeout,
|
||||
bool transferBlocks, out double duration, out bool sense)
|
||||
{
|
||||
duration = 0;
|
||||
sense = false;
|
||||
errorRegisters = new AtaErrorRegistersLBA48();
|
||||
|
||||
if(buffer == null)
|
||||
return -1;
|
||||
if(buffer == null) return -1;
|
||||
|
||||
byte[] cdb = new byte[16];
|
||||
cdb[0] = (byte)ScsiCommands.AtaPassThrough16;
|
||||
cdb[1] = (byte)(((byte)protocol << 1) & 0x1E);
|
||||
cdb[1] |= 0x01;
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer &&
|
||||
protocol != AtaProtocol.NonData)
|
||||
if(transferRegister != AtaTransferRegister.NoTransfer && protocol != AtaProtocol.NonData)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -285,8 +270,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
break;
|
||||
}
|
||||
|
||||
if(transferBlocks)
|
||||
cdb[2] |= 0x04;
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
|
||||
cdb[2] |= (byte)((int)transferRegister & 0x03);
|
||||
}
|
||||
@@ -307,10 +291,10 @@ namespace DiscImageChef.Devices.Linux
|
||||
cdb[14] = registers.command;
|
||||
|
||||
byte[] senseBuffer;
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout, AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
int error = SendScsiCommand(fd, cdb, ref buffer, out senseBuffer, timeout,
|
||||
AtaProtocolToScsiDirection(protocol), out duration, out sense);
|
||||
|
||||
if(senseBuffer.Length < 22 || (senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C))
|
||||
return error;
|
||||
if(senseBuffer.Length < 22 || (senseBuffer[8] != 0x09 && senseBuffer[9] != 0x0C)) return error;
|
||||
|
||||
errorRegisters.error = senseBuffer[11];
|
||||
|
||||
@@ -345,14 +329,15 @@ namespace DiscImageChef.Devices.Linux
|
||||
/// <param name="argument">Command argument</param>
|
||||
/// <param name="response">Response registers</param>
|
||||
/// <param name="blockSize">Size of block in bytes</param>
|
||||
internal static int SendMmcCommand(int fd, MmcCommands command, bool write, bool isApplication, MmcFlags flags, uint argument, uint blockSize, uint blocks, ref byte[] buffer, out uint[] response, out double duration, out bool sense, uint timeout = 0)
|
||||
internal static int SendMmcCommand(int fd, MmcCommands command, bool write, bool isApplication, MmcFlags flags,
|
||||
uint argument, uint blockSize, uint blocks, ref byte[] buffer,
|
||||
out uint[] response, out double duration, out bool sense, uint timeout = 0)
|
||||
{
|
||||
response = null;
|
||||
duration = 0;
|
||||
sense = false;
|
||||
|
||||
if(buffer == null)
|
||||
return -1;
|
||||
if(buffer == null) return -1;
|
||||
|
||||
mmc_ioc_cmd io_cmd = new mmc_ioc_cmd();
|
||||
|
||||
@@ -380,8 +365,7 @@ namespace DiscImageChef.Devices.Linux
|
||||
|
||||
sense |= error < 0;
|
||||
|
||||
if(error < 0)
|
||||
error = Marshal.GetLastWin32Error();
|
||||
if(error < 0) error = Marshal.GetLastWin32Error();
|
||||
|
||||
Marshal.Copy(bufPtr, buffer, 0, buffer.Length);
|
||||
|
||||
@@ -401,16 +385,14 @@ namespace DiscImageChef.Devices.Linux
|
||||
if(Interop.DetectOS.Is64Bit())
|
||||
{
|
||||
long result64 = Extern.readlink64(path, buf, 4096);
|
||||
if(result64 <= 0)
|
||||
return null;
|
||||
if(result64 <= 0) return null;
|
||||
|
||||
resultSize = (int)result64;
|
||||
}
|
||||
else
|
||||
{
|
||||
int result = Extern.readlink(path, buf, 4096);
|
||||
if(result <= 0)
|
||||
return null;
|
||||
if(result <= 0) return null;
|
||||
|
||||
resultSize = result;
|
||||
}
|
||||
@@ -421,5 +403,4 @@ namespace DiscImageChef.Devices.Linux
|
||||
return System.Text.Encoding.ASCII.GetString(resultString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user