Files
Aaru/DiscImageChef.Tests.Devices/ATA/AtaCHS.cs

925 lines
41 KiB
C#
Raw Normal View History

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : AtaCHS.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : DiscImageChef device testing.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using DiscImageChef.Console;
2017-09-08 16:34:57 +01:00
using DiscImageChef.Decoders.ATA;
using DiscImageChef.Devices;
namespace DiscImageChef.Tests.Devices.ATA
{
public static class AtaCHS
{
public static void Menu(string devPath, Device dev)
{
while(true)
{
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Send a CHS ATA command to the device:");
DicConsole.WriteLine("1.- Send IDENTIFY DEVICE command.");
DicConsole.WriteLine("2.- Send READ DMA command.");
DicConsole.WriteLine("3.- Send READ DMA WITH RETRIES command.");
DicConsole.WriteLine("4.- Send READ LONG command.");
DicConsole.WriteLine("5.- Send READ LONG WITH RETRIES command.");
DicConsole.WriteLine("6.- Send READ MULTIPLE command.");
DicConsole.WriteLine("7.- Send READ SECTORS command.");
DicConsole.WriteLine("8.- Send READ SECTORS WITH RETRIES command.");
DicConsole.WriteLine("9.- Send SEEK command.");
DicConsole.WriteLine("0.- Return to ATA commands menu.");
DicConsole.Write("Choose: ");
string strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out int item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
continue;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to ATA commands menu...");
return;
2017-09-08 16:34:57 +01:00
case 1:
Identify(devPath, dev);
continue;
case 2:
ReadDma(devPath, dev, false);
continue;
case 3:
ReadDma(devPath, dev, true);
continue;
case 4:
ReadLong(devPath, dev, false);
continue;
case 5:
ReadLong(devPath, dev, true);
continue;
case 6:
ReadMultiple(devPath, dev);
continue;
case 7:
ReadSectors(devPath, dev, false);
continue;
case 8:
ReadSectors(devPath, dev, true);
continue;
case 9:
Seek(devPath, dev);
continue;
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
continue;
}
}
}
2017-09-08 16:34:57 +01:00
2017-09-08 18:21:52 +01:00
static void Identify(string devPath, Device dev)
2017-09-08 16:34:57 +01:00
{
2017-12-19 20:33:03 +00:00
start:
2017-09-08 16:34:57 +01:00
System.Console.Clear();
2017-12-19 20:33:03 +00:00
bool sense = dev.AtaIdentify(out byte[] buffer, out AtaErrorRegistersCHS errorRegisters,
out double duration);
2017-09-08 16:34:57 +01:00
2017-12-19 20:33:03 +00:00
menu:
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Sending IDENTIFY DEVICE to the device:");
DicConsole.WriteLine("Command took {0} ms.", duration);
DicConsole.WriteLine("Sense is {0}.", sense);
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Print buffer.");
DicConsole.WriteLine("2.- Decode buffer.");
DicConsole.WriteLine("3.- Decode error registers.");
DicConsole.WriteLine("4.- Send command again.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
DicConsole.Write("Choose: ");
string strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out int item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("IDENTIFY DEVICE response:");
2017-12-19 20:33:03 +00:00
if(buffer != null) PrintHex.PrintHexArray(buffer, 64);
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
case 2:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("IDENTIFY DEVICE decoded response:");
2017-12-19 20:33:03 +00:00
if(buffer != null) DicConsole.WriteLine("{0}", Decoders.ATA.Identify.Prettify(buffer));
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
case 3:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("IDENTIFY DEVICE status registers:");
DicConsole.Write("{0}", MainClass.DecodeATARegisters(errorRegisters));
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
2017-12-19 20:33:03 +00:00
case 4: goto start;
2017-09-08 16:34:57 +01:00
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
}
2017-09-08 18:21:52 +01:00
static void ReadDma(string devPath, Device dev, bool retries)
2017-09-08 16:34:57 +01:00
{
ushort cylinder = 0;
byte head = 0;
byte sector = 1;
byte count = 1;
string strDev;
int item;
2017-12-19 20:33:03 +00:00
parameters:
2017-09-08 16:34:57 +01:00
while(true)
{
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Parameters for READ DMA {0}command:", retries ? "WITH RETRIES " : "");
DicConsole.WriteLine("Cylinder: {0}", cylinder);
DicConsole.WriteLine("Head: {0}", head);
DicConsole.WriteLine("Sector: {0}", sector);
DicConsole.WriteLine("Count: {0}", count);
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Change parameters.");
DicConsole.WriteLine("2.- Send command with these parameters.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
continue;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
DicConsole.Write("What cylinder?: ");
strDev = System.Console.ReadLine();
if(!ushort.TryParse(strDev, out cylinder))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
cylinder = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("What head?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out head))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
head = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
if(head > 15)
{
DicConsole.WriteLine("Head cannot be bigger than 15. Setting it to 15...");
head = 15;
}
DicConsole.Write("What sector?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out sector))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
sector = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("How many sectors?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out count))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
count = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
break;
2017-12-19 20:33:03 +00:00
case 2: goto start;
2017-09-08 16:34:57 +01:00
}
}
2017-12-19 20:33:03 +00:00
start:
2017-09-08 16:34:57 +01:00
System.Console.Clear();
2017-12-19 20:33:03 +00:00
bool sense = dev.ReadDma(out byte[] buffer, out AtaErrorRegistersCHS errorRegisters, retries, cylinder,
head, sector, count, dev.Timeout, out double duration);
2017-09-08 16:34:57 +01:00
2017-12-19 20:33:03 +00:00
menu:
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Sending READ DMA {0}to the device:", retries ? "WITH RETRIES " : "");
DicConsole.WriteLine("Command took {0} ms.", duration);
DicConsole.WriteLine("Sense is {0}.", sense);
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Print buffer.");
DicConsole.WriteLine("2.- Decode error registers.");
DicConsole.WriteLine("3.- Send command again.");
DicConsole.WriteLine("4.- Change parameters.");
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
DicConsole.Write("Choose: ");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ DMA {0}response:", retries ? "WITH RETRIES " : "");
2017-12-19 20:33:03 +00:00
if(buffer != null) PrintHex.PrintHexArray(buffer, 64);
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
case 2:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ DMA {0}status registers:", retries ? "WITH RETRIES " : "");
DicConsole.Write("{0}", MainClass.DecodeATARegisters(errorRegisters));
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
2017-12-19 20:33:03 +00:00
case 3: goto start;
case 4: goto parameters;
2017-09-08 16:34:57 +01:00
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
}
2017-09-08 18:21:52 +01:00
static void ReadLong(string devPath, Device dev, bool retries)
2017-09-08 16:34:57 +01:00
{
ushort cylinder = 0;
byte head = 0;
byte sector = 1;
uint blockSize = 1;
string strDev;
int item;
2017-12-19 20:33:03 +00:00
parameters:
2017-09-08 16:34:57 +01:00
while(true)
{
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Parameters for READ LONG {0}command:", retries ? "WITH RETRIES " : "");
DicConsole.WriteLine("Cylinder: {0}", cylinder);
DicConsole.WriteLine("Head: {0}", head);
DicConsole.WriteLine("Sector: {0}", sector);
DicConsole.WriteLine("Block size: {0}", blockSize);
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Change parameters.");
DicConsole.WriteLine("2.- Send command with these parameters.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
continue;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
DicConsole.Write("What cylinder?: ");
strDev = System.Console.ReadLine();
if(!ushort.TryParse(strDev, out cylinder))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
cylinder = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("What head?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out head))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
head = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
if(head > 15)
{
DicConsole.WriteLine("Head cannot be bigger than 15. Setting it to 15...");
head = 15;
}
DicConsole.Write("What sector?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out sector))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
sector = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("How many bytes to expect?: ");
strDev = System.Console.ReadLine();
if(!uint.TryParse(strDev, out blockSize))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
blockSize = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
break;
2017-12-19 20:33:03 +00:00
case 2: goto start;
2017-09-08 16:34:57 +01:00
}
}
2017-12-19 20:33:03 +00:00
start:
2017-09-08 16:34:57 +01:00
System.Console.Clear();
2017-12-19 20:33:03 +00:00
bool sense = dev.ReadLong(out byte[] buffer, out AtaErrorRegistersCHS errorRegisters, retries, cylinder,
head, sector, blockSize, dev.Timeout, out double duration);
2017-09-08 16:34:57 +01:00
2017-12-19 20:33:03 +00:00
menu:
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Sending READ LONG {0}to the device:", retries ? "WITH RETRIES " : "");
DicConsole.WriteLine("Command took {0} ms.", duration);
DicConsole.WriteLine("Sense is {0}.", sense);
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Print buffer.");
DicConsole.WriteLine("2.- Decode error registers.");
DicConsole.WriteLine("3.- Send command again.");
DicConsole.WriteLine("4.- Change parameters.");
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
DicConsole.Write("Choose: ");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ LONG {0}response:", retries ? "WITH RETRIES " : "");
2017-12-19 20:33:03 +00:00
if(buffer != null) PrintHex.PrintHexArray(buffer, 64);
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
case 2:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ LONG {0}status registers:", retries ? "WITH RETRIES " : "");
DicConsole.Write("{0}", MainClass.DecodeATARegisters(errorRegisters));
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
2017-12-19 20:33:03 +00:00
case 3: goto start;
case 4: goto parameters;
2017-09-08 16:34:57 +01:00
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
}
2017-09-08 18:21:52 +01:00
static void ReadMultiple(string devPath, Device dev)
2017-09-08 16:34:57 +01:00
{
ushort cylinder = 0;
byte head = 0;
byte sector = 1;
byte count = 1;
string strDev;
int item;
2017-12-19 20:33:03 +00:00
parameters:
2017-09-08 16:34:57 +01:00
while(true)
{
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Parameters for READ MULTIPLE command:");
DicConsole.WriteLine("Cylinder: {0}", cylinder);
DicConsole.WriteLine("Head: {0}", head);
DicConsole.WriteLine("Sector: {0}", sector);
DicConsole.WriteLine("Count: {0}", count);
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Change parameters.");
DicConsole.WriteLine("2.- Send command with these parameters.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
continue;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
DicConsole.Write("What cylinder?: ");
strDev = System.Console.ReadLine();
if(!ushort.TryParse(strDev, out cylinder))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
cylinder = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("What head?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out head))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
head = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
if(head > 15)
{
DicConsole.WriteLine("Head cannot be bigger than 15. Setting it to 15...");
head = 15;
}
DicConsole.Write("What sector?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out sector))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
sector = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("How many sectors?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out count))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
count = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
break;
2017-12-19 20:33:03 +00:00
case 2: goto start;
2017-09-08 16:34:57 +01:00
}
}
2017-12-19 20:33:03 +00:00
start:
2017-09-08 16:34:57 +01:00
System.Console.Clear();
2017-12-19 20:33:03 +00:00
bool sense = dev.ReadMultiple(out byte[] buffer, out AtaErrorRegistersCHS errorRegisters, cylinder, head,
sector, count, dev.Timeout, out double duration);
2017-09-08 16:34:57 +01:00
2017-12-19 20:33:03 +00:00
menu:
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Sending READ MULTIPLE to the device:");
DicConsole.WriteLine("Command took {0} ms.", duration);
DicConsole.WriteLine("Sense is {0}.", sense);
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Print buffer.");
DicConsole.WriteLine("2.- Decode error registers.");
DicConsole.WriteLine("3.- Send command again.");
DicConsole.WriteLine("4.- Change parameters.");
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
DicConsole.Write("Choose: ");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ MULTIPLE response:");
2017-12-19 20:33:03 +00:00
if(buffer != null) PrintHex.PrintHexArray(buffer, 64);
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
case 2:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ MULTIPLE status registers:");
DicConsole.Write("{0}", MainClass.DecodeATARegisters(errorRegisters));
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
2017-12-19 20:33:03 +00:00
case 3: goto start;
case 4: goto parameters;
2017-09-08 16:34:57 +01:00
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
}
2017-09-08 18:21:52 +01:00
static void ReadSectors(string devPath, Device dev, bool retries)
2017-09-08 16:34:57 +01:00
{
ushort cylinder = 0;
byte head = 0;
byte sector = 1;
byte count = 1;
string strDev;
int item;
2017-12-19 20:33:03 +00:00
parameters:
2017-09-08 16:34:57 +01:00
while(true)
{
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Parameters for READ SECTORS {0}command:", retries ? "WITH RETRIES " : "");
DicConsole.WriteLine("Cylinder: {0}", cylinder);
DicConsole.WriteLine("Head: {0}", head);
DicConsole.WriteLine("Sector: {0}", sector);
DicConsole.WriteLine("Count: {0}", count);
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Change parameters.");
DicConsole.WriteLine("2.- Send command with these parameters.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
continue;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
DicConsole.Write("What cylinder?: ");
strDev = System.Console.ReadLine();
if(!ushort.TryParse(strDev, out cylinder))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
cylinder = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("What head?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out head))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
head = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
if(head > 15)
{
DicConsole.WriteLine("Head cannot be bigger than 15. Setting it to 15...");
head = 15;
}
DicConsole.Write("What sector?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out sector))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
sector = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("How many sectors?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out count))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
count = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
break;
2017-12-19 20:33:03 +00:00
case 2: goto start;
2017-09-08 16:34:57 +01:00
}
}
2017-12-19 20:33:03 +00:00
start:
2017-09-08 16:34:57 +01:00
System.Console.Clear();
2017-12-19 20:33:03 +00:00
bool sense = dev.Read(out byte[] buffer, out AtaErrorRegistersCHS errorRegisters, retries, cylinder, head,
sector, count, dev.Timeout, out double duration);
2017-09-08 16:34:57 +01:00
2017-12-19 20:33:03 +00:00
menu:
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Sending READ SECTORS {0}to the device:", retries ? "WITH RETRIES " : "");
DicConsole.WriteLine("Command took {0} ms.", duration);
DicConsole.WriteLine("Sense is {0}.", sense);
DicConsole.WriteLine("Buffer is {0} bytes.", buffer == null ? "null" : buffer.Length.ToString());
DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer));
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Print buffer.");
DicConsole.WriteLine("2.- Decode error registers.");
DicConsole.WriteLine("3.- Send command again.");
DicConsole.WriteLine("4.- Change parameters.");
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
DicConsole.Write("Choose: ");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ SECTORS {0}response:", retries ? "WITH RETRIES " : "");
2017-12-19 20:33:03 +00:00
if(buffer != null) PrintHex.PrintHexArray(buffer, 64);
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
case 2:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("READ SECTORS {0}status registers:", retries ? "WITH RETRIES " : "");
DicConsole.Write("{0}", MainClass.DecodeATARegisters(errorRegisters));
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
2017-12-19 20:33:03 +00:00
case 3: goto start;
case 4: goto parameters;
2017-09-08 16:34:57 +01:00
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
}
2017-09-08 18:21:52 +01:00
static void Seek(string devPath, Device dev)
2017-09-08 16:34:57 +01:00
{
ushort cylinder = 0;
byte head = 0;
byte sector = 1;
string strDev;
int item;
2017-12-19 20:33:03 +00:00
parameters:
2017-09-08 16:34:57 +01:00
while(true)
{
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Parameters for SEEK command:");
DicConsole.WriteLine("Cylinder: {0}", cylinder);
DicConsole.WriteLine("Head: {0}", head);
DicConsole.WriteLine("Sector: {0}", sector);
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Change parameters.");
DicConsole.WriteLine("2.- Send command with these parameters.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
continue;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
DicConsole.Write("What cylinder?: ");
strDev = System.Console.ReadLine();
if(!ushort.TryParse(strDev, out cylinder))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
cylinder = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
DicConsole.Write("What head?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out head))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
head = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
if(head > 15)
{
DicConsole.WriteLine("Head cannot be bigger than 15. Setting it to 15...");
head = 15;
}
DicConsole.Write("What sector?: ");
strDev = System.Console.ReadLine();
if(!byte.TryParse(strDev, out sector))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
sector = 0;
System.Console.ReadKey();
continue;
}
2017-12-19 20:33:03 +00:00
2017-09-08 16:34:57 +01:00
break;
2017-12-19 20:33:03 +00:00
case 2: goto start;
2017-09-08 16:34:57 +01:00
}
}
2017-12-19 20:33:03 +00:00
start:
2017-09-08 16:34:57 +01:00
System.Console.Clear();
2017-12-19 20:33:03 +00:00
bool sense = dev.Seek(out AtaErrorRegistersCHS errorRegisters, cylinder, head, sector, dev.Timeout,
out double duration);
2017-09-08 16:34:57 +01:00
2017-12-19 20:33:03 +00:00
menu:
2017-09-08 16:34:57 +01:00
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("Sending SEEK to the device:");
DicConsole.WriteLine("Command took {0} ms.", duration);
DicConsole.WriteLine("Sense is {0}.", sense);
DicConsole.WriteLine();
DicConsole.WriteLine("Choose what to do:");
DicConsole.WriteLine("1.- Decode error registers.");
DicConsole.WriteLine("2.- Send command again.");
DicConsole.WriteLine("3.- Change parameters.");
DicConsole.WriteLine("0.- Return to CHS ATA commands menu.");
DicConsole.Write("Choose: ");
strDev = System.Console.ReadLine();
if(!int.TryParse(strDev, out item))
{
DicConsole.WriteLine("Not a number. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
switch(item)
{
case 0:
DicConsole.WriteLine("Returning to CHS ATA commands menu...");
return;
case 1:
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
DicConsole.WriteLine("SEEK status registers:");
DicConsole.Write("{0}", MainClass.DecodeATARegisters(errorRegisters));
DicConsole.WriteLine("Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
DicConsole.WriteLine("Device: {0}", devPath);
goto menu;
2017-12-19 20:33:03 +00:00
case 2: goto start;
case 3: goto parameters;
2017-09-08 16:34:57 +01:00
default:
DicConsole.WriteLine("Incorrect option. Press any key to continue...");
System.Console.ReadKey();
System.Console.Clear();
goto menu;
}
}
}
2017-12-19 20:33:03 +00:00
}