diff --git a/Aaru.Server.Task/Program.cs b/Aaru.Server.Task/Program.cs index b97af50a..333f7029 100644 --- a/Aaru.Server.Task/Program.cs +++ b/Aaru.Server.Task/Program.cs @@ -40,122 +40,76 @@ using Aaru.Server.Models; using HtmlAgilityPack; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Task -{ - internal class Program - { - public static void Main(string[] args) - { - DateTime start, end; +namespace Aaru.Server.Task; - start = DateTime.UtcNow; - System.Console.WriteLine("{0}: Connecting to database...", DateTime.UtcNow); - var ctx = new AaruServerContext(); +internal class Program +{ + public static void Main(string[] args) + { + DateTime start, end; + + start = DateTime.UtcNow; + System.Console.WriteLine("{0}: Connecting to database...", DateTime.UtcNow); + var ctx = new AaruServerContext(); + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + System.Console.WriteLine("{0}: Migrating database to latest version...", DateTime.UtcNow); + start = DateTime.UtcNow; + ctx.Database.Migrate(); + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", DateTime.UtcNow, (end - start).TotalSeconds); + + WebClient client; + + try + { + System.Console.WriteLine("{0}: Retrieving USB IDs from Linux USB...", DateTime.UtcNow); + start = DateTime.UtcNow; + client = new WebClient(); + var sr = new StringReader(client.DownloadString("http://www.linux-usb.org/usb.ids")); end = DateTime.UtcNow; System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - System.Console.WriteLine("{0}: Migrating database to latest version...", DateTime.UtcNow); + UsbVendor vendor = null; + int newVendors = 0; + int newProducts = 0; + int modifiedVendors = 0; + int modifiedProducts = 0; + int counter = 0; + start = DateTime.UtcNow; - ctx.Database.Migrate(); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", DateTime.UtcNow, (end - start).TotalSeconds); + System.Console.WriteLine("{0}: Adding and updating database entries...", DateTime.UtcNow); - WebClient client; - - try + do { - System.Console.WriteLine("{0}: Retrieving USB IDs from Linux USB...", DateTime.UtcNow); - start = DateTime.UtcNow; - client = new WebClient(); - var sr = new StringReader(client.DownloadString("http://www.linux-usb.org/usb.ids")); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - - UsbVendor vendor = null; - int newVendors = 0; - int newProducts = 0; - int modifiedVendors = 0; - int modifiedProducts = 0; - int counter = 0; - - start = DateTime.UtcNow; - System.Console.WriteLine("{0}: Adding and updating database entries...", DateTime.UtcNow); - - do + if(counter == 1000) { - if(counter == 1000) - { - DateTime start2 = DateTime.UtcNow; - System.Console.WriteLine("{0}: Saving changes", start2); - ctx.SaveChanges(); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start2).TotalSeconds); - counter = 0; - } + DateTime start2 = DateTime.UtcNow; + System.Console.WriteLine("{0}: Saving changes", start2); + ctx.SaveChanges(); + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start2).TotalSeconds); + counter = 0; + } - string line = sr.ReadLine(); + string line = sr.ReadLine(); - if(line is null) - break; + if(line is null) + break; - if(line.Length == 0 || - line[0] == '#') - continue; + if(line.Length == 0 || + line[0] == '#') + continue; - ushort number; - string name; - - if(line[0] == '\t') - { - try - { - number = Convert.ToUInt16(line.Substring(1, 4), 16); - } - catch(FormatException) - { - continue; - } - - if(number == 0) - continue; - - name = line.Substring(7); - - UsbProduct product = - ctx.UsbProducts.FirstOrDefault(p => p.ProductId == number && p.Vendor != null && - p.Vendor.VendorId == vendor.VendorId); - - if(product is null) - { - product = new UsbProduct(vendor, number, name); - ctx.UsbProducts.Add(product); - - System.Console.WriteLine("{0}: Will add product {1} with ID {2:X4} and vendor {3} ({4:X4})", - DateTime.UtcNow, product.Product, product.ProductId, - product.Vendor?.Vendor ?? "null", product.Vendor?.VendorId ?? 0); - - newProducts++; - counter++; - } - else if(name != product.Product) - { - System.Console. - WriteLine("{0}: Will modify product with ID {1:X4} and vendor {2} ({3:X4}) from \"{4}\" to \"{5}\"", - DateTime.UtcNow, product.ProductId, product.Vendor?.Vendor ?? "null", - product.Vendor?.VendorId ?? 0, product.Product, name); - - product.Product = name; - product.ModifiedWhen = DateTime.UtcNow; - modifiedProducts++; - counter++; - } - - continue; - } + ushort number; + string name; + if(line[0] == '\t') + { try { - number = Convert.ToUInt16(line.Substring(0, 4), 16); + number = Convert.ToUInt16(line.Substring(1, 4), 16); } catch(FormatException) { @@ -165,378 +119,423 @@ namespace Aaru.Server.Task if(number == 0) continue; - name = line.Substring(6); + name = line.Substring(7); - vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == number); + UsbProduct product = + ctx.UsbProducts.FirstOrDefault(p => p.ProductId == number && p.Vendor != null && + p.Vendor.VendorId == vendor.VendorId); - if(vendor is null) + if(product is null) { - vendor = new UsbVendor(number, name); - ctx.UsbVendors.Add(vendor); + product = new UsbProduct(vendor, number, name); + ctx.UsbProducts.Add(product); - System.Console.WriteLine("{0}: Will add vendor {1} with ID {2:X4}", DateTime.UtcNow, - vendor.Vendor, vendor.VendorId); + System.Console.WriteLine("{0}: Will add product {1} with ID {2:X4} and vendor {3} ({4:X4})", + DateTime.UtcNow, product.Product, product.ProductId, + product.Vendor?.Vendor ?? "null", product.Vendor?.VendorId ?? 0); - newVendors++; + newProducts++; counter++; } - else if(name != vendor.Vendor) + else if(name != product.Product) { - System.Console.WriteLine("{0}: Will modify vendor with ID {1:X4} from \"{2}\" to \"{3}\"", - DateTime.UtcNow, vendor.VendorId, vendor.Vendor, name); + System.Console. + WriteLine("{0}: Will modify product with ID {1:X4} and vendor {2} ({3:X4}) from \"{4}\" to \"{5}\"", + DateTime.UtcNow, product.ProductId, product.Vendor?.Vendor ?? "null", + product.Vendor?.VendorId ?? 0, product.Product, name); - vendor.Vendor = name; - vendor.ModifiedWhen = DateTime.UtcNow; - modifiedVendors++; + product.Product = name; + product.ModifiedWhen = DateTime.UtcNow; + modifiedProducts++; counter++; } - } while(true); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + continue; + } - System.Console.WriteLine("{0}: Saving database changes...", DateTime.UtcNow); - start = DateTime.UtcNow; - ctx.SaveChanges(); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + try + { + number = Convert.ToUInt16(line.Substring(0, 4), 16); + } + catch(FormatException) + { + continue; + } - System.Console.WriteLine("{0}: {1} vendors added.", DateTime.UtcNow, newVendors); - System.Console.WriteLine("{0}: {1} products added.", DateTime.UtcNow, newProducts); - System.Console.WriteLine("{0}: {1} vendors modified.", DateTime.UtcNow, modifiedVendors); - System.Console.WriteLine("{0}: {1} products modified.", DateTime.UtcNow, modifiedProducts); + if(number == 0) + continue; - System.Console.WriteLine("{0}: Looking up a vendor", DateTime.UtcNow); - start = DateTime.UtcNow; - vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == 0x8086); + name = line.Substring(6); + + vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == number); if(vendor is null) - System.Console.WriteLine("{0}: Error, could not find vendor.", DateTime.UtcNow); - else - System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, vendor.Vendor); + { + vendor = new UsbVendor(number, name); + ctx.UsbVendors.Add(vendor); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + System.Console.WriteLine("{0}: Will add vendor {1} with ID {2:X4}", DateTime.UtcNow, + vendor.Vendor, vendor.VendorId); - System.Console.WriteLine("{0}: Looking up a product", DateTime.UtcNow); - start = DateTime.UtcNow; + newVendors++; + counter++; + } + else if(name != vendor.Vendor) + { + System.Console.WriteLine("{0}: Will modify vendor with ID {1:X4} from \"{2}\" to \"{3}\"", + DateTime.UtcNow, vendor.VendorId, vendor.Vendor, name); - UsbProduct prd = - ctx.UsbProducts.FirstOrDefault(p => p.ProductId == 0x0001 && p.Vendor.VendorId == 0x8086); - - if(prd is null) - System.Console.WriteLine("{0}: Error, could not find product.", DateTime.UtcNow); - else - System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, prd.Product); - - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - } - catch(Exception ex) - { - #if DEBUG - if(Debugger.IsAttached) - throw; - #endif - System.Console.WriteLine("{0}: Exception {1} filling USB IDs...", DateTime.UtcNow, ex); - } - - System.Console.WriteLine("{0}: Fixing all devices without modification time...", DateTime.UtcNow); - start = DateTime.UtcNow; - - foreach(Device device in ctx.Devices.Where(d => d.ModifiedWhen == null)) - device.ModifiedWhen = device.AddedWhen; + vendor.Vendor = name; + vendor.ModifiedWhen = DateTime.UtcNow; + modifiedVendors++; + counter++; + } + } while(true); end = DateTime.UtcNow; System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + System.Console.WriteLine("{0}: Saving database changes...", DateTime.UtcNow); + start = DateTime.UtcNow; + ctx.SaveChanges(); + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + System.Console.WriteLine("{0}: {1} vendors added.", DateTime.UtcNow, newVendors); + System.Console.WriteLine("{0}: {1} products added.", DateTime.UtcNow, newProducts); + System.Console.WriteLine("{0}: {1} vendors modified.", DateTime.UtcNow, modifiedVendors); + System.Console.WriteLine("{0}: {1} products modified.", DateTime.UtcNow, modifiedProducts); + + System.Console.WriteLine("{0}: Looking up a vendor", DateTime.UtcNow); + start = DateTime.UtcNow; + vendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == 0x8086); + + if(vendor is null) + System.Console.WriteLine("{0}: Error, could not find vendor.", DateTime.UtcNow); + else + System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, vendor.Vendor); + + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + System.Console.WriteLine("{0}: Looking up a product", DateTime.UtcNow); + start = DateTime.UtcNow; + + UsbProduct prd = + ctx.UsbProducts.FirstOrDefault(p => p.ProductId == 0x0001 && p.Vendor.VendorId == 0x8086); + + if(prd is null) + System.Console.WriteLine("{0}: Error, could not find product.", DateTime.UtcNow); + else + System.Console.WriteLine("{0}: Found {1}.", DateTime.UtcNow, prd.Product); + + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + } + catch(Exception ex) + { + #if DEBUG + if(Debugger.IsAttached) + throw; + #endif + System.Console.WriteLine("{0}: Exception {1} filling USB IDs...", DateTime.UtcNow, ex); + } + + System.Console.WriteLine("{0}: Fixing all devices without modification time...", DateTime.UtcNow); + start = DateTime.UtcNow; + + foreach(Device device in ctx.Devices.Where(d => d.ModifiedWhen == null)) + device.ModifiedWhen = device.AddedWhen; + + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + System.Console.WriteLine("{0}: Committing changes...", DateTime.UtcNow); + start = DateTime.UtcNow; + ctx.SaveChanges(); + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + try + { + System.Console.WriteLine("{0}: Retrieving CompactDisc read offsets from AccurateRip...", + DateTime.UtcNow); + + start = DateTime.UtcNow; + + client = new WebClient(); + string html = client.DownloadString("http://www.accuraterip.com/driveoffsets.htm"); + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + // The HTML is too malformed to process easily, so find start of table + html = "" + + html.Substring(html.IndexOf("
", StringComparison.Ordinal)); + + var doc = new HtmlDocument(); + doc.LoadHtml(html); + HtmlNode firstTable = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[1]"); + + bool firstRow = true; + + int addedOffsets = 0; + int modifiedOffsets = 0; + + System.Console.WriteLine("{0}: Processing offsets...", DateTime.UtcNow); + start = DateTime.UtcNow; + + foreach(HtmlNode row in firstTable.Descendants("tr")) + { + HtmlNode[] columns = row.Descendants("td").ToArray(); + + if(columns.Length != 4) + { + System.Console.WriteLine("{0}: Row does not have correct number of columns...", + DateTime.UtcNow); + + continue; + } + + string column0 = columns[0].InnerText; + string column1 = columns[1].InnerText; + string column2 = columns[2].InnerText; + string column3 = columns[3].InnerText; + + if(firstRow) + { + if(column0.ToLowerInvariant() != "cd drive") + { + System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, + columns[0].InnerText); + + break; + } + + if(column1.ToLowerInvariant() != "correction offset") + { + System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, + columns[1].InnerText); + + break; + } + + if(column2.ToLowerInvariant() != "submitted by") + { + System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, + columns[2].InnerText); + + break; + } + + if(column3.ToLowerInvariant() != "percentage agree") + { + System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, + columns[3].InnerText); + + break; + } + + firstRow = false; + + continue; + } + + string manufacturer; + string model; + + if(column0[0] == '-' && + column0[1] == ' ') + { + manufacturer = null; + model = column0.Substring(2).Trim(); + } + else + { + int cutOffset = column0.IndexOf(" - ", StringComparison.Ordinal); + + if(cutOffset == -1) + { + manufacturer = null; + model = column0; + } + else + { + manufacturer = column0.Substring(0, cutOffset).Trim(); + model = column0.Substring(cutOffset + 3).Trim(); + } + } + + switch(manufacturer) + { + case "Lite-ON": + manufacturer = "JLMS"; + + break; + case "LG Electronics": + manufacturer = "HL-DT-ST"; + + break; + case "Panasonic": + manufacturer = "MATSHITA"; + + break; + } + + CompactDiscOffset cdOffset = + ctx.CdOffsets.FirstOrDefault(o => o.Manufacturer == manufacturer && o.Model == model); + + if(column1.ToLowerInvariant() == "[purged]") + { + if(cdOffset != null) + ctx.CdOffsets.Remove(cdOffset); + + continue; + } + + if(!short.TryParse(column1, out short offset)) + continue; + + if(!int.TryParse(column2, out int submissions)) + continue; + + if(column3[^1] != '%') + continue; + + column3 = column3.Substring(0, column3.Length - 1); + + if(!float.TryParse(column3, out float percentage)) + continue; + + percentage /= 100; + + if(cdOffset is null) + { + cdOffset = new CompactDiscOffset + { + AddedWhen = DateTime.UtcNow, + ModifiedWhen = DateTime.UtcNow, + Agreement = percentage, + Manufacturer = manufacturer, + Model = model, + Offset = offset, + Submissions = submissions + }; + + ctx.CdOffsets.Add(cdOffset); + addedOffsets++; + } + else + { + if(Math.Abs(cdOffset.Agreement - percentage) > 0) + { + cdOffset.Agreement = percentage; + cdOffset.ModifiedWhen = DateTime.UtcNow; + } + + if(cdOffset.Offset != offset) + { + cdOffset.Offset = offset; + cdOffset.ModifiedWhen = DateTime.UtcNow; + } + + if(cdOffset.Submissions != submissions) + { + cdOffset.Submissions = submissions; + cdOffset.ModifiedWhen = DateTime.UtcNow; + } + + if(Math.Abs(cdOffset.Agreement - percentage) > 0 || + cdOffset.Offset != offset || + cdOffset.Submissions != submissions) + modifiedOffsets++; + } + + foreach(Device device in ctx.Devices. + Where(d => d.Manufacturer == null && d.Model != null && + d.Model.Trim() == model). + Union(ctx.Devices.Where(d => d.Manufacturer != null && + d.Manufacturer.Trim() == manufacturer && + d.Model != null && d.Model == model))) + { + if(device.CdOffset == cdOffset && + device.ModifiedWhen == cdOffset.ModifiedWhen) + continue; + + device.CdOffset = cdOffset; + device.ModifiedWhen = cdOffset.ModifiedWhen; + } + } + + end = DateTime.UtcNow; + System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); + + if(File.Exists("drive_offsets.json")) + { + var sr = new StreamReader("drive_offsets.json"); + + CompactDiscOffset[] offsets = JsonSerializer.Deserialize(sr.ReadToEnd()); + + if(offsets != null) + { + foreach(CompactDiscOffset offset in offsets) + { + CompactDiscOffset cdOffset = + ctx.CdOffsets.FirstOrDefault(o => o.Manufacturer == offset.Manufacturer && + o.Model == offset.Model); + + if(cdOffset is null) + { + offset.ModifiedWhen = DateTime.UtcNow; + + ctx.CdOffsets.Add(offset); + addedOffsets++; + } + else + { + if(Math.Abs(cdOffset.Agreement - offset.Agreement) > 0 || + offset.Agreement < 0) + { + cdOffset.Agreement = offset.Agreement; + cdOffset.ModifiedWhen = DateTime.UtcNow; + } + + if(cdOffset.Offset != offset.Offset) + { + cdOffset.Offset = offset.Offset; + cdOffset.ModifiedWhen = DateTime.UtcNow; + } + + if(cdOffset.Submissions != offset.Submissions) + { + cdOffset.Submissions = offset.Submissions; + cdOffset.ModifiedWhen = DateTime.UtcNow; + } + + if(Math.Abs(cdOffset.Agreement - offset.Agreement) > 0 || + cdOffset.Offset != offset.Offset || + cdOffset.Submissions != offset.Submissions) + modifiedOffsets++; + } + } + } + } + System.Console.WriteLine("{0}: Committing changes...", DateTime.UtcNow); start = DateTime.UtcNow; ctx.SaveChanges(); end = DateTime.UtcNow; System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - try - { - System.Console.WriteLine("{0}: Retrieving CompactDisc read offsets from AccurateRip...", - DateTime.UtcNow); - - start = DateTime.UtcNow; - - client = new WebClient(); - string html = client.DownloadString("http://www.accuraterip.com/driveoffsets.htm"); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - - // The HTML is too malformed to process easily, so find start of table - html = "" + - html.Substring(html.IndexOf("
", StringComparison.Ordinal)); - - var doc = new HtmlDocument(); - doc.LoadHtml(html); - HtmlNode firstTable = doc.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[1]"); - - bool firstRow = true; - - int addedOffsets = 0; - int modifiedOffsets = 0; - - System.Console.WriteLine("{0}: Processing offsets...", DateTime.UtcNow); - start = DateTime.UtcNow; - - foreach(HtmlNode row in firstTable.Descendants("tr")) - { - HtmlNode[] columns = row.Descendants("td").ToArray(); - - if(columns.Length != 4) - { - System.Console.WriteLine("{0}: Row does not have correct number of columns...", - DateTime.UtcNow); - - continue; - } - - string column0 = columns[0].InnerText; - string column1 = columns[1].InnerText; - string column2 = columns[2].InnerText; - string column3 = columns[3].InnerText; - - if(firstRow) - { - if(column0.ToLowerInvariant() != "cd drive") - { - System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, - columns[0].InnerText); - - break; - } - - if(column1.ToLowerInvariant() != "correction offset") - { - System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, - columns[1].InnerText); - - break; - } - - if(column2.ToLowerInvariant() != "submitted by") - { - System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, - columns[2].InnerText); - - break; - } - - if(column3.ToLowerInvariant() != "percentage agree") - { - System.Console.WriteLine("{0}: Unexpected header \"{1}\" found...", DateTime.UtcNow, - columns[3].InnerText); - - break; - } - - firstRow = false; - - continue; - } - - string manufacturer; - string model; - - if(column0[0] == '-' && - column0[1] == ' ') - { - manufacturer = null; - model = column0.Substring(2).Trim(); - } - else - { - int cutOffset = column0.IndexOf(" - ", StringComparison.Ordinal); - - if(cutOffset == -1) - { - manufacturer = null; - model = column0; - } - else - { - manufacturer = column0.Substring(0, cutOffset).Trim(); - model = column0.Substring(cutOffset + 3).Trim(); - } - } - - switch(manufacturer) - { - case "Lite-ON": - manufacturer = "JLMS"; - - break; - case "LG Electronics": - manufacturer = "HL-DT-ST"; - - break; - case "Panasonic": - manufacturer = "MATSHITA"; - - break; - } - - CompactDiscOffset cdOffset = - ctx.CdOffsets.FirstOrDefault(o => o.Manufacturer == manufacturer && o.Model == model); - - if(column1.ToLowerInvariant() == "[purged]") - { - if(cdOffset != null) - ctx.CdOffsets.Remove(cdOffset); - - continue; - } - - if(!short.TryParse(column1, out short offset)) - continue; - - if(!int.TryParse(column2, out int submissions)) - continue; - - if(column3[^1] != '%') - continue; - - column3 = column3.Substring(0, column3.Length - 1); - - if(!float.TryParse(column3, out float percentage)) - continue; - - percentage /= 100; - - if(cdOffset is null) - { - cdOffset = new CompactDiscOffset - { - AddedWhen = DateTime.UtcNow, - ModifiedWhen = DateTime.UtcNow, - Agreement = percentage, - Manufacturer = manufacturer, - Model = model, - Offset = offset, - Submissions = submissions - }; - - ctx.CdOffsets.Add(cdOffset); - addedOffsets++; - } - else - { - if(Math.Abs(cdOffset.Agreement - percentage) > 0) - { - cdOffset.Agreement = percentage; - cdOffset.ModifiedWhen = DateTime.UtcNow; - } - - if(cdOffset.Offset != offset) - { - cdOffset.Offset = offset; - cdOffset.ModifiedWhen = DateTime.UtcNow; - } - - if(cdOffset.Submissions != submissions) - { - cdOffset.Submissions = submissions; - cdOffset.ModifiedWhen = DateTime.UtcNow; - } - - if(Math.Abs(cdOffset.Agreement - percentage) > 0 || - cdOffset.Offset != offset || - cdOffset.Submissions != submissions) - modifiedOffsets++; - } - - foreach(Device device in ctx.Devices. - Where(d => d.Manufacturer == null && d.Model != null && - d.Model.Trim() == model). - Union(ctx.Devices.Where(d => d.Manufacturer != null && - d.Manufacturer.Trim() == manufacturer && - d.Model != null && d.Model == model))) - { - if(device.CdOffset == cdOffset && - device.ModifiedWhen == cdOffset.ModifiedWhen) - continue; - - device.CdOffset = cdOffset; - device.ModifiedWhen = cdOffset.ModifiedWhen; - } - } - - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - - if(File.Exists("drive_offsets.json")) - { - var sr = new StreamReader("drive_offsets.json"); - - CompactDiscOffset[] offsets = JsonSerializer.Deserialize(sr.ReadToEnd()); - - if(offsets != null) - { - foreach(CompactDiscOffset offset in offsets) - { - CompactDiscOffset cdOffset = - ctx.CdOffsets.FirstOrDefault(o => o.Manufacturer == offset.Manufacturer && - o.Model == offset.Model); - - if(cdOffset is null) - { - offset.ModifiedWhen = DateTime.UtcNow; - - ctx.CdOffsets.Add(offset); - addedOffsets++; - } - else - { - if(Math.Abs(cdOffset.Agreement - offset.Agreement) > 0 || - offset.Agreement < 0) - { - cdOffset.Agreement = offset.Agreement; - cdOffset.ModifiedWhen = DateTime.UtcNow; - } - - if(cdOffset.Offset != offset.Offset) - { - cdOffset.Offset = offset.Offset; - cdOffset.ModifiedWhen = DateTime.UtcNow; - } - - if(cdOffset.Submissions != offset.Submissions) - { - cdOffset.Submissions = offset.Submissions; - cdOffset.ModifiedWhen = DateTime.UtcNow; - } - - if(Math.Abs(cdOffset.Agreement - offset.Agreement) > 0 || - cdOffset.Offset != offset.Offset || - cdOffset.Submissions != offset.Submissions) - modifiedOffsets++; - } - } - } - } - - System.Console.WriteLine("{0}: Committing changes...", DateTime.UtcNow); - start = DateTime.UtcNow; - ctx.SaveChanges(); - end = DateTime.UtcNow; - System.Console.WriteLine("{0}: Took {1:F2} seconds", end, (end - start).TotalSeconds); - - System.Console.WriteLine("{0}: Added {1} offsets", end, addedOffsets); - System.Console.WriteLine("{0}: Modified {1} offsets", end, modifiedOffsets); - } - catch(Exception ex) - { - #if DEBUG - if(Debugger.IsAttached) - throw; - #endif - System.Console.WriteLine("{0}: Exception {1} filling CompactDisc read offsets...", DateTime.UtcNow, ex); - } + System.Console.WriteLine("{0}: Added {1} offsets", end, addedOffsets); + System.Console.WriteLine("{0}: Modified {1} offsets", end, modifiedOffsets); + } + catch(Exception ex) + { + #if DEBUG + if(Debugger.IsAttached) + throw; + #endif + System.Console.WriteLine("{0}: Exception {1} filling CompactDisc read offsets...", DateTime.UtcNow, ex); } } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/AtasController.cs b/Aaru.Server/Areas/Admin/Controllers/AtasController.cs index f37be22e..0596f637 100644 --- a/Aaru.Server/Areas/Admin/Controllers/AtasController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/AtasController.cs @@ -13,436 +13,496 @@ using Newtonsoft.Json; using Ata = Aaru.CommonTypes.Metadata.Ata; using TestedMedia = Aaru.CommonTypes.Metadata.TestedMedia; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class AtasController : Controller { - [Area("Admin"), Authorize] - public sealed class AtasController : Controller + readonly AaruServerContext _context; + + public AtasController(AaruServerContext context) => _context = context; + + // GET: Admin/Atas + public IActionResult Index() => View(_context.Ata.AsEnumerable().OrderBy(m => m.IdentifyDevice?.Model). + ThenBy(m => m.IdentifyDevice?.FirmwareRevision)); + + // GET: Admin/Atas/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public AtasController(AaruServerContext context) => _context = context; - - // GET: Admin/Atas - public IActionResult Index() => View(_context.Ata.AsEnumerable().OrderBy(m => m.IdentifyDevice?.Model). - ThenBy(m => m.IdentifyDevice?.FirmwareRevision)); - - // GET: Admin/Atas/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - Ata ata = await _context.Ata.FirstOrDefaultAsync(m => m.Id == id); - - if(ata == null) - { - return NotFound(); - } - - return View(ata); + return NotFound(); } - // GET: Admin/Atas/Delete/5 - public async Task Delete(int? id) + Ata ata = await _context.Ata.FirstOrDefaultAsync(m => m.Id == id); + + if(ata == null) { - if(id == null) - { - return NotFound(); - } - - Ata ata = await _context.Ata.FirstOrDefaultAsync(m => m.Id == id); - - if(ata == null) - { - return NotFound(); - } - - return View(ata); + return NotFound(); } - // POST: Admin/Atas/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Ata ata = await _context.Ata.FindAsync(id); - _context.Ata.Remove(ata); - await _context.SaveChangesAsync(); + return View(ata); + } - return RedirectToAction(nameof(Index)); + // GET: Admin/Atas/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); } - public IActionResult Consolidate() + Ata ata = await _context.Ata.FirstOrDefaultAsync(m => m.Id == id); + + if(ata == null) { - List hashes = _context.Ata.Select(m => new IdHashModel(m.Id, Hash.Sha512(m.Identify))). - ToList(); - - List dups = hashes.GroupBy(x => x.Hash).Where(g => g.Count() > 1). - Select(x => hashes.FirstOrDefault(y => y.Hash == x.Key)).ToList(); - - for(int i = 0; i < dups.Count; i++) - { - Ata unique = _context.Ata.First(a => a.Id == dups[i].Id); - - dups[i].Description = unique.IdentifyDevice?.Model; - dups[i].Duplicates = hashes.Where(h => h.Hash == dups[i].Hash).Skip(1).Select(x => x.Id).ToArray(); - } - - return View(new IdHashModelForView - { - List = dups, - Json = JsonConvert.SerializeObject(dups) - }); + return NotFound(); } - [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] - public IActionResult ConsolidateConfirmed(string models) + return View(ata); + } + + // POST: Admin/Atas/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Ata ata = await _context.Ata.FindAsync(id); + _context.Ata.Remove(ata); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult Consolidate() + { + List hashes = _context.Ata.Select(m => new IdHashModel(m.Id, Hash.Sha512(m.Identify))). + ToList(); + + List dups = hashes.GroupBy(x => x.Hash).Where(g => g.Count() > 1). + Select(x => hashes.FirstOrDefault(y => y.Hash == x.Key)).ToList(); + + for(int i = 0; i < dups.Count; i++) { - IdHashModel[] duplicates; + Ata unique = _context.Ata.First(a => a.Id == dups[i].Id); - try - { - duplicates = JsonConvert.DeserializeObject(models); - } - catch(JsonSerializationException) - { - return BadRequest(); - } - - if(duplicates is null) - return BadRequest(); - - foreach(IdHashModel duplicate in duplicates) - { - Ata master = _context.Ata.FirstOrDefault(m => m.Id == duplicate.Id); - - if(master is null) - continue; - - foreach(int duplicateId in duplicate.Duplicates) - { - Ata slave = _context.Ata.FirstOrDefault(m => m.Id == duplicateId); - - if(slave is null) - continue; - - foreach(Device ataDevice in _context.Devices.Where(d => d.ATA.Id == duplicateId)) - { - ataDevice.ATA = master; - } - - foreach(Device atapiDevice in _context.Devices.Where(d => d.ATAPI.Id == duplicateId)) - { - atapiDevice.ATAPI = master; - } - - foreach(UploadedReport ataReport in _context.Reports.Where(d => d.ATA.Id == duplicateId)) - { - ataReport.ATA = master; - } - - foreach(UploadedReport atapiReport in _context.Reports.Where(d => d.ATAPI.Id == duplicateId)) - { - atapiReport.ATAPI = master; - } - - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == duplicateId)) - { - testedMedia.AtaId = duplicate.Id; - _context.Update(testedMedia); - } - - if(master.ReadCapabilities is null && - slave.ReadCapabilities != null) - master.ReadCapabilities = slave.ReadCapabilities; - - _context.Ata.Remove(slave); - } - } - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); + dups[i].Description = unique.IdentifyDevice?.Model; + dups[i].Duplicates = hashes.Where(h => h.Hash == dups[i].Hash).Skip(1).Select(x => x.Id).ToArray(); } - public IActionResult ConsolidateWithIds(int masterId, int slaveId) + return View(new IdHashModelForView { - Ata master = _context.Ata.FirstOrDefault(m => m.Id == masterId); + List = dups, + Json = JsonConvert.SerializeObject(dups) + }); + } + + [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] + public IActionResult ConsolidateConfirmed(string models) + { + IdHashModel[] duplicates; + + try + { + duplicates = JsonConvert.DeserializeObject(models); + } + catch(JsonSerializationException) + { + return BadRequest(); + } + + if(duplicates is null) + return BadRequest(); + + foreach(IdHashModel duplicate in duplicates) + { + Ata master = _context.Ata.FirstOrDefault(m => m.Id == duplicate.Id); if(master is null) - return RedirectToAction(nameof(Compare), new + continue; + + foreach(int duplicateId in duplicate.Duplicates) + { + Ata slave = _context.Ata.FirstOrDefault(m => m.Id == duplicateId); + + if(slave is null) + continue; + + foreach(Device ataDevice in _context.Devices.Where(d => d.ATA.Id == duplicateId)) { - id = masterId, - rightId = slaveId - }); + ataDevice.ATA = master; + } - Ata slave = _context.Ata.FirstOrDefault(m => m.Id == slaveId); - - if(slave is null) - return RedirectToAction(nameof(Compare), new + foreach(Device atapiDevice in _context.Devices.Where(d => d.ATAPI.Id == duplicateId)) { - id = masterId, - rightId = slaveId - }); + atapiDevice.ATAPI = master; + } - foreach(Device ataDevice in _context.Devices.Where(d => d.ATA.Id == slaveId)) - { - ataDevice.ATA = master; + foreach(UploadedReport ataReport in _context.Reports.Where(d => d.ATA.Id == duplicateId)) + { + ataReport.ATA = master; + } + + foreach(UploadedReport atapiReport in _context.Reports.Where(d => d.ATAPI.Id == duplicateId)) + { + atapiReport.ATAPI = master; + } + + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == duplicateId)) + { + testedMedia.AtaId = duplicate.Id; + _context.Update(testedMedia); + } + + if(master.ReadCapabilities is null && + slave.ReadCapabilities != null) + master.ReadCapabilities = slave.ReadCapabilities; + + _context.Ata.Remove(slave); } - - foreach(Device atapiDevice in _context.Devices.Where(d => d.ATAPI.Id == slaveId)) - { - atapiDevice.ATAPI = master; - } - - foreach(UploadedReport ataReport in _context.Reports.Where(d => d.ATA.Id == slaveId)) - { - ataReport.ATA = master; - } - - foreach(UploadedReport atapiReport in _context.Reports.Where(d => d.ATAPI.Id == slaveId)) - { - atapiReport.ATAPI = master; - } - - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveId)) - { - testedMedia.AtaId = masterId; - _context.Update(testedMedia); - } - - if(master.ReadCapabilities is null && - slave.ReadCapabilities != null) - master.ReadCapabilities = slave.ReadCapabilities; - - _context.Ata.Remove(slave); - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); } - public IActionResult Compare(int id, int rightId) + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult ConsolidateWithIds(int masterId, int slaveId) + { + Ata master = _context.Ata.FirstOrDefault(m => m.Id == masterId); + + if(master is null) + return RedirectToAction(nameof(Compare), new + { + id = masterId, + rightId = slaveId + }); + + Ata slave = _context.Ata.FirstOrDefault(m => m.Id == slaveId); + + if(slave is null) + return RedirectToAction(nameof(Compare), new + { + id = masterId, + rightId = slaveId + }); + + foreach(Device ataDevice in _context.Devices.Where(d => d.ATA.Id == slaveId)) { - var model = new CompareModel - { - LeftId = id, - RightId = rightId - }; + ataDevice.ATA = master; + } - Ata left = _context.Ata.FirstOrDefault(l => l.Id == id); - Ata right = _context.Ata.FirstOrDefault(r => r.Id == rightId); + foreach(Device atapiDevice in _context.Devices.Where(d => d.ATAPI.Id == slaveId)) + { + atapiDevice.ATAPI = master; + } - if(left is null) - { - model.ErrorMessage = $"ATA with id {id} has not been found"; - model.HasError = true; + foreach(UploadedReport ataReport in _context.Reports.Where(d => d.ATA.Id == slaveId)) + { + ataReport.ATA = master; + } - return View(model); - } + foreach(UploadedReport atapiReport in _context.Reports.Where(d => d.ATAPI.Id == slaveId)) + { + atapiReport.ATAPI = master; + } - if(right is null) - { - model.ErrorMessage = $"ATA with id {rightId} has not been found"; - model.HasError = true; + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveId)) + { + testedMedia.AtaId = masterId; + _context.Update(testedMedia); + } - return View(model); - } + if(master.ReadCapabilities is null && + slave.ReadCapabilities != null) + master.ReadCapabilities = slave.ReadCapabilities; - Identify.IdentifyDevice? leftNullable = left.IdentifyDevice; - Identify.IdentifyDevice? rightNullable = right.IdentifyDevice; - model.ValueNames = new List(); - model.LeftValues = new List(); - model.RightValues = new List(); + _context.Ata.Remove(slave); - if(!leftNullable.HasValue && - !rightNullable.HasValue) - { - model.AreEqual = true; + _context.SaveChanges(); - return View(model); - } + return RedirectToAction(nameof(Index)); + } - if(leftNullable.HasValue && - !rightNullable.HasValue) - { - model.ValueNames.Add("Decoded"); - model.LeftValues.Add("decoded"); - model.RightValues.Add("null"); + public IActionResult Compare(int id, int rightId) + { + var model = new CompareModel + { + LeftId = id, + RightId = rightId + }; - return View(model); - } + Ata left = _context.Ata.FirstOrDefault(l => l.Id == id); + Ata right = _context.Ata.FirstOrDefault(r => r.Id == rightId); - if(!leftNullable.HasValue) - { - model.ValueNames.Add("Decoded"); - model.LeftValues.Add("null"); - model.RightValues.Add("decoded"); - - return View(model); - } - - Identify.IdentifyDevice leftValue = left.IdentifyDevice.Value; - Identify.IdentifyDevice rightValue = right.IdentifyDevice.Value; - - foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields()) - { - object lv = fieldInfo.GetValue(leftValue); - object rv = fieldInfo.GetValue(rightValue); - - if(fieldInfo.FieldType.IsArray) - { - var la = lv as Array; - var ra = rv as Array; - - switch(la) - { - case null when ra is null: continue; - case null: - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("null"); - model.RightValues.Add("[]"); - - continue; - } - - if(ra is null) - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("[]"); - model.RightValues.Add("null"); - - continue; - } - - List ll = la.Cast().ToList(); - List rl = ra.Cast().ToList(); - - for(int i = 0; i < ll.Count; i++) - { - if(ll[i].Equals(rl[i])) - continue; - - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("[]"); - model.RightValues.Add("[]"); - - break; - } - } - else if(lv == null && - rv == null) {} - else if(lv != null && - rv == null) - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add($"{lv}"); - model.RightValues.Add("null"); - } - else if(lv == null) - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("null"); - model.RightValues.Add($"{rv}"); - } - else if(!lv.Equals(rv)) - - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add($"{lv}"); - model.RightValues.Add($"{rv}"); - } - } - - model.AreEqual = model.LeftValues.Count == 0 && model.RightValues.Count == 0; + if(left is null) + { + model.ErrorMessage = $"ATA with id {id} has not been found"; + model.HasError = true; return View(model); } - public IActionResult CheckPrivate() + if(right is null) { - List havePrivacy = new(); - byte[] tmp; + model.ErrorMessage = $"ATA with id {rightId} has not been found"; + model.HasError = true; - foreach(Ata ata in _context.Ata) - { - Identify.IdentifyDevice? id = ata.IdentifyDevice; - - if(id is null) - continue; - - if(!string.IsNullOrWhiteSpace(id.Value.SerialNumber) || - id.Value.WWN != 0 || - id.Value.WWNExtension != 0 || - !string.IsNullOrWhiteSpace(id.Value.MediaSerial)) - { - havePrivacy.Add(ata); - - continue; - } - - tmp = new byte[10]; - Array.Copy(ata.Identify, 121 * 2, tmp, 0, 10); - - if(tmp.All(b => b > 0x20) && - tmp.All(b => b <= 0x5F)) - { - havePrivacy.Add(ata); - - continue; - } - - tmp = new byte[62]; - Array.Copy(ata.Identify, 129 * 2, tmp, 0, 62); - - if(tmp.All(b => b > 0x20) && - tmp.All(b => b <= 0x5F)) - { - havePrivacy.Add(ata); - - continue; - } - - tmp = new byte[14]; - Array.Copy(ata.Identify, 161 * 2, tmp, 0, 14); - - if(tmp.All(b => b > 0x20) && - tmp.All(b => b <= 0x5F)) - { - havePrivacy.Add(ata); - - continue; - } - - tmp = new byte[12]; - Array.Copy(ata.Identify, 224 * 2, tmp, 0, 12); - - if(tmp.All(b => b > 0x20) && - tmp.All(b => b <= 0x5F)) - { - havePrivacy.Add(ata); - - continue; - } - - tmp = new byte[38]; - Array.Copy(ata.Identify, 236 * 2, tmp, 0, 38); - - if(tmp.All(b => b > 0x20) && - tmp.All(b => b <= 0x5F)) - { - havePrivacy.Add(ata); - } - } - - return View(havePrivacy); + return View(model); } - public IActionResult ClearPrivate(int id) - { - Ata ata = _context.Ata.FirstOrDefault(a => a.Id == id); + Identify.IdentifyDevice? leftNullable = left.IdentifyDevice; + Identify.IdentifyDevice? rightNullable = right.IdentifyDevice; + model.ValueNames = new List(); + model.LeftValues = new List(); + model.RightValues = new List(); + if(!leftNullable.HasValue && + !rightNullable.HasValue) + { + model.AreEqual = true; + + return View(model); + } + + if(leftNullable.HasValue && + !rightNullable.HasValue) + { + model.ValueNames.Add("Decoded"); + model.LeftValues.Add("decoded"); + model.RightValues.Add("null"); + + return View(model); + } + + if(!leftNullable.HasValue) + { + model.ValueNames.Add("Decoded"); + model.LeftValues.Add("null"); + model.RightValues.Add("decoded"); + + return View(model); + } + + Identify.IdentifyDevice leftValue = left.IdentifyDevice.Value; + Identify.IdentifyDevice rightValue = right.IdentifyDevice.Value; + + foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields()) + { + object lv = fieldInfo.GetValue(leftValue); + object rv = fieldInfo.GetValue(rightValue); + + if(fieldInfo.FieldType.IsArray) + { + var la = lv as Array; + var ra = rv as Array; + + switch(la) + { + case null when ra is null: continue; + case null: + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("null"); + model.RightValues.Add("[]"); + + continue; + } + + if(ra is null) + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("[]"); + model.RightValues.Add("null"); + + continue; + } + + List ll = la.Cast().ToList(); + List rl = ra.Cast().ToList(); + + for(int i = 0; i < ll.Count; i++) + { + if(ll[i].Equals(rl[i])) + continue; + + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("[]"); + model.RightValues.Add("[]"); + + break; + } + } + else if(lv == null && + rv == null) {} + else if(lv != null && + rv == null) + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add($"{lv}"); + model.RightValues.Add("null"); + } + else if(lv == null) + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("null"); + model.RightValues.Add($"{rv}"); + } + else if(!lv.Equals(rv)) + + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add($"{lv}"); + model.RightValues.Add($"{rv}"); + } + } + + model.AreEqual = model.LeftValues.Count == 0 && model.RightValues.Count == 0; + + return View(model); + } + + public IActionResult CheckPrivate() + { + List havePrivacy = new(); + byte[] tmp; + + foreach(Ata ata in _context.Ata) + { + Identify.IdentifyDevice? id = ata.IdentifyDevice; + + if(id is null) + continue; + + if(!string.IsNullOrWhiteSpace(id.Value.SerialNumber) || + id.Value.WWN != 0 || + id.Value.WWNExtension != 0 || + !string.IsNullOrWhiteSpace(id.Value.MediaSerial)) + { + havePrivacy.Add(ata); + + continue; + } + + tmp = new byte[10]; + Array.Copy(ata.Identify, 121 * 2, tmp, 0, 10); + + if(tmp.All(b => b > 0x20) && + tmp.All(b => b <= 0x5F)) + { + havePrivacy.Add(ata); + + continue; + } + + tmp = new byte[62]; + Array.Copy(ata.Identify, 129 * 2, tmp, 0, 62); + + if(tmp.All(b => b > 0x20) && + tmp.All(b => b <= 0x5F)) + { + havePrivacy.Add(ata); + + continue; + } + + tmp = new byte[14]; + Array.Copy(ata.Identify, 161 * 2, tmp, 0, 14); + + if(tmp.All(b => b > 0x20) && + tmp.All(b => b <= 0x5F)) + { + havePrivacy.Add(ata); + + continue; + } + + tmp = new byte[12]; + Array.Copy(ata.Identify, 224 * 2, tmp, 0, 12); + + if(tmp.All(b => b > 0x20) && + tmp.All(b => b <= 0x5F)) + { + havePrivacy.Add(ata); + + continue; + } + + tmp = new byte[38]; + Array.Copy(ata.Identify, 236 * 2, tmp, 0, 38); + + if(tmp.All(b => b > 0x20) && + tmp.All(b => b <= 0x5F)) + { + havePrivacy.Add(ata); + } + } + + return View(havePrivacy); + } + + public IActionResult ClearPrivate(int id) + { + Ata ata = _context.Ata.FirstOrDefault(a => a.Id == id); + + if(ata is null) + return RedirectToAction(nameof(CheckPrivate)); + + // Serial number + for(int i = 0; i < 20; i++) + ata.Identify[(10 * 2) + i] = 0x20; + + // Media serial number + for(int i = 0; i < 40; i++) + ata.Identify[(176 * 2) + i] = 0x20; + + // WWN and WWN Extension + for(int i = 0; i < 16; i++) + ata.Identify[(108 * 2) + i] = 0; + + // We need to tell EFCore the entity has changed + _context.Update(ata); + _context.SaveChanges(); + + return RedirectToAction(nameof(CheckPrivate)); + } + + public IActionResult ClearReserved(int id) + { + Ata ata = _context.Ata.FirstOrDefault(a => a.Id == id); + + if(ata is null) + return RedirectToAction(nameof(CheckPrivate)); + + // ReservedWords121 + for(int i = 0; i < 10; i++) + ata.Identify[(121 * 2) + i] = 0; + + // ReservedWords129 + for(int i = 0; i < 40; i++) + ata.Identify[(129 * 2) + i] = 0; + + // ReservedCFA + for(int i = 0; i < 14; i++) + ata.Identify[(161 * 2) + i] = 0; + + // ReservedCEATA224 + for(int i = 0; i < 12; i++) + ata.Identify[(224 * 2) + i] = 0; + + // ReservedWords + for(int i = 0; i < 14; i++) + ata.Identify[(161 * 2) + i] = 0; + + // We need to tell EFCore the entity has changed + _context.Update(ata); + _context.SaveChanges(); + + return RedirectToAction(nameof(CheckPrivate)); + } + + public IActionResult ClearPrivateAll() + { + foreach(Ata ata in _context.Ata) + { if(ata is null) return RedirectToAction(nameof(CheckPrivate)); @@ -460,18 +520,17 @@ namespace Aaru.Server.Areas.Admin.Controllers // We need to tell EFCore the entity has changed _context.Update(ata); - _context.SaveChanges(); - - return RedirectToAction(nameof(CheckPrivate)); } - public IActionResult ClearReserved(int id) + _context.SaveChanges(); + + return RedirectToAction(nameof(CheckPrivate)); + } + + public IActionResult ClearReservedAll() + { + foreach(Ata ata in _context.Ata) { - Ata ata = _context.Ata.FirstOrDefault(a => a.Id == id); - - if(ata is null) - return RedirectToAction(nameof(CheckPrivate)); - // ReservedWords121 for(int i = 0; i < 10; i++) ata.Identify[(121 * 2) + i] = 0; @@ -494,70 +553,10 @@ namespace Aaru.Server.Areas.Admin.Controllers // We need to tell EFCore the entity has changed _context.Update(ata); - _context.SaveChanges(); - - return RedirectToAction(nameof(CheckPrivate)); } - public IActionResult ClearPrivateAll() - { - foreach(Ata ata in _context.Ata) - { - if(ata is null) - return RedirectToAction(nameof(CheckPrivate)); + _context.SaveChanges(); - // Serial number - for(int i = 0; i < 20; i++) - ata.Identify[(10 * 2) + i] = 0x20; - - // Media serial number - for(int i = 0; i < 40; i++) - ata.Identify[(176 * 2) + i] = 0x20; - - // WWN and WWN Extension - for(int i = 0; i < 16; i++) - ata.Identify[(108 * 2) + i] = 0; - - // We need to tell EFCore the entity has changed - _context.Update(ata); - } - - _context.SaveChanges(); - - return RedirectToAction(nameof(CheckPrivate)); - } - - public IActionResult ClearReservedAll() - { - foreach(Ata ata in _context.Ata) - { - // ReservedWords121 - for(int i = 0; i < 10; i++) - ata.Identify[(121 * 2) + i] = 0; - - // ReservedWords129 - for(int i = 0; i < 40; i++) - ata.Identify[(129 * 2) + i] = 0; - - // ReservedCFA - for(int i = 0; i < 14; i++) - ata.Identify[(161 * 2) + i] = 0; - - // ReservedCEATA224 - for(int i = 0; i < 12; i++) - ata.Identify[(224 * 2) + i] = 0; - - // ReservedWords - for(int i = 0; i < 14; i++) - ata.Identify[(161 * 2) + i] = 0; - - // We need to tell EFCore the entity has changed - _context.Update(ata); - } - - _context.SaveChanges(); - - return RedirectToAction(nameof(CheckPrivate)); - } + return RedirectToAction(nameof(CheckPrivate)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/BlockDescriptorsController.cs b/Aaru.Server/Areas/Admin/Controllers/BlockDescriptorsController.cs index ce2dd012..50b3ee5c 100644 --- a/Aaru.Server/Areas/Admin/Controllers/BlockDescriptorsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/BlockDescriptorsController.cs @@ -5,18 +5,17 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class BlockDescriptorsController : Controller { - [Area("Admin"), Authorize] - public sealed class BlockDescriptorsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public BlockDescriptorsController(AaruServerContext context) => _context = context; + public BlockDescriptorsController(AaruServerContext context) => _context = context; - // GET: Admin/BlockDescriptors - public async Task Index() => View(await _context.BlockDescriptor.OrderBy(b => b.BlockLength). - ThenBy(b => b.Blocks).ThenBy(b => b.Density). - ToListAsync()); - } + // GET: Admin/BlockDescriptors + public async Task Index() => View(await _context.BlockDescriptor.OrderBy(b => b.BlockLength). + ThenBy(b => b.Blocks).ThenBy(b => b.Density). + ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/ChsController.cs b/Aaru.Server/Areas/Admin/Controllers/ChsController.cs index 5a44f953..026adb79 100644 --- a/Aaru.Server/Areas/Admin/Controllers/ChsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/ChsController.cs @@ -8,88 +8,87 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class ChsController : Controller { - [Area("Admin"), Authorize] - public sealed class ChsController : Controller + readonly AaruServerContext _context; + + public ChsController(AaruServerContext context) => _context = context; + + // GET: Admin/Chs + public async Task Index() => View(await _context.Chs.OrderBy(c => c.Cylinders). + ThenBy(c => c.Heads).ThenBy(c => c.Sectors). + ToListAsync()); + + public IActionResult Consolidate() { - readonly AaruServerContext _context; - - public ChsController(AaruServerContext context) => _context = context; - - // GET: Admin/Chs - public async Task Index() => View(await _context.Chs.OrderBy(c => c.Cylinders). - ThenBy(c => c.Heads).ThenBy(c => c.Sectors). - ToListAsync()); - - public IActionResult Consolidate() + List dups = _context.Chs.GroupBy(x => new { - List dups = _context.Chs.GroupBy(x => new - { - x.Cylinders, - x.Heads, - x.Sectors - }).Where(x => x.Count() > 1).Select(x => new ChsModel - { - Cylinders = x.Key.Cylinders, - Heads = x.Key.Heads, - Sectors = x.Key.Sectors - }).ToList(); + x.Cylinders, + x.Heads, + x.Sectors + }).Where(x => x.Count() > 1).Select(x => new ChsModel + { + Cylinders = x.Key.Cylinders, + Heads = x.Key.Heads, + Sectors = x.Key.Sectors + }).ToList(); - return View(new ChsModelForView - { - List = dups, - Json = JsonConvert.SerializeObject(dups) - }); + return View(new ChsModelForView + { + List = dups, + Json = JsonConvert.SerializeObject(dups) + }); + } + + [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] + public IActionResult ConsolidateConfirmed(string models) + { + ChsModel[] duplicates; + + try + { + duplicates = JsonConvert.DeserializeObject(models); + } + catch(JsonSerializationException) + { + return BadRequest(); } - [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] - public IActionResult ConsolidateConfirmed(string models) + if(duplicates is null) + return BadRequest(); + + foreach(ChsModel duplicate in duplicates) { - ChsModel[] duplicates; + Chs master = _context.Chs.FirstOrDefault(m => m.Cylinders == duplicate.Cylinders && + m.Heads == duplicate.Heads && + m.Sectors == duplicate.Sectors); - try + if(master is null) + continue; + + foreach(Chs chs in _context.Chs.Where(m => m.Cylinders == duplicate.Cylinders && + m.Heads == duplicate.Heads && + m.Sectors == duplicate.Sectors).Skip(1).ToArray()) { - duplicates = JsonConvert.DeserializeObject(models); - } - catch(JsonSerializationException) - { - return BadRequest(); - } - - if(duplicates is null) - return BadRequest(); - - foreach(ChsModel duplicate in duplicates) - { - Chs master = _context.Chs.FirstOrDefault(m => m.Cylinders == duplicate.Cylinders && - m.Heads == duplicate.Heads && - m.Sectors == duplicate.Sectors); - - if(master is null) - continue; - - foreach(Chs chs in _context.Chs.Where(m => m.Cylinders == duplicate.Cylinders && - m.Heads == duplicate.Heads && - m.Sectors == duplicate.Sectors).Skip(1).ToArray()) + foreach(TestedMedia media in _context.TestedMedia.Where(d => d.CHS.Id == chs.Id)) { - foreach(TestedMedia media in _context.TestedMedia.Where(d => d.CHS.Id == chs.Id)) - { - media.CHS = master; - } - - foreach(TestedMedia media in _context.TestedMedia.Where(d => d.CurrentCHS.Id == chs.Id)) - { - media.CurrentCHS = master; - } - - _context.Chs.Remove(chs); + media.CHS = master; } + + foreach(TestedMedia media in _context.TestedMedia.Where(d => d.CurrentCHS.Id == chs.Id)) + { + media.CurrentCHS = master; + } + + _context.Chs.Remove(chs); } - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); } + + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/CommandsController.cs b/Aaru.Server/Areas/Admin/Controllers/CommandsController.cs index 658ba8a6..570d5e49 100644 --- a/Aaru.Server/Areas/Admin/Controllers/CommandsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/CommandsController.cs @@ -5,16 +5,15 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class CommandsController : Controller { - [Area("Admin"), Authorize] - public sealed class CommandsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public CommandsController(AaruServerContext context) => _context = context; + public CommandsController(AaruServerContext context) => _context = context; - // GET: Admin/Commands - public async Task Index() => View(await _context.Commands.OrderBy(c => c.Name).ToListAsync()); - } + // GET: Admin/Commands + public async Task Index() => View(await _context.Commands.OrderBy(c => c.Name).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/CompactDiscOffsetsController.cs b/Aaru.Server/Areas/Admin/Controllers/CompactDiscOffsetsController.cs index ef4db390..21267671 100644 --- a/Aaru.Server/Areas/Admin/Controllers/CompactDiscOffsetsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/CompactDiscOffsetsController.cs @@ -6,105 +6,104 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class CompactDiscOffsetsController : Controller { - [Area("Admin"), Authorize] - public sealed class CompactDiscOffsetsController : Controller + readonly AaruServerContext _context; + + public CompactDiscOffsetsController(AaruServerContext context) => _context = context; + + // GET: Admin/CompactDiscOffsets + public async Task Index() => View(await _context.CdOffsets.OrderBy(o => o.Manufacturer). + ThenBy(o => o.Model).ThenBy(o => o.Offset). + ToListAsync()); + + // GET: Admin/CompactDiscOffsets/Edit/5 + public async Task Edit(int? id) { - readonly AaruServerContext _context; - - public CompactDiscOffsetsController(AaruServerContext context) => _context = context; - - // GET: Admin/CompactDiscOffsets - public async Task Index() => View(await _context.CdOffsets.OrderBy(o => o.Manufacturer). - ThenBy(o => o.Model).ThenBy(o => o.Offset). - ToListAsync()); - - // GET: Admin/CompactDiscOffsets/Edit/5 - public async Task Edit(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - CompactDiscOffset compactDiscOffset = await _context.CdOffsets.FindAsync(id); - - if(compactDiscOffset == null) - { - return NotFound(); - } - - return View(compactDiscOffset); + return NotFound(); } - // POST: Admin/CompactDiscOffsets/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("Id,Manufacturer,Model,Offset,Submissions,Agreement")] - CompactDiscOffset changedModel) + CompactDiscOffset compactDiscOffset = await _context.CdOffsets.FindAsync(id); + + if(compactDiscOffset == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - CompactDiscOffset model = await _context.CdOffsets.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.Manufacturer = changedModel.Manufacturer; - model.Model = changedModel.Model; - model.Offset = changedModel.Offset; - model.Submissions = changedModel.Submissions; - model.Agreement = changedModel.Agreement; - model.ModifiedWhen = DateTime.UtcNow; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/CompactDiscOffsets/Delete/5 - public async Task Delete(int? id) - { - if(id == null) - { - return NotFound(); - } - - CompactDiscOffset compactDiscOffset = await _context.CdOffsets.FirstOrDefaultAsync(m => m.Id == id); - - if(compactDiscOffset == null) - { - return NotFound(); - } - - return View(compactDiscOffset); - } - - // POST: Admin/CompactDiscOffsets/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - CompactDiscOffset compactDiscOffset = await _context.CdOffsets.FindAsync(id); - _context.CdOffsets.Remove(compactDiscOffset); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - public IActionResult Update() => throw new NotImplementedException(); + return View(compactDiscOffset); } + + // POST: Admin/CompactDiscOffsets/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("Id,Manufacturer,Model,Offset,Submissions,Agreement")] + CompactDiscOffset changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + CompactDiscOffset model = await _context.CdOffsets.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.Manufacturer = changedModel.Manufacturer; + model.Model = changedModel.Model; + model.Offset = changedModel.Offset; + model.Submissions = changedModel.Submissions; + model.Agreement = changedModel.Agreement; + model.ModifiedWhen = DateTime.UtcNow; + + try + { + _context.Update(model); + await _context.SaveChangesAsync(); + } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); + } + + return RedirectToAction(nameof(Index)); + } + + // GET: Admin/CompactDiscOffsets/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); + } + + CompactDiscOffset compactDiscOffset = await _context.CdOffsets.FirstOrDefaultAsync(m => m.Id == id); + + if(compactDiscOffset == null) + { + return NotFound(); + } + + return View(compactDiscOffset); + } + + // POST: Admin/CompactDiscOffsets/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + CompactDiscOffset compactDiscOffset = await _context.CdOffsets.FindAsync(id); + _context.CdOffsets.Remove(compactDiscOffset); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult Update() => throw new NotImplementedException(); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/DeviceStatsController.cs b/Aaru.Server/Areas/Admin/Controllers/DeviceStatsController.cs index 5c75a16b..b310c5fc 100644 --- a/Aaru.Server/Areas/Admin/Controllers/DeviceStatsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/DeviceStatsController.cs @@ -5,101 +5,100 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class DeviceStatsController : Controller { - [Area("Admin"), Authorize] - public sealed class DeviceStatsController : Controller + readonly AaruServerContext _context; + + public DeviceStatsController(AaruServerContext context) => _context = context; + + // GET: Admin/DeviceStats + public async Task Index() => View(await _context.DeviceStats.OrderBy(d => d.Manufacturer). + ThenBy(d => d.Model).ThenBy(d => d.Bus). + ToListAsync()); + + // GET: Admin/DeviceStats/Edit/5 + public async Task Edit(int? id) { - readonly AaruServerContext _context; - - public DeviceStatsController(AaruServerContext context) => _context = context; - - // GET: Admin/DeviceStats - public async Task Index() => View(await _context.DeviceStats.OrderBy(d => d.Manufacturer). - ThenBy(d => d.Model).ThenBy(d => d.Bus). - ToListAsync()); - - // GET: Admin/DeviceStats/Edit/5 - public async Task Edit(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - DeviceStat deviceStat = await _context.DeviceStats.FindAsync(id); - - if(deviceStat == null) - { - return NotFound(); - } - - return View(deviceStat); + return NotFound(); } - // POST: Admin/DeviceStats/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("Id,Manufacturer,Model,Revision,Bus")] - DeviceStat changedModel) + DeviceStat deviceStat = await _context.DeviceStats.FindAsync(id); + + if(deviceStat == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - DeviceStat model = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.Manufacturer = changedModel.Manufacturer; - model.Model = changedModel.Model; - model.Revision = changedModel.Revision; - model.Bus = changedModel.Bus; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/DeviceStats/Delete/5 - public async Task Delete(int? id) + return View(deviceStat); + } + + // POST: Admin/DeviceStats/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("Id,Manufacturer,Model,Revision,Bus")] + DeviceStat changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + DeviceStat model = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.Manufacturer = changedModel.Manufacturer; + model.Model = changedModel.Model; + model.Revision = changedModel.Revision; + model.Bus = changedModel.Bus; + + try { - if(id == null) - { - return NotFound(); - } - - DeviceStat deviceStat = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id); - - if(deviceStat == null) - { - return NotFound(); - } - - return View(deviceStat); - } - - // POST: Admin/DeviceStats/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - DeviceStat deviceStat = await _context.DeviceStats.FindAsync(id); - _context.DeviceStats.Remove(deviceStat); + _context.Update(model); await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); + } + + return RedirectToAction(nameof(Index)); + } + + // GET: Admin/DeviceStats/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); + } + + DeviceStat deviceStat = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id); + + if(deviceStat == null) + { + return NotFound(); + } + + return View(deviceStat); + } + + // POST: Admin/DeviceStats/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + DeviceStat deviceStat = await _context.DeviceStats.FindAsync(id); + _context.DeviceStats.Remove(deviceStat); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/DevicesController.cs b/Aaru.Server/Areas/Admin/Controllers/DevicesController.cs index cd33cd05..480efb10 100644 --- a/Aaru.Server/Areas/Admin/Controllers/DevicesController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/DevicesController.cs @@ -7,415 +7,414 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class DevicesController : Controller { - [Area("Admin"), Authorize] - public sealed class DevicesController : Controller + readonly AaruServerContext _context; + + public DevicesController(AaruServerContext context) => _context = context; + + // GET: Admin/Devices + public async Task Index() => View(await _context.Devices.OrderBy(d => d.Manufacturer). + ThenBy(d => d.Model).ThenBy(d => d.Revision). + ThenBy(d => d.CompactFlash).ThenBy(d => d.Type). + ToListAsync()); + + // GET: Admin/Devices/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public DevicesController(AaruServerContext context) => _context = context; - - // GET: Admin/Devices - public async Task Index() => View(await _context.Devices.OrderBy(d => d.Manufacturer). - ThenBy(d => d.Model).ThenBy(d => d.Revision). - ThenBy(d => d.CompactFlash).ThenBy(d => d.Type). - ToListAsync()); - - // GET: Admin/Devices/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - var model = new DeviceDetails - { - Report = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id) - }; - - if(model.Report is null) - { - return NotFound(); - } - - model.ReportAll = _context.Reports. - Where(d => d.Manufacturer == model.Report.Manufacturer && - d.Model == model.Report.Model && d.Revision == model.Report.Revision). - Select(d => d.Id).ToList(); - - model.ReportButManufacturer = _context.Reports. - Where(d => d.Model == model.Report.Model && - d.Revision == model.Report.Revision).Select(d => d.Id). - Where(d => model.ReportAll.All(r => r != d)).ToList(); - - model.SameAll = _context.Devices. - Where(d => d.Manufacturer == model.Report.Manufacturer && - d.Model == model.Report.Model && d.Revision == model.Report.Revision && - d.Id != id).Select(d => d.Id).ToList(); - - model.SameButManufacturer = _context.Devices. - Where(d => d.Model == model.Report.Model && - d.Revision == model.Report.Revision && d.Id != id). - Select(d => d.Id).Where(d => model.SameAll.All(r => r != d)).ToList(); - - model.StatsAll = _context.DeviceStats. - Where(d => d.Manufacturer == model.Report.Manufacturer && - d.Model == model.Report.Model && d.Revision == model.Report.Revision && - d.Report.Id != model.Report.Id).ToList(); - - model.StatsButManufacturer = _context.DeviceStats. - Where(d => d.Model == model.Report.Model && - d.Revision == model.Report.Revision && - d.Report.Id != model.Report.Id).AsEnumerable(). - Where(d => model.StatsAll.All(s => s.Id != d.Id)).ToList(); - - model.ReadCapabilitiesId = - model.Report.ATA?.ReadCapabilities?.Id ?? model.Report.SCSI?.ReadCapabilities?.Id ?? 0; - - // So we can check, as we know IDs with 0 will never exist, and EFCore does not allow null propagation in the LINQ - int ataId = model.Report.ATA?.Id ?? 0; - int atapiId = model.Report.ATAPI?.Id ?? 0; - int scsiId = model.Report.SCSI?.Id ?? 0; - int mmcId = model.Report.SCSI?.MultiMediaDevice?.Id ?? 0; - int sscId = model.Report.SCSI?.SequentialDevice?.Id ?? 0; - - model.TestedMedias = _context.TestedMedia. - Where(t => t.AtaId == ataId || t.AtaId == atapiId || t.ScsiId == scsiId || - t.MmcId == mmcId).OrderBy(t => t.Manufacturer). - ThenBy(t => t.Model).ThenBy(t => t.MediumTypeName).ToList(); - - model.TestedSequentialMedias = _context.TestedSequentialMedia.Where(t => t.SscId == sscId). - OrderBy(t => t.Manufacturer).ThenBy(t => t.Model). - ThenBy(t => t.MediumTypeName).ToList(); - - return View(model); + return NotFound(); } - // GET: Admin/Devices/Edit/5 - public async Task Edit(int? id) + var model = new DeviceDetails { - if(id == null) - { - return NotFound(); - } + Report = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id) + }; - Device device = await _context.Devices.FindAsync(id); - - if(device == null) - { - return NotFound(); - } - - return View(device); + if(model.Report is null) + { + return NotFound(); } - // POST: Admin/Devices/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit( - int id, [Bind("OptimalMultipleSectorsRead,Id,CompactFlash,Manufacturer,Model,Revision,Type")] - Device changedModel) + model.ReportAll = _context.Reports. + Where(d => d.Manufacturer == model.Report.Manufacturer && + d.Model == model.Report.Model && d.Revision == model.Report.Revision). + Select(d => d.Id).ToList(); + + model.ReportButManufacturer = _context.Reports. + Where(d => d.Model == model.Report.Model && + d.Revision == model.Report.Revision).Select(d => d.Id). + Where(d => model.ReportAll.All(r => r != d)).ToList(); + + model.SameAll = _context.Devices. + Where(d => d.Manufacturer == model.Report.Manufacturer && + d.Model == model.Report.Model && d.Revision == model.Report.Revision && + d.Id != id).Select(d => d.Id).ToList(); + + model.SameButManufacturer = _context.Devices. + Where(d => d.Model == model.Report.Model && + d.Revision == model.Report.Revision && d.Id != id). + Select(d => d.Id).Where(d => model.SameAll.All(r => r != d)).ToList(); + + model.StatsAll = _context.DeviceStats. + Where(d => d.Manufacturer == model.Report.Manufacturer && + d.Model == model.Report.Model && d.Revision == model.Report.Revision && + d.Report.Id != model.Report.Id).ToList(); + + model.StatsButManufacturer = _context.DeviceStats. + Where(d => d.Model == model.Report.Model && + d.Revision == model.Report.Revision && + d.Report.Id != model.Report.Id).AsEnumerable(). + Where(d => model.StatsAll.All(s => s.Id != d.Id)).ToList(); + + model.ReadCapabilitiesId = + model.Report.ATA?.ReadCapabilities?.Id ?? model.Report.SCSI?.ReadCapabilities?.Id ?? 0; + + // So we can check, as we know IDs with 0 will never exist, and EFCore does not allow null propagation in the LINQ + int ataId = model.Report.ATA?.Id ?? 0; + int atapiId = model.Report.ATAPI?.Id ?? 0; + int scsiId = model.Report.SCSI?.Id ?? 0; + int mmcId = model.Report.SCSI?.MultiMediaDevice?.Id ?? 0; + int sscId = model.Report.SCSI?.SequentialDevice?.Id ?? 0; + + model.TestedMedias = _context.TestedMedia. + Where(t => t.AtaId == ataId || t.AtaId == atapiId || t.ScsiId == scsiId || + t.MmcId == mmcId).OrderBy(t => t.Manufacturer). + ThenBy(t => t.Model).ThenBy(t => t.MediumTypeName).ToList(); + + model.TestedSequentialMedias = _context.TestedSequentialMedia.Where(t => t.SscId == sscId). + OrderBy(t => t.Manufacturer).ThenBy(t => t.Model). + ThenBy(t => t.MediumTypeName).ToList(); + + return View(model); + } + + // GET: Admin/Devices/Edit/5 + public async Task Edit(int? id) + { + if(id == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - Device model = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.CanReadGdRomUsingSwapDisc = changedModel.CanReadGdRomUsingSwapDisc; - model.OptimalMultipleSectorsRead = changedModel.OptimalMultipleSectorsRead; - model.CompactFlash = changedModel.CompactFlash; - model.Manufacturer = changedModel.Manufacturer; - model.Model = changedModel.Model; - model.Revision = changedModel.Revision; - model.Type = changedModel.Type; - model.ModifiedWhen = DateTime.UtcNow; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/Devices/Delete/5 - public async Task Delete(int? id) + Device device = await _context.Devices.FindAsync(id); + + if(device == null) { - if(id == null) - { - return NotFound(); - } - - Device device = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id); - - if(device == null) - { - return NotFound(); - } - - return View(device); + return NotFound(); } - // POST: Admin/Devices/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) + return View(device); + } + + // POST: Admin/Devices/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit( + int id, [Bind("OptimalMultipleSectorsRead,Id,CompactFlash,Manufacturer,Model,Revision,Type")] + Device changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + Device model = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.CanReadGdRomUsingSwapDisc = changedModel.CanReadGdRomUsingSwapDisc; + model.OptimalMultipleSectorsRead = changedModel.OptimalMultipleSectorsRead; + model.CompactFlash = changedModel.CompactFlash; + model.Manufacturer = changedModel.Manufacturer; + model.Model = changedModel.Model; + model.Revision = changedModel.Revision; + model.Type = changedModel.Type; + model.ModifiedWhen = DateTime.UtcNow; + + try { - Device device = await _context.Devices.FindAsync(id); - _context.Devices.Remove(device); + _context.Update(model); await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); + } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); } - bool DeviceExists(int id) => _context.Devices.Any(e => e.Id == id); + return RedirectToAction(nameof(Index)); + } - public IActionResult Merge(int? master, int? slave) + // GET: Admin/Devices/Delete/5 + public async Task Delete(int? id) + { + if(id == null) { - if(master is null || - slave is null) - return NotFound(); + return NotFound(); + } - Device masterDevice = _context.Devices.FirstOrDefault(m => m.Id == master); - Device slaveDevice = _context.Devices.FirstOrDefault(m => m.Id == slave); + Device device = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id); - if(masterDevice is null || - slaveDevice is null) - return NotFound(); + if(device == null) + { + return NotFound(); + } - if(masterDevice.ATAId != null && - masterDevice.ATAId != slaveDevice.ATAId) - { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveDevice.ATAId)) - { - testedMedia.AtaId = masterDevice.ATAId; - _context.Update(testedMedia); - } - } - else if(masterDevice.ATAId == null && - slaveDevice.ATAId != null) - { - masterDevice.ATAId = slaveDevice.ATAId; - _context.Update(masterDevice); - } + return View(device); + } - if(masterDevice.ATAPIId != null && - masterDevice.ATAPIId != slaveDevice.ATAPIId) - { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveDevice.ATAPIId)) - { - testedMedia.AtaId = masterDevice.ATAPIId; - _context.Update(testedMedia); - } - } - else if(masterDevice.ATAPIId == null && - slaveDevice.ATAPIId != null) - { - masterDevice.ATAPIId = slaveDevice.ATAPIId; - _context.Update(masterDevice); - } + // POST: Admin/Devices/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Device device = await _context.Devices.FindAsync(id); + _context.Devices.Remove(device); + await _context.SaveChangesAsync(); - if(masterDevice.SCSIId != null && - masterDevice.SCSIId != slaveDevice.SCSIId) - { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == slaveDevice.SCSIId)) - { - testedMedia.ScsiId = masterDevice.SCSIId; - _context.Update(testedMedia); - } - } - else if(masterDevice.SCSIId == null && - slaveDevice.SCSIId != null) - { - masterDevice.SCSIId = slaveDevice.SCSIId; - _context.Update(masterDevice); - } + return RedirectToAction(nameof(Index)); + } - masterDevice.ModifiedWhen = DateTime.UtcNow; + bool DeviceExists(int id) => _context.Devices.Any(e => e.Id == id); + + public IActionResult Merge(int? master, int? slave) + { + if(master is null || + slave is null) + return NotFound(); + + Device masterDevice = _context.Devices.FirstOrDefault(m => m.Id == master); + Device slaveDevice = _context.Devices.FirstOrDefault(m => m.Id == slave); + + if(masterDevice is null || + slaveDevice is null) + return NotFound(); + + if(masterDevice.ATAId != null && + masterDevice.ATAId != slaveDevice.ATAId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveDevice.ATAId)) + { + testedMedia.AtaId = masterDevice.ATAId; + _context.Update(testedMedia); + } + } + else if(masterDevice.ATAId == null && + slaveDevice.ATAId != null) + { + masterDevice.ATAId = slaveDevice.ATAId; _context.Update(masterDevice); - _context.Remove(slaveDevice); - _context.SaveChanges(); - - return RedirectToAction(nameof(Details), new - { - Id = master - }); } - public IActionResult MergeReports(int? deviceId, int? reportId) + if(masterDevice.ATAPIId != null && + masterDevice.ATAPIId != slaveDevice.ATAPIId) { - if(deviceId is null || - reportId is null) - return NotFound(); - - Device device = _context.Devices.FirstOrDefault(m => m.Id == deviceId); - UploadedReport report = _context.Reports.FirstOrDefault(m => m.Id == reportId); - - if(device is null || - report is null) - return NotFound(); - - if(device.ATAId != null && - device.ATAId != report.ATAId) + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveDevice.ATAPIId)) { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == report.ATAId)) - { - testedMedia.AtaId = device.ATAId; - _context.Update(testedMedia); - } - - if(device.ATA != null && - device.ATA.ReadCapabilities is null && - report.ATA?.ReadCapabilities != null) - { - device.ATA.ReadCapabilities = report.ATA.ReadCapabilities; - _context.Update(device.ATA); - } + testedMedia.AtaId = masterDevice.ATAPIId; + _context.Update(testedMedia); } - else if(device.ATAId == null && - report.ATAId != null) + } + else if(masterDevice.ATAPIId == null && + slaveDevice.ATAPIId != null) + { + masterDevice.ATAPIId = slaveDevice.ATAPIId; + _context.Update(masterDevice); + } + + if(masterDevice.SCSIId != null && + masterDevice.SCSIId != slaveDevice.SCSIId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == slaveDevice.SCSIId)) { - device.ATAId = report.ATAId; - _context.Update(device); + testedMedia.ScsiId = masterDevice.SCSIId; + _context.Update(testedMedia); + } + } + else if(masterDevice.SCSIId == null && + slaveDevice.SCSIId != null) + { + masterDevice.SCSIId = slaveDevice.SCSIId; + _context.Update(masterDevice); + } + + masterDevice.ModifiedWhen = DateTime.UtcNow; + _context.Update(masterDevice); + _context.Remove(slaveDevice); + _context.SaveChanges(); + + return RedirectToAction(nameof(Details), new + { + Id = master + }); + } + + public IActionResult MergeReports(int? deviceId, int? reportId) + { + if(deviceId is null || + reportId is null) + return NotFound(); + + Device device = _context.Devices.FirstOrDefault(m => m.Id == deviceId); + UploadedReport report = _context.Reports.FirstOrDefault(m => m.Id == reportId); + + if(device is null || + report is null) + return NotFound(); + + if(device.ATAId != null && + device.ATAId != report.ATAId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == report.ATAId)) + { + testedMedia.AtaId = device.ATAId; + _context.Update(testedMedia); } - if(device.ATAPIId != null && - device.ATAPIId != report.ATAPIId) + if(device.ATA != null && + device.ATA.ReadCapabilities is null && + report.ATA?.ReadCapabilities != null) { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == report.ATAPIId)) - { - testedMedia.AtaId = device.ATAPIId; - _context.Update(testedMedia); - } + device.ATA.ReadCapabilities = report.ATA.ReadCapabilities; + _context.Update(device.ATA); } - else if(device.ATAPIId == null && - report.ATAPIId != null) + } + else if(device.ATAId == null && + report.ATAId != null) + { + device.ATAId = report.ATAId; + _context.Update(device); + } + + if(device.ATAPIId != null && + device.ATAPIId != report.ATAPIId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == report.ATAPIId)) { - device.ATAPIId = report.ATAPIId; - _context.Update(device); + testedMedia.AtaId = device.ATAPIId; + _context.Update(testedMedia); + } + } + else if(device.ATAPIId == null && + report.ATAPIId != null) + { + device.ATAPIId = report.ATAPIId; + _context.Update(device); + } + + if(device.SCSIId != null && + device.SCSIId != report.SCSIId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == report.SCSIId)) + { + testedMedia.ScsiId = device.SCSIId; + _context.Update(testedMedia); } - if(device.SCSIId != null && - device.SCSIId != report.SCSIId) + if(device.SCSI != null && + device.SCSI.ReadCapabilities is null && + report.SCSI?.ReadCapabilities != null) { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == report.SCSIId)) - { - testedMedia.ScsiId = device.SCSIId; - _context.Update(testedMedia); - } + device.SCSI.ReadCapabilities = report.SCSI.ReadCapabilities; + _context.Update(device.SCSI); + } - if(device.SCSI != null && - device.SCSI.ReadCapabilities is null && - report.SCSI?.ReadCapabilities != null) - { - device.SCSI.ReadCapabilities = report.SCSI.ReadCapabilities; - _context.Update(device.SCSI); - } - - if(device.SCSI != null && - device.SCSI.MultiMediaDevice is null && - report.SCSI?.MultiMediaDevice != null) - { - device.SCSI.MultiMediaDevice = report.SCSI.MultiMediaDevice; - _context.Update(device.SCSI); - } - else if(device.SCSI?.MultiMediaDevice != null && - report.SCSI?.MultiMediaDevice != null) - { - foreach(TestedMedia testedMedia in + if(device.SCSI != null && + device.SCSI.MultiMediaDevice is null && + report.SCSI?.MultiMediaDevice != null) + { + device.SCSI.MultiMediaDevice = report.SCSI.MultiMediaDevice; + _context.Update(device.SCSI); + } + else if(device.SCSI?.MultiMediaDevice != null && + report.SCSI?.MultiMediaDevice != null) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.MmcId == report.SCSI.MultiMediaDevice.Id)) - { - testedMedia.MmcId = device.SCSI.MultiMediaDevice.Id; - _context.Update(testedMedia); - } + { + testedMedia.MmcId = device.SCSI.MultiMediaDevice.Id; + _context.Update(testedMedia); } + } - if(device.SCSI != null && - device.SCSI.SequentialDevice is null && - report.SCSI?.SequentialDevice != null) - { - device.SCSI.SequentialDevice = report.SCSI.SequentialDevice; - _context.Update(device.SCSI); - } - else if(device.SCSI?.SequentialDevice != null && - report.SCSI?.SequentialDevice != null) - { - foreach(TestedSequentialMedia testedSequentialMedia in + if(device.SCSI != null && + device.SCSI.SequentialDevice is null && + report.SCSI?.SequentialDevice != null) + { + device.SCSI.SequentialDevice = report.SCSI.SequentialDevice; + _context.Update(device.SCSI); + } + else if(device.SCSI?.SequentialDevice != null && + report.SCSI?.SequentialDevice != null) + { + foreach(TestedSequentialMedia testedSequentialMedia in _context.TestedSequentialMedia.Where(d => d.SscId == report.SCSI.SequentialDevice.Id)) - { - testedSequentialMedia.SscId = device.SCSI.SequentialDevice.Id; - _context.Update(testedSequentialMedia); - } + { + testedSequentialMedia.SscId = device.SCSI.SequentialDevice.Id; + _context.Update(testedSequentialMedia); } } - else if(device.SCSIId == null && - report.SCSIId != null) - { - device.SCSIId = report.SCSIId; - _context.Update(device); - } - - _context.Remove(report); - _context.SaveChanges(); - - return RedirectToAction(nameof(Details), new - { - Id = deviceId - }); } - - public IActionResult LinkReports(int? statsId, int? deviceId) + else if(device.SCSIId == null && + report.SCSIId != null) { - if(statsId is null || - deviceId is null) - return NotFound(); - - Device device = _context.Devices.FirstOrDefault(m => m.Id == deviceId); - DeviceStat stat = _context.DeviceStats.FirstOrDefault(m => m.Id == statsId); - - if(device is null || - stat is null) - return NotFound(); - - stat.Report = device; - _context.Update(stat); - _context.SaveChanges(); - - return RedirectToAction(nameof(Details), new - { - Id = deviceId - }); + device.SCSIId = report.SCSIId; + _context.Update(device); } - public IActionResult Find(int id, string manufacturer, string model, string revision, string bus) + _context.Remove(report); + _context.SaveChanges(); + + return RedirectToAction(nameof(Details), new { - if(model is null) - return NotFound(); + Id = deviceId + }); + } - var found = new FindReportModel - { - Id = id, - Manufacturer = manufacturer, - Model = model, - Revision = revision, - Bus = bus, - LikeDevices = _context.Devices.Where(r => r.Model.ToLower().Contains(model.ToLower())).ToList() - }; + public IActionResult LinkReports(int? statsId, int? deviceId) + { + if(statsId is null || + deviceId is null) + return NotFound(); - return View(found); - } + Device device = _context.Devices.FirstOrDefault(m => m.Id == deviceId); + DeviceStat stat = _context.DeviceStats.FirstOrDefault(m => m.Id == statsId); + + if(device is null || + stat is null) + return NotFound(); + + stat.Report = device; + _context.Update(stat); + _context.SaveChanges(); + + return RedirectToAction(nameof(Details), new + { + Id = deviceId + }); + } + + public IActionResult Find(int id, string manufacturer, string model, string revision, string bus) + { + if(model is null) + return NotFound(); + + var found = new FindReportModel + { + Id = id, + Manufacturer = manufacturer, + Model = model, + Revision = revision, + Bus = bus, + LikeDevices = _context.Devices.Where(r => r.Model.ToLower().Contains(model.ToLower())).ToList() + }; + + return View(found); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/FilesystemsController.cs b/Aaru.Server/Areas/Admin/Controllers/FilesystemsController.cs index db8dbcad..bb6962cd 100644 --- a/Aaru.Server/Areas/Admin/Controllers/FilesystemsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/FilesystemsController.cs @@ -5,16 +5,15 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class FilesystemsController : Controller { - [Area("Admin"), Authorize] - public sealed class FilesystemsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public FilesystemsController(AaruServerContext context) => _context = context; + public FilesystemsController(AaruServerContext context) => _context = context; - // GET: Admin/Filesystems - public async Task Index() => View(await _context.Filesystems.OrderBy(f => f.Name).ToListAsync()); - } + // GET: Admin/Filesystems + public async Task Index() => View(await _context.Filesystems.OrderBy(f => f.Name).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/FiltersController.cs b/Aaru.Server/Areas/Admin/Controllers/FiltersController.cs index 61f61e11..11b7b067 100644 --- a/Aaru.Server/Areas/Admin/Controllers/FiltersController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/FiltersController.cs @@ -5,16 +5,15 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class FiltersController : Controller { - [Area("Admin"), Authorize] - public sealed class FiltersController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public FiltersController(AaruServerContext context) => _context = context; + public FiltersController(AaruServerContext context) => _context = context; - // GET: Admin/Filters - public async Task Index() => View(await _context.Filters.OrderBy(f => f.Name).ToListAsync()); - } + // GET: Admin/Filters + public async Task Index() => View(await _context.Filters.OrderBy(f => f.Name).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/FireWiresController.cs b/Aaru.Server/Areas/Admin/Controllers/FireWiresController.cs index 27858946..9b1204ca 100644 --- a/Aaru.Server/Areas/Admin/Controllers/FireWiresController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/FireWiresController.cs @@ -8,183 +8,182 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class FireWiresController : Controller { - [Area("Admin"), Authorize] - public sealed class FireWiresController : Controller + readonly AaruServerContext _context; + + public FireWiresController(AaruServerContext context) => _context = context; + + // GET: Admin/FireWires + public async Task Index() => + View(await _context.FireWire.OrderBy(f => f.Manufacturer).ThenBy(f => f.Product).ToListAsync()); + + // GET: Admin/FireWires/Edit/5 + public async Task Edit(int? id) { - readonly AaruServerContext _context; - - public FireWiresController(AaruServerContext context) => _context = context; - - // GET: Admin/FireWires - public async Task Index() => - View(await _context.FireWire.OrderBy(f => f.Manufacturer).ThenBy(f => f.Product).ToListAsync()); - - // GET: Admin/FireWires/Edit/5 - public async Task Edit(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - FireWire fireWire = await _context.FireWire.FindAsync(id); - - if(fireWire == null) - { - return NotFound(); - } - - return View(fireWire); + return NotFound(); } - // POST: Admin/FireWires/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit( - int id, [Bind("Id,VendorID,ProductID,Manufacturer,Product,RemovableMedia")] - FireWire changedModel) + FireWire fireWire = await _context.FireWire.FindAsync(id); + + if(fireWire == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - FireWire model = await _context.FireWire.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.VendorID = changedModel.VendorID; - model.ProductID = changedModel.ProductID; - model.Manufacturer = changedModel.Manufacturer; - model.Product = changedModel.Product; - model.RemovableMedia = changedModel.RemovableMedia; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/FireWires/Delete/5 - public async Task Delete(int? id) + return View(fireWire); + } + + // POST: Admin/FireWires/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit( + int id, [Bind("Id,VendorID,ProductID,Manufacturer,Product,RemovableMedia")] + FireWire changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + FireWire model = await _context.FireWire.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.VendorID = changedModel.VendorID; + model.ProductID = changedModel.ProductID; + model.Manufacturer = changedModel.Manufacturer; + model.Product = changedModel.Product; + model.RemovableMedia = changedModel.RemovableMedia; + + try { - if(id == null) - { - return NotFound(); - } - - FireWire fireWire = await _context.FireWire.FirstOrDefaultAsync(m => m.Id == id); - - if(fireWire == null) - { - return NotFound(); - } - - return View(fireWire); - } - - // POST: Admin/FireWires/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - FireWire fireWire = await _context.FireWire.FindAsync(id); - _context.FireWire.Remove(fireWire); + _context.Update(model); await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); + } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); } - bool FireWireExists(int id) => _context.FireWire.Any(e => e.Id == id); + return RedirectToAction(nameof(Index)); + } - public IActionResult Consolidate() + // GET: Admin/FireWires/Delete/5 + public async Task Delete(int? id) + { + if(id == null) { - List dups = _context.FireWire.GroupBy(x => new - { - x.VendorID, - x.ProductID, - x.Manufacturer, - x.Product, - x.RemovableMedia - }).Where(x => x.Count() > 1).Select(x => new FireWireModel - { - VendorID = x.Key.VendorID, - ProductID = x.Key.ProductID, - Manufacturer = x.Key.Manufacturer, - Product = x.Key.Product, - RemovableMedia = x.Key.RemovableMedia - }).ToList(); - - return View(new FireWireModelForView - { - List = dups, - Json = JsonConvert.SerializeObject(dups) - }); + return NotFound(); } - [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] - public IActionResult ConsolidateConfirmed(string models) + FireWire fireWire = await _context.FireWire.FirstOrDefaultAsync(m => m.Id == id); + + if(fireWire == null) { - FireWireModel[] duplicates; + return NotFound(); + } - try + return View(fireWire); + } + + // POST: Admin/FireWires/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + FireWire fireWire = await _context.FireWire.FindAsync(id); + _context.FireWire.Remove(fireWire); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + bool FireWireExists(int id) => _context.FireWire.Any(e => e.Id == id); + + public IActionResult Consolidate() + { + List dups = _context.FireWire.GroupBy(x => new + { + x.VendorID, + x.ProductID, + x.Manufacturer, + x.Product, + x.RemovableMedia + }).Where(x => x.Count() > 1).Select(x => new FireWireModel + { + VendorID = x.Key.VendorID, + ProductID = x.Key.ProductID, + Manufacturer = x.Key.Manufacturer, + Product = x.Key.Product, + RemovableMedia = x.Key.RemovableMedia + }).ToList(); + + return View(new FireWireModelForView + { + List = dups, + Json = JsonConvert.SerializeObject(dups) + }); + } + + [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] + public IActionResult ConsolidateConfirmed(string models) + { + FireWireModel[] duplicates; + + try + { + duplicates = JsonConvert.DeserializeObject(models); + } + catch(JsonSerializationException) + { + return BadRequest(); + } + + if(duplicates is null) + return BadRequest(); + + foreach(FireWireModel duplicate in duplicates) + { + FireWire master = _context.FireWire.FirstOrDefault(m => m.VendorID == duplicate.VendorID && + m.ProductID == duplicate.ProductID && + m.Manufacturer == duplicate.Manufacturer && + m.Product == duplicate.Product && + m.RemovableMedia == duplicate.RemovableMedia); + + if(master is null) + continue; + + foreach(FireWire firewire in _context.FireWire.Where(m => m.VendorID == duplicate.VendorID && + m.ProductID == duplicate.ProductID && + m.Manufacturer == duplicate.Manufacturer && + m.Product == duplicate.Product && + m.RemovableMedia == duplicate.RemovableMedia). + Skip(1).ToArray()) { - duplicates = JsonConvert.DeserializeObject(models); - } - catch(JsonSerializationException) - { - return BadRequest(); - } - - if(duplicates is null) - return BadRequest(); - - foreach(FireWireModel duplicate in duplicates) - { - FireWire master = _context.FireWire.FirstOrDefault(m => m.VendorID == duplicate.VendorID && - m.ProductID == duplicate.ProductID && - m.Manufacturer == duplicate.Manufacturer && - m.Product == duplicate.Product && - m.RemovableMedia == duplicate.RemovableMedia); - - if(master is null) - continue; - - foreach(FireWire firewire in _context.FireWire.Where(m => m.VendorID == duplicate.VendorID && - m.ProductID == duplicate.ProductID && - m.Manufacturer == duplicate.Manufacturer && - m.Product == duplicate.Product && - m.RemovableMedia == duplicate.RemovableMedia). - Skip(1).ToArray()) + foreach(Device device in _context.Devices.Where(d => d.FireWire.Id == firewire.Id)) { - foreach(Device device in _context.Devices.Where(d => d.FireWire.Id == firewire.Id)) - { - device.FireWire = master; - } - - foreach(UploadedReport report in _context.Reports.Where(d => d.FireWire.Id == firewire.Id)) - { - report.FireWire = master; - } - - _context.FireWire.Remove(firewire); + device.FireWire = master; } + + foreach(UploadedReport report in _context.Reports.Where(d => d.FireWire.Id == firewire.Id)) + { + report.FireWire = master; + } + + _context.FireWire.Remove(firewire); } - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); } + + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/GdRomSwapDiscCapabilitiesController.cs b/Aaru.Server/Areas/Admin/Controllers/GdRomSwapDiscCapabilitiesController.cs index bedaa5d0..9e2f1ecc 100644 --- a/Aaru.Server/Areas/Admin/Controllers/GdRomSwapDiscCapabilitiesController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/GdRomSwapDiscCapabilitiesController.cs @@ -11,383 +11,382 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class GdRomSwapDiscCapabilitiesController : Controller { - [Area("Admin"), Authorize] - public sealed class GdRomSwapDiscCapabilitiesController : Controller + readonly AaruServerContext _context; + + public GdRomSwapDiscCapabilitiesController(AaruServerContext context) => _context = context; + + // GET: Admin/GdRomSwapDiscCapabilities/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public GdRomSwapDiscCapabilitiesController(AaruServerContext context) => _context = context; - - // GET: Admin/GdRomSwapDiscCapabilities/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - GdRomSwapDiscCapabilities caps = - await _context.GdRomSwapDiscCapabilities.FirstOrDefaultAsync(m => m.Id == id); - - if(caps == null) - { - return NotFound(); - } - - return View(caps); + return NotFound(); } - // GET: Admin/GdRomSwapDiscCapabilities/Delete/5 - public async Task Delete(int? id) + GdRomSwapDiscCapabilities caps = + await _context.GdRomSwapDiscCapabilities.FirstOrDefaultAsync(m => m.Id == id); + + if(caps == null) { - if(id == null) - { - return NotFound(); - } - - GdRomSwapDiscCapabilities caps = - await _context.GdRomSwapDiscCapabilities.FirstOrDefaultAsync(m => m.Id == id); - - if(caps == null) - { - return NotFound(); - } - - return View(caps); + return NotFound(); } - // POST: Admin/GdRomSwapDiscCapabilities/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - GdRomSwapDiscCapabilities caps = await _context.GdRomSwapDiscCapabilities.FindAsync(id); - _context.GdRomSwapDiscCapabilities.Remove(caps); - await _context.SaveChangesAsync(); + return View(caps); + } - return RedirectToAction("Index", "Admin"); + // GET: Admin/GdRomSwapDiscCapabilities/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); } - public IActionResult ViewData(int id, string data) + GdRomSwapDiscCapabilities caps = + await _context.GdRomSwapDiscCapabilities.FirstOrDefaultAsync(m => m.Id == id); + + if(caps == null) { - if(string.IsNullOrWhiteSpace(data)) - return NotFound(); + return NotFound(); + } - GdRomSwapDiscCapabilities caps = _context.GdRomSwapDiscCapabilities.FirstOrDefault(m => m.Id == id); + return View(caps); + } - if(caps == null) - { - return NotFound(); - } + // POST: Admin/GdRomSwapDiscCapabilities/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + GdRomSwapDiscCapabilities caps = await _context.GdRomSwapDiscCapabilities.FindAsync(id); + _context.GdRomSwapDiscCapabilities.Remove(caps); + await _context.SaveChangesAsync(); - var model = new TestedMediaDataModel - { - TestedMediaId = id, - DataName = data - }; + return RedirectToAction("Index", "Admin"); + } - byte[] buffer; - var sb = new StringBuilder(); - byte[] sector = new byte[2352]; - byte[] subq = new byte[16]; - byte[] fullsub = new byte[96]; + public IActionResult ViewData(int id, string data) + { + if(string.IsNullOrWhiteSpace(data)) + return NotFound(); - bool audio = true; - bool pq = false; - bool rw = false; + GdRomSwapDiscCapabilities caps = _context.GdRomSwapDiscCapabilities.FirstOrDefault(m => m.Id == id); - switch(data) - { - case nameof(caps.Lba0Data): - buffer = caps.Lba0Data; - audio = false; + if(caps == null) + { + return NotFound(); + } - break; - case nameof(caps.Lba0ScrambledData): - buffer = caps.Lba0ScrambledData; + var model = new TestedMediaDataModel + { + TestedMediaId = id, + DataName = data + }; - break; - case nameof(caps.Lba44990Data): - buffer = caps.Lba44990Data; - audio = false; + byte[] buffer; + var sb = new StringBuilder(); + byte[] sector = new byte[2352]; + byte[] subq = new byte[16]; + byte[] fullsub = new byte[96]; - break; - case nameof(caps.Lba44990PqData): - buffer = caps.Lba44990PqData; - audio = false; - pq = true; + bool audio = true; + bool pq = false; + bool rw = false; - break; - case nameof(caps.Lba44990RwData): - buffer = caps.Lba44990RwData; - audio = false; - rw = true; + switch(data) + { + case nameof(caps.Lba0Data): + buffer = caps.Lba0Data; + audio = false; - break; - case nameof(caps.Lba44990AudioData): - buffer = caps.Lba44990AudioData; + break; + case nameof(caps.Lba0ScrambledData): + buffer = caps.Lba0ScrambledData; - break; - case nameof(caps.Lba44990AudioPqData): - buffer = caps.Lba44990AudioPqData; - pq = true; + break; + case nameof(caps.Lba44990Data): + buffer = caps.Lba44990Data; + audio = false; - break; - case nameof(caps.Lba44990AudioRwData): - buffer = caps.Lba44990AudioRwData; - rw = true; + break; + case nameof(caps.Lba44990PqData): + buffer = caps.Lba44990PqData; + audio = false; + pq = true; - break; - case nameof(caps.Lba45000Data): - buffer = caps.Lba45000Data; - audio = false; + break; + case nameof(caps.Lba44990RwData): + buffer = caps.Lba44990RwData; + audio = false; + rw = true; - break; - case nameof(caps.Lba45000PqData): - buffer = caps.Lba45000PqData; - audio = false; - pq = true; + break; + case nameof(caps.Lba44990AudioData): + buffer = caps.Lba44990AudioData; - break; - case nameof(caps.Lba45000RwData): - buffer = caps.Lba45000RwData; - audio = false; - rw = true; + break; + case nameof(caps.Lba44990AudioPqData): + buffer = caps.Lba44990AudioPqData; + pq = true; - break; - case nameof(caps.Lba45000AudioData): - buffer = caps.Lba45000AudioData; + break; + case nameof(caps.Lba44990AudioRwData): + buffer = caps.Lba44990AudioRwData; + rw = true; - break; - case nameof(caps.Lba45000AudioPqData): - buffer = caps.Lba45000AudioPqData; - pq = true; + break; + case nameof(caps.Lba45000Data): + buffer = caps.Lba45000Data; + audio = false; - break; - case nameof(caps.Lba45000AudioRwData): - buffer = caps.Lba45000AudioRwData; - rw = true; + break; + case nameof(caps.Lba45000PqData): + buffer = caps.Lba45000PqData; + audio = false; + pq = true; - break; - case nameof(caps.Lba50000Data): - buffer = caps.Lba50000Data; - audio = false; + break; + case nameof(caps.Lba45000RwData): + buffer = caps.Lba45000RwData; + audio = false; + rw = true; - break; - case nameof(caps.Lba50000PqData): - buffer = caps.Lba50000PqData; - audio = false; - pq = true; + break; + case nameof(caps.Lba45000AudioData): + buffer = caps.Lba45000AudioData; - break; - case nameof(caps.Lba50000RwData): - buffer = caps.Lba50000RwData; - audio = false; - rw = true; + break; + case nameof(caps.Lba45000AudioPqData): + buffer = caps.Lba45000AudioPqData; + pq = true; - break; - case nameof(caps.Lba50000AudioData): - buffer = caps.Lba50000AudioData; + break; + case nameof(caps.Lba45000AudioRwData): + buffer = caps.Lba45000AudioRwData; + rw = true; - break; - case nameof(caps.Lba50000AudioPqData): - buffer = caps.Lba50000AudioPqData; - pq = true; + break; + case nameof(caps.Lba50000Data): + buffer = caps.Lba50000Data; + audio = false; - break; - case nameof(caps.Lba50000AudioRwData): - buffer = caps.Lba50000AudioRwData; - rw = true; + break; + case nameof(caps.Lba50000PqData): + buffer = caps.Lba50000PqData; + audio = false; + pq = true; - break; - case nameof(caps.Lba100000Data): - buffer = caps.Lba100000Data; - audio = false; + break; + case nameof(caps.Lba50000RwData): + buffer = caps.Lba50000RwData; + audio = false; + rw = true; - break; - case nameof(caps.Lba100000PqData): - buffer = caps.Lba100000PqData; - audio = false; - pq = true; + break; + case nameof(caps.Lba50000AudioData): + buffer = caps.Lba50000AudioData; - break; - case nameof(caps.Lba100000RwData): - buffer = caps.Lba100000RwData; - audio = false; - rw = true; + break; + case nameof(caps.Lba50000AudioPqData): + buffer = caps.Lba50000AudioPqData; + pq = true; - break; - case nameof(caps.Lba100000AudioData): - buffer = caps.Lba100000AudioData; + break; + case nameof(caps.Lba50000AudioRwData): + buffer = caps.Lba50000AudioRwData; + rw = true; - break; - case nameof(caps.Lba100000AudioPqData): - buffer = caps.Lba100000AudioPqData; - pq = true; + break; + case nameof(caps.Lba100000Data): + buffer = caps.Lba100000Data; + audio = false; - break; - case nameof(caps.Lba100000AudioRwData): - buffer = caps.Lba100000AudioRwData; - rw = true; + break; + case nameof(caps.Lba100000PqData): + buffer = caps.Lba100000PqData; + audio = false; + pq = true; - break; - case nameof(caps.Lba400000Data): - buffer = caps.Lba400000Data; - audio = false; + break; + case nameof(caps.Lba100000RwData): + buffer = caps.Lba100000RwData; + audio = false; + rw = true; - break; - case nameof(caps.Lba400000PqData): - buffer = caps.Lba400000PqData; - audio = false; - pq = true; + break; + case nameof(caps.Lba100000AudioData): + buffer = caps.Lba100000AudioData; - break; - case nameof(caps.Lba400000RwData): - buffer = caps.Lba400000RwData; - audio = false; - rw = true; + break; + case nameof(caps.Lba100000AudioPqData): + buffer = caps.Lba100000AudioPqData; + pq = true; - break; - case nameof(caps.Lba400000AudioData): - buffer = caps.Lba400000AudioData; + break; + case nameof(caps.Lba100000AudioRwData): + buffer = caps.Lba100000AudioRwData; + rw = true; - break; - case nameof(caps.Lba400000AudioPqData): - buffer = caps.Lba400000AudioPqData; - pq = true; + break; + case nameof(caps.Lba400000Data): + buffer = caps.Lba400000Data; + audio = false; - break; - case nameof(caps.Lba400000AudioRwData): - buffer = caps.Lba400000AudioRwData; - rw = true; + break; + case nameof(caps.Lba400000PqData): + buffer = caps.Lba400000PqData; + audio = false; + pq = true; - break; - case nameof(caps.Lba450000Data): - buffer = caps.Lba450000Data; - audio = false; + break; + case nameof(caps.Lba400000RwData): + buffer = caps.Lba400000RwData; + audio = false; + rw = true; - break; - case nameof(caps.Lba450000PqData): - buffer = caps.Lba450000PqData; - audio = false; - pq = true; + break; + case nameof(caps.Lba400000AudioData): + buffer = caps.Lba400000AudioData; - break; - case nameof(caps.Lba450000RwData): - buffer = caps.Lba450000RwData; - audio = false; - rw = true; + break; + case nameof(caps.Lba400000AudioPqData): + buffer = caps.Lba400000AudioPqData; + pq = true; - break; - case nameof(caps.Lba450000AudioData): - buffer = caps.Lba450000AudioData; + break; + case nameof(caps.Lba400000AudioRwData): + buffer = caps.Lba400000AudioRwData; + rw = true; - break; - case nameof(caps.Lba450000AudioPqData): - buffer = caps.Lba450000AudioPqData; - pq = true; + break; + case nameof(caps.Lba450000Data): + buffer = caps.Lba450000Data; + audio = false; - break; - case nameof(caps.Lba450000AudioRwData): - buffer = caps.Lba450000AudioRwData; - rw = true; + break; + case nameof(caps.Lba450000PqData): + buffer = caps.Lba450000PqData; + audio = false; + pq = true; - break; - default: return NotFound(); - } + break; + case nameof(caps.Lba450000RwData): + buffer = caps.Lba450000RwData; + audio = false; + rw = true; - if(pq && - buffer != null && - buffer.Length % 2368 != 0) - pq = false; + break; + case nameof(caps.Lba450000AudioData): + buffer = caps.Lba450000AudioData; - if(rw && - buffer != null && - buffer.Length % 2448 != 0) - rw = false; + break; + case nameof(caps.Lba450000AudioPqData): + buffer = caps.Lba450000AudioPqData; + pq = true; - int blockSize = pq - ? 2368 - : rw - ? 2448 - : 2352; + break; + case nameof(caps.Lba450000AudioRwData): + buffer = caps.Lba450000AudioRwData; + rw = true; - model.RawDataAsHex = PrintHex.ByteArrayToHexArrayString(buffer); + break; + default: return NotFound(); + } - if(model.RawDataAsHex != null) - model.RawDataAsHex = HttpUtility.HtmlEncode(model.RawDataAsHex).Replace("\n", "
"); + if(pq && + buffer != null && + buffer.Length % 2368 != 0) + pq = false; - if(buffer == null) - return View(model); + if(rw && + buffer != null && + buffer.Length % 2448 != 0) + rw = false; - for(int i = 0; i < buffer.Length; i += blockSize) - { - if(audio) - { - sb.AppendLine("Audio or scrambled data sector."); - } - else - { - Array.Copy(buffer, i, sector, 0, 2352); + int blockSize = pq + ? 2368 + : rw + ? 2448 + : 2352; - sb.AppendLine(Sector.Prettify(sector)); - } + model.RawDataAsHex = PrintHex.ByteArrayToHexArrayString(buffer); - if(pq) - { - Array.Copy(buffer, i + 2352, subq, 0, 16); - fullsub = Subchannel.ConvertQToRaw(subq); - - sb.AppendLine(GetPrettySub(fullsub)); - } - else if(rw) - { - Array.Copy(buffer, i + 2352, fullsub, 0, 96); - - sb.AppendLine(GetPrettySub(fullsub)); - } - - sb.AppendLine(); - } - - model.Decoded = HttpUtility.HtmlEncode(sb.ToString()).Replace("\n", "
"); + if(model.RawDataAsHex != null) + model.RawDataAsHex = HttpUtility.HtmlEncode(model.RawDataAsHex).Replace("\n", "
"); + if(buffer == null) return View(model); - } - static string GetPrettySub(byte[] sub) + for(int i = 0; i < buffer.Length; i += blockSize) { - byte[] deint = Subchannel.Deinterleave(sub); - - bool validP = true; - bool validRw = true; - - for(int i = 0; i < 12; i++) + if(audio) { - if(deint[i] == 0x00 || - deint[i] == 0xFF) - continue; + sb.AppendLine("Audio or scrambled data sector."); + } + else + { + Array.Copy(buffer, i, sector, 0, 2352); - validP = false; - - break; + sb.AppendLine(Sector.Prettify(sector)); } - for(int i = 24; i < 96; i++) + if(pq) { - if(deint[i] == 0x00) - continue; + Array.Copy(buffer, i + 2352, subq, 0, 16); + fullsub = Subchannel.ConvertQToRaw(subq); - validRw = false; + sb.AppendLine(GetPrettySub(fullsub)); + } + else if(rw) + { + Array.Copy(buffer, i + 2352, fullsub, 0, 96); - break; + sb.AppendLine(GetPrettySub(fullsub)); } - byte[] q = new byte[12]; - Array.Copy(deint, 12, q, 0, 12); - - return Subchannel.PrettifyQ(q, deint[21] > 0x10, 16, !validP, false, validRw); + sb.AppendLine(); } + + model.Decoded = HttpUtility.HtmlEncode(sb.ToString()).Replace("\n", "
"); + + return View(model); + } + + static string GetPrettySub(byte[] sub) + { + byte[] deint = Subchannel.Deinterleave(sub); + + bool validP = true; + bool validRw = true; + + for(int i = 0; i < 12; i++) + { + if(deint[i] == 0x00 || + deint[i] == 0xFF) + continue; + + validP = false; + + break; + } + + for(int i = 24; i < 96; i++) + { + if(deint[i] == 0x00) + continue; + + validRw = false; + + break; + } + + byte[] q = new byte[12]; + Array.Copy(deint, 12, q, 0, 12); + + return Subchannel.PrettifyQ(q, deint[21] > 0x10, 16, !validP, false, validRw); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/HomeController.cs b/Aaru.Server/Areas/Admin/Controllers/HomeController.cs index 3d1015f0..cbdc9419 100644 --- a/Aaru.Server/Areas/Admin/Controllers/HomeController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/HomeController.cs @@ -33,11 +33,10 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class HomeController : Controller { - [Area("Admin"), Authorize] - public sealed class HomeController : Controller - { - public ActionResult Index() => View(); - } + public ActionResult Index() => View(); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/MediaFormatsController.cs b/Aaru.Server/Areas/Admin/Controllers/MediaFormatsController.cs index c5042f4d..8f101f94 100644 --- a/Aaru.Server/Areas/Admin/Controllers/MediaFormatsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/MediaFormatsController.cs @@ -5,46 +5,45 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class MediaFormatsController : Controller { - [Area("Admin"), Authorize] - public sealed class MediaFormatsController : Controller + readonly AaruServerContext _context; + + public MediaFormatsController(AaruServerContext context) => _context = context; + + // GET: Admin/MediaFormats + public async Task Index() => + View(await _context.MediaFormats.OrderBy(mf => mf.Name).ToListAsync()); + + // GET: Admin/MediaFormats/Delete/5 + public async Task Delete(int? id) { - readonly AaruServerContext _context; - - public MediaFormatsController(AaruServerContext context) => _context = context; - - // GET: Admin/MediaFormats - public async Task Index() => - View(await _context.MediaFormats.OrderBy(mf => mf.Name).ToListAsync()); - - // GET: Admin/MediaFormats/Delete/5 - public async Task Delete(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - MediaFormat mediaFormat = await _context.MediaFormats.FirstOrDefaultAsync(m => m.Id == id); - - if(mediaFormat == null) - { - return NotFound(); - } - - return View(mediaFormat); + return NotFound(); } - // POST: Admin/MediaFormats/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - MediaFormat mediaFormat = await _context.MediaFormats.FindAsync(id); - _context.MediaFormats.Remove(mediaFormat); - await _context.SaveChangesAsync(); + MediaFormat mediaFormat = await _context.MediaFormats.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(mediaFormat == null) + { + return NotFound(); } + + return View(mediaFormat); + } + + // POST: Admin/MediaFormats/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + MediaFormat mediaFormat = await _context.MediaFormats.FindAsync(id); + _context.MediaFormats.Remove(mediaFormat); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/MediasController.cs b/Aaru.Server/Areas/Admin/Controllers/MediasController.cs index b2ada67e..cda56afe 100644 --- a/Aaru.Server/Areas/Admin/Controllers/MediasController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/MediasController.cs @@ -5,56 +5,55 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class MediasController : Controller { - [Area("Admin"), Authorize] - public sealed class MediasController : Controller + readonly AaruServerContext _context; + + public MediasController(AaruServerContext context) => _context = context; + + // GET: Admin/Medias + public IActionResult Index(bool? real) { - readonly AaruServerContext _context; - - public MediasController(AaruServerContext context) => _context = context; - - // GET: Admin/Medias - public IActionResult Index(bool? real) + switch(real) { - switch(real) - { - case null: - return View(_context.Medias.ToList().OrderBy(m => m.PhysicalType).ThenBy(m => m.LogicalType). - ThenBy(m => m.Real)); - default: - return View(_context.Medias.Where(m => m.Real == real).ToList().OrderBy(m => m.PhysicalType). - ThenBy(m => m.LogicalType)); - } - } - - // GET: Admin/Medias/Delete/5 - public async Task Delete(int? id) - { - if(id == null) - { - return NotFound(); - } - - Media media = await _context.Medias.FirstOrDefaultAsync(m => m.Id == id); - - if(media == null) - { - return NotFound(); - } - - return View(media); - } - - // POST: Admin/Medias/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Media media = await _context.Medias.FindAsync(id); - _context.Medias.Remove(media); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); + case null: + return View(_context.Medias.ToList().OrderBy(m => m.PhysicalType).ThenBy(m => m.LogicalType). + ThenBy(m => m.Real)); + default: + return View(_context.Medias.Where(m => m.Real == real).ToList().OrderBy(m => m.PhysicalType). + ThenBy(m => m.LogicalType)); } } + + // GET: Admin/Medias/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); + } + + Media media = await _context.Medias.FirstOrDefaultAsync(m => m.Id == id); + + if(media == null) + { + return NotFound(); + } + + return View(media); + } + + // POST: Admin/Medias/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Media media = await _context.Medias.FindAsync(id); + _context.Medias.Remove(media); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/MmcController.cs b/Aaru.Server/Areas/Admin/Controllers/MmcController.cs index 178cd71e..8e9cdb0d 100644 --- a/Aaru.Server/Areas/Admin/Controllers/MmcController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/MmcController.cs @@ -6,87 +6,86 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class MmcController : Controller { - [Area("Admin"), Authorize] - public sealed class MmcController : Controller + readonly AaruServerContext _context; + + public MmcController(AaruServerContext context) => _context = context; + + // GET: Admin/Mmc + public IActionResult Index() => View(_context.Mmc.Where(m => m.ModeSense2AData != null). + Select(m => new MmcModelForView + { + Id = m.Id, + FeaturesId = m.FeaturesId, + DataLength = m.ModeSense2AData.Length + }).ToList(). + Concat(_context.Mmc.Where(m => m.ModeSense2AData == null). + Select(m => new MmcModelForView + { + Id = m.Id, + FeaturesId = m.FeaturesId, + DataLength = 0 + }).ToList()).OrderBy(m => m.Id)); + + // GET: Admin/Mmc/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public MmcController(AaruServerContext context) => _context = context; - - // GET: Admin/Mmc - public IActionResult Index() => View(_context.Mmc.Where(m => m.ModeSense2AData != null). - Select(m => new MmcModelForView - { - Id = m.Id, - FeaturesId = m.FeaturesId, - DataLength = m.ModeSense2AData.Length - }).ToList(). - Concat(_context.Mmc.Where(m => m.ModeSense2AData == null). - Select(m => new MmcModelForView - { - Id = m.Id, - FeaturesId = m.FeaturesId, - DataLength = 0 - }).ToList()).OrderBy(m => m.Id)); - - // GET: Admin/Mmc/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - Mmc mmc = await _context.Mmc.FirstOrDefaultAsync(m => m.Id == id); - - if(mmc == null) - { - return NotFound(); - } - - return View(mmc); + return NotFound(); } - // GET: Admin/Mmc/Delete/5 - public async Task Delete(int? id) + Mmc mmc = await _context.Mmc.FirstOrDefaultAsync(m => m.Id == id); + + if(mmc == null) { - if(id == null) - { - return NotFound(); - } - - Mmc mmc = await _context.Mmc.FirstOrDefaultAsync(m => m.Id == id); - - if(mmc == null) - { - return NotFound(); - } - - return View(mmc); + return NotFound(); } - // POST: Admin/Mmc/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) + return View(mmc); + } + + // GET: Admin/Mmc/Delete/5 + public async Task Delete(int? id) + { + if(id == null) { - Mmc mmc = await _context.Mmc.FindAsync(id); - MmcFeatures feature = await _context.MmcFeatures.FirstOrDefaultAsync(f => f.Id == mmc.FeaturesId); - - _context.MmcFeatures.Remove(feature); - _context.Mmc.Remove(mmc); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); + return NotFound(); } - public async Task Clean() - { - _context.Mmc.RemoveRange(_context.Mmc.Where(m => m.FeaturesId == null && m.ModeSense2AData == null)); - await _context.SaveChangesAsync(); + Mmc mmc = await _context.Mmc.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(mmc == null) + { + return NotFound(); } + + return View(mmc); + } + + // POST: Admin/Mmc/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Mmc mmc = await _context.Mmc.FindAsync(id); + MmcFeatures feature = await _context.MmcFeatures.FirstOrDefaultAsync(f => f.Id == mmc.FeaturesId); + + _context.MmcFeatures.Remove(feature); + _context.Mmc.Remove(mmc); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + public async Task Clean() + { + _context.Mmc.RemoveRange(_context.Mmc.Where(m => m.FeaturesId == null && m.ModeSense2AData == null)); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/MmcFeaturesController.cs b/Aaru.Server/Areas/Admin/Controllers/MmcFeaturesController.cs index 34e44785..29c2a637 100644 --- a/Aaru.Server/Areas/Admin/Controllers/MmcFeaturesController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/MmcFeaturesController.cs @@ -5,34 +5,33 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class MmcFeaturesController : Controller { - [Area("Admin"), Authorize] - public sealed class MmcFeaturesController : Controller + readonly AaruServerContext _context; + + public MmcFeaturesController(AaruServerContext context) => _context = context; + + // GET: Admin/MmcFeatures + public async Task Index() => View(await _context.MmcFeatures.ToListAsync()); + + // GET: Admin/MmcFeatures/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public MmcFeaturesController(AaruServerContext context) => _context = context; - - // GET: Admin/MmcFeatures - public async Task Index() => View(await _context.MmcFeatures.ToListAsync()); - - // GET: Admin/MmcFeatures/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - MmcFeatures mmcFeatures = await _context.MmcFeatures.FirstOrDefaultAsync(m => m.Id == id); - - if(mmcFeatures == null) - { - return NotFound(); - } - - return View(mmcFeatures); + return NotFound(); } + + MmcFeatures mmcFeatures = await _context.MmcFeatures.FirstOrDefaultAsync(m => m.Id == id); + + if(mmcFeatures == null) + { + return NotFound(); + } + + return View(mmcFeatures); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/MmcSdsController.cs b/Aaru.Server/Areas/Admin/Controllers/MmcSdsController.cs index 32d128c8..91b68367 100644 --- a/Aaru.Server/Areas/Admin/Controllers/MmcSdsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/MmcSdsController.cs @@ -5,63 +5,62 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class MmcSdsController : Controller { - [Area("Admin"), Authorize] - public sealed class MmcSdsController : Controller + readonly AaruServerContext _context; + + public MmcSdsController(AaruServerContext context) => _context = context; + + // GET: Admin/MmcSds + public async Task Index() => View(await _context.MmcSd.ToListAsync()); + + // GET: Admin/MmcSds/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public MmcSdsController(AaruServerContext context) => _context = context; - - // GET: Admin/MmcSds - public async Task Index() => View(await _context.MmcSd.ToListAsync()); - - // GET: Admin/MmcSds/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - MmcSd mmcSd = await _context.MmcSd.FirstOrDefaultAsync(m => m.Id == id); - - if(mmcSd == null) - { - return NotFound(); - } - - return View(mmcSd); + return NotFound(); } - // GET: Admin/MmcSds/Delete/5 - public async Task Delete(int? id) + MmcSd mmcSd = await _context.MmcSd.FirstOrDefaultAsync(m => m.Id == id); + + if(mmcSd == null) { - if(id == null) - { - return NotFound(); - } - - MmcSd mmcSd = await _context.MmcSd.FirstOrDefaultAsync(m => m.Id == id); - - if(mmcSd == null) - { - return NotFound(); - } - - return View(mmcSd); + return NotFound(); } - // POST: Admin/MmcSds/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - MmcSd mmcSd = await _context.MmcSd.FindAsync(id); - _context.MmcSd.Remove(mmcSd); - await _context.SaveChangesAsync(); + return View(mmcSd); + } - return RedirectToAction(nameof(Index)); + // GET: Admin/MmcSds/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); } + + MmcSd mmcSd = await _context.MmcSd.FirstOrDefaultAsync(m => m.Id == id); + + if(mmcSd == null) + { + return NotFound(); + } + + return View(mmcSd); + } + + // POST: Admin/MmcSds/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + MmcSd mmcSd = await _context.MmcSd.FindAsync(id); + _context.MmcSd.Remove(mmcSd); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/OperatingSystemsController.cs b/Aaru.Server/Areas/Admin/Controllers/OperatingSystemsController.cs index 5914844a..62909726 100644 --- a/Aaru.Server/Areas/Admin/Controllers/OperatingSystemsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/OperatingSystemsController.cs @@ -5,17 +5,16 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class OperatingSystemsController : Controller { - [Area("Admin"), Authorize] - public sealed class OperatingSystemsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public OperatingSystemsController(AaruServerContext context) => _context = context; + public OperatingSystemsController(AaruServerContext context) => _context = context; - // GET: Admin/OperatingSystems - public async Task Index() => - View(await _context.OperatingSystems.OrderBy(o => o.Name).ThenBy(o => o.Version).ToListAsync()); - } + // GET: Admin/OperatingSystems + public async Task Index() => + View(await _context.OperatingSystems.OrderBy(o => o.Name).ThenBy(o => o.Version).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/PartitionsController.cs b/Aaru.Server/Areas/Admin/Controllers/PartitionsController.cs index 240faa4e..9528d3f2 100644 --- a/Aaru.Server/Areas/Admin/Controllers/PartitionsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/PartitionsController.cs @@ -5,16 +5,15 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class PartitionsController : Controller { - [Area("Admin"), Authorize] - public sealed class PartitionsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public PartitionsController(AaruServerContext context) => _context = context; + public PartitionsController(AaruServerContext context) => _context = context; - // GET: Admin/Partitions - public async Task Index() => View(await _context.Partitions.OrderBy(p => p.Name).ToListAsync()); - } + // GET: Admin/Partitions + public async Task Index() => View(await _context.Partitions.OrderBy(p => p.Name).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/PcmciasController.cs b/Aaru.Server/Areas/Admin/Controllers/PcmciasController.cs index ccdf03a0..a97e7f81 100644 --- a/Aaru.Server/Areas/Admin/Controllers/PcmciasController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/PcmciasController.cs @@ -5,45 +5,44 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class PcmciasController : Controller { - [Area("Admin"), Authorize] - public sealed class PcmciasController : Controller + readonly AaruServerContext _context; + + public PcmciasController(AaruServerContext context) => _context = context; + + // GET: Admin/Pcmcias + public async Task Index() => View(await _context.Pcmcia.ToListAsync()); + + // GET: Admin/Pcmcias/Delete/5 + public async Task Delete(int? id) { - readonly AaruServerContext _context; - - public PcmciasController(AaruServerContext context) => _context = context; - - // GET: Admin/Pcmcias - public async Task Index() => View(await _context.Pcmcia.ToListAsync()); - - // GET: Admin/Pcmcias/Delete/5 - public async Task Delete(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - Pcmcia pcmcia = await _context.Pcmcia.FirstOrDefaultAsync(m => m.Id == id); - - if(pcmcia == null) - { - return NotFound(); - } - - return View(pcmcia); + return NotFound(); } - // POST: Admin/Pcmcias/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Pcmcia pcmcia = await _context.Pcmcia.FindAsync(id); - _context.Pcmcia.Remove(pcmcia); - await _context.SaveChangesAsync(); + Pcmcia pcmcia = await _context.Pcmcia.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(pcmcia == null) + { + return NotFound(); } + + return View(pcmcia); + } + + // POST: Admin/Pcmcias/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Pcmcia pcmcia = await _context.Pcmcia.FindAsync(id); + _context.Pcmcia.Remove(pcmcia); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/ReportsController.cs b/Aaru.Server/Areas/Admin/Controllers/ReportsController.cs index 38353af2..05419019 100644 --- a/Aaru.Server/Areas/Admin/Controllers/ReportsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/ReportsController.cs @@ -7,295 +7,294 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class ReportsController : Controller { - [Area("Admin"), Authorize] - public sealed class ReportsController : Controller + readonly AaruServerContext _context; + + public ReportsController(AaruServerContext context) => _context = context; + + // GET: Admin/Reports + public async Task Index() => View(await _context.Reports.OrderBy(r => r.Manufacturer). + ThenBy(r => r.Model).ThenBy(r => r.Revision). + ThenBy(r => r.CompactFlash).ThenBy(r => r.Type). + ToListAsync()); + + // GET: Admin/Reports/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public ReportsController(AaruServerContext context) => _context = context; - - // GET: Admin/Reports - public async Task Index() => View(await _context.Reports.OrderBy(r => r.Manufacturer). - ThenBy(r => r.Model).ThenBy(r => r.Revision). - ThenBy(r => r.CompactFlash).ThenBy(r => r.Type). - ToListAsync()); - - // GET: Admin/Reports/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - var model = new UploadedReportDetails - { - Report = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id) - }; - - if(model.Report is null) - { - return NotFound(); - } - - model.ReportAll = _context.Devices. - Where(d => d.Manufacturer == model.Report.Manufacturer && - d.Model == model.Report.Model && d.Revision == model.Report.Revision). - Select(d => d.Id).ToList(); - - model.ReportButManufacturer = _context.Devices. - Where(d => d.Model == model.Report.Model && - d.Revision == model.Report.Revision).Select(d => d.Id). - Where(d => model.ReportAll.All(r => r != d)).ToList(); - - model.SameAll = _context.Reports. - Where(d => d.Manufacturer == model.Report.Manufacturer && - d.Model == model.Report.Model && d.Revision == model.Report.Revision && - d.Id != id).Select(d => d.Id).ToList(); - - model.SameButManufacturer = _context.Reports. - Where(d => d.Model == model.Report.Model && - d.Revision == model.Report.Revision && d.Id != id). - Select(d => d.Id).Where(d => model.SameAll.All(r => r != d)).ToList(); - - model.ReadCapabilitiesId = - model.Report.ATA?.ReadCapabilities?.Id ?? model.Report.SCSI?.ReadCapabilities?.Id ?? 0; - - // So we can check, as we know IDs with 0 will never exist, and EFCore does not allow null propagation in the LINQ - int ataId = model.Report.ATA?.Id ?? 0; - int atapiId = model.Report.ATAPI?.Id ?? 0; - int scsiId = model.Report.SCSI?.Id ?? 0; - int mmcId = model.Report.SCSI?.MultiMediaDevice?.Id ?? 0; - int sscId = model.Report.SCSI?.SequentialDevice?.Id ?? 0; - - model.TestedMedias = _context.TestedMedia. - Where(t => t.AtaId == ataId || t.AtaId == atapiId || t.ScsiId == scsiId || - t.MmcId == mmcId).OrderBy(t => t.Manufacturer). - ThenBy(t => t.Model).ThenBy(t => t.MediumTypeName).ToList(); - - model.TestedSequentialMedias = _context.TestedSequentialMedia.Where(t => t.SscId == sscId). - OrderBy(t => t.Manufacturer).ThenBy(t => t.Model). - ThenBy(t => t.MediumTypeName).ToList(); - - return View(model); + return NotFound(); } - // GET: Admin/Reports/Edit/5 - public async Task Edit(int? id) + var model = new UploadedReportDetails { - if(id == null) - { - return NotFound(); - } + Report = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id) + }; - UploadedReport uploadedReport = await _context.Reports.FindAsync(id); - - if(uploadedReport == null) - { - return NotFound(); - } - - return View(uploadedReport); + if(model.Report is null) + { + return NotFound(); } - // POST: Admin/Reports/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("Id,CompactFlash,Manufacturer,Model,Revision,Type")] - UploadedReport changedModel) + model.ReportAll = _context.Devices. + Where(d => d.Manufacturer == model.Report.Manufacturer && + d.Model == model.Report.Model && d.Revision == model.Report.Revision). + Select(d => d.Id).ToList(); + + model.ReportButManufacturer = _context.Devices. + Where(d => d.Model == model.Report.Model && + d.Revision == model.Report.Revision).Select(d => d.Id). + Where(d => model.ReportAll.All(r => r != d)).ToList(); + + model.SameAll = _context.Reports. + Where(d => d.Manufacturer == model.Report.Manufacturer && + d.Model == model.Report.Model && d.Revision == model.Report.Revision && + d.Id != id).Select(d => d.Id).ToList(); + + model.SameButManufacturer = _context.Reports. + Where(d => d.Model == model.Report.Model && + d.Revision == model.Report.Revision && d.Id != id). + Select(d => d.Id).Where(d => model.SameAll.All(r => r != d)).ToList(); + + model.ReadCapabilitiesId = + model.Report.ATA?.ReadCapabilities?.Id ?? model.Report.SCSI?.ReadCapabilities?.Id ?? 0; + + // So we can check, as we know IDs with 0 will never exist, and EFCore does not allow null propagation in the LINQ + int ataId = model.Report.ATA?.Id ?? 0; + int atapiId = model.Report.ATAPI?.Id ?? 0; + int scsiId = model.Report.SCSI?.Id ?? 0; + int mmcId = model.Report.SCSI?.MultiMediaDevice?.Id ?? 0; + int sscId = model.Report.SCSI?.SequentialDevice?.Id ?? 0; + + model.TestedMedias = _context.TestedMedia. + Where(t => t.AtaId == ataId || t.AtaId == atapiId || t.ScsiId == scsiId || + t.MmcId == mmcId).OrderBy(t => t.Manufacturer). + ThenBy(t => t.Model).ThenBy(t => t.MediumTypeName).ToList(); + + model.TestedSequentialMedias = _context.TestedSequentialMedia.Where(t => t.SscId == sscId). + OrderBy(t => t.Manufacturer).ThenBy(t => t.Model). + ThenBy(t => t.MediumTypeName).ToList(); + + return View(model); + } + + // GET: Admin/Reports/Edit/5 + public async Task Edit(int? id) + { + if(id == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - UploadedReport model = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.CompactFlash = changedModel.CompactFlash; - model.Manufacturer = changedModel.Manufacturer; - model.Model = changedModel.Model; - model.Revision = changedModel.Revision; - model.Type = changedModel.Type; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/Reports/Delete/5 - public async Task Delete(int? id) + UploadedReport uploadedReport = await _context.Reports.FindAsync(id); + + if(uploadedReport == null) { - if(id == null) - { - return NotFound(); - } - - UploadedReport uploadedReport = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id); - - if(uploadedReport == null) - { - return NotFound(); - } - - return View(uploadedReport); + return NotFound(); } - // POST: Admin/Reports/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) + return View(uploadedReport); + } + + // POST: Admin/Reports/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("Id,CompactFlash,Manufacturer,Model,Revision,Type")] + UploadedReport changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + UploadedReport model = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.CompactFlash = changedModel.CompactFlash; + model.Manufacturer = changedModel.Manufacturer; + model.Model = changedModel.Model; + model.Revision = changedModel.Revision; + model.Type = changedModel.Type; + + try { - UploadedReport uploadedReport = await _context.Reports.FindAsync(id); - _context.Reports.Remove(uploadedReport); + _context.Update(model); await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); + } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); } - public IActionResult Promote(int? id) + return RedirectToAction(nameof(Index)); + } + + // GET: Admin/Reports/Delete/5 + public async Task Delete(int? id) + { + if(id == null) { - if(id == null) - { - return NotFound(); - } - - UploadedReport uploadedReport = _context.Reports.FirstOrDefault(m => m.Id == id); - - if(uploadedReport == null) - { - return NotFound(); - } - - var device = new Device(uploadedReport.ATAId, uploadedReport.ATAPIId, uploadedReport.FireWireId, - uploadedReport.MultiMediaCardId, uploadedReport.PCMCIAId, - uploadedReport.SecureDigitalId, uploadedReport.SCSIId, uploadedReport.USBId, - uploadedReport.UploadedWhen, uploadedReport.Manufacturer, uploadedReport.Model, - uploadedReport.Revision, uploadedReport.CompactFlash, uploadedReport.Type, - uploadedReport.GdRomSwapDiscCapabilitiesId); - - EntityEntry res = _context.Devices.Add(device); - _context.Reports.Remove(uploadedReport); - _context.SaveChanges(); - - return RedirectToAction(nameof(DevicesController.Details), "Devices", new - { - id = res.Entity.Id - }); + return NotFound(); } - public IActionResult Merge(int? master, int? slave) + UploadedReport uploadedReport = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id); + + if(uploadedReport == null) { - if(master is null || - slave is null) - return NotFound(); + return NotFound(); + } - UploadedReport masterReport = _context.Reports.FirstOrDefault(m => m.Id == master); - UploadedReport slaveReport = _context.Reports.FirstOrDefault(m => m.Id == slave); + return View(uploadedReport); + } - if(masterReport is null || - slaveReport is null) - return NotFound(); + // POST: Admin/Reports/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + UploadedReport uploadedReport = await _context.Reports.FindAsync(id); + _context.Reports.Remove(uploadedReport); + await _context.SaveChangesAsync(); - if(masterReport.ATAId != null && - masterReport.ATAId != slaveReport.ATAId) - { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveReport.ATAId)) - { - testedMedia.AtaId = masterReport.ATAId; - _context.Update(testedMedia); - } - } - else if(masterReport.ATAId == null && - slaveReport.ATAId != null) - { - masterReport.ATAId = slaveReport.ATAId; - _context.Update(masterReport); - } + return RedirectToAction(nameof(Index)); + } - if(masterReport.ATAPIId != null && - masterReport.ATAPIId != slaveReport.ATAPIId) - { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveReport.ATAPIId)) - { - testedMedia.AtaId = masterReport.ATAPIId; - _context.Update(testedMedia); - } - } - else if(masterReport.ATAPIId == null && - slaveReport.ATAPIId != null) - { - masterReport.ATAPIId = slaveReport.ATAPIId; - _context.Update(masterReport); - } + public IActionResult Promote(int? id) + { + if(id == null) + { + return NotFound(); + } - if(masterReport.SCSIId != null && - masterReport.SCSIId != slaveReport.SCSIId) - { - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == slaveReport.SCSIId)) - { - testedMedia.ScsiId = masterReport.SCSIId; - _context.Update(testedMedia); - } - } - else if(masterReport.SCSIId == null && - slaveReport.SCSIId != null) - { - masterReport.SCSIId = slaveReport.SCSIId; - _context.Update(masterReport); - } + UploadedReport uploadedReport = _context.Reports.FirstOrDefault(m => m.Id == id); - if(masterReport.SCSI?.SequentialDeviceId != null && - masterReport.SCSI?.SequentialDeviceId != slaveReport.SCSI?.SequentialDeviceId) + if(uploadedReport == null) + { + return NotFound(); + } + + var device = new Device(uploadedReport.ATAId, uploadedReport.ATAPIId, uploadedReport.FireWireId, + uploadedReport.MultiMediaCardId, uploadedReport.PCMCIAId, + uploadedReport.SecureDigitalId, uploadedReport.SCSIId, uploadedReport.USBId, + uploadedReport.UploadedWhen, uploadedReport.Manufacturer, uploadedReport.Model, + uploadedReport.Revision, uploadedReport.CompactFlash, uploadedReport.Type, + uploadedReport.GdRomSwapDiscCapabilitiesId); + + EntityEntry res = _context.Devices.Add(device); + _context.Reports.Remove(uploadedReport); + _context.SaveChanges(); + + return RedirectToAction(nameof(DevicesController.Details), "Devices", new + { + id = res.Entity.Id + }); + } + + public IActionResult Merge(int? master, int? slave) + { + if(master is null || + slave is null) + return NotFound(); + + UploadedReport masterReport = _context.Reports.FirstOrDefault(m => m.Id == master); + UploadedReport slaveReport = _context.Reports.FirstOrDefault(m => m.Id == slave); + + if(masterReport is null || + slaveReport is null) + return NotFound(); + + if(masterReport.ATAId != null && + masterReport.ATAId != slaveReport.ATAId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveReport.ATAId)) { - foreach(TestedSequentialMedia testedMedia in + testedMedia.AtaId = masterReport.ATAId; + _context.Update(testedMedia); + } + } + else if(masterReport.ATAId == null && + slaveReport.ATAId != null) + { + masterReport.ATAId = slaveReport.ATAId; + _context.Update(masterReport); + } + + if(masterReport.ATAPIId != null && + masterReport.ATAPIId != slaveReport.ATAPIId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveReport.ATAPIId)) + { + testedMedia.AtaId = masterReport.ATAPIId; + _context.Update(testedMedia); + } + } + else if(masterReport.ATAPIId == null && + slaveReport.ATAPIId != null) + { + masterReport.ATAPIId = slaveReport.ATAPIId; + _context.Update(masterReport); + } + + if(masterReport.SCSIId != null && + masterReport.SCSIId != slaveReport.SCSIId) + { + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == slaveReport.SCSIId)) + { + testedMedia.ScsiId = masterReport.SCSIId; + _context.Update(testedMedia); + } + } + else if(masterReport.SCSIId == null && + slaveReport.SCSIId != null) + { + masterReport.SCSIId = slaveReport.SCSIId; + _context.Update(masterReport); + } + + if(masterReport.SCSI?.SequentialDeviceId != null && + masterReport.SCSI?.SequentialDeviceId != slaveReport.SCSI?.SequentialDeviceId) + { + foreach(TestedSequentialMedia testedMedia in _context.TestedSequentialMedia.Where(d => d.SscId == slaveReport.SCSI.SequentialDeviceId)) - { - testedMedia.SscId = masterReport.SCSI.SequentialDeviceId; - _context.Update(testedMedia); - } - } - else if(masterReport.SCSI != null && - masterReport.SCSI?.SequentialDeviceId == null && - slaveReport.SCSI?.SequentialDeviceId != null) { - masterReport.SCSI.SequentialDeviceId = slaveReport.SCSI.SequentialDeviceId; - _context.Update(masterReport); + testedMedia.SscId = masterReport.SCSI.SequentialDeviceId; + _context.Update(testedMedia); } - - if(masterReport.GdRomSwapDiscCapabilitiesId == null && - slaveReport.GdRomSwapDiscCapabilitiesId != null) - { - masterReport.GdRomSwapDiscCapabilitiesId = slaveReport.GdRomSwapDiscCapabilitiesId; - _context.Update(masterReport); - } - else if(masterReport.GdRomSwapDiscCapabilitiesId != null && - slaveReport.GdRomSwapDiscCapabilitiesId != null) - { - masterReport.GdRomSwapDiscCapabilitiesId = slaveReport.GdRomSwapDiscCapabilitiesId; - _context.Update(masterReport); - } - - _context.Remove(slaveReport); - _context.SaveChanges(); - - return RedirectToAction(nameof(Details), new - { - Id = master - }); } + else if(masterReport.SCSI != null && + masterReport.SCSI?.SequentialDeviceId == null && + slaveReport.SCSI?.SequentialDeviceId != null) + { + masterReport.SCSI.SequentialDeviceId = slaveReport.SCSI.SequentialDeviceId; + _context.Update(masterReport); + } + + if(masterReport.GdRomSwapDiscCapabilitiesId == null && + slaveReport.GdRomSwapDiscCapabilitiesId != null) + { + masterReport.GdRomSwapDiscCapabilitiesId = slaveReport.GdRomSwapDiscCapabilitiesId; + _context.Update(masterReport); + } + else if(masterReport.GdRomSwapDiscCapabilitiesId != null && + slaveReport.GdRomSwapDiscCapabilitiesId != null) + { + masterReport.GdRomSwapDiscCapabilitiesId = slaveReport.GdRomSwapDiscCapabilitiesId; + _context.Update(masterReport); + } + + _context.Remove(slaveReport); + _context.SaveChanges(); + + return RedirectToAction(nameof(Details), new + { + Id = master + }); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/ScsiModesController.cs b/Aaru.Server/Areas/Admin/Controllers/ScsiModesController.cs index c318b5c1..1f5318cf 100644 --- a/Aaru.Server/Areas/Admin/Controllers/ScsiModesController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/ScsiModesController.cs @@ -5,45 +5,44 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class ScsiModesController : Controller { - [Area("Admin"), Authorize] - public sealed class ScsiModesController : Controller + readonly AaruServerContext _context; + + public ScsiModesController(AaruServerContext context) => _context = context; + + // GET: Admin/ScsiModes + public async Task Index() => View(await _context.ScsiMode.ToListAsync()); + + // GET: Admin/ScsiModes/Delete/5 + public async Task Delete(int? id) { - readonly AaruServerContext _context; - - public ScsiModesController(AaruServerContext context) => _context = context; - - // GET: Admin/ScsiModes - public async Task Index() => View(await _context.ScsiMode.ToListAsync()); - - // GET: Admin/ScsiModes/Delete/5 - public async Task Delete(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - ScsiMode scsiMode = await _context.ScsiMode.FirstOrDefaultAsync(m => m.Id == id); - - if(scsiMode == null) - { - return NotFound(); - } - - return View(scsiMode); + return NotFound(); } - // POST: Admin/ScsiModes/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - ScsiMode scsiMode = await _context.ScsiMode.FindAsync(id); - _context.ScsiMode.Remove(scsiMode); - await _context.SaveChangesAsync(); + ScsiMode scsiMode = await _context.ScsiMode.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(scsiMode == null) + { + return NotFound(); } + + return View(scsiMode); + } + + // POST: Admin/ScsiModes/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + ScsiMode scsiMode = await _context.ScsiMode.FindAsync(id); + _context.ScsiMode.Remove(scsiMode); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/ScsiPagesController.cs b/Aaru.Server/Areas/Admin/Controllers/ScsiPagesController.cs index f583d465..fdc63ae3 100644 --- a/Aaru.Server/Areas/Admin/Controllers/ScsiPagesController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/ScsiPagesController.cs @@ -5,45 +5,44 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class ScsiPagesController : Controller { - [Area("Admin"), Authorize] - public sealed class ScsiPagesController : Controller + readonly AaruServerContext _context; + + public ScsiPagesController(AaruServerContext context) => _context = context; + + // GET: Admin/ScsiPages + public async Task Index() => View(await _context.ScsiPage.ToListAsync()); + + // GET: Admin/ScsiPages/Delete/5 + public async Task Delete(int? id) { - readonly AaruServerContext _context; - - public ScsiPagesController(AaruServerContext context) => _context = context; - - // GET: Admin/ScsiPages - public async Task Index() => View(await _context.ScsiPage.ToListAsync()); - - // GET: Admin/ScsiPages/Delete/5 - public async Task Delete(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - ScsiPage scsiPage = await _context.ScsiPage.FirstOrDefaultAsync(m => m.Id == id); - - if(scsiPage == null) - { - return NotFound(); - } - - return View(scsiPage); + return NotFound(); } - // POST: Admin/ScsiPages/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - ScsiPage scsiPage = await _context.ScsiPage.FindAsync(id); - _context.ScsiPage.Remove(scsiPage); - await _context.SaveChangesAsync(); + ScsiPage scsiPage = await _context.ScsiPage.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(scsiPage == null) + { + return NotFound(); } + + return View(scsiPage); + } + + // POST: Admin/ScsiPages/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + ScsiPage scsiPage = await _context.ScsiPage.FindAsync(id); + _context.ScsiPage.Remove(scsiPage); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/ScsisController.cs b/Aaru.Server/Areas/Admin/Controllers/ScsisController.cs index f63b8162..ea995969 100644 --- a/Aaru.Server/Areas/Admin/Controllers/ScsisController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/ScsisController.cs @@ -14,367 +14,366 @@ using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using TestedMedia = Aaru.CommonTypes.Metadata.TestedMedia; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class ScsisController : Controller { - [Area("Admin"), Authorize] - public sealed class ScsisController : Controller + readonly AaruServerContext _context; + + public ScsisController(AaruServerContext context) => _context = context; + + // GET: Admin/Scsis + public IActionResult Index() => View(_context.Scsi.AsEnumerable(). + OrderBy(m => StringHandlers.CToString(m.Inquiry?. + VendorIdentification)). + ThenBy(m => StringHandlers.CToString(m.Inquiry?. + ProductIdentification)). + ThenBy(m => StringHandlers.CToString(m.Inquiry?. + ProductRevisionLevel))); + + // GET: Admin/Scsis/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public ScsisController(AaruServerContext context) => _context = context; - - // GET: Admin/Scsis - public IActionResult Index() => View(_context.Scsi.AsEnumerable(). - OrderBy(m => StringHandlers.CToString(m.Inquiry?. - VendorIdentification)). - ThenBy(m => StringHandlers.CToString(m.Inquiry?. - ProductIdentification)). - ThenBy(m => StringHandlers.CToString(m.Inquiry?. - ProductRevisionLevel))); - - // GET: Admin/Scsis/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - Scsi scsi = await _context.Scsi.FirstOrDefaultAsync(m => m.Id == id); - - if(scsi == null) - { - return NotFound(); - } - - return View(scsi); + return NotFound(); } - // GET: Admin/Scsis/Delete/5 - public async Task Delete(int? id) + Scsi scsi = await _context.Scsi.FirstOrDefaultAsync(m => m.Id == id); + + if(scsi == null) { - if(id == null) - { - return NotFound(); - } - - Scsi scsi = await _context.Scsi.FirstOrDefaultAsync(m => m.Id == id); - - if(scsi == null) - { - return NotFound(); - } - - return View(scsi); + return NotFound(); } - // POST: Admin/Scsis/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Scsi scsi = await _context.Scsi.FindAsync(id); - _context.Scsi.Remove(scsi); - await _context.SaveChangesAsync(); + return View(scsi); + } - return RedirectToAction(nameof(Index)); + // GET: Admin/Scsis/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); } - public IActionResult Consolidate() + Scsi scsi = await _context.Scsi.FirstOrDefaultAsync(m => m.Id == id); + + if(scsi == null) { - List hashes = _context.Scsi.Where(m => m.InquiryData != null). - Select(m => new IdHashModel(m.Id, Hash.Sha512(m.InquiryData))).ToList(); - - List dups = hashes.GroupBy(x => x.Hash).Where(g => g.Count() > 1). - Select(x => hashes.FirstOrDefault(y => y.Hash == x.Key)).ToList(); - - for(int i = 0; i < dups.Count; i++) - { - Scsi unique = _context.Scsi.First(a => a.Id == dups[i].Id); - - dups[i].Description = - $"{StringHandlers.CToString(unique.Inquiry?.VendorIdentification)} {StringHandlers.CToString(unique.Inquiry?.ProductIdentification)}"; - - dups[i].Duplicates = hashes.Where(h => h.Hash == dups[i].Hash).Skip(1).Select(x => x.Id).ToArray(); - } - - return View(new IdHashModelForView - { - List = dups, - Json = JsonConvert.SerializeObject(dups) - }); + return NotFound(); } - [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] - public IActionResult ConsolidateConfirmed(string models) + return View(scsi); + } + + // POST: Admin/Scsis/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Scsi scsi = await _context.Scsi.FindAsync(id); + _context.Scsi.Remove(scsi); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult Consolidate() + { + List hashes = _context.Scsi.Where(m => m.InquiryData != null). + Select(m => new IdHashModel(m.Id, Hash.Sha512(m.InquiryData))).ToList(); + + List dups = hashes.GroupBy(x => x.Hash).Where(g => g.Count() > 1). + Select(x => hashes.FirstOrDefault(y => y.Hash == x.Key)).ToList(); + + for(int i = 0; i < dups.Count; i++) { - IdHashModel[] duplicates; + Scsi unique = _context.Scsi.First(a => a.Id == dups[i].Id); - try + dups[i].Description = + $"{StringHandlers.CToString(unique.Inquiry?.VendorIdentification)} {StringHandlers.CToString(unique.Inquiry?.ProductIdentification)}"; + + dups[i].Duplicates = hashes.Where(h => h.Hash == dups[i].Hash).Skip(1).Select(x => x.Id).ToArray(); + } + + return View(new IdHashModelForView + { + List = dups, + Json = JsonConvert.SerializeObject(dups) + }); + } + + [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] + public IActionResult ConsolidateConfirmed(string models) + { + IdHashModel[] duplicates; + + try + { + duplicates = JsonConvert.DeserializeObject(models); + } + catch(JsonSerializationException) + { + return BadRequest(); + } + + if(duplicates is null) + return BadRequest(); + + foreach(IdHashModel duplicate in duplicates) + { + Scsi master = _context.Scsi.FirstOrDefault(m => m.Id == duplicate.Id); + + if(master is null) + continue; + + foreach(int duplicateId in duplicate.Duplicates) { - duplicates = JsonConvert.DeserializeObject(models); - } - catch(JsonSerializationException) - { - return BadRequest(); - } + Scsi slave = _context.Scsi.FirstOrDefault(m => m.Id == duplicateId); - if(duplicates is null) - return BadRequest(); - - foreach(IdHashModel duplicate in duplicates) - { - Scsi master = _context.Scsi.FirstOrDefault(m => m.Id == duplicate.Id); - - if(master is null) + if(slave is null) continue; - foreach(int duplicateId in duplicate.Duplicates) + foreach(Device scsiDevice in _context.Devices.Where(d => d.SCSI.Id == duplicateId)) { - Scsi slave = _context.Scsi.FirstOrDefault(m => m.Id == duplicateId); - - if(slave is null) - continue; - - foreach(Device scsiDevice in _context.Devices.Where(d => d.SCSI.Id == duplicateId)) - { - scsiDevice.SCSI = master; - } - - foreach(UploadedReport scsiReport in _context.Reports.Where(d => d.SCSI.Id == duplicateId)) - { - scsiReport.SCSI = master; - } - - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == duplicateId)) - { - testedMedia.ScsiId = duplicate.Id; - _context.Update(testedMedia); - } - - if(master.ReadCapabilities is null && - slave.ReadCapabilities != null) - master.ReadCapabilities = slave.ReadCapabilities; - - _context.Scsi.Remove(slave); + scsiDevice.SCSI = master; } + + foreach(UploadedReport scsiReport in _context.Reports.Where(d => d.SCSI.Id == duplicateId)) + { + scsiReport.SCSI = master; + } + + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == duplicateId)) + { + testedMedia.ScsiId = duplicate.Id; + _context.Update(testedMedia); + } + + if(master.ReadCapabilities is null && + slave.ReadCapabilities != null) + master.ReadCapabilities = slave.ReadCapabilities; + + _context.Scsi.Remove(slave); } - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); } - public IActionResult Compare(int id, int rightId) + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult Compare(int id, int rightId) + { + var model = new CompareModel { - var model = new CompareModel - { - LeftId = id, - RightId = rightId - }; + LeftId = id, + RightId = rightId + }; - Scsi left = _context.Scsi.FirstOrDefault(l => l.Id == id); - Scsi right = _context.Scsi.FirstOrDefault(r => r.Id == rightId); + Scsi left = _context.Scsi.FirstOrDefault(l => l.Id == id); + Scsi right = _context.Scsi.FirstOrDefault(r => r.Id == rightId); - if(left is null) - { - model.ErrorMessage = $"SCSI with id {id} has not been found"; - model.HasError = true; - - return View(model); - } - - if(right is null) - { - model.ErrorMessage = $"SCSI with id {rightId} has not been found"; - model.HasError = true; - - return View(model); - } - - Inquiry? leftNullable = left.Inquiry; - Inquiry? rightNullable = right.Inquiry; - model.ValueNames = new List(); - model.LeftValues = new List(); - model.RightValues = new List(); - - if(!leftNullable.HasValue && - !rightNullable.HasValue) - { - model.AreEqual = true; - - return View(model); - } - - if(leftNullable.HasValue && - !rightNullable.HasValue) - { - model.ValueNames.Add("Decoded"); - model.LeftValues.Add("decoded"); - model.RightValues.Add("null"); - - return View(model); - } - - if(!leftNullable.HasValue) - { - model.ValueNames.Add("Decoded"); - model.LeftValues.Add("null"); - model.RightValues.Add("decoded"); - - return View(model); - } - - Inquiry leftValue = left.Inquiry.Value; - Inquiry rightValue = right.Inquiry.Value; - - foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields()) - { - object lv = fieldInfo.GetValue(leftValue); - object rv = fieldInfo.GetValue(rightValue); - - if(fieldInfo.FieldType.IsArray) - { - var la = lv as Array; - var ra = rv as Array; - - switch(la) - { - case null when ra is null: continue; - case null: - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("null"); - model.RightValues.Add("[]"); - - continue; - } - - if(ra is null) - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("[]"); - model.RightValues.Add("null"); - - continue; - } - - List ll = la.Cast().ToList(); - List rl = ra.Cast().ToList(); - - for(int i = 0; i < ll.Count; i++) - { - if(ll[i].Equals(rl[i])) - continue; - - switch(fieldInfo.Name) - { - case nameof(Inquiry.KreonIdentifier): - case nameof(Inquiry.ProductIdentification): - case nameof(Inquiry.ProductRevisionLevel): - case nameof(Inquiry.Qt_ModuleRevision): - case nameof(Inquiry.Seagate_Copyright): - case nameof(Inquiry.Seagate_DriveSerialNumber): - case nameof(Inquiry.Seagate_ServoPROMPartNo): - case nameof(Inquiry.VendorIdentification): - byte[] lb = new byte[ll.Count]; - byte[] rb = new byte[rl.Count]; - - for(int j = 0; j < ll.Count; j++) - lb[j] = (byte)ll[j]; - - for(int j = 0; j < ll.Count; j++) - rb[j] = (byte)rl[j]; - - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add($"{StringHandlers.CToString(lb) ?? ""}"); - model.RightValues.Add($"{StringHandlers.CToString(rb) ?? ""}"); - - break; - - default: - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("[]"); - model.RightValues.Add("[]"); - - break; - } - - break; - } - } - else if(lv == null && - rv == null) {} - else if(lv != null && - rv == null) - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add($"{lv}"); - model.RightValues.Add("null"); - } - else if(lv == null) - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add("null"); - model.RightValues.Add($"{rv}"); - } - else if(!lv.Equals(rv)) - - { - model.ValueNames.Add(fieldInfo.Name); - model.LeftValues.Add($"{lv}"); - model.RightValues.Add($"{rv}"); - } - } - - model.AreEqual = model.LeftValues.Count == 0 && model.RightValues.Count == 0; + if(left is null) + { + model.ErrorMessage = $"SCSI with id {id} has not been found"; + model.HasError = true; return View(model); } - public IActionResult ConsolidateWithIds(int masterId, int slaveId) + if(right is null) { - Scsi master = _context.Scsi.FirstOrDefault(m => m.Id == masterId); + model.ErrorMessage = $"SCSI with id {rightId} has not been found"; + model.HasError = true; - if(master is null) - return RedirectToAction(nameof(Compare), new - { - id = masterId, - rightId = slaveId - }); - - Scsi slave = _context.Scsi.FirstOrDefault(m => m.Id == slaveId); - - if(slave is null) - return RedirectToAction(nameof(Compare), new - { - id = masterId, - rightId = slaveId - }); - - foreach(Device scsiDevice in _context.Devices.Where(d => d.SCSI.Id == slaveId)) - { - scsiDevice.SCSI = master; - } - - foreach(UploadedReport scsiReport in _context.Reports.Where(d => d.SCSI.Id == slaveId)) - { - scsiReport.SCSI = master; - } - - foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == slaveId)) - { - testedMedia.ScsiId = masterId; - _context.Update(testedMedia); - } - - if(master.ReadCapabilities is null && - slave.ReadCapabilities != null) - master.ReadCapabilities = slave.ReadCapabilities; - - _context.Scsi.Remove(slave); - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); + return View(model); } + + Inquiry? leftNullable = left.Inquiry; + Inquiry? rightNullable = right.Inquiry; + model.ValueNames = new List(); + model.LeftValues = new List(); + model.RightValues = new List(); + + if(!leftNullable.HasValue && + !rightNullable.HasValue) + { + model.AreEqual = true; + + return View(model); + } + + if(leftNullable.HasValue && + !rightNullable.HasValue) + { + model.ValueNames.Add("Decoded"); + model.LeftValues.Add("decoded"); + model.RightValues.Add("null"); + + return View(model); + } + + if(!leftNullable.HasValue) + { + model.ValueNames.Add("Decoded"); + model.LeftValues.Add("null"); + model.RightValues.Add("decoded"); + + return View(model); + } + + Inquiry leftValue = left.Inquiry.Value; + Inquiry rightValue = right.Inquiry.Value; + + foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields()) + { + object lv = fieldInfo.GetValue(leftValue); + object rv = fieldInfo.GetValue(rightValue); + + if(fieldInfo.FieldType.IsArray) + { + var la = lv as Array; + var ra = rv as Array; + + switch(la) + { + case null when ra is null: continue; + case null: + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("null"); + model.RightValues.Add("[]"); + + continue; + } + + if(ra is null) + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("[]"); + model.RightValues.Add("null"); + + continue; + } + + List ll = la.Cast().ToList(); + List rl = ra.Cast().ToList(); + + for(int i = 0; i < ll.Count; i++) + { + if(ll[i].Equals(rl[i])) + continue; + + switch(fieldInfo.Name) + { + case nameof(Inquiry.KreonIdentifier): + case nameof(Inquiry.ProductIdentification): + case nameof(Inquiry.ProductRevisionLevel): + case nameof(Inquiry.Qt_ModuleRevision): + case nameof(Inquiry.Seagate_Copyright): + case nameof(Inquiry.Seagate_DriveSerialNumber): + case nameof(Inquiry.Seagate_ServoPROMPartNo): + case nameof(Inquiry.VendorIdentification): + byte[] lb = new byte[ll.Count]; + byte[] rb = new byte[rl.Count]; + + for(int j = 0; j < ll.Count; j++) + lb[j] = (byte)ll[j]; + + for(int j = 0; j < ll.Count; j++) + rb[j] = (byte)rl[j]; + + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add($"{StringHandlers.CToString(lb) ?? ""}"); + model.RightValues.Add($"{StringHandlers.CToString(rb) ?? ""}"); + + break; + + default: + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("[]"); + model.RightValues.Add("[]"); + + break; + } + + break; + } + } + else if(lv == null && + rv == null) {} + else if(lv != null && + rv == null) + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add($"{lv}"); + model.RightValues.Add("null"); + } + else if(lv == null) + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add("null"); + model.RightValues.Add($"{rv}"); + } + else if(!lv.Equals(rv)) + + { + model.ValueNames.Add(fieldInfo.Name); + model.LeftValues.Add($"{lv}"); + model.RightValues.Add($"{rv}"); + } + } + + model.AreEqual = model.LeftValues.Count == 0 && model.RightValues.Count == 0; + + return View(model); + } + + public IActionResult ConsolidateWithIds(int masterId, int slaveId) + { + Scsi master = _context.Scsi.FirstOrDefault(m => m.Id == masterId); + + if(master is null) + return RedirectToAction(nameof(Compare), new + { + id = masterId, + rightId = slaveId + }); + + Scsi slave = _context.Scsi.FirstOrDefault(m => m.Id == slaveId); + + if(slave is null) + return RedirectToAction(nameof(Compare), new + { + id = masterId, + rightId = slaveId + }); + + foreach(Device scsiDevice in _context.Devices.Where(d => d.SCSI.Id == slaveId)) + { + scsiDevice.SCSI = master; + } + + foreach(UploadedReport scsiReport in _context.Reports.Where(d => d.SCSI.Id == slaveId)) + { + scsiReport.SCSI = master; + } + + foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.ScsiId == slaveId)) + { + testedMedia.ScsiId = masterId; + _context.Update(testedMedia); + } + + if(master.ReadCapabilities is null && + slave.ReadCapabilities != null) + master.ReadCapabilities = slave.ReadCapabilities; + + _context.Scsi.Remove(slave); + + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/SscsController.cs b/Aaru.Server/Areas/Admin/Controllers/SscsController.cs index 9ef147a9..d78dcc6d 100644 --- a/Aaru.Server/Areas/Admin/Controllers/SscsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/SscsController.cs @@ -8,116 +8,115 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class SscsController : Controller { - [Area("Admin"), Authorize] - public sealed class SscsController : Controller + readonly AaruServerContext _context; + + public SscsController(AaruServerContext context) => _context = context; + + // GET: Admin/Sscs + public async Task Index() => View(await _context.Ssc.OrderBy(s => s.MinBlockLength). + ThenBy(s => s.MaxBlockLength). + ThenBy(s => s.BlockSizeGranularity). + ToListAsync()); + + // GET: Admin/Sscs/Delete/5 + public async Task Delete(int? id) { - readonly AaruServerContext _context; - - public SscsController(AaruServerContext context) => _context = context; - - // GET: Admin/Sscs - public async Task Index() => View(await _context.Ssc.OrderBy(s => s.MinBlockLength). - ThenBy(s => s.MaxBlockLength). - ThenBy(s => s.BlockSizeGranularity). - ToListAsync()); - - // GET: Admin/Sscs/Delete/5 - public async Task Delete(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - Ssc ssc = await _context.Ssc.FirstOrDefaultAsync(m => m.Id == id); - - if(ssc == null) - { - return NotFound(); - } - - return View(ssc); + return NotFound(); } - // POST: Admin/Sscs/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Ssc ssc = await _context.Ssc.FindAsync(id); - _context.Ssc.Remove(ssc); - await _context.SaveChangesAsync(); + Ssc ssc = await _context.Ssc.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(ssc == null) + { + return NotFound(); } - public IActionResult Consolidate() - { - List dups = _context.Ssc.GroupBy(x => new - { - x.BlockSizeGranularity, - x.MaxBlockLength, - x.MinBlockLength - }).Where(x => x.Count() > 1).Select(x => new SscModel - { - BlockSizeGranularity = x.Key.BlockSizeGranularity, - MaxBlockLength = x.Key.MaxBlockLength, - MinBlockLength = x.Key.MinBlockLength - }).ToList(); + return View(ssc); + } - return View(new SscModelForView - { - List = dups, - Json = JsonConvert.SerializeObject(dups) - }); + // POST: Admin/Sscs/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Ssc ssc = await _context.Ssc.FindAsync(id); + _context.Ssc.Remove(ssc); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult Consolidate() + { + List dups = _context.Ssc.GroupBy(x => new + { + x.BlockSizeGranularity, + x.MaxBlockLength, + x.MinBlockLength + }).Where(x => x.Count() > 1).Select(x => new SscModel + { + BlockSizeGranularity = x.Key.BlockSizeGranularity, + MaxBlockLength = x.Key.MaxBlockLength, + MinBlockLength = x.Key.MinBlockLength + }).ToList(); + + return View(new SscModelForView + { + List = dups, + Json = JsonConvert.SerializeObject(dups) + }); + } + + [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] + public IActionResult ConsolidateConfirmed(string models) + { + SscModel[] duplicates; + + try + { + duplicates = JsonConvert.DeserializeObject(models); + } + catch(JsonSerializationException) + { + return BadRequest(); } - [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] - public IActionResult ConsolidateConfirmed(string models) + if(duplicates is null) + return BadRequest(); + + foreach(SscModel duplicate in duplicates) { - SscModel[] duplicates; + Ssc master = + _context.Ssc.FirstOrDefault(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity && + m.MaxBlockLength == duplicate.MaxBlockLength && + m.MinBlockLength == duplicate.MinBlockLength); - try + if(master is null) + continue; + + foreach(Ssc ssc in _context.Ssc.Where(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity && + m.MaxBlockLength == duplicate.MaxBlockLength && + m.MinBlockLength == duplicate.MinBlockLength).Skip(1). + ToArray()) { - duplicates = JsonConvert.DeserializeObject(models); - } - catch(JsonSerializationException) - { - return BadRequest(); - } - - if(duplicates is null) - return BadRequest(); - - foreach(SscModel duplicate in duplicates) - { - Ssc master = - _context.Ssc.FirstOrDefault(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity && - m.MaxBlockLength == duplicate.MaxBlockLength && - m.MinBlockLength == duplicate.MinBlockLength); - - if(master is null) - continue; - - foreach(Ssc ssc in _context.Ssc.Where(m => m.BlockSizeGranularity == duplicate.BlockSizeGranularity && - m.MaxBlockLength == duplicate.MaxBlockLength && - m.MinBlockLength == duplicate.MinBlockLength).Skip(1). - ToArray()) + foreach(TestedSequentialMedia media in _context.TestedSequentialMedia.Where(d => d.SscId == ssc.Id)) { - foreach(TestedSequentialMedia media in _context.TestedSequentialMedia.Where(d => d.SscId == ssc.Id)) - { - media.SscId = master.Id; - } - - _context.Ssc.Update(ssc); - _context.Ssc.Remove(ssc); + media.SscId = master.Id; } + + _context.Ssc.Update(ssc); + _context.Ssc.Remove(ssc); } - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); } + + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/SupportedDensitiesController.cs b/Aaru.Server/Areas/Admin/Controllers/SupportedDensitiesController.cs index e726b832..dc510c6c 100644 --- a/Aaru.Server/Areas/Admin/Controllers/SupportedDensitiesController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/SupportedDensitiesController.cs @@ -6,54 +6,53 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class SupportedDensitiesController : Controller { - [Area("Admin"), Authorize] - public sealed class SupportedDensitiesController : Controller + readonly AaruServerContext _context; + + public SupportedDensitiesController(AaruServerContext context) => _context = context; + + // GET: Admin/SupportedDensities + public async Task Index() => View(await _context.SupportedDensity.OrderBy(d => d.Organization). + ThenBy(d => d.Name).ThenBy(d => d.Description). + ThenBy(d => d.Capacity). + ThenBy(d => d.PrimaryCode). + ThenBy(d => d.SecondaryCode). + ThenBy(d => d.BitsPerMm).ThenBy(d => d.Width). + ThenBy(d => d.Tracks). + ThenBy(d => d.DefaultDensity). + ThenBy(d => d.Writable). + ThenBy(d => d.Duplicate).ToListAsync()); + + // GET: Admin/SupportedDensities/Delete/5 + public async Task Delete(int? id) { - readonly AaruServerContext _context; - - public SupportedDensitiesController(AaruServerContext context) => _context = context; - - // GET: Admin/SupportedDensities - public async Task Index() => View(await _context.SupportedDensity.OrderBy(d => d.Organization). - ThenBy(d => d.Name).ThenBy(d => d.Description). - ThenBy(d => d.Capacity). - ThenBy(d => d.PrimaryCode). - ThenBy(d => d.SecondaryCode). - ThenBy(d => d.BitsPerMm).ThenBy(d => d.Width). - ThenBy(d => d.Tracks). - ThenBy(d => d.DefaultDensity). - ThenBy(d => d.Writable). - ThenBy(d => d.Duplicate).ToListAsync()); - - // GET: Admin/SupportedDensities/Delete/5 - public async Task Delete(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - SupportedDensity supportedDensity = await _context.SupportedDensity.FirstOrDefaultAsync(m => m.Id == id); - - if(supportedDensity == null) - { - return NotFound(); - } - - return View(supportedDensity); + return NotFound(); } - // POST: Admin/SupportedDensities/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - SupportedDensity supportedDensity = await _context.SupportedDensity.FindAsync(id); - _context.SupportedDensity.Remove(supportedDensity); - await _context.SaveChangesAsync(); + SupportedDensity supportedDensity = await _context.SupportedDensity.FirstOrDefaultAsync(m => m.Id == id); - return RedirectToAction(nameof(Index)); + if(supportedDensity == null) + { + return NotFound(); } + + return View(supportedDensity); + } + + // POST: Admin/SupportedDensities/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + SupportedDensity supportedDensity = await _context.SupportedDensity.FindAsync(id); + _context.SupportedDensity.Remove(supportedDensity); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/TestedMediasController.cs b/Aaru.Server/Areas/Admin/Controllers/TestedMediasController.cs index c2d4af54..02898165 100644 --- a/Aaru.Server/Areas/Admin/Controllers/TestedMediasController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/TestedMediasController.cs @@ -20,735 +20,734 @@ using DMI = Aaru.Decoders.Xbox.DMI; using MediaType = Aaru.CommonTypes.MediaType; using Spare = Aaru.Decoders.Bluray.Spare; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class TestedMediasController : Controller { - [Area("Admin"), Authorize] - public sealed class TestedMediasController : Controller + readonly AaruServerContext _context; + + public TestedMediasController(AaruServerContext context) => _context = context; + + // GET: Admin/TestedMedias + public async Task Index() => View(await _context.TestedMedia.OrderBy(m => m.Manufacturer). + ThenBy(m => m.Model). + ThenBy(m => m.MediumTypeName). + ThenBy(m => m.MediaIsRecognized). + ThenBy(m => m.LongBlockSize). + ThenBy(m => m.BlockSize).ThenBy(m => m.Blocks). + ToListAsync()); + + // GET: Admin/TestedMedias/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public TestedMediasController(AaruServerContext context) => _context = context; - - // GET: Admin/TestedMedias - public async Task Index() => View(await _context.TestedMedia.OrderBy(m => m.Manufacturer). - ThenBy(m => m.Model). - ThenBy(m => m.MediumTypeName). - ThenBy(m => m.MediaIsRecognized). - ThenBy(m => m.LongBlockSize). - ThenBy(m => m.BlockSize).ThenBy(m => m.Blocks). - ToListAsync()); - - // GET: Admin/TestedMedias/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - TestedMedia testedMedia = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id); - - if(testedMedia == null) - { - return NotFound(); - } - - return View(testedMedia); + return NotFound(); } - // GET: Admin/TestedMedias/Edit/5 - public async Task Edit(int? id) + TestedMedia testedMedia = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id); + + if(testedMedia == null) { - if(id == null) - { - return NotFound(); - } - - TestedMedia testedMedia = await _context.TestedMedia.FindAsync(id); - - if(testedMedia == null) - { - return NotFound(); - } - - return View(testedMedia); + return NotFound(); } - // POST: Admin/TestedMedias/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit( - int id, [Bind("Id,Blocks,BlockSize,LongBlockSize,Manufacturer,MediumTypeName,Model")] - TestedMedia changedModel) + return View(testedMedia); + } + + // GET: Admin/TestedMedias/Edit/5 + public async Task Edit(int? id) + { + if(id == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - TestedMedia model = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.Blocks = changedModel.Blocks; - model.BlockSize = changedModel.BlockSize; - model.LongBlockSize = changedModel.LongBlockSize; - model.Manufacturer = changedModel.Manufacturer; - model.MediumTypeName = changedModel.MediumTypeName; - model.Model = changedModel.Model; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/TestedMedias/Delete/5 - public async Task Delete(int? id) + TestedMedia testedMedia = await _context.TestedMedia.FindAsync(id); + + if(testedMedia == null) { - if(id == null) - { - return NotFound(); - } - - TestedMedia testedMedia = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id); - - if(testedMedia == null) - { - return NotFound(); - } - - return View(testedMedia); + return NotFound(); } - // POST: Admin/TestedMedias/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) + return View(testedMedia); + } + + // POST: Admin/TestedMedias/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit( + int id, [Bind("Id,Blocks,BlockSize,LongBlockSize,Manufacturer,MediumTypeName,Model")] + TestedMedia changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + TestedMedia model = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.Blocks = changedModel.Blocks; + model.BlockSize = changedModel.BlockSize; + model.LongBlockSize = changedModel.LongBlockSize; + model.Manufacturer = changedModel.Manufacturer; + model.MediumTypeName = changedModel.MediumTypeName; + model.Model = changedModel.Model; + + try { - TestedMedia testedMedia = await _context.TestedMedia.FindAsync(id); - _context.TestedMedia.Remove(testedMedia); + _context.Update(model); await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); + } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); } - public IActionResult ViewData(int id, string data) + return RedirectToAction(nameof(Index)); + } + + // GET: Admin/TestedMedias/Delete/5 + public async Task Delete(int? id) + { + if(id == null) { - if(string.IsNullOrWhiteSpace(data)) - return NotFound(); - - TestedMedia testedMedia = _context.TestedMedia.FirstOrDefault(m => m.Id == id); - - if(testedMedia == null) - { - return NotFound(); - } - - var model = new TestedMediaDataModel - { - TestedMediaId = id, - DataName = data - }; - - byte[] buffer; - byte[] sector = new byte[2352]; - byte[] subq = new byte[16]; - byte[] fullsub = new byte[96]; - bool c2Errors = false; - bool scrambled = false; - - switch(data) - { - case nameof(testedMedia.AdipData): - buffer = testedMedia.AdipData; - - break; - case nameof(testedMedia.AtipData): - buffer = testedMedia.AtipData; - model.Decoded = ATIP.Prettify(buffer); - - break; - case nameof(testedMedia.BluBcaData): - buffer = testedMedia.BluBcaData; - - break; - case nameof(testedMedia.BluDdsData): - buffer = testedMedia.BluDdsData; - model.Decoded = DDS.Prettify(buffer); - - break; - case nameof(testedMedia.BluDiData): - buffer = testedMedia.BluDiData; - model.Decoded = DI.Prettify(buffer); - - break; - case nameof(testedMedia.BluPacData): - buffer = testedMedia.BluPacData; - model.Decoded = Cartridge.Prettify(buffer); - - break; - case nameof(testedMedia.BluSaiData): - buffer = testedMedia.BluSaiData; - model.Decoded = Spare.Prettify(buffer); - - break; - case nameof(testedMedia.C2PointersData): - buffer = testedMedia.C2PointersData; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - for(int i = 2352; i < buffer.Length; i++) - { - if(buffer[i] == 0x00) - continue; - - c2Errors = true; - - break; - } - - model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); - - break; - case nameof(testedMedia.CmiData): - buffer = testedMedia.CmiData; - model.Decoded = CSS_CPRM.PrettifyLeadInCopyright(buffer); - - break; - case nameof(testedMedia.CorrectedSubchannelData): - buffer = testedMedia.CorrectedSubchannelData; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - if(buffer.Length < 2448) - break; - - Array.Copy(buffer, 2352, fullsub, 0, 96); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - break; - case nameof(testedMedia.CorrectedSubchannelWithC2Data): - buffer = testedMedia.CorrectedSubchannelWithC2Data; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - if(buffer.Length < 2448) - break; - - for(int i = 2352; i < 2616; i++) - { - if(buffer[i] == 0x00) - continue; - - c2Errors = true; - - break; - } - - model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); - - break; - case nameof(testedMedia.DcbData): - buffer = testedMedia.DcbData; - - break; - case nameof(testedMedia.DmiData): - buffer = testedMedia.DmiData; - - if(DMI.IsXbox(buffer)) - model.Decoded = DMI.PrettifyXbox(buffer); - else if(DMI.IsXbox360(buffer)) - model.Decoded = DMI.PrettifyXbox360(buffer); - - break; - case nameof(testedMedia.DvdAacsData): - buffer = testedMedia.DvdAacsData; - - break; - case nameof(testedMedia.DvdBcaData): - buffer = testedMedia.DvdBcaData; - - break; - case nameof(testedMedia.DvdDdsData): - buffer = testedMedia.DvdDdsData; - model.Decoded = Decoders.DVD.DDS.Prettify(buffer); - - break; - case nameof(testedMedia.DvdLayerData): - buffer = testedMedia.DvdLayerData; - - break; - case nameof(testedMedia.DvdSaiData): - buffer = testedMedia.DvdSaiData; - model.Decoded = Decoders.DVD.Spare.Prettify(buffer); - - break; - case nameof(testedMedia.EmbossedPfiData): - buffer = testedMedia.EmbossedPfiData; - model.Decoded = PFI.Prettify(buffer, MediaType.DVDROM); // TODO: Get real media type here - - break; - case nameof(testedMedia.FullTocData): - buffer = testedMedia.FullTocData; - model.Decoded = FullTOC.Prettify(buffer); - - break; - case nameof(testedMedia.HdCmiData): - buffer = testedMedia.HdCmiData; - - break; - case nameof(testedMedia.HLDTSTReadRawDVDData): - buffer = testedMedia.HLDTSTReadRawDVDData; - - break; - case nameof(testedMedia.IdentifyData): - buffer = testedMedia.IdentifyData; - model.Decoded = Identify.Prettify(buffer); - - break; - case nameof(testedMedia.IntersessionLeadInData): - buffer = testedMedia.IntersessionLeadInData; - - break; - case nameof(testedMedia.IntersessionLeadOutData): - buffer = testedMedia.IntersessionLeadOutData; - - break; - case nameof(testedMedia.LeadInData): - buffer = testedMedia.LeadInData; - model.Decoded = Sector.Prettify(buffer); - - break; - case nameof(testedMedia.LeadOutData): - buffer = testedMedia.LeadOutData; - model.Decoded = Sector.Prettify(buffer); - - break; - case nameof(testedMedia.ModeSense6Data): - buffer = testedMedia.ModeSense6Data; - model.Decoded = Modes.PrettifyModeHeader6(buffer, PeripheralDeviceTypes.DirectAccess); - - break; - case nameof(testedMedia.ModeSense10Data): - buffer = testedMedia.ModeSense10Data; - model.Decoded = Modes.PrettifyModeHeader10(buffer, PeripheralDeviceTypes.DirectAccess); - - break; - case nameof(testedMedia.NecReadCddaData): - buffer = testedMedia.NecReadCddaData; - - break; - case nameof(testedMedia.PfiData): - buffer = testedMedia.PfiData; - model.Decoded = PFI.Prettify(buffer, MediaType.DVDROM); // TODO: Get real media type here - - break; - case nameof(testedMedia.PioneerReadCddaData): - buffer = testedMedia.PioneerReadCddaData; - - break; - case nameof(testedMedia.PioneerReadCddaMsfData): - buffer = testedMedia.PioneerReadCddaMsfData; - - break; - case nameof(testedMedia.PlextorReadCddaData): - buffer = testedMedia.PlextorReadCddaData; - - break; - case nameof(testedMedia.PlextorReadRawDVDData): - buffer = testedMedia.PlextorReadRawDVDData; - - break; - case nameof(testedMedia.PmaData): - buffer = testedMedia.PmaData; - model.Decoded = PMA.Prettify(buffer); - - break; - case nameof(testedMedia.PQSubchannelData): - buffer = testedMedia.PQSubchannelData; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - if(buffer.Length < 2368) - break; - - Array.Copy(buffer, 2352, subq, 0, 16); - fullsub = Subchannel.ConvertQToRaw(subq); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - break; - case nameof(testedMedia.PQSubchannelWithC2Data): - buffer = testedMedia.PQSubchannelWithC2Data; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - if(buffer.Length < 2368) - break; - - Array.Copy(buffer, 2646, subq, 0, 16); - fullsub = Subchannel.ConvertQToRaw(subq); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - for(int i = 2352; i < 2646; i++) - { - if(buffer[i] == 0x00) - continue; - - c2Errors = true; - - break; - } - - model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); - - break; - case nameof(testedMedia.PriData): - buffer = testedMedia.PriData; - - break; - case nameof(testedMedia.Read6Data): - buffer = testedMedia.Read6Data; - - break; - case nameof(testedMedia.Read10Data): - buffer = testedMedia.Read10Data; - - break; - case nameof(testedMedia.Read12Data): - buffer = testedMedia.Read12Data; - - break; - case nameof(testedMedia.Read16Data): - buffer = testedMedia.Read16Data; - - break; - case nameof(testedMedia.ReadCdData): - buffer = testedMedia.ReadCdData; - - break; - case nameof(testedMedia.ReadCdFullData): - buffer = testedMedia.ReadCdFullData; - model.Decoded = Sector.Prettify(buffer); - - break; - case nameof(testedMedia.ReadCdMsfData): - buffer = testedMedia.ReadCdMsfData; - - break; - case nameof(testedMedia.ReadCdMsfFullData): - buffer = testedMedia.ReadCdMsfFullData; - model.Decoded = Sector.Prettify(buffer); - - break; - case nameof(testedMedia.ReadDmaData): - buffer = testedMedia.ReadDmaData; - - break; - case nameof(testedMedia.ReadDmaLba48Data): - buffer = testedMedia.ReadDmaLba48Data; - - break; - case nameof(testedMedia.ReadDmaLbaData): - buffer = testedMedia.ReadDmaLbaData; - - break; - case nameof(testedMedia.ReadDmaRetryData): - buffer = testedMedia.ReadDmaRetryData; - - break; - case nameof(testedMedia.ReadDmaRetryLbaData): - buffer = testedMedia.ReadDmaRetryLbaData; - - break; - case nameof(testedMedia.ReadLba48Data): - buffer = testedMedia.ReadLba48Data; - - break; - case nameof(testedMedia.ReadLbaData): - buffer = testedMedia.ReadLbaData; - - break; - case nameof(testedMedia.ReadLong10Data): - buffer = testedMedia.ReadLong10Data; - - break; - case nameof(testedMedia.ReadLong16Data): - buffer = testedMedia.ReadLong16Data; - - break; - case nameof(testedMedia.ReadLongData): - buffer = testedMedia.ReadLongData; - - break; - case nameof(testedMedia.ReadLongLbaData): - buffer = testedMedia.ReadLongLbaData; - - break; - case nameof(testedMedia.ReadLongRetryData): - buffer = testedMedia.ReadLongRetryData; - - break; - case nameof(testedMedia.ReadLongRetryLbaData): - buffer = testedMedia.ReadLongRetryLbaData; - - break; - case nameof(testedMedia.ReadRetryLbaData): - buffer = testedMedia.ReadRetryLbaData; - - break; - case nameof(testedMedia.ReadSectorsData): - buffer = testedMedia.ReadSectorsData; - - break; - case nameof(testedMedia.ReadSectorsRetryData): - buffer = testedMedia.ReadSectorsRetryData; - - break; - case nameof(testedMedia.RWSubchannelData): - buffer = testedMedia.RWSubchannelData; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - if(buffer.Length < 2448) - break; - - Array.Copy(buffer, 2352, fullsub, 0, 96); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - break; - case nameof(testedMedia.RWSubchannelWithC2Data): - buffer = testedMedia.RWSubchannelWithC2Data; - - if(buffer is null || - buffer.Length < 2352 || - buffer.All(c => c == 0)) - break; - - Array.Copy(buffer, 0, sector, 0, 2352); - - model.Decoded = Sector.Prettify(sector); - - if(buffer.Length < 2448) - break; - - Array.Copy(buffer, 2352, fullsub, 0, 96); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - for(int i = 2448; i < buffer.Length; i++) - { - if(buffer[i] != 0x00) - { - c2Errors = true; - - break; - } - } - - model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); - - break; - case nameof(testedMedia.TocData): - buffer = testedMedia.TocData; - model.Decoded = TOC.Prettify(buffer); - - break; - case nameof(testedMedia.Track1PregapData): - buffer = testedMedia.Track1PregapData; - - model.Decoded = Sector.Prettify(buffer); - - break; - case nameof(testedMedia.ReadCdScrambledData): - buffer = testedMedia.ReadCdScrambledData; - - break; - case nameof(testedMedia.ReadF1_06Data): - buffer = testedMedia.ReadF1_06Data; - - if(buffer.Length != 0xB00) - { - model.Decoded = Sense.PrettifySense(buffer); - - break; - } - - Array.Copy(buffer, 0, sector, 0, 2352); - - if((sector[0xD] & 0x80) == 0x80) - { - scrambled = true; - Sector.Scramble(sector); - } - - model.Decoded = Sector.Prettify(sector) + "\n" + (scrambled ? "Scrambled." : "Descrambled."); - - Array.Copy(buffer, 2352, fullsub, 0, 96); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - Array.Copy(buffer, 2448, subq, 0, 16); - fullsub = Subchannel.ConvertQToRaw(subq); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - for(int i = 2468; i < 2762; i++) - { - if(buffer[i] == 0x00) - continue; - - c2Errors = true; - - break; - } - - model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); - - break; - case nameof(testedMedia.ReadF1_06LeadOutData): - buffer = testedMedia.ReadF1_06LeadOutData; - - if(buffer.Length != 0xB00) - { - model.Decoded = Sense.PrettifySense(buffer); - - break; - } - - Array.Copy(buffer, 0, sector, 0, 2352); - - if((sector[0xD] & 0x80) == 0x80) - { - scrambled = true; - Sector.Scramble(sector); - } - - model.Decoded = Sector.Prettify(sector) + "\n" + (scrambled ? "Scrambled." : "Descrambled."); - - Array.Copy(buffer, 2352, fullsub, 0, 96); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - Array.Copy(buffer, 2448, subq, 0, 16); - fullsub = Subchannel.ConvertQToRaw(subq); - - model.Decoded += "\n" + GetPrettySub(fullsub); - - for(int i = 2468; i < 2762; i++) - { - if(buffer[i] == 0x00) - continue; - - c2Errors = true; - - break; - } - - model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); - - break; - default: return NotFound(); - } - - model.RawDataAsHex = PrintHex.ByteArrayToHexArrayString(buffer); - - if(model.RawDataAsHex != null) - model.RawDataAsHex = HttpUtility.HtmlEncode(model.RawDataAsHex).Replace("\n", "
"); - - if(model.Decoded != null) - model.Decoded = HttpUtility.HtmlEncode(model.Decoded).Replace("\n", "
"); - - return View(model); + return NotFound(); } - static string GetPrettySub(byte[] sub) + TestedMedia testedMedia = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id); + + if(testedMedia == null) { - byte[] deint = Subchannel.Deinterleave(sub); + return NotFound(); + } - bool validP = true; - bool validRw = true; + return View(testedMedia); + } - for(int i = 0; i < 12; i++) - { - if(deint[i] == 0x00 || - deint[i] == 0xFF) - continue; + // POST: Admin/TestedMedias/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + TestedMedia testedMedia = await _context.TestedMedia.FindAsync(id); + _context.TestedMedia.Remove(testedMedia); + await _context.SaveChangesAsync(); - validP = false; + return RedirectToAction(nameof(Index)); + } + + public IActionResult ViewData(int id, string data) + { + if(string.IsNullOrWhiteSpace(data)) + return NotFound(); + + TestedMedia testedMedia = _context.TestedMedia.FirstOrDefault(m => m.Id == id); + + if(testedMedia == null) + { + return NotFound(); + } + + var model = new TestedMediaDataModel + { + TestedMediaId = id, + DataName = data + }; + + byte[] buffer; + byte[] sector = new byte[2352]; + byte[] subq = new byte[16]; + byte[] fullsub = new byte[96]; + bool c2Errors = false; + bool scrambled = false; + + switch(data) + { + case nameof(testedMedia.AdipData): + buffer = testedMedia.AdipData; break; - } - - for(int i = 24; i < 96; i++) - { - if(deint[i] == 0x00) - continue; - - validRw = false; + case nameof(testedMedia.AtipData): + buffer = testedMedia.AtipData; + model.Decoded = ATIP.Prettify(buffer); break; - } + case nameof(testedMedia.BluBcaData): + buffer = testedMedia.BluBcaData; - byte[] q = new byte[12]; - Array.Copy(deint, 12, q, 0, 12); + break; + case nameof(testedMedia.BluDdsData): + buffer = testedMedia.BluDdsData; + model.Decoded = DDS.Prettify(buffer); - return Subchannel.PrettifyQ(q, deint[21] > 0x10, 16, !validP, false, validRw); + break; + case nameof(testedMedia.BluDiData): + buffer = testedMedia.BluDiData; + model.Decoded = DI.Prettify(buffer); + + break; + case nameof(testedMedia.BluPacData): + buffer = testedMedia.BluPacData; + model.Decoded = Cartridge.Prettify(buffer); + + break; + case nameof(testedMedia.BluSaiData): + buffer = testedMedia.BluSaiData; + model.Decoded = Spare.Prettify(buffer); + + break; + case nameof(testedMedia.C2PointersData): + buffer = testedMedia.C2PointersData; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + for(int i = 2352; i < buffer.Length; i++) + { + if(buffer[i] == 0x00) + continue; + + c2Errors = true; + + break; + } + + model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); + + break; + case nameof(testedMedia.CmiData): + buffer = testedMedia.CmiData; + model.Decoded = CSS_CPRM.PrettifyLeadInCopyright(buffer); + + break; + case nameof(testedMedia.CorrectedSubchannelData): + buffer = testedMedia.CorrectedSubchannelData; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + if(buffer.Length < 2448) + break; + + Array.Copy(buffer, 2352, fullsub, 0, 96); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + break; + case nameof(testedMedia.CorrectedSubchannelWithC2Data): + buffer = testedMedia.CorrectedSubchannelWithC2Data; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + if(buffer.Length < 2448) + break; + + for(int i = 2352; i < 2616; i++) + { + if(buffer[i] == 0x00) + continue; + + c2Errors = true; + + break; + } + + model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); + + break; + case nameof(testedMedia.DcbData): + buffer = testedMedia.DcbData; + + break; + case nameof(testedMedia.DmiData): + buffer = testedMedia.DmiData; + + if(DMI.IsXbox(buffer)) + model.Decoded = DMI.PrettifyXbox(buffer); + else if(DMI.IsXbox360(buffer)) + model.Decoded = DMI.PrettifyXbox360(buffer); + + break; + case nameof(testedMedia.DvdAacsData): + buffer = testedMedia.DvdAacsData; + + break; + case nameof(testedMedia.DvdBcaData): + buffer = testedMedia.DvdBcaData; + + break; + case nameof(testedMedia.DvdDdsData): + buffer = testedMedia.DvdDdsData; + model.Decoded = Decoders.DVD.DDS.Prettify(buffer); + + break; + case nameof(testedMedia.DvdLayerData): + buffer = testedMedia.DvdLayerData; + + break; + case nameof(testedMedia.DvdSaiData): + buffer = testedMedia.DvdSaiData; + model.Decoded = Decoders.DVD.Spare.Prettify(buffer); + + break; + case nameof(testedMedia.EmbossedPfiData): + buffer = testedMedia.EmbossedPfiData; + model.Decoded = PFI.Prettify(buffer, MediaType.DVDROM); // TODO: Get real media type here + + break; + case nameof(testedMedia.FullTocData): + buffer = testedMedia.FullTocData; + model.Decoded = FullTOC.Prettify(buffer); + + break; + case nameof(testedMedia.HdCmiData): + buffer = testedMedia.HdCmiData; + + break; + case nameof(testedMedia.HLDTSTReadRawDVDData): + buffer = testedMedia.HLDTSTReadRawDVDData; + + break; + case nameof(testedMedia.IdentifyData): + buffer = testedMedia.IdentifyData; + model.Decoded = Identify.Prettify(buffer); + + break; + case nameof(testedMedia.IntersessionLeadInData): + buffer = testedMedia.IntersessionLeadInData; + + break; + case nameof(testedMedia.IntersessionLeadOutData): + buffer = testedMedia.IntersessionLeadOutData; + + break; + case nameof(testedMedia.LeadInData): + buffer = testedMedia.LeadInData; + model.Decoded = Sector.Prettify(buffer); + + break; + case nameof(testedMedia.LeadOutData): + buffer = testedMedia.LeadOutData; + model.Decoded = Sector.Prettify(buffer); + + break; + case nameof(testedMedia.ModeSense6Data): + buffer = testedMedia.ModeSense6Data; + model.Decoded = Modes.PrettifyModeHeader6(buffer, PeripheralDeviceTypes.DirectAccess); + + break; + case nameof(testedMedia.ModeSense10Data): + buffer = testedMedia.ModeSense10Data; + model.Decoded = Modes.PrettifyModeHeader10(buffer, PeripheralDeviceTypes.DirectAccess); + + break; + case nameof(testedMedia.NecReadCddaData): + buffer = testedMedia.NecReadCddaData; + + break; + case nameof(testedMedia.PfiData): + buffer = testedMedia.PfiData; + model.Decoded = PFI.Prettify(buffer, MediaType.DVDROM); // TODO: Get real media type here + + break; + case nameof(testedMedia.PioneerReadCddaData): + buffer = testedMedia.PioneerReadCddaData; + + break; + case nameof(testedMedia.PioneerReadCddaMsfData): + buffer = testedMedia.PioneerReadCddaMsfData; + + break; + case nameof(testedMedia.PlextorReadCddaData): + buffer = testedMedia.PlextorReadCddaData; + + break; + case nameof(testedMedia.PlextorReadRawDVDData): + buffer = testedMedia.PlextorReadRawDVDData; + + break; + case nameof(testedMedia.PmaData): + buffer = testedMedia.PmaData; + model.Decoded = PMA.Prettify(buffer); + + break; + case nameof(testedMedia.PQSubchannelData): + buffer = testedMedia.PQSubchannelData; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + if(buffer.Length < 2368) + break; + + Array.Copy(buffer, 2352, subq, 0, 16); + fullsub = Subchannel.ConvertQToRaw(subq); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + break; + case nameof(testedMedia.PQSubchannelWithC2Data): + buffer = testedMedia.PQSubchannelWithC2Data; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + if(buffer.Length < 2368) + break; + + Array.Copy(buffer, 2646, subq, 0, 16); + fullsub = Subchannel.ConvertQToRaw(subq); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + for(int i = 2352; i < 2646; i++) + { + if(buffer[i] == 0x00) + continue; + + c2Errors = true; + + break; + } + + model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); + + break; + case nameof(testedMedia.PriData): + buffer = testedMedia.PriData; + + break; + case nameof(testedMedia.Read6Data): + buffer = testedMedia.Read6Data; + + break; + case nameof(testedMedia.Read10Data): + buffer = testedMedia.Read10Data; + + break; + case nameof(testedMedia.Read12Data): + buffer = testedMedia.Read12Data; + + break; + case nameof(testedMedia.Read16Data): + buffer = testedMedia.Read16Data; + + break; + case nameof(testedMedia.ReadCdData): + buffer = testedMedia.ReadCdData; + + break; + case nameof(testedMedia.ReadCdFullData): + buffer = testedMedia.ReadCdFullData; + model.Decoded = Sector.Prettify(buffer); + + break; + case nameof(testedMedia.ReadCdMsfData): + buffer = testedMedia.ReadCdMsfData; + + break; + case nameof(testedMedia.ReadCdMsfFullData): + buffer = testedMedia.ReadCdMsfFullData; + model.Decoded = Sector.Prettify(buffer); + + break; + case nameof(testedMedia.ReadDmaData): + buffer = testedMedia.ReadDmaData; + + break; + case nameof(testedMedia.ReadDmaLba48Data): + buffer = testedMedia.ReadDmaLba48Data; + + break; + case nameof(testedMedia.ReadDmaLbaData): + buffer = testedMedia.ReadDmaLbaData; + + break; + case nameof(testedMedia.ReadDmaRetryData): + buffer = testedMedia.ReadDmaRetryData; + + break; + case nameof(testedMedia.ReadDmaRetryLbaData): + buffer = testedMedia.ReadDmaRetryLbaData; + + break; + case nameof(testedMedia.ReadLba48Data): + buffer = testedMedia.ReadLba48Data; + + break; + case nameof(testedMedia.ReadLbaData): + buffer = testedMedia.ReadLbaData; + + break; + case nameof(testedMedia.ReadLong10Data): + buffer = testedMedia.ReadLong10Data; + + break; + case nameof(testedMedia.ReadLong16Data): + buffer = testedMedia.ReadLong16Data; + + break; + case nameof(testedMedia.ReadLongData): + buffer = testedMedia.ReadLongData; + + break; + case nameof(testedMedia.ReadLongLbaData): + buffer = testedMedia.ReadLongLbaData; + + break; + case nameof(testedMedia.ReadLongRetryData): + buffer = testedMedia.ReadLongRetryData; + + break; + case nameof(testedMedia.ReadLongRetryLbaData): + buffer = testedMedia.ReadLongRetryLbaData; + + break; + case nameof(testedMedia.ReadRetryLbaData): + buffer = testedMedia.ReadRetryLbaData; + + break; + case nameof(testedMedia.ReadSectorsData): + buffer = testedMedia.ReadSectorsData; + + break; + case nameof(testedMedia.ReadSectorsRetryData): + buffer = testedMedia.ReadSectorsRetryData; + + break; + case nameof(testedMedia.RWSubchannelData): + buffer = testedMedia.RWSubchannelData; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + if(buffer.Length < 2448) + break; + + Array.Copy(buffer, 2352, fullsub, 0, 96); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + break; + case nameof(testedMedia.RWSubchannelWithC2Data): + buffer = testedMedia.RWSubchannelWithC2Data; + + if(buffer is null || + buffer.Length < 2352 || + buffer.All(c => c == 0)) + break; + + Array.Copy(buffer, 0, sector, 0, 2352); + + model.Decoded = Sector.Prettify(sector); + + if(buffer.Length < 2448) + break; + + Array.Copy(buffer, 2352, fullsub, 0, 96); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + for(int i = 2448; i < buffer.Length; i++) + { + if(buffer[i] != 0x00) + { + c2Errors = true; + + break; + } + } + + model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); + + break; + case nameof(testedMedia.TocData): + buffer = testedMedia.TocData; + model.Decoded = TOC.Prettify(buffer); + + break; + case nameof(testedMedia.Track1PregapData): + buffer = testedMedia.Track1PregapData; + + model.Decoded = Sector.Prettify(buffer); + + break; + case nameof(testedMedia.ReadCdScrambledData): + buffer = testedMedia.ReadCdScrambledData; + + break; + case nameof(testedMedia.ReadF1_06Data): + buffer = testedMedia.ReadF1_06Data; + + if(buffer.Length != 0xB00) + { + model.Decoded = Sense.PrettifySense(buffer); + + break; + } + + Array.Copy(buffer, 0, sector, 0, 2352); + + if((sector[0xD] & 0x80) == 0x80) + { + scrambled = true; + Sector.Scramble(sector); + } + + model.Decoded = Sector.Prettify(sector) + "\n" + (scrambled ? "Scrambled." : "Descrambled."); + + Array.Copy(buffer, 2352, fullsub, 0, 96); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + Array.Copy(buffer, 2448, subq, 0, 16); + fullsub = Subchannel.ConvertQToRaw(subq); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + for(int i = 2468; i < 2762; i++) + { + if(buffer[i] == 0x00) + continue; + + c2Errors = true; + + break; + } + + model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); + + break; + case nameof(testedMedia.ReadF1_06LeadOutData): + buffer = testedMedia.ReadF1_06LeadOutData; + + if(buffer.Length != 0xB00) + { + model.Decoded = Sense.PrettifySense(buffer); + + break; + } + + Array.Copy(buffer, 0, sector, 0, 2352); + + if((sector[0xD] & 0x80) == 0x80) + { + scrambled = true; + Sector.Scramble(sector); + } + + model.Decoded = Sector.Prettify(sector) + "\n" + (scrambled ? "Scrambled." : "Descrambled."); + + Array.Copy(buffer, 2352, fullsub, 0, 96); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + Array.Copy(buffer, 2448, subq, 0, 16); + fullsub = Subchannel.ConvertQToRaw(subq); + + model.Decoded += "\n" + GetPrettySub(fullsub); + + for(int i = 2468; i < 2762; i++) + { + if(buffer[i] == 0x00) + continue; + + c2Errors = true; + + break; + } + + model.Decoded += "\n" + (c2Errors ? "C2 errors found." : "No C2 errors."); + + break; + default: return NotFound(); } + + model.RawDataAsHex = PrintHex.ByteArrayToHexArrayString(buffer); + + if(model.RawDataAsHex != null) + model.RawDataAsHex = HttpUtility.HtmlEncode(model.RawDataAsHex).Replace("\n", "
"); + + if(model.Decoded != null) + model.Decoded = HttpUtility.HtmlEncode(model.Decoded).Replace("\n", "
"); + + return View(model); + } + + static string GetPrettySub(byte[] sub) + { + byte[] deint = Subchannel.Deinterleave(sub); + + bool validP = true; + bool validRw = true; + + for(int i = 0; i < 12; i++) + { + if(deint[i] == 0x00 || + deint[i] == 0xFF) + continue; + + validP = false; + + break; + } + + for(int i = 24; i < 96; i++) + { + if(deint[i] == 0x00) + continue; + + validRw = false; + + break; + } + + byte[] q = new byte[12]; + Array.Copy(deint, 12, q, 0, 12); + + return Subchannel.PrettifyQ(q, deint[21] > 0x10, 16, !validP, false, validRw); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/TestedSequentialMediasController.cs b/Aaru.Server/Areas/Admin/Controllers/TestedSequentialMediasController.cs index 54c4da3d..686e2d93 100644 --- a/Aaru.Server/Areas/Admin/Controllers/TestedSequentialMediasController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/TestedSequentialMediasController.cs @@ -6,102 +6,101 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class TestedSequentialMediasController : Controller { - [Area("Admin"), Authorize] - public sealed class TestedSequentialMediasController : Controller + readonly AaruServerContext _context; + + public TestedSequentialMediasController(AaruServerContext context) => _context = context; + + // GET: Admin/TestedSequentialMedias + public async Task Index() => View(await _context.TestedSequentialMedia. + OrderBy(m => m.Manufacturer). + ThenBy(m => m.Model). + ThenBy(m => m.MediumTypeName).ToListAsync()); + + // GET: Admin/TestedSequentialMedias/Edit/5 + public async Task Edit(int? id) { - readonly AaruServerContext _context; - - public TestedSequentialMediasController(AaruServerContext context) => _context = context; - - // GET: Admin/TestedSequentialMedias - public async Task Index() => View(await _context.TestedSequentialMedia. - OrderBy(m => m.Manufacturer). - ThenBy(m => m.Model). - ThenBy(m => m.MediumTypeName).ToListAsync()); - - // GET: Admin/TestedSequentialMedias/Edit/5 - public async Task Edit(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - TestedSequentialMedia testedSequentialMedia = await _context.TestedSequentialMedia.FindAsync(id); - - if(testedSequentialMedia == null) - { - return NotFound(); - } - - return View(testedSequentialMedia); + return NotFound(); } - // POST: Admin/TestedSequentialMedias/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit(int id, [Bind("Id,Manufacturer,MediumTypeName,Model")] - TestedSequentialMedia changedModel) + TestedSequentialMedia testedSequentialMedia = await _context.TestedSequentialMedia.FindAsync(id); + + if(testedSequentialMedia == null) { - if(id != changedModel.Id) - return NotFound(); - - if(!ModelState.IsValid) - return View(changedModel); - - TestedSequentialMedia model = await _context.TestedSequentialMedia.FirstOrDefaultAsync(m => m.Id == id); - - if(model is null) - return NotFound(); - - model.Manufacturer = changedModel.Manufacturer; - model.MediumTypeName = changedModel.MediumTypeName; - model.Model = changedModel.Model; - - try - { - _context.Update(model); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); - } - - return RedirectToAction(nameof(Index)); + return NotFound(); } - // GET: Admin/TestedSequentialMedias/Delete/5 - public async Task Delete(int? id) + return View(testedSequentialMedia); + } + + // POST: Admin/TestedSequentialMedias/Edit/5 + // To protect from overposting attacks, please enable the specific properties you want to bind to, for + // more details see http://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost, ValidateAntiForgeryToken] + public async Task Edit(int id, [Bind("Id,Manufacturer,MediumTypeName,Model")] + TestedSequentialMedia changedModel) + { + if(id != changedModel.Id) + return NotFound(); + + if(!ModelState.IsValid) + return View(changedModel); + + TestedSequentialMedia model = await _context.TestedSequentialMedia.FirstOrDefaultAsync(m => m.Id == id); + + if(model is null) + return NotFound(); + + model.Manufacturer = changedModel.Manufacturer; + model.MediumTypeName = changedModel.MediumTypeName; + model.Model = changedModel.Model; + + try { - if(id == null) - { - return NotFound(); - } - - TestedSequentialMedia testedSequentialMedia = - await _context.TestedSequentialMedia.FirstOrDefaultAsync(m => m.Id == id); - - if(testedSequentialMedia == null) - { - return NotFound(); - } - - return View(testedSequentialMedia); - } - - // POST: Admin/TestedSequentialMedias/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - TestedSequentialMedia testedSequentialMedia = await _context.TestedSequentialMedia.FindAsync(id); - _context.TestedSequentialMedia.Remove(testedSequentialMedia); + _context.Update(model); await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); } + catch(DbUpdateConcurrencyException) + { + ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator."); + } + + return RedirectToAction(nameof(Index)); + } + + // GET: Admin/TestedSequentialMedias/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); + } + + TestedSequentialMedia testedSequentialMedia = + await _context.TestedSequentialMedia.FirstOrDefaultAsync(m => m.Id == id); + + if(testedSequentialMedia == null) + { + return NotFound(); + } + + return View(testedSequentialMedia); + } + + // POST: Admin/TestedSequentialMedias/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + TestedSequentialMedia testedSequentialMedia = await _context.TestedSequentialMedia.FindAsync(id); + _context.TestedSequentialMedia.Remove(testedSequentialMedia); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/UsbProductsController.cs b/Aaru.Server/Areas/Admin/Controllers/UsbProductsController.cs index a8405ee5..46adeb77 100644 --- a/Aaru.Server/Areas/Admin/Controllers/UsbProductsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/UsbProductsController.cs @@ -5,25 +5,24 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class UsbProductsController : Controller { - [Area("Admin"), Authorize] - public sealed class UsbProductsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public UsbProductsController(AaruServerContext context) => _context = context; + public UsbProductsController(AaruServerContext context) => _context = context; - // GET: Admin/UsbProducts - public async Task Index() => View(await _context.UsbProducts.Include(u => u.Vendor). - OrderBy(p => p.Vendor.Vendor). - ThenBy(p => p.Product).ThenBy(p => p.ProductId). - Select(p => new UsbProductModel - { - ProductId = p.ProductId, - ProductName = p.Product, - VendorId = p.Vendor.Id, - VendorName = p.Vendor.Vendor - }).ToListAsync()); - } + // GET: Admin/UsbProducts + public async Task Index() => View(await _context.UsbProducts.Include(u => u.Vendor). + OrderBy(p => p.Vendor.Vendor). + ThenBy(p => p.Product).ThenBy(p => p.ProductId). + Select(p => new UsbProductModel + { + ProductId = p.ProductId, + ProductName = p.Product, + VendorId = p.Vendor.Id, + VendorName = p.Vendor.Vendor + }).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/UsbVendorsController.cs b/Aaru.Server/Areas/Admin/Controllers/UsbVendorsController.cs index 144ebae8..6be7d938 100644 --- a/Aaru.Server/Areas/Admin/Controllers/UsbVendorsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/UsbVendorsController.cs @@ -5,45 +5,44 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class UsbVendorsController : Controller { - [Area("Admin"), Authorize] - public sealed class UsbVendorsController : Controller + readonly AaruServerContext _context; + + public UsbVendorsController(AaruServerContext context) => _context = context; + + // GET: Admin/UsbVendors + public async Task Index() => + View(await _context.UsbVendors.OrderBy(v => v.Vendor).ThenBy(v => v.VendorId).ToListAsync()); + + // GET: Admin/UsbVendors/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public UsbVendorsController(AaruServerContext context) => _context = context; - - // GET: Admin/UsbVendors - public async Task Index() => - View(await _context.UsbVendors.OrderBy(v => v.Vendor).ThenBy(v => v.VendorId).ToListAsync()); - - // GET: Admin/UsbVendors/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - UsbVendor usbVendor = await _context.UsbVendors.FirstOrDefaultAsync(m => m.Id == id); - - if(usbVendor == null) - { - return NotFound(); - } - - return View(new UsbVendorModel - { - Vendor = usbVendor.Vendor, - VendorId = usbVendor.VendorId, - Products = _context.UsbProducts.Where(p => p.VendorId == usbVendor.Id).OrderBy(p => p.Product). - ThenBy(p => p.ProductId).Select(p => new UsbProductModel - { - ProductId = p.ProductId, - ProductName = p.Product - }).ToList() - }); + return NotFound(); } + + UsbVendor usbVendor = await _context.UsbVendors.FirstOrDefaultAsync(m => m.Id == id); + + if(usbVendor == null) + { + return NotFound(); + } + + return View(new UsbVendorModel + { + Vendor = usbVendor.Vendor, + VendorId = usbVendor.VendorId, + Products = _context.UsbProducts.Where(p => p.VendorId == usbVendor.Id).OrderBy(p => p.Product). + ThenBy(p => p.ProductId).Select(p => new UsbProductModel + { + ProductId = p.ProductId, + ProductName = p.Product + }).ToList() + }); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/UsbsController.cs b/Aaru.Server/Areas/Admin/Controllers/UsbsController.cs index 20895893..630e8b80 100644 --- a/Aaru.Server/Areas/Admin/Controllers/UsbsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/UsbsController.cs @@ -8,153 +8,152 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class UsbsController : Controller { - [Area("Admin"), Authorize] - public sealed class UsbsController : Controller + readonly AaruServerContext _context; + + public UsbsController(AaruServerContext context) => _context = context; + + // GET: Admin/Usbs + public async Task Index() => View(await _context.Usb.OrderBy(u => u.Manufacturer). + ThenBy(u => u.Product).ThenBy(u => u.VendorID). + ThenBy(u => u.ProductID).ToListAsync()); + + // GET: Admin/Usbs/Details/5 + public async Task Details(int? id) { - readonly AaruServerContext _context; - - public UsbsController(AaruServerContext context) => _context = context; - - // GET: Admin/Usbs - public async Task Index() => View(await _context.Usb.OrderBy(u => u.Manufacturer). - ThenBy(u => u.Product).ThenBy(u => u.VendorID). - ThenBy(u => u.ProductID).ToListAsync()); - - // GET: Admin/Usbs/Details/5 - public async Task Details(int? id) + if(id == null) { - if(id == null) - { - return NotFound(); - } - - Usb usb = await _context.Usb.FirstOrDefaultAsync(m => m.Id == id); - - if(usb == null) - { - return NotFound(); - } - - return View(usb); + return NotFound(); } - // GET: Admin/Usbs/Delete/5 - public async Task Delete(int? id) + Usb usb = await _context.Usb.FirstOrDefaultAsync(m => m.Id == id); + + if(usb == null) { - if(id == null) - { - return NotFound(); - } - - Usb usb = await _context.Usb.FirstOrDefaultAsync(m => m.Id == id); - - if(usb == null) - { - return NotFound(); - } - - return View(usb); + return NotFound(); } - // POST: Admin/Usbs/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Usb usb = await _context.Usb.FindAsync(id); - _context.Usb.Remove(usb); - await _context.SaveChangesAsync(); + return View(usb); + } - return RedirectToAction(nameof(Index)); + // GET: Admin/Usbs/Delete/5 + public async Task Delete(int? id) + { + if(id == null) + { + return NotFound(); } - public IActionResult Consolidate() - { - List dups = _context.Usb.GroupBy(x => new - { - x.Manufacturer, - x.Product, - x.VendorID, - x.ProductID - }).Where(x => x.Count() > 1).Select(x => new UsbModel - { - Manufacturer = x.Key.Manufacturer, - Product = x.Key.Product, - VendorID = x.Key.VendorID, - ProductID = x.Key.ProductID - }).ToList(); + Usb usb = await _context.Usb.FirstOrDefaultAsync(m => m.Id == id); - return View(new UsbModelForView - { - List = dups, - Json = JsonConvert.SerializeObject(dups) - }); + if(usb == null) + { + return NotFound(); } - [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] - public IActionResult ConsolidateConfirmed(string models) + return View(usb); + } + + // POST: Admin/Usbs/Delete/5 + [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] + public async Task DeleteConfirmed(int id) + { + Usb usb = await _context.Usb.FindAsync(id); + _context.Usb.Remove(usb); + await _context.SaveChangesAsync(); + + return RedirectToAction(nameof(Index)); + } + + public IActionResult Consolidate() + { + List dups = _context.Usb.GroupBy(x => new { - UsbModel[] duplicates; + x.Manufacturer, + x.Product, + x.VendorID, + x.ProductID + }).Where(x => x.Count() > 1).Select(x => new UsbModel + { + Manufacturer = x.Key.Manufacturer, + Product = x.Key.Product, + VendorID = x.Key.VendorID, + ProductID = x.Key.ProductID + }).ToList(); - try + return View(new UsbModelForView + { + List = dups, + Json = JsonConvert.SerializeObject(dups) + }); + } + + [HttpPost, ActionName("Consolidate"), ValidateAntiForgeryToken] + public IActionResult ConsolidateConfirmed(string models) + { + UsbModel[] duplicates; + + try + { + duplicates = JsonConvert.DeserializeObject(models); + } + catch(JsonSerializationException) + { + return BadRequest(); + } + + if(duplicates is null) + return BadRequest(); + + foreach(UsbModel duplicate in duplicates) + { + Usb master = _context.Usb.FirstOrDefault(m => m.Manufacturer == duplicate.Manufacturer && + m.Product == duplicate.Product && + m.VendorID == duplicate.VendorID && + m.ProductID == duplicate.ProductID); + + if(master is null) + continue; + + foreach(Usb slave in _context.Usb.Where(m => m.Manufacturer == duplicate.Manufacturer && + m.Product == duplicate.Product && + m.VendorID == duplicate.VendorID && + m.ProductID == duplicate.ProductID).Skip(1).ToArray()) { - duplicates = JsonConvert.DeserializeObject(models); - } - catch(JsonSerializationException) - { - return BadRequest(); - } - - if(duplicates is null) - return BadRequest(); - - foreach(UsbModel duplicate in duplicates) - { - Usb master = _context.Usb.FirstOrDefault(m => m.Manufacturer == duplicate.Manufacturer && - m.Product == duplicate.Product && - m.VendorID == duplicate.VendorID && - m.ProductID == duplicate.ProductID); - - if(master is null) - continue; - - foreach(Usb slave in _context.Usb.Where(m => m.Manufacturer == duplicate.Manufacturer && - m.Product == duplicate.Product && - m.VendorID == duplicate.VendorID && - m.ProductID == duplicate.ProductID).Skip(1).ToArray()) + if(slave.Descriptors != null && + master.Descriptors != null) { - if(slave.Descriptors != null && - master.Descriptors != null) - { - if(!master.Descriptors.SequenceEqual(slave.Descriptors)) - continue; - } - - foreach(Device device in _context.Devices.Where(d => d.USB.Id == slave.Id)) - { - device.USB = master; - } - - foreach(UploadedReport report in _context.Reports.Where(d => d.USB.Id == slave.Id)) - { - report.USB = master; - } - - if(master.Descriptors is null && - slave.Descriptors != null) - { - master.Descriptors = slave.Descriptors; - _context.Usb.Update(master); - } - - _context.Usb.Remove(slave); + if(!master.Descriptors.SequenceEqual(slave.Descriptors)) + continue; } + + foreach(Device device in _context.Devices.Where(d => d.USB.Id == slave.Id)) + { + device.USB = master; + } + + foreach(UploadedReport report in _context.Reports.Where(d => d.USB.Id == slave.Id)) + { + report.USB = master; + } + + if(master.Descriptors is null && + slave.Descriptors != null) + { + master.Descriptors = slave.Descriptors; + _context.Usb.Update(master); + } + + _context.Usb.Remove(slave); } - - _context.SaveChanges(); - - return RedirectToAction(nameof(Index)); } + + _context.SaveChanges(); + + return RedirectToAction(nameof(Index)); } } \ No newline at end of file diff --git a/Aaru.Server/Areas/Admin/Controllers/VersionsController.cs b/Aaru.Server/Areas/Admin/Controllers/VersionsController.cs index b880b7b0..1d120b83 100644 --- a/Aaru.Server/Areas/Admin/Controllers/VersionsController.cs +++ b/Aaru.Server/Areas/Admin/Controllers/VersionsController.cs @@ -5,16 +5,15 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace Aaru.Server.Areas.Admin.Controllers +namespace Aaru.Server.Areas.Admin.Controllers; + +[Area("Admin"), Authorize] +public sealed class VersionsController : Controller { - [Area("Admin"), Authorize] - public sealed class VersionsController : Controller - { - readonly AaruServerContext _context; + readonly AaruServerContext _context; - public VersionsController(AaruServerContext context) => _context = context; + public VersionsController(AaruServerContext context) => _context = context; - // GET: Admin/Versions - public async Task Index() => View(await _context.Versions.OrderBy(v => v.Name).ToListAsync()); - } + // GET: Admin/Versions + public async Task Index() => View(await _context.Versions.OrderBy(v => v.Name).ToListAsync()); } \ No newline at end of file diff --git a/Aaru.Server/Areas/Identity/Pages/Account/Register.cshtml.cs b/Aaru.Server/Areas/Identity/Pages/Account/Register.cshtml.cs index 9794552a..9ce5241f 100644 --- a/Aaru.Server/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/Aaru.Server/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -2,13 +2,12 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace Aaru.Server.Areas.Identity.Pages.Account -{ - [AllowAnonymous] - public sealed class RegisterModel : PageModel - { - public IActionResult OnGetAsync(string returnUrl = null) => RedirectToPage("Login"); +namespace Aaru.Server.Areas.Identity.Pages.Account; - public IActionResult OnPostAsync(string returnUrl = null) => RedirectToPage("Login"); - } +[AllowAnonymous] +public sealed class RegisterModel : PageModel +{ + public IActionResult OnGetAsync(string returnUrl = null) => RedirectToPage("Login"); + + public IActionResult OnPostAsync(string returnUrl = null) => RedirectToPage("Login"); } \ No newline at end of file diff --git a/Aaru.Server/BasicAuthMiddleware.cs b/Aaru.Server/BasicAuthMiddleware.cs index 0922ccf2..543e72f5 100644 --- a/Aaru.Server/BasicAuthMiddleware.cs +++ b/Aaru.Server/BasicAuthMiddleware.cs @@ -10,71 +10,70 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; -namespace Aaru.Server +namespace Aaru.Server; + +public sealed class BasicAuthMiddleware { - public sealed class BasicAuthMiddleware + readonly RequestDelegate _next; + readonly string _realm; + + public BasicAuthMiddleware(RequestDelegate next, string realm) { - readonly RequestDelegate _next; - readonly string _realm; + _next = next; + _realm = realm; + } - public BasicAuthMiddleware(RequestDelegate next, string realm) + public async Task Invoke(HttpContext context) + { + string authHeader = context.Request.Headers["Authorization"]; + + if(authHeader?.StartsWith("Basic ") == true) { - _next = next; - _realm = realm; - } + // Get the encoded username and password + string encodedUsernamePassword = + authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1]?.Trim(); - public async Task Invoke(HttpContext context) - { - string authHeader = context.Request.Headers["Authorization"]; + // Decode from Base64 to string + string decodedUsernamePassword = + Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernamePassword)); - if(authHeader?.StartsWith("Basic ") == true) + // Split username and password + string username = decodedUsernamePassword.Split(':', 2)[0]; + string password = decodedUsernamePassword.Split(':', 2)[1]; + + // Check if login is correct + if(IsAuthorized(username, password)) { - // Get the encoded username and password - string encodedUsernamePassword = - authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1]?.Trim(); + await _next.Invoke(context); - // Decode from Base64 to string - string decodedUsernamePassword = - Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernamePassword)); - - // Split username and password - string username = decodedUsernamePassword.Split(':', 2)[0]; - string password = decodedUsernamePassword.Split(':', 2)[1]; - - // Check if login is correct - if(IsAuthorized(username, password)) - { - await _next.Invoke(context); - - return; - } + return; } - - // Return authentication type (causes browser to show login dialog) - context.Response.Headers["WWW-Authenticate"] = "Basic"; - - // Add realm if it is not null - if(!string.IsNullOrWhiteSpace(_realm)) - { - context.Response.Headers["WWW-Authenticate"] += $" realm=\"{_realm}\""; - } - - // Return unauthorized - context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; } - // Make your own implementation of this - // Check that username and password are correct - public bool IsAuthorized(string username, string password) + // Return authentication type (causes browser to show login dialog) + context.Response.Headers["WWW-Authenticate"] = "Basic"; + + // Add realm if it is not null + if(!string.IsNullOrWhiteSpace(_realm)) { - IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); - IConfigurationRoot configuration = builder.Build(); - string validUser = configuration.GetValue("MetricsAuthentication:Username"); - string validPassword = configuration.GetValue("MetricsAuthentication:Password"); - - return !string.IsNullOrWhiteSpace(validUser) && !string.IsNullOrWhiteSpace(validPassword) && - username.Equals(validUser, StringComparison.InvariantCultureIgnoreCase) && - password.Equals(validPassword); + context.Response.Headers["WWW-Authenticate"] += $" realm=\"{_realm}\""; } + + // Return unauthorized + context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; + } + + // Make your own implementation of this + // Check that username and password are correct + public bool IsAuthorized(string username, string password) + { + IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); + IConfigurationRoot configuration = builder.Build(); + string validUser = configuration.GetValue("MetricsAuthentication:Username"); + string validPassword = configuration.GetValue("MetricsAuthentication:Password"); + + return !string.IsNullOrWhiteSpace(validUser) && !string.IsNullOrWhiteSpace(validPassword) && + username.Equals(validUser, StringComparison.InvariantCultureIgnoreCase) && + password.Equals(validPassword); } } \ No newline at end of file diff --git a/Aaru.Server/Controllers/ReportController.cs b/Aaru.Server/Controllers/ReportController.cs index edf18844..fad558b1 100644 --- a/Aaru.Server/Controllers/ReportController.cs +++ b/Aaru.Server/Controllers/ReportController.cs @@ -46,498 +46,497 @@ using Inquiry = Aaru.CommonTypes.Structs.Devices.SCSI.Inquiry; using TestedMedia = Aaru.CommonTypes.Metadata.TestedMedia; using Tuple = Aaru.Decoders.PCMCIA.Tuple; -namespace Aaru.Server.Controllers +namespace Aaru.Server.Controllers; + +public sealed class ReportController : Controller { - public sealed class ReportController : Controller + readonly AaruServerContext _ctx; + + public ReportController(AaruServerContext context) => _ctx = context; + + public ActionResult Index() => RedirectToAction("View", "Report", new RouteValueDictionary { - readonly AaruServerContext _ctx; - - public ReportController(AaruServerContext context) => _ctx = context; - - public ActionResult Index() => RedirectToAction("View", "Report", new RouteValueDictionary { + "id", 1 + } + }); + + public ActionResult View(int? id) + { + if(id == null || + id <= 0) + return Content("Incorrect device report request"); + + try + { + Device report = _ctx.Devices.FirstOrDefault(d => d.Id == id); + + if(report is null) + return Content("Cannot find requested report"); + + ViewBag.lblManufacturer = report.Manufacturer; + ViewBag.lblModel = report.Model; + ViewBag.lblRevision = report.Revision; + + if(report.USB != null) { - "id", 1 + string usbVendorDescription = null; + string usbProductDescription = null; + + UsbProduct dbProduct = + _ctx.UsbProducts.FirstOrDefault(p => p.ProductId == report.USB.ProductID && p.Vendor != null && + p.Vendor.VendorId == report.USB.VendorID); + + if(dbProduct is null) + { + UsbVendor dbVendor = _ctx.UsbVendors.FirstOrDefault(v => v.VendorId == report.USB.VendorID); + + if(!(dbVendor is null)) + usbVendorDescription = dbVendor.Vendor; + } + else + { + usbProductDescription = dbProduct.Product; + usbVendorDescription = dbProduct.Vendor.Vendor; + } + + ViewBag.UsbItem = new Item + { + Manufacturer = report.USB.Manufacturer, + Product = report.USB.Product, + VendorDescription = usbVendorDescription != null + ? $"0x{report.USB.VendorID:x4} ({usbVendorDescription})" + : $"0x{report.USB.VendorID:x4}", + ProductDescription = usbProductDescription != null + ? $"0x{report.USB.ProductID:x4} ({usbProductDescription})" + : $"0x{report.USB.ProductID:x4}" + }; } - }); - public ActionResult View(int? id) - { - if(id == null || - id <= 0) - return Content("Incorrect device report request"); + if(report.FireWire != null) + ViewBag.FireWireItem = new Item + { + Manufacturer = report.FireWire.Manufacturer, + Product = report.FireWire.Product, + VendorDescription = $"0x{report.FireWire.VendorID:x8}", + ProductDescription = $"0x{report.FireWire.ProductID:x8}" + }; - try + if(report.PCMCIA != null) { - Device report = _ctx.Devices.FirstOrDefault(d => d.Id == id); - - if(report is null) - return Content("Cannot find requested report"); - - ViewBag.lblManufacturer = report.Manufacturer; - ViewBag.lblModel = report.Model; - ViewBag.lblRevision = report.Revision; - - if(report.USB != null) + ViewBag.PcmciaItem = new PcmciaItem { - string usbVendorDescription = null; - string usbProductDescription = null; + Manufacturer = report.PCMCIA.Manufacturer, + Product = report.PCMCIA.ProductName, + VendorDescription = $"0x{report.PCMCIA.ManufacturerCode:x4}", + ProductDescription = $"0x{report.PCMCIA.CardCode:x4}", + Compliance = report.PCMCIA.Compliance + }; - UsbProduct dbProduct = - _ctx.UsbProducts.FirstOrDefault(p => p.ProductId == report.USB.ProductID && p.Vendor != null && - p.Vendor.VendorId == report.USB.VendorID); + Tuple[] tuples = CIS.GetTuples(report.PCMCIA.CIS); - if(dbProduct is null) - { - UsbVendor dbVendor = _ctx.UsbVendors.FirstOrDefault(v => v.VendorId == report.USB.VendorID); + if(tuples != null) + { + Dictionary decodedTuples = new(); - if(!(dbVendor is null)) - usbVendorDescription = dbVendor.Vendor; - } - else - { - usbProductDescription = dbProduct.Product; - usbVendorDescription = dbProduct.Vendor.Vendor; - } + foreach(Tuple tuple in tuples) + switch(tuple.Code) + { + case TupleCodes.CISTPL_NULL: + case TupleCodes.CISTPL_END: + case TupleCodes.CISTPL_MANFID: + case TupleCodes.CISTPL_VERS_1: break; + case TupleCodes.CISTPL_DEVICEGEO: + case TupleCodes.CISTPL_DEVICEGEO_A: + DeviceGeometryTuple geom = CIS.DecodeDeviceGeometryTuple(tuple.Data); - ViewBag.UsbItem = new Item - { - Manufacturer = report.USB.Manufacturer, - Product = report.USB.Product, - VendorDescription = usbVendorDescription != null - ? $"0x{report.USB.VendorID:x4} ({usbVendorDescription})" - : $"0x{report.USB.VendorID:x4}", - ProductDescription = usbProductDescription != null - ? $"0x{report.USB.ProductID:x4} ({usbProductDescription})" - : $"0x{report.USB.ProductID:x4}" - }; + if(geom?.Geometries != null) + foreach(DeviceGeometry geometry in geom.Geometries) + { + decodedTuples.Add("Device width", + $"{(1 << (geometry.CardInterface - 1)) * 8} bits"); + + decodedTuples.Add("Erase block", + $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes"); + + decodedTuples.Add("Read block", + $"{(1 << (geometry.ReadBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes"); + + decodedTuples.Add("Write block", + $"{(1 << (geometry.WriteBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes"); + + decodedTuples.Add("Partition alignment", + $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1)) * (1 << (geometry.Partitions - 1))} bytes"); + } + + break; + case TupleCodes.CISTPL_ALTSTR: + case TupleCodes.CISTPL_BAR: + case TupleCodes.CISTPL_BATTERY: + case TupleCodes.CISTPL_BYTEORDER: + case TupleCodes.CISTPL_CFTABLE_ENTRY: + case TupleCodes.CISTPL_CFTABLE_ENTRY_CB: + case TupleCodes.CISTPL_CHECKSUM: + case TupleCodes.CISTPL_CONFIG: + case TupleCodes.CISTPL_CONFIG_CB: + case TupleCodes.CISTPL_DATE: + case TupleCodes.CISTPL_DEVICE: + case TupleCodes.CISTPL_DEVICE_A: + case TupleCodes.CISTPL_DEVICE_OA: + case TupleCodes.CISTPL_DEVICE_OC: + case TupleCodes.CISTPL_EXTDEVIC: + case TupleCodes.CISTPL_FORMAT: + case TupleCodes.CISTPL_FORMAT_A: + case TupleCodes.CISTPL_FUNCE: + case TupleCodes.CISTPL_FUNCID: + case TupleCodes.CISTPL_GEOMETRY: + case TupleCodes.CISTPL_INDIRECT: + case TupleCodes.CISTPL_JEDEC_A: + case TupleCodes.CISTPL_JEDEC_C: + case TupleCodes.CISTPL_LINKTARGET: + case TupleCodes.CISTPL_LONGLINK_A: + case TupleCodes.CISTPL_LONGLINK_C: + case TupleCodes.CISTPL_LONGLINK_CB: + case TupleCodes.CISTPL_LONGLINK_MFC: + case TupleCodes.CISTPL_NO_LINK: + case TupleCodes.CISTPL_ORG: + case TupleCodes.CISTPL_PWR_MGMNT: + case TupleCodes.CISTPL_SPCL: + case TupleCodes.CISTPL_SWIL: + case TupleCodes.CISTPL_VERS_2: + decodedTuples.Add("Undecoded tuple ID", tuple.Code.ToString()); + + break; + default: + decodedTuples.Add("Unknown tuple ID", $"0x{(byte)tuple.Code:X2}"); + + break; + } + + if(decodedTuples.Count > 0) + ViewBag.repPcmciaTuples = decodedTuples; + } + } + + bool removable = true; + List testedMedia = null; + bool atapi = false; + bool sscMedia = false; + + if(report.ATA != null || + report.ATAPI != null) + { + List ataOneValue = new(); + Dictionary ataTwoValue = new(); + Ata ataReport; + + if(report.ATAPI != null) + { + ViewBag.AtaItem = "ATAPI"; + ataReport = report.ATAPI; + atapi = true; + } + else + { + ViewBag.AtaItem = "ATA"; + ataReport = report.ATA; } - if(report.FireWire != null) - ViewBag.FireWireItem = new Item - { - Manufacturer = report.FireWire.Manufacturer, - Product = report.FireWire.Product, - VendorDescription = $"0x{report.FireWire.VendorID:x8}", - ProductDescription = $"0x{report.FireWire.ProductID:x8}" - }; + bool cfa = report.CompactFlash; - if(report.PCMCIA != null) + if(atapi && !cfa) + ViewBag.lblAtaDeviceType = "ATAPI device"; + else if(!atapi && cfa) + ViewBag.lblAtaDeviceType = "CompactFlash device"; + else + ViewBag.lblAtaDeviceType = "ATA device"; + + Core.Ata.Report(ataReport, cfa, atapi, ref removable, ref ataOneValue, ref ataTwoValue, + ref testedMedia); + + ViewBag.repAtaOne = ataOneValue; + ViewBag.repAtaTwo = ataTwoValue; + } + + if(report.SCSI != null) + { + List scsiOneValue = new(); + Dictionary modePages = new(); + Dictionary evpdPages = new(); + + string vendorId = StringHandlers.CToString(report.SCSI.Inquiry?.VendorIdentification); + + if(report.SCSI.Inquiry != null) { - ViewBag.PcmciaItem = new PcmciaItem - { - Manufacturer = report.PCMCIA.Manufacturer, - Product = report.PCMCIA.ProductName, - VendorDescription = $"0x{report.PCMCIA.ManufacturerCode:x4}", - ProductDescription = $"0x{report.PCMCIA.CardCode:x4}", - Compliance = report.PCMCIA.Compliance - }; + Inquiry inq = report.SCSI.Inquiry.Value; - Tuple[] tuples = CIS.GetTuples(report.PCMCIA.CIS); + ViewBag.lblScsiVendor = VendorString.Prettify(vendorId) != vendorId + ? $"{vendorId} ({VendorString.Prettify(vendorId)})" : vendorId; - if(tuples != null) - { - Dictionary decodedTuples = new(); - - foreach(Tuple tuple in tuples) - switch(tuple.Code) - { - case TupleCodes.CISTPL_NULL: - case TupleCodes.CISTPL_END: - case TupleCodes.CISTPL_MANFID: - case TupleCodes.CISTPL_VERS_1: break; - case TupleCodes.CISTPL_DEVICEGEO: - case TupleCodes.CISTPL_DEVICEGEO_A: - DeviceGeometryTuple geom = CIS.DecodeDeviceGeometryTuple(tuple.Data); - - if(geom?.Geometries != null) - foreach(DeviceGeometry geometry in geom.Geometries) - { - decodedTuples.Add("Device width", - $"{(1 << (geometry.CardInterface - 1)) * 8} bits"); - - decodedTuples.Add("Erase block", - $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes"); - - decodedTuples.Add("Read block", - $"{(1 << (geometry.ReadBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes"); - - decodedTuples.Add("Write block", - $"{(1 << (geometry.WriteBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes"); - - decodedTuples.Add("Partition alignment", - $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1)) * (1 << (geometry.Partitions - 1))} bytes"); - } - - break; - case TupleCodes.CISTPL_ALTSTR: - case TupleCodes.CISTPL_BAR: - case TupleCodes.CISTPL_BATTERY: - case TupleCodes.CISTPL_BYTEORDER: - case TupleCodes.CISTPL_CFTABLE_ENTRY: - case TupleCodes.CISTPL_CFTABLE_ENTRY_CB: - case TupleCodes.CISTPL_CHECKSUM: - case TupleCodes.CISTPL_CONFIG: - case TupleCodes.CISTPL_CONFIG_CB: - case TupleCodes.CISTPL_DATE: - case TupleCodes.CISTPL_DEVICE: - case TupleCodes.CISTPL_DEVICE_A: - case TupleCodes.CISTPL_DEVICE_OA: - case TupleCodes.CISTPL_DEVICE_OC: - case TupleCodes.CISTPL_EXTDEVIC: - case TupleCodes.CISTPL_FORMAT: - case TupleCodes.CISTPL_FORMAT_A: - case TupleCodes.CISTPL_FUNCE: - case TupleCodes.CISTPL_FUNCID: - case TupleCodes.CISTPL_GEOMETRY: - case TupleCodes.CISTPL_INDIRECT: - case TupleCodes.CISTPL_JEDEC_A: - case TupleCodes.CISTPL_JEDEC_C: - case TupleCodes.CISTPL_LINKTARGET: - case TupleCodes.CISTPL_LONGLINK_A: - case TupleCodes.CISTPL_LONGLINK_C: - case TupleCodes.CISTPL_LONGLINK_CB: - case TupleCodes.CISTPL_LONGLINK_MFC: - case TupleCodes.CISTPL_NO_LINK: - case TupleCodes.CISTPL_ORG: - case TupleCodes.CISTPL_PWR_MGMNT: - case TupleCodes.CISTPL_SPCL: - case TupleCodes.CISTPL_SWIL: - case TupleCodes.CISTPL_VERS_2: - decodedTuples.Add("Undecoded tuple ID", tuple.Code.ToString()); - - break; - default: - decodedTuples.Add("Unknown tuple ID", $"0x{(byte)tuple.Code:X2}"); - - break; - } - - if(decodedTuples.Count > 0) - ViewBag.repPcmciaTuples = decodedTuples; - } + ViewBag.lblScsiProduct = StringHandlers.CToString(inq.ProductIdentification); + ViewBag.lblScsiRevision = StringHandlers.CToString(inq.ProductRevisionLevel); } - bool removable = true; - List testedMedia = null; - bool atapi = false; - bool sscMedia = false; + scsiOneValue.AddRange(ScsiInquiry.Report(report.SCSI.Inquiry)); - if(report.ATA != null || - report.ATAPI != null) + if(report.SCSI.SupportsModeSense6) + scsiOneValue.Add("Device supports MODE SENSE (6)"); + + if(report.SCSI.SupportsModeSense10) + scsiOneValue.Add("Device supports MODE SENSE (10)"); + + if(report.SCSI.SupportsModeSubpages) + scsiOneValue.Add("Device supports MODE SENSE subpages"); + + if(report.SCSI.ModeSense != null) { - List ataOneValue = new(); - Dictionary ataTwoValue = new(); - Ata ataReport; - - if(report.ATAPI != null) - { - ViewBag.AtaItem = "ATAPI"; - ataReport = report.ATAPI; - atapi = true; - } - else - { - ViewBag.AtaItem = "ATA"; - ataReport = report.ATA; - } - - bool cfa = report.CompactFlash; - - if(atapi && !cfa) - ViewBag.lblAtaDeviceType = "ATAPI device"; - else if(!atapi && cfa) - ViewBag.lblAtaDeviceType = "CompactFlash device"; - else - ViewBag.lblAtaDeviceType = "ATA device"; - - Core.Ata.Report(ataReport, cfa, atapi, ref removable, ref ataOneValue, ref ataTwoValue, - ref testedMedia); - - ViewBag.repAtaOne = ataOneValue; - ViewBag.repAtaTwo = ataTwoValue; - } - - if(report.SCSI != null) - { - List scsiOneValue = new(); - Dictionary modePages = new(); - Dictionary evpdPages = new(); - - string vendorId = StringHandlers.CToString(report.SCSI.Inquiry?.VendorIdentification); + PeripheralDeviceTypes devType = PeripheralDeviceTypes.DirectAccess; if(report.SCSI.Inquiry != null) + devType = (PeripheralDeviceTypes)report.SCSI.Inquiry.Value.PeripheralDeviceType; + + ScsiModeSense.Report(report.SCSI.ModeSense, vendorId, devType, ref scsiOneValue, ref modePages); + } + + if(modePages.Count > 0) + ViewBag.repModeSense = modePages; + + if(report.SCSI.EVPDPages != null) + ScsiEvpd.Report(report.SCSI.EVPDPages, vendorId, ref evpdPages); + + if(evpdPages.Count > 0) + ViewBag.repEvpd = evpdPages; + + if(report.SCSI.MultiMediaDevice != null) + { + testedMedia = report.SCSI.MultiMediaDevice.TestedMedia; + + if(report.SCSI.MultiMediaDevice.ModeSense2A != null) { - Inquiry inq = report.SCSI.Inquiry.Value; + List mmcModeOneValue = new(); + ScsiMmcMode.Report(report.SCSI.MultiMediaDevice.ModeSense2A, ref mmcModeOneValue); - ViewBag.lblScsiVendor = VendorString.Prettify(vendorId) != vendorId - ? $"{vendorId} ({VendorString.Prettify(vendorId)})" : vendorId; - - ViewBag.lblScsiProduct = StringHandlers.CToString(inq.ProductIdentification); - ViewBag.lblScsiRevision = StringHandlers.CToString(inq.ProductRevisionLevel); + if(mmcModeOneValue.Count > 0) + ViewBag.repScsiMmcMode = mmcModeOneValue; } - scsiOneValue.AddRange(ScsiInquiry.Report(report.SCSI.Inquiry)); - - if(report.SCSI.SupportsModeSense6) - scsiOneValue.Add("Device supports MODE SENSE (6)"); - - if(report.SCSI.SupportsModeSense10) - scsiOneValue.Add("Device supports MODE SENSE (10)"); - - if(report.SCSI.SupportsModeSubpages) - scsiOneValue.Add("Device supports MODE SENSE subpages"); - - if(report.SCSI.ModeSense != null) + if(report.SCSI.MultiMediaDevice.Features != null) { - PeripheralDeviceTypes devType = PeripheralDeviceTypes.DirectAccess; + List mmcFeaturesOneValue = new(); + ScsiMmcFeatures.Report(report.SCSI.MultiMediaDevice.Features, ref mmcFeaturesOneValue); - if(report.SCSI.Inquiry != null) - devType = (PeripheralDeviceTypes)report.SCSI.Inquiry.Value.PeripheralDeviceType; - - ScsiModeSense.Report(report.SCSI.ModeSense, vendorId, devType, ref scsiOneValue, ref modePages); + if(mmcFeaturesOneValue.Count > 0) + ViewBag.repScsiMmcFeatures = mmcFeaturesOneValue; } + } + else if(report.SCSI.SequentialDevice != null) + { + ViewBag.divScsiSscVisible = true; - if(modePages.Count > 0) - ViewBag.repModeSense = modePages; + ViewBag.lblScsiSscGranularity = + report.SCSI.SequentialDevice.BlockSizeGranularity?.ToString() ?? "Unspecified"; - if(report.SCSI.EVPDPages != null) - ScsiEvpd.Report(report.SCSI.EVPDPages, vendorId, ref evpdPages); + ViewBag.lblScsiSscMaxBlock = + report.SCSI.SequentialDevice.MaxBlockLength?.ToString() ?? "Unspecified"; - if(evpdPages.Count > 0) - ViewBag.repEvpd = evpdPages; + ViewBag.lblScsiSscMinBlock = + report.SCSI.SequentialDevice.MinBlockLength?.ToString() ?? "Unspecified"; - if(report.SCSI.MultiMediaDevice != null) + if(report.SCSI.SequentialDevice.SupportedDensities != null) + ViewBag.repScsiSscDensities = report.SCSI.SequentialDevice.SupportedDensities; + + if(report.SCSI.SequentialDevice.SupportedMediaTypes != null) + ViewBag.repScsiSscMedias = report.SCSI.SequentialDevice.SupportedMediaTypes; + + if(report.SCSI.SequentialDevice.TestedMedia != null) { - testedMedia = report.SCSI.MultiMediaDevice.TestedMedia; + List mediaOneValue = new(); + SscTestedMedia.Report(report.SCSI.SequentialDevice.TestedMedia, ref mediaOneValue); - if(report.SCSI.MultiMediaDevice.ModeSense2A != null) + if(mediaOneValue.Count > 0) { - List mmcModeOneValue = new(); - ScsiMmcMode.Report(report.SCSI.MultiMediaDevice.ModeSense2A, ref mmcModeOneValue); - - if(mmcModeOneValue.Count > 0) - ViewBag.repScsiMmcMode = mmcModeOneValue; - } - - if(report.SCSI.MultiMediaDevice.Features != null) - { - List mmcFeaturesOneValue = new(); - ScsiMmcFeatures.Report(report.SCSI.MultiMediaDevice.Features, ref mmcFeaturesOneValue); - - if(mmcFeaturesOneValue.Count > 0) - ViewBag.repScsiMmcFeatures = mmcFeaturesOneValue; + sscMedia = true; + ViewBag.repTestedMedia = mediaOneValue; } } - else if(report.SCSI.SequentialDevice != null) + } + else if(report.SCSI.ReadCapabilities != null) + { + removable = false; + scsiOneValue.Add(""); + + if(report.SCSI.ReadCapabilities.Blocks.HasValue && + report.SCSI.ReadCapabilities.BlockSize.HasValue) { - ViewBag.divScsiSscVisible = true; + scsiOneValue. + Add($"Device has {report.SCSI.ReadCapabilities.Blocks} blocks of {report.SCSI.ReadCapabilities.BlockSize} bytes each"); - ViewBag.lblScsiSscGranularity = - report.SCSI.SequentialDevice.BlockSizeGranularity?.ToString() ?? "Unspecified"; - - ViewBag.lblScsiSscMaxBlock = - report.SCSI.SequentialDevice.MaxBlockLength?.ToString() ?? "Unspecified"; - - ViewBag.lblScsiSscMinBlock = - report.SCSI.SequentialDevice.MinBlockLength?.ToString() ?? "Unspecified"; - - if(report.SCSI.SequentialDevice.SupportedDensities != null) - ViewBag.repScsiSscDensities = report.SCSI.SequentialDevice.SupportedDensities; - - if(report.SCSI.SequentialDevice.SupportedMediaTypes != null) - ViewBag.repScsiSscMedias = report.SCSI.SequentialDevice.SupportedMediaTypes; - - if(report.SCSI.SequentialDevice.TestedMedia != null) - { - List mediaOneValue = new(); - SscTestedMedia.Report(report.SCSI.SequentialDevice.TestedMedia, ref mediaOneValue); - - if(mediaOneValue.Count > 0) - { - sscMedia = true; - ViewBag.repTestedMedia = mediaOneValue; - } - } - } - else if(report.SCSI.ReadCapabilities != null) - { - removable = false; - scsiOneValue.Add(""); - - if(report.SCSI.ReadCapabilities.Blocks.HasValue && - report.SCSI.ReadCapabilities.BlockSize.HasValue) - { + if(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1024 / + 1024 > 1000000) scsiOneValue. - Add($"Device has {report.SCSI.ReadCapabilities.Blocks} blocks of {report.SCSI.ReadCapabilities.BlockSize} bytes each"); - - if(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1024 / - 1024 > 1000000) - scsiOneValue. - Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); - else if(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / - 1024 / 1024 > 1000) - scsiOneValue. - Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); - else - scsiOneValue. - Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000} Mb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024:F2} MiB"); - } - - if(report.SCSI.ReadCapabilities.MediumType.HasValue) - scsiOneValue.Add($"Medium type code: {report.SCSI.ReadCapabilities.MediumType:X2}h"); - - if(report.SCSI.ReadCapabilities.Density.HasValue) - scsiOneValue.Add($"Density code: {report.SCSI.ReadCapabilities.Density:X2}h"); - - if((report.SCSI.ReadCapabilities.SupportsReadLong == true || - report.SCSI.ReadCapabilities.SupportsReadLong16 == true) && - report.SCSI.ReadCapabilities.LongBlockSize.HasValue) - scsiOneValue.Add($"Long block size: {report.SCSI.ReadCapabilities.LongBlockSize} bytes"); - - if(report.SCSI.ReadCapabilities.SupportsReadCapacity == true) - scsiOneValue.Add("Device supports READ CAPACITY (10) command."); - - if(report.SCSI.ReadCapabilities.SupportsReadCapacity16 == true) - scsiOneValue.Add("Device supports READ CAPACITY (16) command."); - - if(report.SCSI.ReadCapabilities.SupportsRead6 == true) - scsiOneValue.Add("Device supports READ (6) command."); - - if(report.SCSI.ReadCapabilities.SupportsRead10 == true) - scsiOneValue.Add("Device supports READ (10) command."); - - if(report.SCSI.ReadCapabilities.SupportsRead12 == true) - scsiOneValue.Add("Device supports READ (12) command."); - - if(report.SCSI.ReadCapabilities.SupportsRead16 == true) - scsiOneValue.Add("Device supports READ (16) command."); - - if(report.SCSI.ReadCapabilities.SupportsReadLong == true) - scsiOneValue.Add("Device supports READ LONG (10) command."); - - if(report.SCSI.ReadCapabilities.SupportsReadLong16 == true) - scsiOneValue.Add("Device supports READ LONG (16) command."); - } - else - { - testedMedia = report.SCSI.RemovableMedias; + Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); + else if(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / + 1024 / 1024 > 1000) + scsiOneValue. + Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); + else + scsiOneValue. + Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000} Mb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024:F2} MiB"); } - ViewBag.repScsi = scsiOneValue; + if(report.SCSI.ReadCapabilities.MediumType.HasValue) + scsiOneValue.Add($"Medium type code: {report.SCSI.ReadCapabilities.MediumType:X2}h"); + + if(report.SCSI.ReadCapabilities.Density.HasValue) + scsiOneValue.Add($"Density code: {report.SCSI.ReadCapabilities.Density:X2}h"); + + if((report.SCSI.ReadCapabilities.SupportsReadLong == true || + report.SCSI.ReadCapabilities.SupportsReadLong16 == true) && + report.SCSI.ReadCapabilities.LongBlockSize.HasValue) + scsiOneValue.Add($"Long block size: {report.SCSI.ReadCapabilities.LongBlockSize} bytes"); + + if(report.SCSI.ReadCapabilities.SupportsReadCapacity == true) + scsiOneValue.Add("Device supports READ CAPACITY (10) command."); + + if(report.SCSI.ReadCapabilities.SupportsReadCapacity16 == true) + scsiOneValue.Add("Device supports READ CAPACITY (16) command."); + + if(report.SCSI.ReadCapabilities.SupportsRead6 == true) + scsiOneValue.Add("Device supports READ (6) command."); + + if(report.SCSI.ReadCapabilities.SupportsRead10 == true) + scsiOneValue.Add("Device supports READ (10) command."); + + if(report.SCSI.ReadCapabilities.SupportsRead12 == true) + scsiOneValue.Add("Device supports READ (12) command."); + + if(report.SCSI.ReadCapabilities.SupportsRead16 == true) + scsiOneValue.Add("Device supports READ (16) command."); + + if(report.SCSI.ReadCapabilities.SupportsReadLong == true) + scsiOneValue.Add("Device supports READ LONG (10) command."); + + if(report.SCSI.ReadCapabilities.SupportsReadLong16 == true) + scsiOneValue.Add("Device supports READ LONG (16) command."); } - - if(report.MultiMediaCard != null) + else { - List mmcOneValue = new(); - - if(report.MultiMediaCard.CID != null) - { - mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCID(report.MultiMediaCard.CID). - Replace("\n", "
")); - - mmcOneValue.Add(""); - } - - if(report.MultiMediaCard.CSD != null) - { - mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.CSD). - Replace("\n", "
")); - - mmcOneValue.Add(""); - } - - if(report.MultiMediaCard.ExtendedCSD != null) - { - mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyExtendedCSD(report.MultiMediaCard.ExtendedCSD). - Replace("\n", "
")); - - mmcOneValue.Add(""); - } - - if(report.MultiMediaCard.OCR != null) - { - mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.OCR). - Replace("\n", "
")); - - mmcOneValue.Add(""); - } - - ViewBag.repMMC = mmcOneValue; + testedMedia = report.SCSI.RemovableMedias; } - if(report.SecureDigital != null) - { - List sdOneValue = new(); - - if(report.SecureDigital.CID != null) - { - sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCID(report.SecureDigital.CID). - Replace("\n", "
")); - - sdOneValue.Add(""); - } - - if(report.SecureDigital.CSD != null) - { - sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.CSD). - Replace("\n", "
")); - - sdOneValue.Add(""); - } - - if(report.SecureDigital.SCR != null) - { - sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifySCR(report.SecureDigital.SCR). - Replace("\n", "
")); - - sdOneValue.Add(""); - } - - if(report.SecureDigital.OCR != null) - { - sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.OCR). - Replace("\n", "
")); - - sdOneValue.Add(""); - } - - ViewBag.repSD = sdOneValue; - } - - if(removable && - !sscMedia && - testedMedia != null) - { - List mediaOneValue = new(); - Core.TestedMedia.Report(testedMedia, ref mediaOneValue); - - if(mediaOneValue.Count > 0) - ViewBag.repTestedMedia = mediaOneValue; - } + ViewBag.repScsi = scsiOneValue; } - catch(Exception) + + if(report.MultiMediaCard != null) { - #if DEBUG - throw; - #endif - return Content("Could not load device report"); + List mmcOneValue = new(); + + if(report.MultiMediaCard.CID != null) + { + mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCID(report.MultiMediaCard.CID). + Replace("\n", "
")); + + mmcOneValue.Add(""); + } + + if(report.MultiMediaCard.CSD != null) + { + mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.CSD). + Replace("\n", "
")); + + mmcOneValue.Add(""); + } + + if(report.MultiMediaCard.ExtendedCSD != null) + { + mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyExtendedCSD(report.MultiMediaCard.ExtendedCSD). + Replace("\n", "
")); + + mmcOneValue.Add(""); + } + + if(report.MultiMediaCard.OCR != null) + { + mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.OCR). + Replace("\n", "
")); + + mmcOneValue.Add(""); + } + + ViewBag.repMMC = mmcOneValue; } - return View(); + if(report.SecureDigital != null) + { + List sdOneValue = new(); + + if(report.SecureDigital.CID != null) + { + sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCID(report.SecureDigital.CID). + Replace("\n", "
")); + + sdOneValue.Add(""); + } + + if(report.SecureDigital.CSD != null) + { + sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.CSD). + Replace("\n", "
")); + + sdOneValue.Add(""); + } + + if(report.SecureDigital.SCR != null) + { + sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifySCR(report.SecureDigital.SCR). + Replace("\n", "
")); + + sdOneValue.Add(""); + } + + if(report.SecureDigital.OCR != null) + { + sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.OCR). + Replace("\n", "
")); + + sdOneValue.Add(""); + } + + ViewBag.repSD = sdOneValue; + } + + if(removable && + !sscMedia && + testedMedia != null) + { + List mediaOneValue = new(); + Core.TestedMedia.Report(testedMedia, ref mediaOneValue); + + if(mediaOneValue.Count > 0) + ViewBag.repTestedMedia = mediaOneValue; + } + } + catch(Exception) + { + #if DEBUG + throw; + #endif + return Content("Could not load device report"); } - } - public class Item - { - public string Manufacturer; - public string Product; - public string ProductDescription; - public string VendorDescription; + return View(); } +} - public sealed class PcmciaItem : Item - { - public string Compliance; - } +public class Item +{ + public string Manufacturer; + public string Product; + public string ProductDescription; + public string VendorDescription; +} + +public sealed class PcmciaItem : Item +{ + public string Compliance; } \ No newline at end of file diff --git a/Aaru.Server/Controllers/StatsController.cs b/Aaru.Server/Controllers/StatsController.cs index 24e4dfc0..cde7ee13 100644 --- a/Aaru.Server/Controllers/StatsController.cs +++ b/Aaru.Server/Controllers/StatsController.cs @@ -48,575 +48,574 @@ using OperatingSystem = Aaru.Server.Models.OperatingSystem; using PlatformID = Aaru.CommonTypes.Interop.PlatformID; using Version = Aaru.Server.Models.Version; -namespace Aaru.Server.Controllers +namespace Aaru.Server.Controllers; + +/// Renders a page with statistics, list of media type, devices, etc +public sealed class StatsController : Controller { - /// Renders a page with statistics, list of media type, devices, etc - public sealed class StatsController : Controller + readonly AaruServerContext _ctx; + readonly IWebHostEnvironment _env; + + public StatsController(IWebHostEnvironment environment, AaruServerContext context) { - readonly AaruServerContext _ctx; - readonly IWebHostEnvironment _env; + _env = environment; + _ctx = context; + } - public StatsController(IWebHostEnvironment environment, AaruServerContext context) + public ActionResult Index() + { + ViewBag.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + + try { - _env = environment; - _ctx = context; - } + if(System.IO.File.Exists(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), + "Statistics", "Statistics.xml"))) + try + { + var statistics = new Stats(); - public ActionResult Index() - { - ViewBag.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + var xs = new XmlSerializer(statistics.GetType()); - try + FileStream fs = + WaitForFile(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), "Statistics", "Statistics.xml"), + FileMode.Open, FileAccess.Read, FileShare.Read); + + statistics = (Stats)xs.Deserialize(fs); + fs.Close(); + + StatsConverter.Convert(statistics); + + System.IO.File. + Delete(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), + "Statistics", "Statistics.xml")); + } + catch(XmlException) + { + // Do nothing + } + + if(_ctx.OperatingSystems.Any()) { - if(System.IO.File.Exists(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), - "Statistics", "Statistics.xml"))) + List operatingSystems = new(); + + foreach(OperatingSystem nvs in _ctx.OperatingSystems) + operatingSystems.Add(new NameValueStats + { + name = + $"{DetectOS.GetPlatformName((PlatformID)Enum.Parse(typeof(PlatformID), nvs.Name), nvs.Version)}{(string.IsNullOrEmpty(nvs.Version) ? "" : " ")}{nvs.Version}", + Value = nvs.Count + }); + + ViewBag.repOperatingSystems = operatingSystems.OrderBy(os => os.name).ToList(); + } + + if(_ctx.Versions.Any()) + { + List versions = new(); + + foreach(Version nvs in _ctx.Versions) + versions.Add(new NameValueStats + { + name = nvs.Name == "previous" ? "Previous than 3.4.99.0" : nvs.Name, + Value = nvs.Count + }); + + ViewBag.repVersions = versions.OrderBy(ver => ver.name).ToList(); + } + + if(_ctx.Commands.Any()) + ViewBag.repCommands = _ctx.Commands.OrderBy(c => c.Name).ToList(); + + if(_ctx.Filters.Any()) + ViewBag.repFilters = _ctx.Filters.OrderBy(filter => filter.Name).ToList(); + + if(_ctx.MediaFormats.Any()) + ViewBag.repMediaImages = _ctx.MediaFormats.OrderBy(filter => filter.Name).ToList(); + + if(_ctx.Partitions.Any()) + ViewBag.repPartitions = _ctx.Partitions.OrderBy(filter => filter.Name).ToList(); + + if(_ctx.Filesystems.Any()) + ViewBag.repFilesystems = _ctx.Filesystems.OrderBy(filter => filter.Name).ToList(); + + if(_ctx.Medias.Any()) + { + List realMedia = new(); + List virtualMedia = new(); + + foreach(Media nvs in _ctx.Medias) try { - var statistics = new Stats(); + (string type, string subType) mediaType = + MediaType.MediaTypeToString((CommonTypes.MediaType) + Enum.Parse(typeof(CommonTypes.MediaType), nvs.Type)); - var xs = new XmlSerializer(statistics.GetType()); + if(nvs.Real) + realMedia.Add(new MediaItem + { + Type = mediaType.type, + SubType = mediaType.subType, + Count = nvs.Count + }); + else + virtualMedia.Add(new MediaItem + { + Type = mediaType.type, + SubType = mediaType.subType, + Count = nvs.Count + }); + } + catch + { + if(nvs.Real) + realMedia.Add(new MediaItem + { + Type = nvs.Type, + SubType = null, + Count = nvs.Count + }); + else + virtualMedia.Add(new MediaItem + { + Type = nvs.Type, + SubType = null, + Count = nvs.Count + }); + } + + if(realMedia.Count > 0) + ViewBag.repRealMedia = realMedia.OrderBy(media => media.Type).ThenBy(media => media.SubType). + ToList(); + + if(virtualMedia.Count > 0) + ViewBag.repVirtualMedia = virtualMedia.OrderBy(media => media.Type). + ThenBy(media => media.SubType).ToList(); + } + + if(_ctx.DeviceStats.Any()) + { + List devices = new(); + + foreach(DeviceStat device in _ctx.DeviceStats.ToList()) + { + string xmlFile; + + if(!string.IsNullOrWhiteSpace(device.Manufacturer) && + !string.IsNullOrWhiteSpace(device.Model) && + !string.IsNullOrWhiteSpace(device.Revision)) + xmlFile = device.Manufacturer + "_" + device.Model + "_" + device.Revision + ".xml"; + else if(!string.IsNullOrWhiteSpace(device.Manufacturer) && + !string.IsNullOrWhiteSpace(device.Model)) + xmlFile = device.Manufacturer + "_" + device.Model + ".xml"; + else if(!string.IsNullOrWhiteSpace(device.Model) && + !string.IsNullOrWhiteSpace(device.Revision)) + xmlFile = device.Model + "_" + device.Revision + ".xml"; + else + xmlFile = device.Model + ".xml"; + + xmlFile = xmlFile.Replace('/', '_').Replace('\\', '_').Replace('?', '_'); + + if(System.IO.File.Exists(Path.Combine(_env.ContentRootPath, "Reports", xmlFile))) + { + var deviceReport = new DeviceReport(); + + var xs = new XmlSerializer(deviceReport.GetType()); FileStream fs = - WaitForFile(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), "Statistics", "Statistics.xml"), + WaitForFile(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), "Reports", xmlFile), FileMode.Open, FileAccess.Read, FileShare.Read); - statistics = (Stats)xs.Deserialize(fs); + deviceReport = (DeviceReport)xs.Deserialize(fs); fs.Close(); - StatsConverter.Convert(statistics); + var deviceReportV2 = new DeviceReportV2(deviceReport); + + device.Report = _ctx.Devices.Add(new Device(deviceReportV2)).Entity; + _ctx.SaveChanges(); System.IO.File. Delete(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), - "Statistics", "Statistics.xml")); + "Reports", xmlFile)); } - catch(XmlException) + + devices.Add(new DeviceItem { - // Do nothing - } - - if(_ctx.OperatingSystems.Any()) - { - List operatingSystems = new(); - - foreach(OperatingSystem nvs in _ctx.OperatingSystems) - operatingSystems.Add(new NameValueStats - { - name = - $"{DetectOS.GetPlatformName((PlatformID)Enum.Parse(typeof(PlatformID), nvs.Name), nvs.Version)}{(string.IsNullOrEmpty(nvs.Version) ? "" : " ")}{nvs.Version}", - Value = nvs.Count - }); - - ViewBag.repOperatingSystems = operatingSystems.OrderBy(os => os.name).ToList(); + Manufacturer = device.Manufacturer, + Model = device.Model, + Revision = device.Revision, + Bus = device.Bus, + ReportId = device.Report != null && device.Report.Id != 0 ? device.Report.Id : 0 + }); } - if(_ctx.Versions.Any()) - { - List versions = new(); - - foreach(Version nvs in _ctx.Versions) - versions.Add(new NameValueStats - { - name = nvs.Name == "previous" ? "Previous than 3.4.99.0" : nvs.Name, - Value = nvs.Count - }); - - ViewBag.repVersions = versions.OrderBy(ver => ver.name).ToList(); - } - - if(_ctx.Commands.Any()) - ViewBag.repCommands = _ctx.Commands.OrderBy(c => c.Name).ToList(); - - if(_ctx.Filters.Any()) - ViewBag.repFilters = _ctx.Filters.OrderBy(filter => filter.Name).ToList(); - - if(_ctx.MediaFormats.Any()) - ViewBag.repMediaImages = _ctx.MediaFormats.OrderBy(filter => filter.Name).ToList(); - - if(_ctx.Partitions.Any()) - ViewBag.repPartitions = _ctx.Partitions.OrderBy(filter => filter.Name).ToList(); - - if(_ctx.Filesystems.Any()) - ViewBag.repFilesystems = _ctx.Filesystems.OrderBy(filter => filter.Name).ToList(); - - if(_ctx.Medias.Any()) - { - List realMedia = new(); - List virtualMedia = new(); - - foreach(Media nvs in _ctx.Medias) - try - { - (string type, string subType) mediaType = - MediaType.MediaTypeToString((CommonTypes.MediaType) - Enum.Parse(typeof(CommonTypes.MediaType), nvs.Type)); - - if(nvs.Real) - realMedia.Add(new MediaItem - { - Type = mediaType.type, - SubType = mediaType.subType, - Count = nvs.Count - }); - else - virtualMedia.Add(new MediaItem - { - Type = mediaType.type, - SubType = mediaType.subType, - Count = nvs.Count - }); - } - catch - { - if(nvs.Real) - realMedia.Add(new MediaItem - { - Type = nvs.Type, - SubType = null, - Count = nvs.Count - }); - else - virtualMedia.Add(new MediaItem - { - Type = nvs.Type, - SubType = null, - Count = nvs.Count - }); - } - - if(realMedia.Count > 0) - ViewBag.repRealMedia = realMedia.OrderBy(media => media.Type).ThenBy(media => media.SubType). - ToList(); - - if(virtualMedia.Count > 0) - ViewBag.repVirtualMedia = virtualMedia.OrderBy(media => media.Type). - ThenBy(media => media.SubType).ToList(); - } - - if(_ctx.DeviceStats.Any()) - { - List devices = new(); - - foreach(DeviceStat device in _ctx.DeviceStats.ToList()) - { - string xmlFile; - - if(!string.IsNullOrWhiteSpace(device.Manufacturer) && - !string.IsNullOrWhiteSpace(device.Model) && - !string.IsNullOrWhiteSpace(device.Revision)) - xmlFile = device.Manufacturer + "_" + device.Model + "_" + device.Revision + ".xml"; - else if(!string.IsNullOrWhiteSpace(device.Manufacturer) && - !string.IsNullOrWhiteSpace(device.Model)) - xmlFile = device.Manufacturer + "_" + device.Model + ".xml"; - else if(!string.IsNullOrWhiteSpace(device.Model) && - !string.IsNullOrWhiteSpace(device.Revision)) - xmlFile = device.Model + "_" + device.Revision + ".xml"; - else - xmlFile = device.Model + ".xml"; - - xmlFile = xmlFile.Replace('/', '_').Replace('\\', '_').Replace('?', '_'); - - if(System.IO.File.Exists(Path.Combine(_env.ContentRootPath, "Reports", xmlFile))) - { - var deviceReport = new DeviceReport(); - - var xs = new XmlSerializer(deviceReport.GetType()); - - FileStream fs = - WaitForFile(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), "Reports", xmlFile), - FileMode.Open, FileAccess.Read, FileShare.Read); - - deviceReport = (DeviceReport)xs.Deserialize(fs); - fs.Close(); - - var deviceReportV2 = new DeviceReportV2(deviceReport); - - device.Report = _ctx.Devices.Add(new Device(deviceReportV2)).Entity; - _ctx.SaveChanges(); - - System.IO.File. - Delete(Path.Combine(_env.ContentRootPath ?? throw new InvalidOperationException(), - "Reports", xmlFile)); - } - - devices.Add(new DeviceItem - { - Manufacturer = device.Manufacturer, - Model = device.Model, - Revision = device.Revision, - Bus = device.Bus, - ReportId = device.Report != null && device.Report.Id != 0 ? device.Report.Id : 0 - }); - } - - ViewBag.repDevices = devices.OrderBy(device => device.Manufacturer).ThenBy(device => device.Model). - ThenBy(device => device.Revision).ThenBy(device => device.Bus). - ToList(); - } + ViewBag.repDevices = devices.OrderBy(device => device.Manufacturer).ThenBy(device => device.Model). + ThenBy(device => device.Revision).ThenBy(device => device.Bus). + ToList(); } - catch(Exception) + } + catch(Exception) + { + #if DEBUG + throw; + #endif + return Content("Could not read statistics"); + } + + return View(); + } + + static FileStream WaitForFile(string fullPath, FileMode mode, FileAccess access, FileShare share) + { + for(int numTries = 0; numTries < 100; numTries++) + { + FileStream fs = null; + + try { - #if DEBUG - throw; - #endif - return Content("Could not read statistics"); + fs = new FileStream(fullPath, mode, access, share); + + return fs; } - - return View(); - } - - static FileStream WaitForFile(string fullPath, FileMode mode, FileAccess access, FileShare share) - { - for(int numTries = 0; numTries < 100; numTries++) + catch(IOException) { - FileStream fs = null; - - try - { - fs = new FileStream(fullPath, mode, access, share); - - return fs; - } - catch(IOException) - { - fs?.Dispose(); - Thread.Sleep(50); - } + fs?.Dispose(); + Thread.Sleep(50); } - - return null; } - public IActionResult GetOsData() + return null; + } + + public IActionResult GetOsData() + { + var query = _ctx.OperatingSystems.GroupBy(x => new { - var query = _ctx.OperatingSystems.GroupBy(x => new - { - x.Name - }, x => x.Count).Select(g => new - { - g.Key.Name, - Count = g.Sum() - }); + x.Name + }, x => x.Count).Select(g => new + { + g.Key.Name, + Count = g.Sum() + }); - string[][] result = new string[2][]; - result[0] = query.Select(x => x.Name).ToArray(); - result[1] = query.Select(x => x.Count.ToString()).ToArray(); + string[][] result = new string[2][]; + result[0] = query.Select(x => x.Name).ToArray(); + result[1] = query.Select(x => x.Count.ToString()).ToArray(); - for(int i = 0; i < result[0].Length; i++) - result[0][i] = DetectOS.GetPlatformName((PlatformID)Enum.Parse(typeof(PlatformID), result[0][i])); + for(int i = 0; i < result[0].Length; i++) + result[0][i] = DetectOS.GetPlatformName((PlatformID)Enum.Parse(typeof(PlatformID), result[0][i])); + return Json(result); + } + + public IActionResult GetLinuxData() + { + string[][] result = + { + _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Linux.ToString()).OrderByDescending(o => o.Count). + Take(10). + Select(x => + $"{DetectOS.GetPlatformName(PlatformID.Linux, x.Version)}{(string.IsNullOrEmpty(x.Version) ? "" : " ")}{x.Version}"). + ToArray(), + _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Linux.ToString()).OrderByDescending(o => o.Count). + Take(10).Select(x => x.Count.ToString()).ToArray() + }; + + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetLinuxData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.OperatingSystems.Where(o => o.Name == PlatformID.Linux.ToString()).Sum(o => o.Count) - + result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetMacOsData() + { + string[][] result = { - string[][] result = - { - _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Linux.ToString()).OrderByDescending(o => o.Count). - Take(10). - Select(x => - $"{DetectOS.GetPlatformName(PlatformID.Linux, x.Version)}{(string.IsNullOrEmpty(x.Version) ? "" : " ")}{x.Version}"). - ToArray(), - _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Linux.ToString()).OrderByDescending(o => o.Count). - Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.OperatingSystems.Where(o => o.Name == PlatformID.Linux.ToString()).Sum(o => o.Count) - - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.OperatingSystems.Where(o => o.Name == PlatformID.MacOSX.ToString()). + OrderByDescending(o => o.Count).Take(10). + Select(x => + $"{DetectOS.GetPlatformName(PlatformID.MacOSX, x.Version)}{(string.IsNullOrEmpty(x.Version) ? "" : " ")}{x.Version}"). + ToArray(), + _ctx.OperatingSystems.Where(o => o.Name == PlatformID.MacOSX.ToString()). + OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetMacOsData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.OperatingSystems.Where(o => o.Name == PlatformID.MacOSX.ToString()).Sum(o => o.Count) - + result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetWindowsData() + { + string[][] result = { - string[][] result = - { - _ctx.OperatingSystems.Where(o => o.Name == PlatformID.MacOSX.ToString()). - OrderByDescending(o => o.Count).Take(10). - Select(x => - $"{DetectOS.GetPlatformName(PlatformID.MacOSX, x.Version)}{(string.IsNullOrEmpty(x.Version) ? "" : " ")}{x.Version}"). - ToArray(), - _ctx.OperatingSystems.Where(o => o.Name == PlatformID.MacOSX.ToString()). - OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.OperatingSystems.Where(o => o.Name == PlatformID.MacOSX.ToString()).Sum(o => o.Count) - - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Win32NT.ToString()). + OrderByDescending(o => o.Count).Take(10). + Select(x => + $"{DetectOS.GetPlatformName(PlatformID.Win32NT, x.Version)}{(string.IsNullOrEmpty(x.Version) ? "" : " ")}{x.Version}"). + ToArray(), + _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Win32NT.ToString()). + OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetWindowsData() + result[0][9] = "Other"; + + result[1][9] = + (_ctx.OperatingSystems.Where(o => o.Name == PlatformID.Win32NT.ToString()).Sum(o => o.Count) - + result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetVersionsData() + { + string[][] result = { - string[][] result = - { - _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Win32NT.ToString()). - OrderByDescending(o => o.Count).Take(10). - Select(x => - $"{DetectOS.GetPlatformName(PlatformID.Win32NT, x.Version)}{(string.IsNullOrEmpty(x.Version) ? "" : " ")}{x.Version}"). - ToArray(), - _ctx.OperatingSystems.Where(o => o.Name == PlatformID.Win32NT.ToString()). - OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = - (_ctx.OperatingSystems.Where(o => o.Name == PlatformID.Win32NT.ToString()).Sum(o => o.Count) - - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.Versions.OrderByDescending(o => o.Count).Take(10). + Select(v => v.Name == "previous" ? "Previous than 3.4.99.0" : v.Name).ToArray(), + _ctx.Versions.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetVersionsData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.Versions.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetCommandsData() + { + string[][] result = { - string[][] result = - { - _ctx.Versions.OrderByDescending(o => o.Count).Take(10). - Select(v => v.Name == "previous" ? "Previous than 3.4.99.0" : v.Name).ToArray(), - _ctx.Versions.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Versions.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.Commands.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + _ctx.Commands.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetCommandsData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.Commands.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetFiltersData() + { + string[][] result = { - string[][] result = - { - _ctx.Commands.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - _ctx.Commands.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Commands.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.Filters.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + _ctx.Filters.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetFiltersData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.Filters.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetFormatsData() + { + string[][] result = { - string[][] result = - { - _ctx.Filters.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - _ctx.Filters.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Filters.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.MediaFormats.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + _ctx.MediaFormats.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetFormatsData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.MediaFormats.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetPartitionsData() + { + string[][] result = { - string[][] result = - { - _ctx.MediaFormats.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - _ctx.MediaFormats.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.MediaFormats.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.Partitions.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + _ctx.Partitions.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetPartitionsData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.Partitions.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetFilesystemsData() + { + string[][] result = { - string[][] result = - { - _ctx.Partitions.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - _ctx.Partitions.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Partitions.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + _ctx.Filesystems.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + _ctx.Filesystems.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetFilesystemsData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.Filesystems.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetVirtualMediaData() + { + Media[] virtualMedias = _ctx.Medias.Where(o => !o.Real).OrderByDescending(o => o.Count).Take(10).ToArray(); + + foreach(Media media in virtualMedias) { - string[][] result = + try { - _ctx.Filesystems.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - _ctx.Filesystems.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; + (string type, string subType) mediaType = + MediaType.MediaTypeToString((CommonTypes.MediaType)Enum.Parse(typeof(CommonTypes.MediaType), + media.Type)); - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Filesystems.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); - - return Json(result); - } - - public IActionResult GetVirtualMediaData() - { - Media[] virtualMedias = _ctx.Medias.Where(o => !o.Real).OrderByDescending(o => o.Count).Take(10).ToArray(); - - foreach(Media media in virtualMedias) - { - try - { - (string type, string subType) mediaType = - MediaType.MediaTypeToString((CommonTypes.MediaType)Enum.Parse(typeof(CommonTypes.MediaType), - media.Type)); - - media.Type = $"{mediaType.type} ({mediaType.subType})"; - } - catch - { - // Could not get media type/subtype pair from type, so just leave it as is - } + media.Type = $"{mediaType.type} ({mediaType.subType})"; } - - string[][] result = + catch { - virtualMedias.Select(v => v.Type).ToArray(), virtualMedias.Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Medias.Where(o => !o.Real).Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)). - ToString(); - - return Json(result); - } - - public IActionResult GetRealMediaData() - { - Media[] realMedias = _ctx.Medias.Where(o => o.Real).OrderByDescending(o => o.Count).Take(10).ToArray(); - - foreach(Media media in realMedias) - { - try - { - (string type, string subType) mediaType = - MediaType.MediaTypeToString((CommonTypes.MediaType)Enum.Parse(typeof(CommonTypes.MediaType), - media.Type)); - - media.Type = $"{mediaType.type} ({mediaType.subType})"; - } - catch - { - // Could not get media type/subtype pair from type, so just leave it as is - } + // Could not get media type/subtype pair from type, so just leave it as is } - - string[][] result = - { - realMedias.Select(v => v.Type).ToArray(), realMedias.Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (_ctx.Medias.Where(o => o.Real).Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)). - ToString(); - - return Json(result); } - public IActionResult GetDevicesByBusData() + string[][] result = { - var data = _ctx.DeviceStats.Select(d => d.Bus).Distinct().Select(deviceBus => new - { - deviceBus, - deviceBusCount = _ctx.DeviceStats.Count(d => d.Bus == deviceBus) - }).Select(t => new - { - Name = t.deviceBus, - Count = t.deviceBusCount - }).ToList(); - - string[][] result = - { - data.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - data.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "Other"; - - result[1][9] = (data.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + virtualMedias.Select(v => v.Type).ToArray(), virtualMedias.Select(x => x.Count.ToString()).ToArray() + }; + if(result[0].Length < 10) return Json(result); - } - public IActionResult GetDevicesByManufacturerData() + result[0][9] = "Other"; + + result[1][9] = (_ctx.Medias.Where(o => !o.Real).Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)). + ToString(); + + return Json(result); + } + + public IActionResult GetRealMediaData() + { + Media[] realMedias = _ctx.Medias.Where(o => o.Real).OrderByDescending(o => o.Count).Take(10).ToArray(); + + foreach(Media media in realMedias) { - List devices = _ctx.Devices.Where(d => d.Manufacturer != null && d.Manufacturer != "").ToList(); - - var data = devices.Select(d => d.Manufacturer.ToLowerInvariant()).Distinct().Select(manufacturer => new + try { - manufacturer, - manufacturerCount = devices.Count(d => d.Manufacturer?.ToLowerInvariant() == manufacturer) - }).Select(t => new + (string type, string subType) mediaType = + MediaType.MediaTypeToString((CommonTypes.MediaType)Enum.Parse(typeof(CommonTypes.MediaType), + media.Type)); + + media.Type = $"{mediaType.type} ({mediaType.subType})"; + } + catch { - Name = t.manufacturer, - Count = t.manufacturerCount - }).ToList(); - - string[][] result = - { - data.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), - data.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() - }; - - if(result[0].Length < 10) - return Json(result); - - result[0][9] = "other"; - - result[1][9] = (data.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); - - return Json(result); + // Could not get media type/subtype pair from type, so just leave it as is + } } + + string[][] result = + { + realMedias.Select(v => v.Type).ToArray(), realMedias.Select(x => x.Count.ToString()).ToArray() + }; + + if(result[0].Length < 10) + return Json(result); + + result[0][9] = "Other"; + + result[1][9] = (_ctx.Medias.Where(o => o.Real).Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)). + ToString(); + + return Json(result); + } + + public IActionResult GetDevicesByBusData() + { + var data = _ctx.DeviceStats.Select(d => d.Bus).Distinct().Select(deviceBus => new + { + deviceBus, + deviceBusCount = _ctx.DeviceStats.Count(d => d.Bus == deviceBus) + }).Select(t => new + { + Name = t.deviceBus, + Count = t.deviceBusCount + }).ToList(); + + string[][] result = + { + data.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + data.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + + if(result[0].Length < 10) + return Json(result); + + result[0][9] = "Other"; + + result[1][9] = (data.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } + + public IActionResult GetDevicesByManufacturerData() + { + List devices = _ctx.Devices.Where(d => d.Manufacturer != null && d.Manufacturer != "").ToList(); + + var data = devices.Select(d => d.Manufacturer.ToLowerInvariant()).Distinct().Select(manufacturer => new + { + manufacturer, + manufacturerCount = devices.Count(d => d.Manufacturer?.ToLowerInvariant() == manufacturer) + }).Select(t => new + { + Name = t.manufacturer, + Count = t.manufacturerCount + }).ToList(); + + string[][] result = + { + data.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + data.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + + if(result[0].Length < 10) + return Json(result); + + result[0][9] = "other"; + + result[1][9] = (data.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); } } \ No newline at end of file diff --git a/Aaru.Server/Controllers/UpdateController.cs b/Aaru.Server/Controllers/UpdateController.cs index 903d20ce..a3bce3c0 100644 --- a/Aaru.Server/Controllers/UpdateController.cs +++ b/Aaru.Server/Controllers/UpdateController.cs @@ -43,69 +43,68 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; -namespace Aaru.Server.Controllers +namespace Aaru.Server.Controllers; + +public sealed class UpdateController : Controller { - public sealed class UpdateController : Controller + readonly AaruServerContext _ctx; + + public UpdateController(AaruServerContext ctx) => _ctx = ctx; + + /// Receives a report from Aaru.Core, verifies it's in the correct format and stores it on the server + /// HTTP response + [Route("api/update"), HttpGet] + public ActionResult Update(long timestamp) { - readonly AaruServerContext _ctx; + var sync = new SyncDto(); + DateTime lastSync = DateHandlers.UnixToDateTime(timestamp); - public UpdateController(AaruServerContext ctx) => _ctx = ctx; + sync.UsbVendors = new List(); - /// Receives a report from Aaru.Core, verifies it's in the correct format and stores it on the server - /// HTTP response - [Route("api/update"), HttpGet] - public ActionResult Update(long timestamp) - { - var sync = new SyncDto(); - DateTime lastSync = DateHandlers.UnixToDateTime(timestamp); - - sync.UsbVendors = new List(); - - foreach(UsbVendor vendor in _ctx.UsbVendors.Where(v => v.ModifiedWhen > lastSync)) - sync.UsbVendors.Add(new UsbVendorDto - { - VendorId = vendor.VendorId, - Vendor = vendor.Vendor - }); - - sync.UsbProducts = new List(); - - foreach(UsbProduct product in _ctx.UsbProducts.Include(p => p.Vendor).Where(p => p.ModifiedWhen > lastSync)) - sync.UsbProducts.Add(new UsbProductDto - { - Id = product.Id, - Product = product.Product, - ProductId = product.ProductId, - VendorId = product.Vendor.VendorId - }); - - sync.Offsets = new List(); - - foreach(CompactDiscOffset offset in _ctx.CdOffsets.Where(o => o.ModifiedWhen > lastSync)) - sync.Offsets.Add(new CdOffsetDto(offset, offset.Id)); - - sync.Devices = new List(); - - foreach(Device device in _ctx.Devices.Where(d => d.ModifiedWhen > lastSync).ToList()) - sync.Devices.Add(new DeviceDto(JsonConvert. - DeserializeObject(JsonConvert.SerializeObject(device, - Formatting.None, new JsonSerializerSettings - { - ReferenceLoopHandling = - ReferenceLoopHandling.Ignore - })), device.Id, device.OptimalMultipleSectorsRead, - device.CanReadGdRomUsingSwapDisc)); - - var js = JsonSerializer.Create(); - var sw = new StringWriter(); - js.Serialize(sw, sync); - - return new ContentResult + foreach(UsbVendor vendor in _ctx.UsbVendors.Where(v => v.ModifiedWhen > lastSync)) + sync.UsbVendors.Add(new UsbVendorDto { - StatusCode = (int)HttpStatusCode.OK, - Content = sw.ToString(), - ContentType = "application/json" - }; - } + VendorId = vendor.VendorId, + Vendor = vendor.Vendor + }); + + sync.UsbProducts = new List(); + + foreach(UsbProduct product in _ctx.UsbProducts.Include(p => p.Vendor).Where(p => p.ModifiedWhen > lastSync)) + sync.UsbProducts.Add(new UsbProductDto + { + Id = product.Id, + Product = product.Product, + ProductId = product.ProductId, + VendorId = product.Vendor.VendorId + }); + + sync.Offsets = new List(); + + foreach(CompactDiscOffset offset in _ctx.CdOffsets.Where(o => o.ModifiedWhen > lastSync)) + sync.Offsets.Add(new CdOffsetDto(offset, offset.Id)); + + sync.Devices = new List(); + + foreach(Device device in _ctx.Devices.Where(d => d.ModifiedWhen > lastSync).ToList()) + sync.Devices.Add(new DeviceDto(JsonConvert. + DeserializeObject(JsonConvert.SerializeObject(device, + Formatting.None, new JsonSerializerSettings + { + ReferenceLoopHandling = + ReferenceLoopHandling.Ignore + })), device.Id, device.OptimalMultipleSectorsRead, + device.CanReadGdRomUsingSwapDisc)); + + var js = JsonSerializer.Create(); + var sw = new StringWriter(); + js.Serialize(sw, sync); + + return new ContentResult + { + StatusCode = (int)HttpStatusCode.OK, + Content = sw.ToString(), + ContentType = "application/json" + }; } } \ No newline at end of file diff --git a/Aaru.Server/Controllers/UploadReportController.cs b/Aaru.Server/Controllers/UploadReportController.cs index c3b75aa5..6ca31eae 100644 --- a/Aaru.Server/Controllers/UploadReportController.cs +++ b/Aaru.Server/Controllers/UploadReportController.cs @@ -48,354 +48,353 @@ using Microsoft.AspNetCore.Mvc; using MimeKit; using Newtonsoft.Json; -namespace Aaru.Server.Controllers +namespace Aaru.Server.Controllers; + +public sealed class UploadReportController : Controller { - public sealed class UploadReportController : Controller + readonly AaruServerContext _ctx; + readonly IWebHostEnvironment _environment; + + public UploadReportController(IWebHostEnvironment environment, AaruServerContext ctx) { - readonly AaruServerContext _ctx; - readonly IWebHostEnvironment _environment; + _environment = environment; + _ctx = ctx; + } - public UploadReportController(IWebHostEnvironment environment, AaruServerContext ctx) + /// Receives a report from Aaru.Core, verifies it's in the correct format and stores it on the server + /// HTTP response + [Route("api/uploadreport"), HttpPost] + public async Task UploadReport() + { + var response = new ContentResult { - _environment = environment; - _ctx = ctx; - } + StatusCode = (int)HttpStatusCode.OK, + ContentType = "text/plain" + }; - /// Receives a report from Aaru.Core, verifies it's in the correct format and stores it on the server - /// HTTP response - [Route("api/uploadreport"), HttpPost] - public async Task UploadReport() + try { - var response = new ContentResult + var newReport = new DeviceReport(); + HttpRequest request = HttpContext.Request; + + var xs = new XmlSerializer(newReport.GetType()); + + newReport = + (DeviceReport) + xs.Deserialize(new StringReader(await new StreamReader(request.Body).ReadToEndAsync())); + + if(newReport == null) { - StatusCode = (int)HttpStatusCode.OK, - ContentType = "text/plain" + response.Content = "notstats"; + + return response; + } + + var reportV2 = new DeviceReportV2(newReport); + var jsonSw = new StringWriter(); + + await jsonSw.WriteAsync(JsonConvert.SerializeObject(reportV2, Formatting.Indented, + new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + })); + + string reportV2String = jsonSw.ToString(); + jsonSw.Close(); + + var newUploadedReport = new UploadedReport(reportV2); + + // Ensure CHS and CurrentCHS are not duplicates + if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null && + newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) + { + if(newUploadedReport.ATA.ReadCapabilities.CHS.Cylinders == + newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Cylinders && + newUploadedReport.ATA.ReadCapabilities.CHS.Heads == + newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Heads && + newUploadedReport.ATA.ReadCapabilities.CHS.Sectors == + newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Sectors) + { + newUploadedReport.ATA.ReadCapabilities.CHS = newUploadedReport.ATA.ReadCapabilities.CurrentCHS; + } + } + + // Check if the CHS or CurrentCHS of this report already exist in the database + if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => + c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CHS. + Cylinders && + c.Heads == newUploadedReport.ATA.ReadCapabilities.CHS.Heads && + c.Sectors == newUploadedReport.ATA.ReadCapabilities.CHS.Sectors); + + if(existingChs != null) + newUploadedReport.ATA.ReadCapabilities.CHS = existingChs; + } + + if(newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => + c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. + Cylinders && + c.Heads == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. + Heads && c.Sectors == newUploadedReport.ATA.ReadCapabilities. + CurrentCHS.Sectors); + + if(existingChs != null) + newUploadedReport.ATA.ReadCapabilities.CurrentCHS = existingChs; + } + + if(newUploadedReport.ATA?.RemovableMedias != null) + { + foreach(TestedMedia media in newUploadedReport.ATA.RemovableMedias) + { + if(media.CHS != null && + media.CurrentCHS != null) + { + if(media.CHS.Cylinders == media.CurrentCHS.Cylinders && + media.CHS.Heads == media.CurrentCHS.Heads && + media.CHS.Sectors == media.CurrentCHS.Sectors) + { + media.CHS = media.CurrentCHS; + } + } + + if(media.CHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CHS.Cylinders && + c.Heads == media.CHS.Heads && + c.Sectors == media.CHS.Sectors); + + if(existingChs != null) + media.CHS = existingChs; + } + + if(media.CHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CurrentCHS.Cylinders && + c.Heads == media.CurrentCHS.Heads && + c.Sectors == media.CurrentCHS.Sectors); + + if(existingChs != null) + media.CurrentCHS = existingChs; + } + } + } + + await _ctx.Reports.AddAsync(newUploadedReport); + await _ctx.SaveChangesAsync(); + + var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportV2String)); + var pgpOut = new MemoryStream(); + var pgp = new ChoPGPEncryptDecrypt(); + + await pgp.EncryptAsync(pgpIn, pgpOut, + Path.Combine(_environment.ContentRootPath ?? throw new InvalidOperationException(), + "public.asc")); + + pgpOut.Position = 0; + reportV2String = Encoding.UTF8.GetString(pgpOut.ToArray()); + + var message = new MimeMessage + { + Subject = "New device report (old version)", + Body = new TextPart("plain") + { + Text = reportV2String + } }; - try + message.From.Add(new MailboxAddress("Aaru Server", "aaru@claunia.com")); + message.To.Add(new MailboxAddress("Natalia Portillo", "claunia@claunia.com")); + + using(var client = new SmtpClient()) { - var newReport = new DeviceReport(); - HttpRequest request = HttpContext.Request; - - var xs = new XmlSerializer(newReport.GetType()); - - newReport = - (DeviceReport) - xs.Deserialize(new StringReader(await new StreamReader(request.Body).ReadToEndAsync())); - - if(newReport == null) - { - response.Content = "notstats"; - - return response; - } - - var reportV2 = new DeviceReportV2(newReport); - var jsonSw = new StringWriter(); - - await jsonSw.WriteAsync(JsonConvert.SerializeObject(reportV2, Formatting.Indented, - new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - })); - - string reportV2String = jsonSw.ToString(); - jsonSw.Close(); - - var newUploadedReport = new UploadedReport(reportV2); - - // Ensure CHS and CurrentCHS are not duplicates - if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null && - newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) - { - if(newUploadedReport.ATA.ReadCapabilities.CHS.Cylinders == - newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Cylinders && - newUploadedReport.ATA.ReadCapabilities.CHS.Heads == - newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Heads && - newUploadedReport.ATA.ReadCapabilities.CHS.Sectors == - newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Sectors) - { - newUploadedReport.ATA.ReadCapabilities.CHS = newUploadedReport.ATA.ReadCapabilities.CurrentCHS; - } - } - - // Check if the CHS or CurrentCHS of this report already exist in the database - if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => - c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CHS. - Cylinders && - c.Heads == newUploadedReport.ATA.ReadCapabilities.CHS.Heads && - c.Sectors == newUploadedReport.ATA.ReadCapabilities.CHS.Sectors); - - if(existingChs != null) - newUploadedReport.ATA.ReadCapabilities.CHS = existingChs; - } - - if(newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => - c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. - Cylinders && - c.Heads == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. - Heads && c.Sectors == newUploadedReport.ATA.ReadCapabilities. - CurrentCHS.Sectors); - - if(existingChs != null) - newUploadedReport.ATA.ReadCapabilities.CurrentCHS = existingChs; - } - - if(newUploadedReport.ATA?.RemovableMedias != null) - { - foreach(TestedMedia media in newUploadedReport.ATA.RemovableMedias) - { - if(media.CHS != null && - media.CurrentCHS != null) - { - if(media.CHS.Cylinders == media.CurrentCHS.Cylinders && - media.CHS.Heads == media.CurrentCHS.Heads && - media.CHS.Sectors == media.CurrentCHS.Sectors) - { - media.CHS = media.CurrentCHS; - } - } - - if(media.CHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CHS.Cylinders && - c.Heads == media.CHS.Heads && - c.Sectors == media.CHS.Sectors); - - if(existingChs != null) - media.CHS = existingChs; - } - - if(media.CHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CurrentCHS.Cylinders && - c.Heads == media.CurrentCHS.Heads && - c.Sectors == media.CurrentCHS.Sectors); - - if(existingChs != null) - media.CurrentCHS = existingChs; - } - } - } - - await _ctx.Reports.AddAsync(newUploadedReport); - await _ctx.SaveChangesAsync(); - - var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportV2String)); - var pgpOut = new MemoryStream(); - var pgp = new ChoPGPEncryptDecrypt(); - - await pgp.EncryptAsync(pgpIn, pgpOut, - Path.Combine(_environment.ContentRootPath ?? throw new InvalidOperationException(), - "public.asc")); - - pgpOut.Position = 0; - reportV2String = Encoding.UTF8.GetString(pgpOut.ToArray()); - - var message = new MimeMessage - { - Subject = "New device report (old version)", - Body = new TextPart("plain") - { - Text = reportV2String - } - }; - - message.From.Add(new MailboxAddress("Aaru Server", "aaru@claunia.com")); - message.To.Add(new MailboxAddress("Natalia Portillo", "claunia@claunia.com")); - - using(var client = new SmtpClient()) - { - await client.ConnectAsync("mail.claunia.com", 25, false); - await client.SendAsync(message); - await client.DisconnectAsync(true); - } - - response.Content = "ok"; - - return response; + await client.ConnectAsync("mail.claunia.com", 25, false); + await client.SendAsync(message); + await client.DisconnectAsync(true); } - // ReSharper disable once RedundantCatchClause - catch - { - #if DEBUG - if(Debugger.IsAttached) - throw; - #endif - response.Content = "error"; + response.Content = "ok"; - return response; - } + return response; } - /// Receives a report from Aaru.Core, verifies it's in the correct format and stores it on the server - /// HTTP response - [Route("api/uploadreportv2"), HttpPost] - public async Task UploadReportV2() + // ReSharper disable once RedundantCatchClause + catch { - var response = new ContentResult + #if DEBUG + if(Debugger.IsAttached) + throw; + #endif + response.Content = "error"; + + return response; + } + } + + /// Receives a report from Aaru.Core, verifies it's in the correct format and stores it on the server + /// HTTP response + [Route("api/uploadreportv2"), HttpPost] + public async Task UploadReportV2() + { + var response = new ContentResult + { + StatusCode = (int)HttpStatusCode.OK, + ContentType = "text/plain" + }; + + try + { + HttpRequest request = HttpContext.Request; + + var sr = new StreamReader(request.Body); + string reportJson = await sr.ReadToEndAsync(); + DeviceReportV2 newReport = JsonConvert.DeserializeObject(reportJson); + + if(newReport == null) { - StatusCode = (int)HttpStatusCode.OK, - ContentType = "text/plain" + response.Content = "notstats"; + + return response; + } + + var newUploadedReport = new UploadedReport(newReport); + + // Ensure CHS and CurrentCHS are not duplicates + if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null && + newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) + { + if(newUploadedReport.ATA.ReadCapabilities.CHS.Cylinders == + newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Cylinders && + newUploadedReport.ATA.ReadCapabilities.CHS.Heads == + newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Heads && + newUploadedReport.ATA.ReadCapabilities.CHS.Sectors == + newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Sectors) + { + newUploadedReport.ATA.ReadCapabilities.CHS = newUploadedReport.ATA.ReadCapabilities.CurrentCHS; + } + } + + // Check if the CHS or CurrentCHS of this report already exist in the database + if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => + c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CHS. + Cylinders && + c.Heads == newUploadedReport.ATA.ReadCapabilities.CHS.Heads && + c.Sectors == newUploadedReport.ATA.ReadCapabilities.CHS.Sectors); + + if(existingChs != null) + newUploadedReport.ATA.ReadCapabilities.CHS = existingChs; + } + + if(newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => + c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. + Cylinders && + c.Heads == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. + Heads && c.Sectors == newUploadedReport.ATA.ReadCapabilities. + CurrentCHS.Sectors); + + if(existingChs != null) + newUploadedReport.ATA.ReadCapabilities.CurrentCHS = existingChs; + } + + if(newUploadedReport.ATA?.RemovableMedias != null) + { + foreach(TestedMedia media in newUploadedReport.ATA.RemovableMedias) + { + if(media.CHS != null && + media.CurrentCHS != null) + { + if(media.CHS.Cylinders == media.CurrentCHS.Cylinders && + media.CHS.Heads == media.CurrentCHS.Heads && + media.CHS.Sectors == media.CurrentCHS.Sectors) + { + media.CHS = media.CurrentCHS; + } + } + + if(media.CHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CHS.Cylinders && + c.Heads == media.CHS.Heads && + c.Sectors == media.CHS.Sectors); + + if(existingChs != null) + media.CHS = existingChs; + } + + if(media.CHS != null) + { + Chs existingChs = + _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CurrentCHS.Cylinders && + c.Heads == media.CurrentCHS.Heads && + c.Sectors == media.CurrentCHS.Sectors); + + if(existingChs != null) + media.CurrentCHS = existingChs; + } + } + } + + await _ctx.Reports.AddAsync(newUploadedReport); + await _ctx.SaveChangesAsync(); + + var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportJson)); + var pgpOut = new MemoryStream(); + var pgp = new ChoPGPEncryptDecrypt(); + + await pgp.EncryptAsync(pgpIn, pgpOut, + Path.Combine(_environment.ContentRootPath ?? throw new InvalidOperationException(), + "public.asc")); + + pgpOut.Position = 0; + reportJson = Encoding.UTF8.GetString(pgpOut.ToArray()); + + var message = new MimeMessage + { + Subject = "New device report", + Body = new TextPart("plain") + { + Text = reportJson + } }; - try + message.From.Add(new MailboxAddress("Aaru Server", "aaru@claunia.com")); + message.To.Add(new MailboxAddress("Natalia Portillo", "claunia@claunia.com")); + + using(var client = new SmtpClient()) { - HttpRequest request = HttpContext.Request; - - var sr = new StreamReader(request.Body); - string reportJson = await sr.ReadToEndAsync(); - DeviceReportV2 newReport = JsonConvert.DeserializeObject(reportJson); - - if(newReport == null) - { - response.Content = "notstats"; - - return response; - } - - var newUploadedReport = new UploadedReport(newReport); - - // Ensure CHS and CurrentCHS are not duplicates - if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null && - newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) - { - if(newUploadedReport.ATA.ReadCapabilities.CHS.Cylinders == - newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Cylinders && - newUploadedReport.ATA.ReadCapabilities.CHS.Heads == - newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Heads && - newUploadedReport.ATA.ReadCapabilities.CHS.Sectors == - newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Sectors) - { - newUploadedReport.ATA.ReadCapabilities.CHS = newUploadedReport.ATA.ReadCapabilities.CurrentCHS; - } - } - - // Check if the CHS or CurrentCHS of this report already exist in the database - if(newUploadedReport.ATA?.ReadCapabilities?.CHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => - c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CHS. - Cylinders && - c.Heads == newUploadedReport.ATA.ReadCapabilities.CHS.Heads && - c.Sectors == newUploadedReport.ATA.ReadCapabilities.CHS.Sectors); - - if(existingChs != null) - newUploadedReport.ATA.ReadCapabilities.CHS = existingChs; - } - - if(newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => - c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. - Cylinders && - c.Heads == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. - Heads && c.Sectors == newUploadedReport.ATA.ReadCapabilities. - CurrentCHS.Sectors); - - if(existingChs != null) - newUploadedReport.ATA.ReadCapabilities.CurrentCHS = existingChs; - } - - if(newUploadedReport.ATA?.RemovableMedias != null) - { - foreach(TestedMedia media in newUploadedReport.ATA.RemovableMedias) - { - if(media.CHS != null && - media.CurrentCHS != null) - { - if(media.CHS.Cylinders == media.CurrentCHS.Cylinders && - media.CHS.Heads == media.CurrentCHS.Heads && - media.CHS.Sectors == media.CurrentCHS.Sectors) - { - media.CHS = media.CurrentCHS; - } - } - - if(media.CHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CHS.Cylinders && - c.Heads == media.CHS.Heads && - c.Sectors == media.CHS.Sectors); - - if(existingChs != null) - media.CHS = existingChs; - } - - if(media.CHS != null) - { - Chs existingChs = - _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CurrentCHS.Cylinders && - c.Heads == media.CurrentCHS.Heads && - c.Sectors == media.CurrentCHS.Sectors); - - if(existingChs != null) - media.CurrentCHS = existingChs; - } - } - } - - await _ctx.Reports.AddAsync(newUploadedReport); - await _ctx.SaveChangesAsync(); - - var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportJson)); - var pgpOut = new MemoryStream(); - var pgp = new ChoPGPEncryptDecrypt(); - - await pgp.EncryptAsync(pgpIn, pgpOut, - Path.Combine(_environment.ContentRootPath ?? throw new InvalidOperationException(), - "public.asc")); - - pgpOut.Position = 0; - reportJson = Encoding.UTF8.GetString(pgpOut.ToArray()); - - var message = new MimeMessage - { - Subject = "New device report", - Body = new TextPart("plain") - { - Text = reportJson - } - }; - - message.From.Add(new MailboxAddress("Aaru Server", "aaru@claunia.com")); - message.To.Add(new MailboxAddress("Natalia Portillo", "claunia@claunia.com")); - - using(var client = new SmtpClient()) - { - await client.ConnectAsync("mail.claunia.com", 25, false); - await client.SendAsync(message); - await client.DisconnectAsync(true); - } - - response.Content = "ok"; - - return response; + await client.ConnectAsync("mail.claunia.com", 25, false); + await client.SendAsync(message); + await client.DisconnectAsync(true); } - // ReSharper disable once RedundantCatchClause - catch - { - #if DEBUG - if(Debugger.IsAttached) - throw; - #endif - response.Content = "error"; + response.Content = "ok"; - return response; - } + return response; + } + + // ReSharper disable once RedundantCatchClause + catch + { + #if DEBUG + if(Debugger.IsAttached) + throw; + #endif + response.Content = "error"; + + return response; } } } \ No newline at end of file diff --git a/Aaru.Server/Core/Ata.cs b/Aaru.Server/Core/Ata.cs index b1ccc032..f583ab35 100644 --- a/Aaru.Server/Core/Ata.cs +++ b/Aaru.Server/Core/Ata.cs @@ -34,1808 +34,1807 @@ using System.Collections.Generic; using Aaru.CommonTypes.Structs.Devices.ATA; using Aaru.CommonTypes.Structs.Devices.SCSI; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class Ata { - public static class Ata + /// + /// Takes the ATA part of a device report and prints it as a list of values and another list of key=value pairs to + /// be sequenced by ASP.NET in the rendering + /// + /// ATA part of a device report + /// true if compact flash device + /// true if atapi device + /// true if removable device + /// List to put values on + /// List to put key=value pairs on + /// List of tested media + public static void Report(CommonTypes.Metadata.Ata ataReport, bool cfa, bool atapi, ref bool removable, + ref List ataOneValue, ref Dictionary ataTwoValue, + ref List testedMedia) { - /// - /// Takes the ATA part of a device report and prints it as a list of values and another list of key=value pairs to - /// be sequenced by ASP.NET in the rendering - /// - /// ATA part of a device report - /// true if compact flash device - /// true if atapi device - /// true if removable device - /// List to put values on - /// List to put key=value pairs on - /// List of tested media - public static void Report(CommonTypes.Metadata.Ata ataReport, bool cfa, bool atapi, ref bool removable, - ref List ataOneValue, ref Dictionary ataTwoValue, - ref List testedMedia) + uint logicalSectorSize = 0; + + Identify.IdentifyDevice? ataIdentifyNullable = Identify.Decode(ataReport.Identify); + + if(!ataIdentifyNullable.HasValue) + return; + + Identify.IdentifyDevice ataIdentify = ataIdentifyNullable.Value; + + if(!string.IsNullOrEmpty(ataIdentify.Model)) + ataTwoValue.Add("Model", ataIdentify.Model); + + if(!string.IsNullOrEmpty(ataIdentify.FirmwareRevision)) + ataTwoValue.Add("Firmware revision", ataIdentify.FirmwareRevision); + + if(!string.IsNullOrEmpty(ataIdentify.AdditionalPID)) + ataTwoValue.Add("Additional product ID", ataIdentify.AdditionalPID); + + bool ata1 = false, ata2 = false, ata3 = false, ata4 = false, ata5 = false, ata6 = false, ata7 = false, + acs = false, acs2 = false, acs3 = false, acs4 = false; + + if((ushort)ataIdentify.MajorVersion == 0x0000 || + (ushort)ataIdentify.MajorVersion == 0xFFFF) { - uint logicalSectorSize = 0; + // Obsolete in ATA-2, if present, device supports ATA-1 + ata1 |= ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.FastIDE) || + ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SlowIDE) || + ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.UltraFastIDE); - Identify.IdentifyDevice? ataIdentifyNullable = Identify.Decode(ataReport.Identify); + ata2 |= ataIdentify.ExtendedIdentify.HasFlag(Identify.ExtendedIdentifyBit.Words54to58Valid) || + ataIdentify.ExtendedIdentify.HasFlag(Identify.ExtendedIdentifyBit.Words64to70Valid) || + ataIdentify.ExtendedIdentify.HasFlag(Identify.ExtendedIdentifyBit.Word88Valid); - if(!ataIdentifyNullable.HasValue) - return; + if(!ata1 && + !ata2 && + !atapi && + !cfa) + ata2 = true; - Identify.IdentifyDevice ataIdentify = ataIdentifyNullable.Value; + ata4 |= atapi; + ata3 |= cfa; - if(!string.IsNullOrEmpty(ataIdentify.Model)) - ataTwoValue.Add("Model", ataIdentify.Model); + if(cfa && ata1) + ata1 = false; - if(!string.IsNullOrEmpty(ataIdentify.FirmwareRevision)) - ataTwoValue.Add("Firmware revision", ataIdentify.FirmwareRevision); + if(cfa && ata2) + ata2 = false; + } + else + { + ata1 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata1); + ata2 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata2); + ata3 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata3); + ata4 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi4); + ata5 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi5); + ata6 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi6); + ata7 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi7); + acs |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata8ACS); + acs2 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.ACS2); + acs3 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.ACS3); + acs4 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.ACS4); + } - if(!string.IsNullOrEmpty(ataIdentify.AdditionalPID)) - ataTwoValue.Add("Additional product ID", ataIdentify.AdditionalPID); + int maxAtaLevel = 0; + int minAtaLevel = 255; + string tmpString = ""; - bool ata1 = false, ata2 = false, ata3 = false, ata4 = false, ata5 = false, ata6 = false, ata7 = false, - acs = false, acs2 = false, acs3 = false, acs4 = false; + if(ata1) + { + tmpString += "ATA-1 "; + maxAtaLevel = 1; + minAtaLevel = 1; + } - if((ushort)ataIdentify.MajorVersion == 0x0000 || - (ushort)ataIdentify.MajorVersion == 0xFFFF) + if(ata2) + { + tmpString += "ATA-2 "; + maxAtaLevel = 2; + + if(minAtaLevel > 2) + minAtaLevel = 2; + } + + if(ata3) + { + tmpString += "ATA-3 "; + maxAtaLevel = 3; + + if(minAtaLevel > 3) + minAtaLevel = 3; + } + + if(ata4) + { + tmpString += "ATA/ATAPI-4 "; + maxAtaLevel = 4; + + if(minAtaLevel > 4) + minAtaLevel = 4; + } + + if(ata5) + { + tmpString += "ATA/ATAPI-5 "; + maxAtaLevel = 5; + + if(minAtaLevel > 5) + minAtaLevel = 5; + } + + if(ata6) + { + tmpString += "ATA/ATAPI-6 "; + maxAtaLevel = 6; + + if(minAtaLevel > 6) + minAtaLevel = 6; + } + + if(ata7) + { + tmpString += "ATA/ATAPI-7 "; + maxAtaLevel = 7; + + if(minAtaLevel > 7) + minAtaLevel = 7; + } + + if(acs) + { + tmpString += "ATA8-ACS "; + maxAtaLevel = 8; + + if(minAtaLevel > 8) + minAtaLevel = 8; + } + + if(acs2) + { + tmpString += "ATA8-ACS2 "; + maxAtaLevel = 9; + + if(minAtaLevel > 9) + minAtaLevel = 9; + } + + if(acs3) + { + tmpString += "ATA8-ACS3 "; + maxAtaLevel = 10; + + if(minAtaLevel > 10) + minAtaLevel = 10; + } + + if(acs4) + { + tmpString += "ATA8-ACS4 "; + maxAtaLevel = 11; + + if(minAtaLevel > 11) + minAtaLevel = 11; + } + + if(tmpString != "") + ataTwoValue.Add("Supported ATA versions", tmpString); + + if(maxAtaLevel >= 3) + { + switch(ataIdentify.MinorVersion) { - // Obsolete in ATA-2, if present, device supports ATA-1 - ata1 |= ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.FastIDE) || - ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SlowIDE) || - ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.UltraFastIDE); - - ata2 |= ataIdentify.ExtendedIdentify.HasFlag(Identify.ExtendedIdentifyBit.Words54to58Valid) || - ataIdentify.ExtendedIdentify.HasFlag(Identify.ExtendedIdentifyBit.Words64to70Valid) || - ataIdentify.ExtendedIdentify.HasFlag(Identify.ExtendedIdentifyBit.Word88Valid); - - if(!ata1 && - !ata2 && - !atapi && - !cfa) - ata2 = true; - - ata4 |= atapi; - ata3 |= cfa; - - if(cfa && ata1) - ata1 = false; - - if(cfa && ata2) - ata2 = false; - } - else - { - ata1 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata1); - ata2 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata2); - ata3 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata3); - ata4 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi4); - ata5 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi5); - ata6 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi6); - ata7 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.AtaAtapi7); - acs |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.Ata8ACS); - acs2 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.ACS2); - acs3 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.ACS3); - acs4 |= ataIdentify.MajorVersion.HasFlag(Identify.MajorVersionBit.ACS4); - } - - int maxAtaLevel = 0; - int minAtaLevel = 255; - string tmpString = ""; - - if(ata1) - { - tmpString += "ATA-1 "; - maxAtaLevel = 1; - minAtaLevel = 1; - } - - if(ata2) - { - tmpString += "ATA-2 "; - maxAtaLevel = 2; - - if(minAtaLevel > 2) - minAtaLevel = 2; - } - - if(ata3) - { - tmpString += "ATA-3 "; - maxAtaLevel = 3; - - if(minAtaLevel > 3) - minAtaLevel = 3; - } - - if(ata4) - { - tmpString += "ATA/ATAPI-4 "; - maxAtaLevel = 4; - - if(minAtaLevel > 4) - minAtaLevel = 4; - } - - if(ata5) - { - tmpString += "ATA/ATAPI-5 "; - maxAtaLevel = 5; - - if(minAtaLevel > 5) - minAtaLevel = 5; - } - - if(ata6) - { - tmpString += "ATA/ATAPI-6 "; - maxAtaLevel = 6; - - if(minAtaLevel > 6) - minAtaLevel = 6; - } - - if(ata7) - { - tmpString += "ATA/ATAPI-7 "; - maxAtaLevel = 7; - - if(minAtaLevel > 7) - minAtaLevel = 7; - } - - if(acs) - { - tmpString += "ATA8-ACS "; - maxAtaLevel = 8; - - if(minAtaLevel > 8) - minAtaLevel = 8; - } - - if(acs2) - { - tmpString += "ATA8-ACS2 "; - maxAtaLevel = 9; - - if(minAtaLevel > 9) - minAtaLevel = 9; - } - - if(acs3) - { - tmpString += "ATA8-ACS3 "; - maxAtaLevel = 10; - - if(minAtaLevel > 10) - minAtaLevel = 10; - } - - if(acs4) - { - tmpString += "ATA8-ACS4 "; - maxAtaLevel = 11; - - if(minAtaLevel > 11) - minAtaLevel = 11; - } - - if(tmpString != "") - ataTwoValue.Add("Supported ATA versions", tmpString); - - if(maxAtaLevel >= 3) - { - switch(ataIdentify.MinorVersion) - { - case 0x0000: - case 0xFFFF: - tmpString = "Minor ATA version not specified"; - - break; - case 0x0001: - tmpString = "ATA (ATA-1) X3T9.2 781D prior to revision 4"; - - break; - case 0x0002: - tmpString = "ATA-1 published, ANSI X3.221-1994"; - - break; - case 0x0003: - tmpString = "ATA (ATA-1) X3T9.2 781D revision 4"; - - break; - case 0x0004: - tmpString = "ATA-2 published, ANSI X3.279-1996"; - - break; - case 0x0005: - tmpString = "ATA-2 X3T10 948D prior to revision 2k"; - - break; - case 0x0006: - tmpString = "ATA-3 X3T10 2008D revision 1"; - - break; - case 0x0007: - tmpString = "ATA-2 X3T10 948D revision 2k"; - - break; - case 0x0008: - tmpString = "ATA-3 X3T10 2008D revision 0"; - - break; - case 0x0009: - tmpString = "ATA-2 X3T10 948D revision 3"; - - break; - case 0x000A: - tmpString = "ATA-3 published, ANSI X3.298-1997"; - - break; - case 0x000B: - tmpString = "ATA-3 X3T10 2008D revision 6"; - - break; - case 0x000C: - tmpString = "ATA-3 X3T13 2008D revision 7"; - - break; - case 0x000D: - tmpString = "ATA/ATAPI-4 X3T13 1153D revision 6"; - - break; - case 0x000E: - tmpString = "ATA/ATAPI-4 T13 1153D revision 13"; - - break; - case 0x000F: - tmpString = "ATA/ATAPI-4 X3T13 1153D revision 7"; - - break; - case 0x0010: - tmpString = "ATA/ATAPI-4 T13 1153D revision 18"; - - break; - case 0x0011: - tmpString = "ATA/ATAPI-4 T13 1153D revision 15"; - - break; - case 0x0012: - tmpString = "ATA/ATAPI-4 published, ANSI INCITS 317-1998"; - - break; - case 0x0013: - tmpString = "ATA/ATAPI-5 T13 1321D revision 3"; - - break; - case 0x0014: - tmpString = "ATA/ATAPI-4 T13 1153D revision 14"; - - break; - case 0x0015: - tmpString = "ATA/ATAPI-5 T13 1321D revision 1"; - - break; - case 0x0016: - tmpString = "ATA/ATAPI-5 published, ANSI INCITS 340-2000"; - - break; - case 0x0017: - tmpString = "ATA/ATAPI-4 T13 1153D revision 17"; - - break; - case 0x0018: - tmpString = "ATA/ATAPI-6 T13 1410D revision 0"; - - break; - case 0x0019: - tmpString = "ATA/ATAPI-6 T13 1410D revision 3a"; - - break; - case 0x001A: - tmpString = "ATA/ATAPI-7 T13 1532D revision 1"; - - break; - case 0x001B: - tmpString = "ATA/ATAPI-6 T13 1410D revision 2"; - - break; - case 0x001C: - tmpString = "ATA/ATAPI-6 T13 1410D revision 1"; - - break; - case 0x001D: - tmpString = "ATA/ATAPI-7 published ANSI INCITS 397-2005"; - - break; - case 0x001E: - tmpString = "ATA/ATAPI-7 T13 1532D revision 0"; - - break; - case 0x001F: - tmpString = "ACS-3 Revision 3b"; - - break; - case 0x0021: - tmpString = "ATA/ATAPI-7 T13 1532D revision 4a"; - - break; - case 0x0022: - tmpString = "ATA/ATAPI-6 published, ANSI INCITS 361-2002"; - - break; - case 0x0027: - tmpString = "ATA8-ACS revision 3c"; - - break; - case 0x0028: - tmpString = "ATA8-ACS revision 6"; - - break; - case 0x0029: - tmpString = "ATA8-ACS revision 4"; - - break; - case 0x0031: - tmpString = "ACS-2 Revision 2"; - - break; - case 0x0033: - tmpString = "ATA8-ACS Revision 3e"; - - break; - case 0x0039: - tmpString = "ATA8-ACS Revision 4c"; - - break; - case 0x0042: - tmpString = "ATA8-ACS Revision 3f"; - - break; - case 0x0052: - tmpString = "ATA8-ACS revision 3b"; - - break; - case 0x006D: - tmpString = "ACS-3 Revision 5"; - - break; - case 0x0082: - tmpString = "ACS-2 published, ANSI INCITS 482-2012"; - - break; - case 0x0107: - tmpString = "ATA8-ACS revision 2d"; - - break; - case 0x0110: - tmpString = "ACS-2 Revision 3"; - - break; - case 0x011B: - tmpString = "ACS-3 Revision 4"; - - break; - default: - tmpString = $"Unknown ATA revision 0x{ataIdentify.MinorVersion:X4}"; - - break; - } - - ataTwoValue.Add("Maximum ATA revision supported", tmpString); - } - - tmpString = ""; - - switch((ataIdentify.TransportMajorVersion & 0xF000) >> 12) - { - case 0x0: - if((ataIdentify.TransportMajorVersion & 0x0002) == 0x0002) - tmpString += "ATA/ATAPI-7 "; - - if((ataIdentify.TransportMajorVersion & 0x0001) == 0x0001) - tmpString += "ATA8-APT "; - - ataTwoValue.Add("Parallel ATA device", tmpString); + case 0x0000: + case 0xFFFF: + tmpString = "Minor ATA version not specified"; break; - case 0x1: - if((ataIdentify.TransportMajorVersion & 0x0001) == 0x0001) - tmpString += "ATA8-AST "; - - if((ataIdentify.TransportMajorVersion & 0x0002) == 0x0002) - tmpString += "SATA 1.0a "; - - if((ataIdentify.TransportMajorVersion & 0x0004) == 0x0004) - tmpString += "SATA II Extensions "; - - if((ataIdentify.TransportMajorVersion & 0x0008) == 0x0008) - tmpString += "SATA 2.5 "; - - if((ataIdentify.TransportMajorVersion & 0x0010) == 0x0010) - tmpString += "SATA 2.6 "; - - if((ataIdentify.TransportMajorVersion & 0x0020) == 0x0020) - tmpString += "SATA 3.0 "; - - if((ataIdentify.TransportMajorVersion & 0x0040) == 0x0040) - tmpString += "SATA 3.1 "; - - ataTwoValue.Add("Serial ATA device: ", tmpString); + case 0x0001: + tmpString = "ATA (ATA-1) X3T9.2 781D prior to revision 4"; break; - case 0xE: - ataTwoValue.Add("SATA Express device", "No version"); + case 0x0002: + tmpString = "ATA-1 published, ANSI X3.221-1994"; + + break; + case 0x0003: + tmpString = "ATA (ATA-1) X3T9.2 781D revision 4"; + + break; + case 0x0004: + tmpString = "ATA-2 published, ANSI X3.279-1996"; + + break; + case 0x0005: + tmpString = "ATA-2 X3T10 948D prior to revision 2k"; + + break; + case 0x0006: + tmpString = "ATA-3 X3T10 2008D revision 1"; + + break; + case 0x0007: + tmpString = "ATA-2 X3T10 948D revision 2k"; + + break; + case 0x0008: + tmpString = "ATA-3 X3T10 2008D revision 0"; + + break; + case 0x0009: + tmpString = "ATA-2 X3T10 948D revision 3"; + + break; + case 0x000A: + tmpString = "ATA-3 published, ANSI X3.298-1997"; + + break; + case 0x000B: + tmpString = "ATA-3 X3T10 2008D revision 6"; + + break; + case 0x000C: + tmpString = "ATA-3 X3T13 2008D revision 7"; + + break; + case 0x000D: + tmpString = "ATA/ATAPI-4 X3T13 1153D revision 6"; + + break; + case 0x000E: + tmpString = "ATA/ATAPI-4 T13 1153D revision 13"; + + break; + case 0x000F: + tmpString = "ATA/ATAPI-4 X3T13 1153D revision 7"; + + break; + case 0x0010: + tmpString = "ATA/ATAPI-4 T13 1153D revision 18"; + + break; + case 0x0011: + tmpString = "ATA/ATAPI-4 T13 1153D revision 15"; + + break; + case 0x0012: + tmpString = "ATA/ATAPI-4 published, ANSI INCITS 317-1998"; + + break; + case 0x0013: + tmpString = "ATA/ATAPI-5 T13 1321D revision 3"; + + break; + case 0x0014: + tmpString = "ATA/ATAPI-4 T13 1153D revision 14"; + + break; + case 0x0015: + tmpString = "ATA/ATAPI-5 T13 1321D revision 1"; + + break; + case 0x0016: + tmpString = "ATA/ATAPI-5 published, ANSI INCITS 340-2000"; + + break; + case 0x0017: + tmpString = "ATA/ATAPI-4 T13 1153D revision 17"; + + break; + case 0x0018: + tmpString = "ATA/ATAPI-6 T13 1410D revision 0"; + + break; + case 0x0019: + tmpString = "ATA/ATAPI-6 T13 1410D revision 3a"; + + break; + case 0x001A: + tmpString = "ATA/ATAPI-7 T13 1532D revision 1"; + + break; + case 0x001B: + tmpString = "ATA/ATAPI-6 T13 1410D revision 2"; + + break; + case 0x001C: + tmpString = "ATA/ATAPI-6 T13 1410D revision 1"; + + break; + case 0x001D: + tmpString = "ATA/ATAPI-7 published ANSI INCITS 397-2005"; + + break; + case 0x001E: + tmpString = "ATA/ATAPI-7 T13 1532D revision 0"; + + break; + case 0x001F: + tmpString = "ACS-3 Revision 3b"; + + break; + case 0x0021: + tmpString = "ATA/ATAPI-7 T13 1532D revision 4a"; + + break; + case 0x0022: + tmpString = "ATA/ATAPI-6 published, ANSI INCITS 361-2002"; + + break; + case 0x0027: + tmpString = "ATA8-ACS revision 3c"; + + break; + case 0x0028: + tmpString = "ATA8-ACS revision 6"; + + break; + case 0x0029: + tmpString = "ATA8-ACS revision 4"; + + break; + case 0x0031: + tmpString = "ACS-2 Revision 2"; + + break; + case 0x0033: + tmpString = "ATA8-ACS Revision 3e"; + + break; + case 0x0039: + tmpString = "ATA8-ACS Revision 4c"; + + break; + case 0x0042: + tmpString = "ATA8-ACS Revision 3f"; + + break; + case 0x0052: + tmpString = "ATA8-ACS revision 3b"; + + break; + case 0x006D: + tmpString = "ACS-3 Revision 5"; + + break; + case 0x0082: + tmpString = "ACS-2 published, ANSI INCITS 482-2012"; + + break; + case 0x0107: + tmpString = "ATA8-ACS revision 2d"; + + break; + case 0x0110: + tmpString = "ACS-2 Revision 3"; + + break; + case 0x011B: + tmpString = "ACS-3 Revision 4"; break; default: - ataTwoValue.Add("Unknown transport type", - $"0x{(ataIdentify.TransportMajorVersion & 0xF000) >> 12:X1}"); + tmpString = $"Unknown ATA revision 0x{ataIdentify.MinorVersion:X4}"; break; } - if(atapi) + ataTwoValue.Add("Maximum ATA revision supported", tmpString); + } + + tmpString = ""; + + switch((ataIdentify.TransportMajorVersion & 0xF000) >> 12) + { + case 0x0: + if((ataIdentify.TransportMajorVersion & 0x0002) == 0x0002) + tmpString += "ATA/ATAPI-7 "; + + if((ataIdentify.TransportMajorVersion & 0x0001) == 0x0001) + tmpString += "ATA8-APT "; + + ataTwoValue.Add("Parallel ATA device", tmpString); + + break; + case 0x1: + if((ataIdentify.TransportMajorVersion & 0x0001) == 0x0001) + tmpString += "ATA8-AST "; + + if((ataIdentify.TransportMajorVersion & 0x0002) == 0x0002) + tmpString += "SATA 1.0a "; + + if((ataIdentify.TransportMajorVersion & 0x0004) == 0x0004) + tmpString += "SATA II Extensions "; + + if((ataIdentify.TransportMajorVersion & 0x0008) == 0x0008) + tmpString += "SATA 2.5 "; + + if((ataIdentify.TransportMajorVersion & 0x0010) == 0x0010) + tmpString += "SATA 2.6 "; + + if((ataIdentify.TransportMajorVersion & 0x0020) == 0x0020) + tmpString += "SATA 3.0 "; + + if((ataIdentify.TransportMajorVersion & 0x0040) == 0x0040) + tmpString += "SATA 3.1 "; + + ataTwoValue.Add("Serial ATA device: ", tmpString); + + break; + case 0xE: + ataTwoValue.Add("SATA Express device", "No version"); + + break; + default: + ataTwoValue.Add("Unknown transport type", + $"0x{(ataIdentify.TransportMajorVersion & 0xF000) >> 12:X1}"); + + break; + } + + if(atapi) + { + // Bits 12 to 8, SCSI Peripheral Device Type + switch((PeripheralDeviceTypes)(((ushort)ataIdentify.GeneralConfiguration & 0x1F00) >> 8)) { - // Bits 12 to 8, SCSI Peripheral Device Type - switch((PeripheralDeviceTypes)(((ushort)ataIdentify.GeneralConfiguration & 0x1F00) >> 8)) - { - case PeripheralDeviceTypes.DirectAccess: //0x00, - ataOneValue.Add("ATAPI Direct-access device"); + case PeripheralDeviceTypes.DirectAccess: //0x00, + ataOneValue.Add("ATAPI Direct-access device"); - break; - case PeripheralDeviceTypes.SequentialAccess: //0x01, - ataOneValue.Add("ATAPI Sequential-access device"); + break; + case PeripheralDeviceTypes.SequentialAccess: //0x01, + ataOneValue.Add("ATAPI Sequential-access device"); - break; - case PeripheralDeviceTypes.PrinterDevice: //0x02, - ataOneValue.Add("ATAPI Printer device"); + break; + case PeripheralDeviceTypes.PrinterDevice: //0x02, + ataOneValue.Add("ATAPI Printer device"); - break; - case PeripheralDeviceTypes.ProcessorDevice: //0x03, - ataOneValue.Add("ATAPI Processor device"); + break; + case PeripheralDeviceTypes.ProcessorDevice: //0x03, + ataOneValue.Add("ATAPI Processor device"); - break; - case PeripheralDeviceTypes.WriteOnceDevice: //0x04, - ataOneValue.Add("ATAPI Write-once device"); + break; + case PeripheralDeviceTypes.WriteOnceDevice: //0x04, + ataOneValue.Add("ATAPI Write-once device"); - break; - case PeripheralDeviceTypes.MultiMediaDevice: //0x05, - ataOneValue.Add("ATAPI CD-ROM/DVD/etc device"); + break; + case PeripheralDeviceTypes.MultiMediaDevice: //0x05, + ataOneValue.Add("ATAPI CD-ROM/DVD/etc device"); - break; - case PeripheralDeviceTypes.ScannerDevice: //0x06, - ataOneValue.Add("ATAPI Scanner device"); + break; + case PeripheralDeviceTypes.ScannerDevice: //0x06, + ataOneValue.Add("ATAPI Scanner device"); - break; - case PeripheralDeviceTypes.OpticalDevice: //0x07, - ataOneValue.Add("ATAPI Optical memory device"); + break; + case PeripheralDeviceTypes.OpticalDevice: //0x07, + ataOneValue.Add("ATAPI Optical memory device"); - break; - case PeripheralDeviceTypes.MediumChangerDevice: //0x08, - ataOneValue.Add("ATAPI Medium change device"); + break; + case PeripheralDeviceTypes.MediumChangerDevice: //0x08, + ataOneValue.Add("ATAPI Medium change device"); - break; - case PeripheralDeviceTypes.CommsDevice: //0x09, - ataOneValue.Add("ATAPI Communications device"); + break; + case PeripheralDeviceTypes.CommsDevice: //0x09, + ataOneValue.Add("ATAPI Communications device"); - break; - case PeripheralDeviceTypes.PrePressDevice1: //0x0A, - ataOneValue.Add("ATAPI Graphics arts pre-press device (defined in ASC IT8)"); + break; + case PeripheralDeviceTypes.PrePressDevice1: //0x0A, + ataOneValue.Add("ATAPI Graphics arts pre-press device (defined in ASC IT8)"); - break; - case PeripheralDeviceTypes.PrePressDevice2: //0x0B, - ataOneValue.Add("ATAPI Graphics arts pre-press device (defined in ASC IT8)"); + break; + case PeripheralDeviceTypes.PrePressDevice2: //0x0B, + ataOneValue.Add("ATAPI Graphics arts pre-press device (defined in ASC IT8)"); - break; - case PeripheralDeviceTypes.ArrayControllerDevice: //0x0C, - ataOneValue.Add("ATAPI Array controller device"); + break; + case PeripheralDeviceTypes.ArrayControllerDevice: //0x0C, + ataOneValue.Add("ATAPI Array controller device"); - break; - case PeripheralDeviceTypes.EnclosureServiceDevice: //0x0D, - ataOneValue.Add("ATAPI Enclosure services device"); + break; + case PeripheralDeviceTypes.EnclosureServiceDevice: //0x0D, + ataOneValue.Add("ATAPI Enclosure services device"); - break; - case PeripheralDeviceTypes.SimplifiedDevice: //0x0E, - ataOneValue.Add("ATAPI Simplified direct-access device"); + break; + case PeripheralDeviceTypes.SimplifiedDevice: //0x0E, + ataOneValue.Add("ATAPI Simplified direct-access device"); - break; - case PeripheralDeviceTypes.OCRWDevice: //0x0F, - ataOneValue.Add("ATAPI Optical card reader/writer device"); + break; + case PeripheralDeviceTypes.OCRWDevice: //0x0F, + ataOneValue.Add("ATAPI Optical card reader/writer device"); - break; - case PeripheralDeviceTypes.BridgingExpander: //0x10, - ataOneValue.Add("ATAPI Bridging Expanders"); + break; + case PeripheralDeviceTypes.BridgingExpander: //0x10, + ataOneValue.Add("ATAPI Bridging Expanders"); - break; - case PeripheralDeviceTypes.ObjectDevice: //0x11, - ataOneValue.Add("ATAPI Object-based Storage Device"); + break; + case PeripheralDeviceTypes.ObjectDevice: //0x11, + ataOneValue.Add("ATAPI Object-based Storage Device"); - break; - case PeripheralDeviceTypes.ADCDevice: //0x12, - ataOneValue.Add("ATAPI Automation/Drive Interface"); + break; + case PeripheralDeviceTypes.ADCDevice: //0x12, + ataOneValue.Add("ATAPI Automation/Drive Interface"); - break; - case PeripheralDeviceTypes.WellKnownDevice: //0x1E, - ataOneValue.Add("ATAPI Well known logical unit"); + break; + case PeripheralDeviceTypes.WellKnownDevice: //0x1E, + ataOneValue.Add("ATAPI Well known logical unit"); - break; - case PeripheralDeviceTypes.UnknownDevice: //0x1F - ataOneValue.Add("ATAPI Unknown or no device type"); + break; + case PeripheralDeviceTypes.UnknownDevice: //0x1F + ataOneValue.Add("ATAPI Unknown or no device type"); - break; - default: - ataOneValue. - Add($"ATAPI Unknown device type field value 0x{((ushort)ataIdentify.GeneralConfiguration & 0x1F00) >> 8:X2}"); + break; + default: + ataOneValue. + Add($"ATAPI Unknown device type field value 0x{((ushort)ataIdentify.GeneralConfiguration & 0x1F00) >> 8:X2}"); - break; - } - - // ATAPI DRQ behaviour - switch(((ushort)ataIdentify.GeneralConfiguration & 0x60) >> 5) - { - case 0: - ataOneValue.Add("Device shall set DRQ within 3 ms of receiving PACKET"); - - break; - case 1: - ataOneValue.Add("Device shall assert INTRQ when DRQ is set to one"); - - break; - case 2: - ataOneValue.Add("Device shall set DRQ within 50 µs of receiving PACKET"); - - break; - default: - ataOneValue. - Add($"Unknown ATAPI DRQ behaviour code {((ushort)ataIdentify.GeneralConfiguration & 0x60) >> 5}"); - - break; - } - - // ATAPI PACKET size - switch((ushort)ataIdentify.GeneralConfiguration & 0x03) - { - case 0: - ataOneValue.Add("ATAPI device uses 12 byte command packet"); - - break; - case 1: - ataOneValue.Add("ATAPI device uses 16 byte command packet"); - - break; - default: - ataOneValue. - Add($"Unknown ATAPI packet size code {(ushort)ataIdentify.GeneralConfiguration & 0x03}"); - - break; - } - } - else if(!cfa) - { - if(minAtaLevel >= 5) - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.IncompleteResponse)) - ataOneValue.Add("Incomplete identify response"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.NonMagnetic)) - ataOneValue.Add("Device uses non-magnetic media"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.Removable)) - ataOneValue.Add("Device is removable"); - - if(minAtaLevel <= 5) - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.Fixed)) - ataOneValue.Add("Device is fixed"); - - if(ata1) - { - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SlowIDE)) - ataOneValue.Add("Device transfer rate is <= 5 Mb/s"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.FastIDE)) - ataOneValue.Add("Device transfer rate is > 5 Mb/s but <= 10 Mb/s"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.UltraFastIDE)) - ataOneValue.Add("Device transfer rate is > 10 Mb/s"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SoftSector)) - ataOneValue.Add("Device is soft sectored"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.HardSector)) - ataOneValue.Add("Device is hard sectored"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.NotMFM)) - ataOneValue.Add("Device is not MFM encoded"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.FormatGapReq)) - ataOneValue.Add("Format speed tolerance gap is required"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.TrackOffset)) - ataOneValue.Add("Track offset option is available"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.DataStrobeOffset)) - ataOneValue.Add("Data strobe offset option is available"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit. - RotationalSpeedTolerance)) - ataOneValue.Add("Rotational speed tolerance is higher than 0,5%"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SpindleControl)) - ataOneValue.Add("Spindle motor control is implemented"); - - if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.HighHeadSwitch)) - ataOneValue.Add("Head switch time is bigger than 15 µs."); - } + break; } - if((ushort)ataIdentify.SpecificConfiguration != 0x0000 && - (ushort)ataIdentify.SpecificConfiguration != 0xFFFF) - switch(ataIdentify.SpecificConfiguration) - { - case Identify.SpecificConfigurationEnum.RequiresSetIncompleteResponse: - ataOneValue. - Add("Device requires SET FEATURES to spin up and IDENTIFY DEVICE response is incomplete."); - - break; - case Identify.SpecificConfigurationEnum.RequiresSetCompleteResponse: - ataOneValue. - Add("Device requires SET FEATURES to spin up and IDENTIFY DEVICE response is complete."); - - break; - case Identify.SpecificConfigurationEnum.NotRequiresSetIncompleteResponse: - ataOneValue. - Add("Device does not require SET FEATURES to spin up and IDENTIFY DEVICE response is incomplete."); - - break; - case Identify.SpecificConfigurationEnum.NotRequiresSetCompleteResponse: - ataOneValue. - Add("Device does not require SET FEATURES to spin up and IDENTIFY DEVICE response is complete."); - - break; - default: - ataOneValue. - Add($"Unknown device specific configuration 0x{(ushort)ataIdentify.SpecificConfiguration:X4}"); - - break; - } - - // Obsolete since ATA-2, however, it is yet used in ATA-8 devices - if(ataIdentify.BufferSize != 0x0000 && - ataIdentify.BufferSize != 0xFFFF && - ataIdentify.BufferType != 0x0000 && - ataIdentify.BufferType != 0xFFFF) - switch(ataIdentify.BufferType) - { - case 1: - ataOneValue. - Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of single ported single sector buffer"); - - break; - case 2: - ataOneValue. - Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of dual ported multi sector buffer"); - - break; - case 3: - ataOneValue. - Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of dual ported multi sector buffer with read caching"); - - break; - default: - ataOneValue. - Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of unknown type {ataIdentify.BufferType} buffer"); - - break; - } - - ataOneValue.Add("Device capabilities:"); - - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.StandardStandbyTimer)) - ataOneValue.Add("Standby time values are standard"); - - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.IORDY)) - ataOneValue.Add(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.CanDisableIORDY) - ? "IORDY is supported and can be disabled" : "IORDY is supported"); - - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.DMASupport)) - ataOneValue.Add("DMA is supported"); - - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.PhysicalAlignment1) || - ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.PhysicalAlignment0)) - ataOneValue.Add($"Long Physical Alignment setting is {(ushort)ataIdentify.Capabilities & 0x03}"); - - if(atapi) + // ATAPI DRQ behaviour + switch(((ushort)ataIdentify.GeneralConfiguration & 0x60) >> 5) { - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.InterleavedDMA)) - ataOneValue.Add("ATAPI device supports interleaved DMA"); + case 0: + ataOneValue.Add("Device shall set DRQ within 3 ms of receiving PACKET"); - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.CommandQueue)) - ataOneValue.Add("ATAPI device supports command queueing"); + break; + case 1: + ataOneValue.Add("Device shall assert INTRQ when DRQ is set to one"); - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.OverlapOperation)) - ataOneValue.Add("ATAPI device supports overlapped operations"); + break; + case 2: + ataOneValue.Add("Device shall set DRQ within 50 µs of receiving PACKET"); - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.RequiresATASoftReset)) - ataOneValue.Add("ATAPI device requires ATA software reset"); + break; + default: + ataOneValue. + Add($"Unknown ATAPI DRQ behaviour code {((ushort)ataIdentify.GeneralConfiguration & 0x60) >> 5}"); + + break; } - if(ataIdentify.Capabilities2.HasFlag(Identify.CapabilitiesBit2.MustBeSet) && - !ataIdentify.Capabilities2.HasFlag(Identify.CapabilitiesBit2.MustBeClear)) - if(ataIdentify.Capabilities2.HasFlag(Identify.CapabilitiesBit2.SpecificStandbyTimer)) - ataOneValue.Add("Device indicates a specific minimum standby timer value"); - - if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.MultipleValid)) + // ATAPI PACKET size + switch((ushort)ataIdentify.GeneralConfiguration & 0x03) { - ataOneValue. - Add($"A maximum of {ataIdentify.MultipleSectorNumber} sectors can be transferred per interrupt on READ/WRITE MULTIPLE"); + case 0: + ataOneValue.Add("ATAPI device uses 12 byte command packet"); - ataOneValue.Add($"Device supports setting a maximum of {ataIdentify.MultipleMaxSectors} sectors"); + break; + case 1: + ataOneValue.Add("ATAPI device uses 16 byte command packet"); + + break; + default: + ataOneValue. + Add($"Unknown ATAPI packet size code {(ushort)ataIdentify.GeneralConfiguration & 0x03}"); + + break; } + } + else if(!cfa) + { + if(minAtaLevel >= 5) + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.IncompleteResponse)) + ataOneValue.Add("Incomplete identify response"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.NonMagnetic)) + ataOneValue.Add("Device uses non-magnetic media"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.Removable)) + ataOneValue.Add("Device is removable"); + + if(minAtaLevel <= 5) + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.Fixed)) + ataOneValue.Add("Device is fixed"); if(ata1) - if(ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.TrustedComputing)) - ataOneValue.Add("Device supports doubleword I/O"); - - if(minAtaLevel <= 3) { - if(ataIdentify.PIOTransferTimingMode > 0) - ataTwoValue.Add("PIO timing mode", $"{ataIdentify.PIOTransferTimingMode}"); + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SlowIDE)) + ataOneValue.Add("Device transfer rate is <= 5 Mb/s"); - if(ataIdentify.DMATransferTimingMode > 0) - ataTwoValue.Add("DMA timing mode", $"{ataIdentify.DMATransferTimingMode}"); + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.FastIDE)) + ataOneValue.Add("Device transfer rate is > 5 Mb/s but <= 10 Mb/s"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.UltraFastIDE)) + ataOneValue.Add("Device transfer rate is > 10 Mb/s"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SoftSector)) + ataOneValue.Add("Device is soft sectored"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.HardSector)) + ataOneValue.Add("Device is hard sectored"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.NotMFM)) + ataOneValue.Add("Device is not MFM encoded"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.FormatGapReq)) + ataOneValue.Add("Format speed tolerance gap is required"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.TrackOffset)) + ataOneValue.Add("Track offset option is available"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.DataStrobeOffset)) + ataOneValue.Add("Data strobe offset option is available"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit. + RotationalSpeedTolerance)) + ataOneValue.Add("Rotational speed tolerance is higher than 0,5%"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.SpindleControl)) + ataOneValue.Add("Spindle motor control is implemented"); + + if(ataIdentify.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.HighHeadSwitch)) + ataOneValue.Add("Head switch time is bigger than 15 µs."); } + } - tmpString = ""; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode0)) - tmpString += "PIO0 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode1)) - tmpString += "PIO1 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode2)) - tmpString += "PIO2 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode3)) - tmpString += "PIO3 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode4)) - tmpString += "PIO4 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode5)) - tmpString += "PIO5 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode6)) - tmpString += "PIO6 "; - - if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode7)) - tmpString += "PIO7 "; - - if(!string.IsNullOrEmpty(tmpString)) - ataTwoValue.Add("Advanced PIO", tmpString); - - if(minAtaLevel <= 3 && - !atapi) + if((ushort)ataIdentify.SpecificConfiguration != 0x0000 && + (ushort)ataIdentify.SpecificConfiguration != 0xFFFF) + switch(ataIdentify.SpecificConfiguration) { - tmpString = ""; - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode0)) - { - tmpString += "DMA0 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode0)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode1)) - { - tmpString += "DMA1 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode1)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode2)) - { - tmpString += "DMA2 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode2)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode3)) - { - tmpString += "DMA3 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode3)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode4)) - { - tmpString += "DMA4 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode4)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode5)) - { - tmpString += "DMA5 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode5)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode6)) - { - tmpString += "DMA6 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode6)) - tmpString += "(active) "; - } - - if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode7)) - { - tmpString += "DMA7 "; - - if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode7)) - tmpString += "(active) "; - } - - if(!string.IsNullOrEmpty(tmpString)) - ataTwoValue.Add("Single-word DMA", tmpString); - } - - tmpString = ""; - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode0)) - { - tmpString += "MDMA0 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode0)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode1)) - { - tmpString += "MDMA1 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode1)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode2)) - { - tmpString += "MDMA2 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode2)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode3)) - { - tmpString += "MDMA3 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode3)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode4)) - { - tmpString += "MDMA4 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode4)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode5)) - { - tmpString += "MDMA5 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode5)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode6)) - { - tmpString += "MDMA6 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode6)) - tmpString += "(active) "; - } - - if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode7)) - { - tmpString += "MDMA7 "; - - if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode7)) - tmpString += "(active) "; - } - - if(!string.IsNullOrEmpty(tmpString)) - ataTwoValue.Add("Multi-word DMA", tmpString); - - tmpString = ""; - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode0)) - { - tmpString += "UDMA0 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode0)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode1)) - { - tmpString += "UDMA1 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode1)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode2)) - { - tmpString += "UDMA2 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode2)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode3)) - { - tmpString += "UDMA3 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode3)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode4)) - { - tmpString += "UDMA4 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode4)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode5)) - { - tmpString += "UDMA5 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode5)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode6)) - { - tmpString += "UDMA6 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode6)) - tmpString += "(active) "; - } - - if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode7)) - { - tmpString += "UDMA7 "; - - if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode7)) - tmpString += "(active) "; - } - - if(!string.IsNullOrEmpty(tmpString)) - ataTwoValue.Add("Ultra DMA", tmpString); - - if(ataIdentify.MinMDMACycleTime != 0 && - ataIdentify.RecMDMACycleTime != 0) - ataOneValue. - Add($"At minimum {ataIdentify.MinMDMACycleTime} ns. transfer cycle time per word in MDMA, " + - $"{ataIdentify.RecMDMACycleTime} ns. recommended"); - - if(ataIdentify.MinPIOCycleTimeNoFlow != 0) - ataOneValue. - Add($"At minimum {ataIdentify.MinPIOCycleTimeNoFlow} ns. transfer cycle time per word in PIO, " + - "without flow control"); - - if(ataIdentify.MinPIOCycleTimeFlow != 0) - ataOneValue. - Add($"At minimum {ataIdentify.MinPIOCycleTimeFlow} ns. transfer cycle time per word in PIO, " + - "with IORDY flow control"); - - if(ataIdentify.MaxQueueDepth != 0) - ataOneValue.Add($"{ataIdentify.MaxQueueDepth + 1} depth of queue maximum"); - - if(atapi) - { - if(ataIdentify.PacketBusRelease != 0) + case Identify.SpecificConfigurationEnum.RequiresSetIncompleteResponse: ataOneValue. - Add($"{ataIdentify.PacketBusRelease} ns. typical to release bus from receipt of PACKET"); + Add("Device requires SET FEATURES to spin up and IDENTIFY DEVICE response is incomplete."); - if(ataIdentify.ServiceBusyClear != 0) + break; + case Identify.SpecificConfigurationEnum.RequiresSetCompleteResponse: ataOneValue. - Add($"{ataIdentify.ServiceBusyClear} ns. typical to clear BSY bit from receipt of SERVICE"); + Add("Device requires SET FEATURES to spin up and IDENTIFY DEVICE response is complete."); + + break; + case Identify.SpecificConfigurationEnum.NotRequiresSetIncompleteResponse: + ataOneValue. + Add("Device does not require SET FEATURES to spin up and IDENTIFY DEVICE response is incomplete."); + + break; + case Identify.SpecificConfigurationEnum.NotRequiresSetCompleteResponse: + ataOneValue. + Add("Device does not require SET FEATURES to spin up and IDENTIFY DEVICE response is complete."); + + break; + default: + ataOneValue. + Add($"Unknown device specific configuration 0x{(ushort)ataIdentify.SpecificConfiguration:X4}"); + + break; } - if((ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0x1 || - (ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0xE) + // Obsolete since ATA-2, however, it is yet used in ATA-8 devices + if(ataIdentify.BufferSize != 0x0000 && + ataIdentify.BufferSize != 0xFFFF && + ataIdentify.BufferType != 0x0000 && + ataIdentify.BufferType != 0xFFFF) + switch(ataIdentify.BufferType) { + case 1: + ataOneValue. + Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of single ported single sector buffer"); + + break; + case 2: + ataOneValue. + Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of dual ported multi sector buffer"); + + break; + case 3: + ataOneValue. + Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of dual ported multi sector buffer with read caching"); + + break; + default: + ataOneValue. + Add($"{ataIdentify.BufferSize * logicalSectorSize / 1024} KiB of unknown type {ataIdentify.BufferType} buffer"); + + break; + } + + ataOneValue.Add("Device capabilities:"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.StandardStandbyTimer)) + ataOneValue.Add("Standby time values are standard"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.IORDY)) + ataOneValue.Add(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.CanDisableIORDY) + ? "IORDY is supported and can be disabled" : "IORDY is supported"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.DMASupport)) + ataOneValue.Add("DMA is supported"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.PhysicalAlignment1) || + ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.PhysicalAlignment0)) + ataOneValue.Add($"Long Physical Alignment setting is {(ushort)ataIdentify.Capabilities & 0x03}"); + + if(atapi) + { + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.InterleavedDMA)) + ataOneValue.Add("ATAPI device supports interleaved DMA"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.CommandQueue)) + ataOneValue.Add("ATAPI device supports command queueing"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.OverlapOperation)) + ataOneValue.Add("ATAPI device supports overlapped operations"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.RequiresATASoftReset)) + ataOneValue.Add("ATAPI device requires ATA software reset"); + } + + if(ataIdentify.Capabilities2.HasFlag(Identify.CapabilitiesBit2.MustBeSet) && + !ataIdentify.Capabilities2.HasFlag(Identify.CapabilitiesBit2.MustBeClear)) + if(ataIdentify.Capabilities2.HasFlag(Identify.CapabilitiesBit2.SpecificStandbyTimer)) + ataOneValue.Add("Device indicates a specific minimum standby timer value"); + + if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.MultipleValid)) + { + ataOneValue. + Add($"A maximum of {ataIdentify.MultipleSectorNumber} sectors can be transferred per interrupt on READ/WRITE MULTIPLE"); + + ataOneValue.Add($"Device supports setting a maximum of {ataIdentify.MultipleMaxSectors} sectors"); + } + + if(ata1) + if(ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.TrustedComputing)) + ataOneValue.Add("Device supports doubleword I/O"); + + if(minAtaLevel <= 3) + { + if(ataIdentify.PIOTransferTimingMode > 0) + ataTwoValue.Add("PIO timing mode", $"{ataIdentify.PIOTransferTimingMode}"); + + if(ataIdentify.DMATransferTimingMode > 0) + ataTwoValue.Add("DMA timing mode", $"{ataIdentify.DMATransferTimingMode}"); + } + + tmpString = ""; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode0)) + tmpString += "PIO0 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode1)) + tmpString += "PIO1 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode2)) + tmpString += "PIO2 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode3)) + tmpString += "PIO3 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode4)) + tmpString += "PIO4 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode5)) + tmpString += "PIO5 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode6)) + tmpString += "PIO6 "; + + if(ataIdentify.APIOSupported.HasFlag(Identify.TransferMode.Mode7)) + tmpString += "PIO7 "; + + if(!string.IsNullOrEmpty(tmpString)) + ataTwoValue.Add("Advanced PIO", tmpString); + + if(minAtaLevel <= 3 && + !atapi) + { + tmpString = ""; + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode0)) + { + tmpString += "DMA0 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode0)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode1)) + { + tmpString += "DMA1 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode1)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode2)) + { + tmpString += "DMA2 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode2)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode3)) + { + tmpString += "DMA3 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode3)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode4)) + { + tmpString += "DMA4 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode4)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode5)) + { + tmpString += "DMA5 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode5)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode6)) + { + tmpString += "DMA6 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode6)) + tmpString += "(active) "; + } + + if(ataIdentify.DMASupported.HasFlag(Identify.TransferMode.Mode7)) + { + tmpString += "DMA7 "; + + if(ataIdentify.DMAActive.HasFlag(Identify.TransferMode.Mode7)) + tmpString += "(active) "; + } + + if(!string.IsNullOrEmpty(tmpString)) + ataTwoValue.Add("Single-word DMA", tmpString); + } + + tmpString = ""; + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode0)) + { + tmpString += "MDMA0 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode0)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode1)) + { + tmpString += "MDMA1 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode1)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode2)) + { + tmpString += "MDMA2 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode2)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode3)) + { + tmpString += "MDMA3 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode3)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode4)) + { + tmpString += "MDMA4 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode4)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode5)) + { + tmpString += "MDMA5 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode5)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode6)) + { + tmpString += "MDMA6 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode6)) + tmpString += "(active) "; + } + + if(ataIdentify.MDMASupported.HasFlag(Identify.TransferMode.Mode7)) + { + tmpString += "MDMA7 "; + + if(ataIdentify.MDMAActive.HasFlag(Identify.TransferMode.Mode7)) + tmpString += "(active) "; + } + + if(!string.IsNullOrEmpty(tmpString)) + ataTwoValue.Add("Multi-word DMA", tmpString); + + tmpString = ""; + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode0)) + { + tmpString += "UDMA0 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode0)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode1)) + { + tmpString += "UDMA1 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode1)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode2)) + { + tmpString += "UDMA2 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode2)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode3)) + { + tmpString += "UDMA3 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode3)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode4)) + { + tmpString += "UDMA4 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode4)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode5)) + { + tmpString += "UDMA5 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode5)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode6)) + { + tmpString += "UDMA6 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode6)) + tmpString += "(active) "; + } + + if(ataIdentify.UDMASupported.HasFlag(Identify.TransferMode.Mode7)) + { + tmpString += "UDMA7 "; + + if(ataIdentify.UDMAActive.HasFlag(Identify.TransferMode.Mode7)) + tmpString += "(active) "; + } + + if(!string.IsNullOrEmpty(tmpString)) + ataTwoValue.Add("Ultra DMA", tmpString); + + if(ataIdentify.MinMDMACycleTime != 0 && + ataIdentify.RecMDMACycleTime != 0) + ataOneValue. + Add($"At minimum {ataIdentify.MinMDMACycleTime} ns. transfer cycle time per word in MDMA, " + + $"{ataIdentify.RecMDMACycleTime} ns. recommended"); + + if(ataIdentify.MinPIOCycleTimeNoFlow != 0) + ataOneValue. + Add($"At minimum {ataIdentify.MinPIOCycleTimeNoFlow} ns. transfer cycle time per word in PIO, " + + "without flow control"); + + if(ataIdentify.MinPIOCycleTimeFlow != 0) + ataOneValue. + Add($"At minimum {ataIdentify.MinPIOCycleTimeFlow} ns. transfer cycle time per word in PIO, " + + "with IORDY flow control"); + + if(ataIdentify.MaxQueueDepth != 0) + ataOneValue.Add($"{ataIdentify.MaxQueueDepth + 1} depth of queue maximum"); + + if(atapi) + { + if(ataIdentify.PacketBusRelease != 0) + ataOneValue. + Add($"{ataIdentify.PacketBusRelease} ns. typical to release bus from receipt of PACKET"); + + if(ataIdentify.ServiceBusyClear != 0) + ataOneValue. + Add($"{ataIdentify.ServiceBusyClear} ns. typical to clear BSY bit from receipt of SERVICE"); + } + + if((ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0x1 || + (ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0xE) + { + if(!ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Clear)) + { + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Gen1Speed)) + ataOneValue.Add("SATA 1.5Gb/s is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Gen2Speed)) + ataOneValue.Add("SATA 3.0Gb/s is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Gen3Speed)) + ataOneValue.Add("SATA 6.0Gb/s is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.PowerReceipt)) + ataOneValue.Add("Receipt of host initiated power management requests is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.PHYEventCounter)) + ataOneValue.Add("PHY Event counters are supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.HostSlumbTrans)) + ataOneValue.Add("Supports host automatic partial to slumber transitions is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.DevSlumbTrans)) + ataOneValue.Add("Supports device automatic partial to slumber transitions is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.NCQ)) + { + ataOneValue.Add("NCQ is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.NCQPriority)) + ataOneValue.Add("NCQ priority is supported"); + + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.UnloadNCQ)) + ataOneValue.Add("Unload is supported with outstanding NCQ commands"); + } + } + + if(!ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.Clear)) + { + if(!ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Clear) && + ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.NCQ)) + { + if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.NCQMgmt)) + ataOneValue.Add("NCQ queue management is supported"); + + if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.NCQStream)) + ataOneValue.Add("NCQ streaming is supported"); + } + + if(atapi) + { + if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.HostEnvDetect)) + ataOneValue.Add("ATAPI device supports host environment detection"); + + if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.DevAttSlimline)) + ataOneValue.Add("ATAPI device supports attention on slimline connected devices"); + } + } + } + + if(ataIdentify.InterseekDelay != 0x0000 && + ataIdentify.InterseekDelay != 0xFFFF) + ataOneValue. + Add($"{ataIdentify.InterseekDelay} microseconds of interseek delay for ISO-7779 acoustic testing"); + + if((ushort)ataIdentify.DeviceFormFactor != 0x0000 && + (ushort)ataIdentify.DeviceFormFactor != 0xFFFF) + switch(ataIdentify.DeviceFormFactor) + { + case Identify.DeviceFormFactorEnum.FiveAndQuarter: + ataOneValue.Add("Device nominal size is 5.25\""); + + break; + case Identify.DeviceFormFactorEnum.ThreeAndHalf: + ataOneValue.Add("Device nominal size is 3.5\""); + + break; + case Identify.DeviceFormFactorEnum.TwoAndHalf: + ataOneValue.Add("Device nominal size is 2.5\""); + + break; + case Identify.DeviceFormFactorEnum.OnePointEight: + ataOneValue.Add("Device nominal size is 1.8\""); + + break; + case Identify.DeviceFormFactorEnum.LessThanOnePointEight: + ataOneValue.Add("Device nominal size is smaller than 1.8\""); + + break; + default: + ataOneValue.Add($"Device nominal size field value {ataIdentify.DeviceFormFactor} is unknown"); + + break; + } + + if(atapi) + if(ataIdentify.ATAPIByteCount > 0) + ataOneValue.Add($"{ataIdentify.ATAPIByteCount} bytes count limit for ATAPI"); + + if(cfa) + if((ataIdentify.CFAPowerMode & 0x8000) == 0x8000) + { + ataOneValue.Add("CompactFlash device supports power mode 1"); + + if((ataIdentify.CFAPowerMode & 0x2000) == 0x2000) + ataOneValue.Add("CompactFlash power mode 1 required for one or more commands"); + + if((ataIdentify.CFAPowerMode & 0x1000) == 0x1000) + ataOneValue.Add("CompactFlash power mode 1 is disabled"); + + ataOneValue.Add($"CompactFlash device uses a maximum of {ataIdentify.CFAPowerMode & 0x0FFF} mA"); + } + + ataOneValue.Add("Command set and features:"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Nop)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Nop) + ? "NOP is supported and enabled" : "NOP is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.ReadBuffer)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.ReadBuffer) + ? "READ BUFFER is supported and enabled" : "READ BUFFER is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.WriteBuffer)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.WriteBuffer) + ? "WRITE BUFFER is supported and enabled" : "WRITE BUFFER is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.HPA)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.HPA) + ? "Host Protected Area is supported and enabled" + : "Host Protected Area is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.DeviceReset)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.DeviceReset) + ? "DEVICE RESET is supported and enabled" : "DEVICE RESET is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Service)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Service) + ? "SERVICE interrupt is supported and enabled" : "SERVICE interrupt is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Release)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Release) + ? "Release is supported and enabled" : "Release is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.LookAhead)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.LookAhead) + ? "Look-ahead read is supported and enabled" : "Look-ahead read is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.WriteCache)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.WriteCache) + ? "Write cache is supported and enabled" : "Write cache is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Packet)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Packet) + ? "PACKET is supported and enabled" : "PACKET is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.PowerManagement)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.PowerManagement) + ? "Power management is supported and enabled" : "Power management is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.RemovableMedia)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.RemovableMedia) + ? "Removable media feature set is supported and enabled" + : "Removable media feature set is supported"); + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.SecurityMode)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.SecurityMode) + ? "Security mode is supported and enabled" : "Security mode is supported"); + + if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.LBASupport)) + ataOneValue.Add("28-bit LBA is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.MustBeSet) && + !ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.MustBeClear)) + { + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.LBA48) + ? "48-bit LBA is supported and enabled" : "48-bit LBA is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.FlushCache)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.FlushCache) + ? "FLUSH CACHE is supported and enabled" : "FLUSH CACHE is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.FlushCacheExt)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.FlushCacheExt) + ? "FLUSH CACHE EXT is supported and enabled" : "FLUSH CACHE EXT is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.DCO)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.DCO) + ? "Device Configuration Overlay feature set is supported and enabled" + : "Device Configuration Overlay feature set is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.AAM)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.AAM) + ? $"Automatic Acoustic Management is supported and enabled with value {ataIdentify.CurrentAAM} (vendor recommends {ataIdentify.RecommendedAAM}" + : "Automatic Acoustic Management is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.SetMax)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.SetMax) + ? "SET MAX security extension is supported and enabled" + : "SET MAX security extension is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.AddressOffsetReservedAreaBoot)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2. + AddressOffsetReservedAreaBoot) + ? "Address Offset Reserved Area Boot is supported and enabled" + : "Address Offset Reserved Area Boot is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.SetFeaturesRequired)) + ataOneValue.Add("SET FEATURES is required before spin-up"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.PowerUpInStandby)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.PowerUpInStandby) + ? "Power-up in standby is supported and enabled" + : "Power-up in standby is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.RemovableNotification)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2. + RemovableNotification) + ? "Removable Media Status Notification is supported and enabled" + : "Removable Media Status Notification is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.APM)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.APM) + ? $"Advanced Power Management is supported and enabled with value {ataIdentify.CurrentAPM}" + : "Advanced Power Management is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.CompactFlash)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.CompactFlash) + ? "CompactFlash feature set is supported and enabled" + : "CompactFlash feature set is supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.RWQueuedDMA)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.RWQueuedDMA) + ? "READ DMA QUEUED and WRITE DMA QUEUED are supported and enabled" + : "READ DMA QUEUED and WRITE DMA QUEUED are supported"); + + if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.DownloadMicrocode)) + ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.DownloadMicrocode) + ? "DOWNLOAD MICROCODE is supported and enabled" + : "DOWNLOAD MICROCODE is supported"); + } + + if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.SMART)) + ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.SMART) + ? "S.M.A.R.T. is supported and enabled" : "S.M.A.R.T. is supported"); + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.Supported)) + ataOneValue.Add("S.M.A.R.T. Command Transport is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeSet) && + !ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeClear)) + { + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.SMARTSelfTest)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.SMARTSelfTest) + ? "S.M.A.R.T. self-testing is supported and enabled" + : "S.M.A.R.T. self-testing is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.SMARTLog)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.SMARTLog) + ? "S.M.A.R.T. error logging is supported and enabled" + : "S.M.A.R.T. error logging is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.IdleImmediate)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.IdleImmediate) + ? "IDLE IMMEDIATE with UNLOAD FEATURE is supported and enabled" + : "IDLE IMMEDIATE with UNLOAD FEATURE is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.WriteURG)) + ataOneValue.Add("URG bit is supported in WRITE STREAM DMA EXT and WRITE STREAM EXT"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.ReadURG)) + ataOneValue.Add("URG bit is supported in READ STREAM DMA EXT and READ STREAM EXT"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.WWN)) + ataOneValue.Add("Device has a World Wide Name"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.FUAWriteQ)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.FUAWriteQ) + ? "WRITE DMA QUEUED FUA EXT is supported and enabled" + : "WRITE DMA QUEUED FUA EXT is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.FUAWrite)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.FUAWrite) + ? "WRITE DMA FUA EXT and WRITE MULTIPLE FUA EXT are supported and enabled" + : "WRITE DMA FUA EXT and WRITE MULTIPLE FUA EXT are supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.GPL)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.GPL) + ? "General Purpose Logging is supported and enabled" + : "General Purpose Logging is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.Streaming)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.Streaming) + ? "Streaming feature set is supported and enabled" + : "Streaming feature set is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MCPT)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.MCPT) + ? "Media Card Pass Through command set is supported and enabled" + : "Media Card Pass Through command set is supported"); + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MediaSerial)) + ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.MediaSerial) + ? "Media Serial is supported and valid" : "Media Serial is supported"); + } + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.MustBeSet) && + !ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.MustBeClear)) + { + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.DSN)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.DSN) + ? "DSN feature set is supported and enabled" : "DSN feature set is supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.AMAC)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.AMAC) + ? "Accessible Max Address Configuration is supported and enabled" + : "Accessible Max Address Configuration is supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.ExtPowerCond)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.ExtPowerCond) + ? "Extended Power Conditions are supported and enabled" + : "Extended Power Conditions are supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.ExtStatusReport)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.ExtStatusReport) + ? "Extended Status Reporting is supported and enabled" + : "Extended Status Reporting is supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.FreeFallControl)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.FreeFallControl) + ? "Free-fall control feature set is supported and enabled" + : "Free-fall control feature set is supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.SegmentedDownloadMicrocode)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4. + SegmentedDownloadMicrocode) + ? "Segmented feature in DOWNLOAD MICROCODE is supported and enabled" + : "Segmented feature in DOWNLOAD MICROCODE is supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.RWDMAExtGpl)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.RWDMAExtGpl) + ? "READ/WRITE DMA EXT GPL are supported and enabled" + : "READ/WRITE DMA EXT GPL are supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.WriteUnc)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.WriteUnc) + ? "WRITE UNCORRECTABLE is supported and enabled" + : "WRITE UNCORRECTABLE is supported"); + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.WRV)) + { + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.WRV) + ? "Write/Read/Verify is supported and enabled" + : "Write/Read/Verify is supported"); + + ataOneValue.Add($"{ataIdentify.WRVSectorCountMode2} sectors for Write/Read/Verify mode 2"); + ataOneValue.Add($"{ataIdentify.WRVSectorCountMode3} sectors for Write/Read/Verify mode 3"); + + if(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.WRV)) + ataOneValue.Add($"Current Write/Read/Verify mode: {ataIdentify.WRVMode}"); + } + + if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.DT1825)) + ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.DT1825) + ? "DT1825 is supported and enabled" : "DT1825 is supported"); + } + + if(true) + { + if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.BlockErase)) + ataOneValue.Add("BLOCK ERASE EXT is supported"); + + if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.Overwrite)) + ataOneValue.Add("OVERWRITE EXT is supported"); + + if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.CryptoScramble)) + ataOneValue.Add("CRYPTO SCRAMBLE EXT is supported"); + } + + if(true) + { + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.DeviceConfDMA)) + ataOneValue.Add("DEVICE CONFIGURATION IDENTIFY DMA and DEVICE CONFIGURATION SET DMA are supported"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ReadBufferDMA)) + ataOneValue.Add("READ BUFFER DMA is supported"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.WriteBufferDMA)) + ataOneValue.Add("WRITE BUFFER DMA is supported"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.DownloadMicroCodeDMA)) + ataOneValue.Add("DOWNLOAD MICROCODE DMA is supported"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.SetMaxDMA)) + ataOneValue.Add("SET PASSWORD DMA and SET UNLOCK DMA are supported"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.Ata28)) + ataOneValue.Add("Not all 28-bit commands are supported"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.CFast)) + ataOneValue.Add("Device follows CFast specification"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.IEEE1667)) + ataOneValue.Add("Device follows IEEE-1667"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.DeterministicTrim)) + { + ataOneValue.Add("Read after TRIM is deterministic"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ReadZeroTrim)) + ataOneValue.Add("Read after TRIM returns empty data"); + } + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.LongPhysSectorAligError)) + ataOneValue.Add("Device supports Long Physical Sector Alignment Error Reporting Control"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.Encrypted)) + ataOneValue.Add("Device encrypts all user data"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.AllCacheNV)) + ataOneValue.Add("Device's write cache is non-volatile"); + + if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ZonedBit0) || + ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ZonedBit1)) + ataOneValue.Add("Device is zoned"); + } + + if(true) + if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.Sanitize)) + { + ataOneValue.Add("Sanitize feature set is supported"); + + ataOneValue.Add(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.SanitizeCommands) + ? "Sanitize commands are specified by ACS-3 or higher" + : "Sanitize commands are specified by ACS-2"); + + if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.SanitizeAntifreeze)) + ataOneValue.Add("SANITIZE ANTIFREEZE LOCK EXT is supported"); + } + + if(!ata1 && + maxAtaLevel >= 8) + if(ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.Set) && + !ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.Clear) && + ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.TrustedComputing)) + ataOneValue.Add("Trusted Computing feature set is supported"); + + if((ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0x1 || + (ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0xE) + { + if(true) if(!ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Clear)) - { - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Gen1Speed)) - ataOneValue.Add("SATA 1.5Gb/s is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Gen2Speed)) - ataOneValue.Add("SATA 3.0Gb/s is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Gen3Speed)) - ataOneValue.Add("SATA 6.0Gb/s is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.PowerReceipt)) - ataOneValue.Add("Receipt of host initiated power management requests is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.PHYEventCounter)) - ataOneValue.Add("PHY Event counters are supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.HostSlumbTrans)) - ataOneValue.Add("Supports host automatic partial to slumber transitions is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.DevSlumbTrans)) - ataOneValue.Add("Supports device automatic partial to slumber transitions is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.NCQ)) - { - ataOneValue.Add("NCQ is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.NCQPriority)) - ataOneValue.Add("NCQ priority is supported"); - - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.UnloadNCQ)) - ataOneValue.Add("Unload is supported with outstanding NCQ commands"); - } - } + if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.ReadLogDMAExt)) + ataOneValue.Add("READ LOG DMA EXT is supported"); + if(true) if(!ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.Clear)) - { - if(!ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Clear) && - ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.NCQ)) - { - if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.NCQMgmt)) - ataOneValue.Add("NCQ queue management is supported"); + if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.FPDMAQ)) + ataOneValue.Add("RECEIVE FPDMA QUEUED and SEND FPDMA QUEUED are supported"); - if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.NCQStream)) - ataOneValue.Add("NCQ streaming is supported"); - } + if(true) + if(!ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.Clear)) + { + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.NonZeroBufferOffset)) + ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. + NonZeroBufferOffset) + ? "Non-zero buffer offsets are supported and enabled" + : "Non-zero buffer offsets are supported"); + + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.DMASetup)) + ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.DMASetup) + ? "DMA Setup auto-activation is supported and enabled" + : "DMA Setup auto-activation is supported"); + + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.InitPowerMgmt)) + ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. + InitPowerMgmt) + ? "Device-initiated power management is supported and enabled" + : "Device-initiated power management is supported"); + + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.InOrderData)) + ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. + InOrderData) + ? "In-order data delivery is supported and enabled" + : "In-order data delivery is supported"); + + if(!atapi) + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.HardwareFeatureControl)) + ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. + HardwareFeatureControl) + ? "Hardware Feature Control is supported and enabled" + : "Hardware Feature Control is supported"); if(atapi) - { - if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.HostEnvDetect)) - ataOneValue.Add("ATAPI device supports host environment detection"); - - if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.DevAttSlimline)) - ataOneValue.Add("ATAPI device supports attention on slimline connected devices"); - } - } - } - - if(ataIdentify.InterseekDelay != 0x0000 && - ataIdentify.InterseekDelay != 0xFFFF) - ataOneValue. - Add($"{ataIdentify.InterseekDelay} microseconds of interseek delay for ISO-7779 acoustic testing"); - - if((ushort)ataIdentify.DeviceFormFactor != 0x0000 && - (ushort)ataIdentify.DeviceFormFactor != 0xFFFF) - switch(ataIdentify.DeviceFormFactor) - { - case Identify.DeviceFormFactorEnum.FiveAndQuarter: - ataOneValue.Add("Device nominal size is 5.25\""); - - break; - case Identify.DeviceFormFactorEnum.ThreeAndHalf: - ataOneValue.Add("Device nominal size is 3.5\""); - - break; - case Identify.DeviceFormFactorEnum.TwoAndHalf: - ataOneValue.Add("Device nominal size is 2.5\""); - - break; - case Identify.DeviceFormFactorEnum.OnePointEight: - ataOneValue.Add("Device nominal size is 1.8\""); - - break; - case Identify.DeviceFormFactorEnum.LessThanOnePointEight: - ataOneValue.Add("Device nominal size is smaller than 1.8\""); - - break; - default: - ataOneValue.Add($"Device nominal size field value {ataIdentify.DeviceFormFactor} is unknown"); - - break; - } - - if(atapi) - if(ataIdentify.ATAPIByteCount > 0) - ataOneValue.Add($"{ataIdentify.ATAPIByteCount} bytes count limit for ATAPI"); - - if(cfa) - if((ataIdentify.CFAPowerMode & 0x8000) == 0x8000) - { - ataOneValue.Add("CompactFlash device supports power mode 1"); - - if((ataIdentify.CFAPowerMode & 0x2000) == 0x2000) - ataOneValue.Add("CompactFlash power mode 1 required for one or more commands"); - - if((ataIdentify.CFAPowerMode & 0x1000) == 0x1000) - ataOneValue.Add("CompactFlash power mode 1 is disabled"); - - ataOneValue.Add($"CompactFlash device uses a maximum of {ataIdentify.CFAPowerMode & 0x0FFF} mA"); - } - - ataOneValue.Add("Command set and features:"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Nop)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Nop) - ? "NOP is supported and enabled" : "NOP is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.ReadBuffer)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.ReadBuffer) - ? "READ BUFFER is supported and enabled" : "READ BUFFER is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.WriteBuffer)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.WriteBuffer) - ? "WRITE BUFFER is supported and enabled" : "WRITE BUFFER is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.HPA)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.HPA) - ? "Host Protected Area is supported and enabled" - : "Host Protected Area is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.DeviceReset)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.DeviceReset) - ? "DEVICE RESET is supported and enabled" : "DEVICE RESET is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Service)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Service) - ? "SERVICE interrupt is supported and enabled" : "SERVICE interrupt is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Release)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Release) - ? "Release is supported and enabled" : "Release is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.LookAhead)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.LookAhead) - ? "Look-ahead read is supported and enabled" : "Look-ahead read is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.WriteCache)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.WriteCache) - ? "Write cache is supported and enabled" : "Write cache is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.Packet)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.Packet) - ? "PACKET is supported and enabled" : "PACKET is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.PowerManagement)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.PowerManagement) - ? "Power management is supported and enabled" : "Power management is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.RemovableMedia)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.RemovableMedia) - ? "Removable media feature set is supported and enabled" - : "Removable media feature set is supported"); - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.SecurityMode)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.SecurityMode) - ? "Security mode is supported and enabled" : "Security mode is supported"); - - if(ataIdentify.Capabilities.HasFlag(Identify.CapabilitiesBit.LBASupport)) - ataOneValue.Add("28-bit LBA is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.MustBeSet) && - !ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.MustBeClear)) - { - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.LBA48) - ? "48-bit LBA is supported and enabled" : "48-bit LBA is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.FlushCache)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.FlushCache) - ? "FLUSH CACHE is supported and enabled" : "FLUSH CACHE is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.FlushCacheExt)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.FlushCacheExt) - ? "FLUSH CACHE EXT is supported and enabled" : "FLUSH CACHE EXT is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.DCO)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.DCO) - ? "Device Configuration Overlay feature set is supported and enabled" - : "Device Configuration Overlay feature set is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.AAM)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.AAM) - ? $"Automatic Acoustic Management is supported and enabled with value {ataIdentify.CurrentAAM} (vendor recommends {ataIdentify.RecommendedAAM}" - : "Automatic Acoustic Management is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.SetMax)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.SetMax) - ? "SET MAX security extension is supported and enabled" - : "SET MAX security extension is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.AddressOffsetReservedAreaBoot)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2. - AddressOffsetReservedAreaBoot) - ? "Address Offset Reserved Area Boot is supported and enabled" - : "Address Offset Reserved Area Boot is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.SetFeaturesRequired)) - ataOneValue.Add("SET FEATURES is required before spin-up"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.PowerUpInStandby)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.PowerUpInStandby) - ? "Power-up in standby is supported and enabled" - : "Power-up in standby is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.RemovableNotification)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2. - RemovableNotification) - ? "Removable Media Status Notification is supported and enabled" - : "Removable Media Status Notification is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.APM)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.APM) - ? $"Advanced Power Management is supported and enabled with value {ataIdentify.CurrentAPM}" - : "Advanced Power Management is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.CompactFlash)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.CompactFlash) - ? "CompactFlash feature set is supported and enabled" - : "CompactFlash feature set is supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.RWQueuedDMA)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.RWQueuedDMA) - ? "READ DMA QUEUED and WRITE DMA QUEUED are supported and enabled" - : "READ DMA QUEUED and WRITE DMA QUEUED are supported"); - - if(ataIdentify.CommandSet2.HasFlag(Identify.CommandSetBit2.DownloadMicrocode)) - ataOneValue.Add(ataIdentify.EnabledCommandSet2.HasFlag(Identify.CommandSetBit2.DownloadMicrocode) - ? "DOWNLOAD MICROCODE is supported and enabled" - : "DOWNLOAD MICROCODE is supported"); - } - - if(ataIdentify.CommandSet.HasFlag(Identify.CommandSetBit.SMART)) - ataOneValue.Add(ataIdentify.EnabledCommandSet.HasFlag(Identify.CommandSetBit.SMART) - ? "S.M.A.R.T. is supported and enabled" : "S.M.A.R.T. is supported"); - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.Supported)) - ataOneValue.Add("S.M.A.R.T. Command Transport is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeSet) && - !ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeClear)) - { - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.SMARTSelfTest)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.SMARTSelfTest) - ? "S.M.A.R.T. self-testing is supported and enabled" - : "S.M.A.R.T. self-testing is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.SMARTLog)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.SMARTLog) - ? "S.M.A.R.T. error logging is supported and enabled" - : "S.M.A.R.T. error logging is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.IdleImmediate)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.IdleImmediate) - ? "IDLE IMMEDIATE with UNLOAD FEATURE is supported and enabled" - : "IDLE IMMEDIATE with UNLOAD FEATURE is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.WriteURG)) - ataOneValue.Add("URG bit is supported in WRITE STREAM DMA EXT and WRITE STREAM EXT"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.ReadURG)) - ataOneValue.Add("URG bit is supported in READ STREAM DMA EXT and READ STREAM EXT"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.WWN)) - ataOneValue.Add("Device has a World Wide Name"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.FUAWriteQ)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.FUAWriteQ) - ? "WRITE DMA QUEUED FUA EXT is supported and enabled" - : "WRITE DMA QUEUED FUA EXT is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.FUAWrite)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.FUAWrite) - ? "WRITE DMA FUA EXT and WRITE MULTIPLE FUA EXT are supported and enabled" - : "WRITE DMA FUA EXT and WRITE MULTIPLE FUA EXT are supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.GPL)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.GPL) - ? "General Purpose Logging is supported and enabled" - : "General Purpose Logging is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.Streaming)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.Streaming) - ? "Streaming feature set is supported and enabled" - : "Streaming feature set is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MCPT)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.MCPT) - ? "Media Card Pass Through command set is supported and enabled" - : "Media Card Pass Through command set is supported"); - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MediaSerial)) - ataOneValue.Add(ataIdentify.EnabledCommandSet3.HasFlag(Identify.CommandSetBit3.MediaSerial) - ? "Media Serial is supported and valid" : "Media Serial is supported"); - } - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.MustBeSet) && - !ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.MustBeClear)) - { - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.DSN)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.DSN) - ? "DSN feature set is supported and enabled" : "DSN feature set is supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.AMAC)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.AMAC) - ? "Accessible Max Address Configuration is supported and enabled" - : "Accessible Max Address Configuration is supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.ExtPowerCond)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.ExtPowerCond) - ? "Extended Power Conditions are supported and enabled" - : "Extended Power Conditions are supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.ExtStatusReport)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.ExtStatusReport) - ? "Extended Status Reporting is supported and enabled" - : "Extended Status Reporting is supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.FreeFallControl)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.FreeFallControl) - ? "Free-fall control feature set is supported and enabled" - : "Free-fall control feature set is supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.SegmentedDownloadMicrocode)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4. - SegmentedDownloadMicrocode) - ? "Segmented feature in DOWNLOAD MICROCODE is supported and enabled" - : "Segmented feature in DOWNLOAD MICROCODE is supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.RWDMAExtGpl)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.RWDMAExtGpl) - ? "READ/WRITE DMA EXT GPL are supported and enabled" - : "READ/WRITE DMA EXT GPL are supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.WriteUnc)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.WriteUnc) - ? "WRITE UNCORRECTABLE is supported and enabled" - : "WRITE UNCORRECTABLE is supported"); - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.WRV)) - { - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.WRV) - ? "Write/Read/Verify is supported and enabled" - : "Write/Read/Verify is supported"); - - ataOneValue.Add($"{ataIdentify.WRVSectorCountMode2} sectors for Write/Read/Verify mode 2"); - ataOneValue.Add($"{ataIdentify.WRVSectorCountMode3} sectors for Write/Read/Verify mode 3"); - - if(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.WRV)) - ataOneValue.Add($"Current Write/Read/Verify mode: {ataIdentify.WRVMode}"); - } - - if(ataIdentify.CommandSet4.HasFlag(Identify.CommandSetBit4.DT1825)) - ataOneValue.Add(ataIdentify.EnabledCommandSet4.HasFlag(Identify.CommandSetBit4.DT1825) - ? "DT1825 is supported and enabled" : "DT1825 is supported"); - } - - if(true) - { - if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.BlockErase)) - ataOneValue.Add("BLOCK ERASE EXT is supported"); - - if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.Overwrite)) - ataOneValue.Add("OVERWRITE EXT is supported"); - - if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.CryptoScramble)) - ataOneValue.Add("CRYPTO SCRAMBLE EXT is supported"); - } - - if(true) - { - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.DeviceConfDMA)) - ataOneValue.Add("DEVICE CONFIGURATION IDENTIFY DMA and DEVICE CONFIGURATION SET DMA are supported"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ReadBufferDMA)) - ataOneValue.Add("READ BUFFER DMA is supported"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.WriteBufferDMA)) - ataOneValue.Add("WRITE BUFFER DMA is supported"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.DownloadMicroCodeDMA)) - ataOneValue.Add("DOWNLOAD MICROCODE DMA is supported"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.SetMaxDMA)) - ataOneValue.Add("SET PASSWORD DMA and SET UNLOCK DMA are supported"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.Ata28)) - ataOneValue.Add("Not all 28-bit commands are supported"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.CFast)) - ataOneValue.Add("Device follows CFast specification"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.IEEE1667)) - ataOneValue.Add("Device follows IEEE-1667"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.DeterministicTrim)) - { - ataOneValue.Add("Read after TRIM is deterministic"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ReadZeroTrim)) - ataOneValue.Add("Read after TRIM returns empty data"); - } - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.LongPhysSectorAligError)) - ataOneValue.Add("Device supports Long Physical Sector Alignment Error Reporting Control"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.Encrypted)) - ataOneValue.Add("Device encrypts all user data"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.AllCacheNV)) - ataOneValue.Add("Device's write cache is non-volatile"); - - if(ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ZonedBit0) || - ataIdentify.CommandSet5.HasFlag(Identify.CommandSetBit5.ZonedBit1)) - ataOneValue.Add("Device is zoned"); - } - - if(true) - if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.Sanitize)) - { - ataOneValue.Add("Sanitize feature set is supported"); - - ataOneValue.Add(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.SanitizeCommands) - ? "Sanitize commands are specified by ACS-3 or higher" - : "Sanitize commands are specified by ACS-2"); - - if(ataIdentify.Capabilities3.HasFlag(Identify.CapabilitiesBit3.SanitizeAntifreeze)) - ataOneValue.Add("SANITIZE ANTIFREEZE LOCK EXT is supported"); - } - - if(!ata1 && - maxAtaLevel >= 8) - if(ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.Set) && - !ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.Clear) && - ataIdentify.TrustedComputing.HasFlag(Identify.TrustedComputingBit.TrustedComputing)) - ataOneValue.Add("Trusted Computing feature set is supported"); - - if((ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0x1 || - (ataIdentify.TransportMajorVersion & 0xF000) >> 12 == 0xE) - { - if(true) - if(!ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.Clear)) - if(ataIdentify.SATACapabilities.HasFlag(Identify.SATACapabilitiesBit.ReadLogDMAExt)) - ataOneValue.Add("READ LOG DMA EXT is supported"); - - if(true) - if(!ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.Clear)) - if(ataIdentify.SATACapabilities2.HasFlag(Identify.SATACapabilitiesBit2.FPDMAQ)) - ataOneValue.Add("RECEIVE FPDMA QUEUED and SEND FPDMA QUEUED are supported"); - - if(true) - if(!ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.Clear)) - { - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.NonZeroBufferOffset)) - ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. - NonZeroBufferOffset) - ? "Non-zero buffer offsets are supported and enabled" - : "Non-zero buffer offsets are supported"); - - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.DMASetup)) - ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.DMASetup) - ? "DMA Setup auto-activation is supported and enabled" - : "DMA Setup auto-activation is supported"); - - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.InitPowerMgmt)) - ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. - InitPowerMgmt) - ? "Device-initiated power management is supported and enabled" - : "Device-initiated power management is supported"); - - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.InOrderData)) - ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. - InOrderData) - ? "In-order data delivery is supported and enabled" - : "In-order data delivery is supported"); - - if(!atapi) - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.HardwareFeatureControl)) - ataOneValue.Add(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit. - HardwareFeatureControl) - ? "Hardware Feature Control is supported and enabled" - : "Hardware Feature Control is supported"); - - if(atapi) - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.AsyncNotification)) - if(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.AsyncNotification)) - ataOneValue.Add("Asynchronous notification is supported"); - else - ataOneValue.Add("Asynchronous notification is supported"); - - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.SettingsPreserve)) - if(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.SettingsPreserve)) - ataOneValue.Add("Software Settings Preservation is supported"); + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.AsyncNotification)) + if(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.AsyncNotification)) + ataOneValue.Add("Asynchronous notification is supported"); else - ataOneValue.Add("Software Settings Preservation is supported"); + ataOneValue.Add("Asynchronous notification is supported"); - if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.NCQAutoSense)) - ataOneValue.Add("NCQ Autosense is supported"); - - if(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.EnabledSlumber)) - ataOneValue.Add("Automatic Partial to Slumber transitions are enabled"); - } - } - - if((ataIdentify.RemovableStatusSet & 0x03) > 0) - ataOneValue.Add("Removable Media Status Notification feature set is supported"); - - if(ataIdentify.FreeFallSensitivity != 0x00 && - ataIdentify.FreeFallSensitivity != 0xFF) - ataOneValue.Add($"Free-fall sensitivity set to {ataIdentify.FreeFallSensitivity}"); - - if(ataIdentify.DataSetMgmt.HasFlag(Identify.DataSetMgmtBit.Trim)) - ataOneValue.Add("TRIM is supported"); - - if(ataIdentify.DataSetMgmtSize > 0) - ataOneValue. - Add($"DATA SET MANAGEMENT can receive a maximum of {ataIdentify.DataSetMgmtSize} blocks of 512 bytes"); - - if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Supported)) - { - ataOneValue.Add("Security:"); - - if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Enabled)) - { - ataOneValue.Add("Security is enabled"); - - ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Locked) - ? "Security is locked" : "Security is not locked"); - - ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Frozen) - ? "Security is frozen" : "Security is not frozen"); - - ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Expired) - ? "Security count has expired" : "Security count has not expired"); - - ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Maximum) - ? "Security level is maximum" : "Security level is high"); - } - else - { - ataOneValue.Add("Security is not enabled"); - } - - if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Enhanced)) - ataOneValue.Add("Supports enhanced security erase"); - - ataOneValue.Add($"{ataIdentify.SecurityEraseTime * 2} minutes to complete secure erase"); - - if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Enhanced)) - ataOneValue. - Add($"{ataIdentify.EnhancedSecurityEraseTime * 2} minutes to complete enhanced secure erase"); - - ataOneValue.Add($"Master password revision code: {ataIdentify.MasterPasswordRevisionCode}"); - } - - if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeSet) && - !ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeClear) && - ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.Streaming)) - { - ataOneValue.Add("Streaming:"); - ataOneValue.Add($"Minimum request size is {ataIdentify.StreamMinReqSize}"); - ataOneValue.Add($"Streaming transfer time in PIO is {ataIdentify.StreamTransferTimePIO}"); - ataOneValue.Add($"Streaming transfer time in DMA is {ataIdentify.StreamTransferTimeDMA}"); - ataOneValue.Add($"Streaming access latency is {ataIdentify.StreamAccessLatency}"); - ataOneValue.Add($"Streaming performance granularity is {ataIdentify.StreamPerformanceGranularity}"); - } - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.Supported)) - { - ataOneValue.Add("S.M.A.R.T. Command Transport (SCT):"); - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.LongSectorAccess)) - ataOneValue.Add("SCT Long Sector Address is supported"); - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.WriteSame)) - ataOneValue.Add("SCT Write Same is supported"); - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.ErrorRecoveryControl)) - ataOneValue.Add("SCT Error Recovery Control is supported"); - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.FeaturesControl)) - ataOneValue.Add("SCT Features Control is supported"); - - if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.DataTables)) - ataOneValue.Add("SCT Data Tables are supported"); - } - - if((ataIdentify.NVCacheCaps & 0x0010) == 0x0010) - { - ataOneValue.Add("Non-Volatile Cache:"); - ataOneValue.Add($"Version {(ataIdentify.NVCacheCaps & 0xF000) >> 12}"); - - if((ataIdentify.NVCacheCaps & 0x0001) == 0x0001) - { - ataOneValue.Add((ataIdentify.NVCacheCaps & 0x0002) == 0x0002 - ? "Power mode feature set is supported and enabled" - : "Power mode feature set is supported"); - - ataOneValue.Add($"Version {(ataIdentify.NVCacheCaps & 0x0F00) >> 8}"); - } - - ataOneValue.Add($"Non-Volatile Cache is {ataIdentify.NVCacheSize * logicalSectorSize} bytes"); - } - - if(ataReport.ReadCapabilities != null) - { - removable = false; - ataOneValue.Add(""); - - if(ataReport.ReadCapabilities.NominalRotationRate != null && - ataReport.ReadCapabilities.NominalRotationRate != 0x0000 && - ataReport.ReadCapabilities.NominalRotationRate != 0xFFFF) - ataOneValue.Add(ataReport.ReadCapabilities.NominalRotationRate == 0x0001 ? "Device does not rotate." - : $"Device rotates at {ataReport.ReadCapabilities.NominalRotationRate} rpm"); - - if(!atapi) - { - if(ataReport.ReadCapabilities.BlockSize != null) - { - ataTwoValue.Add("Logical sector size", $"{ataReport.ReadCapabilities.BlockSize} bytes"); - logicalSectorSize = ataReport.ReadCapabilities.BlockSize.Value; - } - - if(ataReport.ReadCapabilities.PhysicalBlockSize != null) - ataTwoValue.Add("Physical sector size", - $"{ataReport.ReadCapabilities.PhysicalBlockSize} bytes"); - - if(ataReport.ReadCapabilities.LongBlockSize != null) - ataTwoValue.Add("READ LONG sector size", $"{ataReport.ReadCapabilities.LongBlockSize} bytes"); - - if(ataReport.ReadCapabilities.BlockSize != null && - ataReport.ReadCapabilities.PhysicalBlockSize != null && - ataReport.ReadCapabilities.BlockSize.Value != - ataReport.ReadCapabilities.PhysicalBlockSize.Value && - (ataReport.ReadCapabilities.LogicalAlignment & 0x8000) == 0x0000 && - (ataReport.ReadCapabilities.LogicalAlignment & 0x4000) == 0x4000) - ataOneValue. - Add($"Logical sector starts at offset {ataReport.ReadCapabilities.LogicalAlignment & 0x3FFF} from physical sector"); - - if(ataReport.ReadCapabilities.CHS != null && - ataReport.ReadCapabilities.CurrentCHS != null) - { - int currentSectors = ataReport.ReadCapabilities.CurrentCHS.Cylinders * - ataReport.ReadCapabilities.CurrentCHS.Heads * - ataReport.ReadCapabilities.CurrentCHS.Sectors; - - ataTwoValue.Add("Cylinders", - $"{ataReport.ReadCapabilities.CHS.Cylinders} max., {ataReport.ReadCapabilities.CurrentCHS.Cylinders} current"); - - ataTwoValue.Add("Heads", - $"{ataReport.ReadCapabilities.CHS.Heads} max., {ataReport.ReadCapabilities.CurrentCHS.Heads} current"); - - ataTwoValue.Add("Sectors per track", - $"{ataReport.ReadCapabilities.CHS.Sectors} max., {ataReport.ReadCapabilities.CurrentCHS.Sectors} current"); - - ataTwoValue.Add("Sectors addressable in CHS mode", - $"{ataReport.ReadCapabilities.CHS.Cylinders * ataReport.ReadCapabilities.CHS.Heads * ataReport.ReadCapabilities.CHS.Sectors} max., {currentSectors} current"); - - ataTwoValue.Add("Device size in CHS mode", - $"{(ulong)currentSectors * logicalSectorSize} bytes, {(ulong)currentSectors * logicalSectorSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); - } - else if(ataReport.ReadCapabilities.CHS != null) - { - int currentSectors = ataReport.ReadCapabilities.CHS.Cylinders * - ataReport.ReadCapabilities.CHS.Heads * - ataReport.ReadCapabilities.CHS.Sectors; - - ataTwoValue.Add("Cylinders", $"{ataReport.ReadCapabilities.CHS.Cylinders}"); - ataTwoValue.Add("Heads", $"{ataReport.ReadCapabilities.CHS.Heads}"); - ataTwoValue.Add("Sectors per track", $"{ataReport.ReadCapabilities.CHS.Sectors}"); - ataTwoValue.Add("Sectors addressable in CHS mode", $"{currentSectors}"); - - ataTwoValue.Add("Device size in CHS mode", - $"{(ulong)currentSectors * logicalSectorSize} bytes, {(ulong)currentSectors * logicalSectorSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); - } - - if(ataReport.ReadCapabilities.LBASectors != null) - { - ataTwoValue.Add("Sectors addressable in sectors in 28-bit LBA mode", - $"{ataReport.ReadCapabilities.LBASectors}"); - - if((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1024 / 1024 > 1000000) - ataTwoValue.Add("Device size in 28-bit LBA mode", - $"{(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize} bytes, {(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); - else if((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1024 / 1024 > 1000) - ataTwoValue.Add("Device size in 28-bit LBA mode", - $"{(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize} bytes, {(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1000 / 1000 / 1000} Gb, {(double)((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize) / 1024 / 1024 / 1024:F2} GiB"); + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.SettingsPreserve)) + if(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.SettingsPreserve)) + ataOneValue.Add("Software Settings Preservation is supported"); else - ataTwoValue.Add("Device size in 28-bit LBA mode", - $"{(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize} bytes, {(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1000 / 1000} Mb, {(double)((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); - } + ataOneValue.Add("Software Settings Preservation is supported"); - if(ataReport.ReadCapabilities.LBA48Sectors != null) - { - ataTwoValue.Add("Sectors addressable in sectors in 48-bit LBA mode", - $"{ataReport.ReadCapabilities.LBA48Sectors}"); + if(ataIdentify.SATAFeatures.HasFlag(Identify.SATAFeaturesBit.NCQAutoSense)) + ataOneValue.Add("NCQ Autosense is supported"); - if(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1024 / 1024 > 1000000) - ataTwoValue.Add("Device size in 48-bit LBA mode", - $"{ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize} bytes, {ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); - else if(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1024 / 1024 > 1000) - ataTwoValue.Add("Device size in 48-bit LBA mode", - $"{ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize} bytes, {ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1000 / 1000 / 1000} Gb, {(double)(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize) / 1024 / 1024 / 1024:F2} GiB"); - else - ataTwoValue.Add("Device size in 48-bit LBA mode", - $"{ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize} bytes, {ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1000 / 1000} Mb, {(double)(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); - } - - if(ata1 || cfa) - { - if(ataReport.ReadCapabilities.UnformattedBPT > 0) - ataTwoValue.Add("Bytes per unformatted track", - $"{ataReport.ReadCapabilities.UnformattedBPT}"); - - if(ataReport.ReadCapabilities.UnformattedBPS > 0) - ataTwoValue.Add("Bytes per unformatted sector", - $"{ataReport.ReadCapabilities.UnformattedBPS}"); - } + if(ataIdentify.EnabledSATAFeatures.HasFlag(Identify.SATAFeaturesBit.EnabledSlumber)) + ataOneValue.Add("Automatic Partial to Slumber transitions are enabled"); } + } - if(ataReport.ReadCapabilities.SupportsReadSectors == true) - ataOneValue.Add("Device supports READ SECTOR(S) command in CHS mode"); + if((ataIdentify.RemovableStatusSet & 0x03) > 0) + ataOneValue.Add("Removable Media Status Notification feature set is supported"); - if(ataReport.ReadCapabilities.SupportsReadRetry == true) - ataOneValue.Add("Device supports READ SECTOR(S) RETRY command in CHS mode"); + if(ataIdentify.FreeFallSensitivity != 0x00 && + ataIdentify.FreeFallSensitivity != 0xFF) + ataOneValue.Add($"Free-fall sensitivity set to {ataIdentify.FreeFallSensitivity}"); - if(ataReport.ReadCapabilities.SupportsReadDma == true) - ataOneValue.Add("Device supports READ DMA command in CHS mode"); + if(ataIdentify.DataSetMgmt.HasFlag(Identify.DataSetMgmtBit.Trim)) + ataOneValue.Add("TRIM is supported"); - if(ataReport.ReadCapabilities.SupportsReadDmaRetry == true) - ataOneValue.Add("Device supports READ DMA RETRY command in CHS mode"); + if(ataIdentify.DataSetMgmtSize > 0) + ataOneValue. + Add($"DATA SET MANAGEMENT can receive a maximum of {ataIdentify.DataSetMgmtSize} blocks of 512 bytes"); - if(ataReport.ReadCapabilities.SupportsReadLong == true) - ataOneValue.Add("Device supports READ LONG command in CHS mode"); + if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Supported)) + { + ataOneValue.Add("Security:"); - if(ataReport.ReadCapabilities.SupportsReadLongRetry == true) - ataOneValue.Add("Device supports READ LONG RETRY command in CHS mode"); + if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Enabled)) + { + ataOneValue.Add("Security is enabled"); - if(ataReport.ReadCapabilities.SupportsReadLba == true) - ataOneValue.Add("Device supports READ SECTOR(S) command in 28-bit LBA mode"); + ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Locked) + ? "Security is locked" : "Security is not locked"); - if(ataReport.ReadCapabilities.SupportsReadRetryLba == true) - ataOneValue.Add("Device supports READ SECTOR(S) RETRY command in 28-bit LBA mode"); + ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Frozen) + ? "Security is frozen" : "Security is not frozen"); - if(ataReport.ReadCapabilities.SupportsReadDmaLba == true) - ataOneValue.Add("Device supports READ DMA command in 28-bit LBA mode"); + ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Expired) + ? "Security count has expired" : "Security count has not expired"); - if(ataReport.ReadCapabilities.SupportsReadDmaRetryLba == true) - ataOneValue.Add("Device supports READ DMA RETRY command in 28-bit LBA mode"); - - if(ataReport.ReadCapabilities.SupportsReadLongLba == true) - ataOneValue.Add("Device supports READ LONG command in 28-bit LBA mode"); - - if(ataReport.ReadCapabilities.SupportsReadLongRetryLba == true) - ataOneValue.Add("Device supports READ LONG RETRY command in 28-bit LBA mode"); - - if(ataReport.ReadCapabilities.SupportsReadLba48 == true) - ataOneValue.Add("Device supports READ SECTOR(S) command in 48-bit LBA mode"); - - if(ataReport.ReadCapabilities.SupportsReadDmaLba48 == true) - ataOneValue.Add("Device supports READ DMA command in 48-bit LBA mode"); - - if(ataReport.ReadCapabilities.SupportsSeek == true) - ataOneValue.Add("Device supports SEEK command in CHS mode"); - - if(ataReport.ReadCapabilities.SupportsSeekLba == true) - ataOneValue.Add("Device supports SEEK command in 28-bit LBA mode"); + ataOneValue.Add(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Maximum) + ? "Security level is maximum" : "Security level is high"); } else { - testedMedia = ataReport.RemovableMedias; + ataOneValue.Add("Security is not enabled"); } + + if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Enhanced)) + ataOneValue.Add("Supports enhanced security erase"); + + ataOneValue.Add($"{ataIdentify.SecurityEraseTime * 2} minutes to complete secure erase"); + + if(ataIdentify.SecurityStatus.HasFlag(Identify.SecurityStatusBit.Enhanced)) + ataOneValue. + Add($"{ataIdentify.EnhancedSecurityEraseTime * 2} minutes to complete enhanced secure erase"); + + ataOneValue.Add($"Master password revision code: {ataIdentify.MasterPasswordRevisionCode}"); + } + + if(ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeSet) && + !ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.MustBeClear) && + ataIdentify.CommandSet3.HasFlag(Identify.CommandSetBit3.Streaming)) + { + ataOneValue.Add("Streaming:"); + ataOneValue.Add($"Minimum request size is {ataIdentify.StreamMinReqSize}"); + ataOneValue.Add($"Streaming transfer time in PIO is {ataIdentify.StreamTransferTimePIO}"); + ataOneValue.Add($"Streaming transfer time in DMA is {ataIdentify.StreamTransferTimeDMA}"); + ataOneValue.Add($"Streaming access latency is {ataIdentify.StreamAccessLatency}"); + ataOneValue.Add($"Streaming performance granularity is {ataIdentify.StreamPerformanceGranularity}"); + } + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.Supported)) + { + ataOneValue.Add("S.M.A.R.T. Command Transport (SCT):"); + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.LongSectorAccess)) + ataOneValue.Add("SCT Long Sector Address is supported"); + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.WriteSame)) + ataOneValue.Add("SCT Write Same is supported"); + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.ErrorRecoveryControl)) + ataOneValue.Add("SCT Error Recovery Control is supported"); + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.FeaturesControl)) + ataOneValue.Add("SCT Features Control is supported"); + + if(ataIdentify.SCTCommandTransport.HasFlag(Identify.SCTCommandTransportBit.DataTables)) + ataOneValue.Add("SCT Data Tables are supported"); + } + + if((ataIdentify.NVCacheCaps & 0x0010) == 0x0010) + { + ataOneValue.Add("Non-Volatile Cache:"); + ataOneValue.Add($"Version {(ataIdentify.NVCacheCaps & 0xF000) >> 12}"); + + if((ataIdentify.NVCacheCaps & 0x0001) == 0x0001) + { + ataOneValue.Add((ataIdentify.NVCacheCaps & 0x0002) == 0x0002 + ? "Power mode feature set is supported and enabled" + : "Power mode feature set is supported"); + + ataOneValue.Add($"Version {(ataIdentify.NVCacheCaps & 0x0F00) >> 8}"); + } + + ataOneValue.Add($"Non-Volatile Cache is {ataIdentify.NVCacheSize * logicalSectorSize} bytes"); + } + + if(ataReport.ReadCapabilities != null) + { + removable = false; + ataOneValue.Add(""); + + if(ataReport.ReadCapabilities.NominalRotationRate != null && + ataReport.ReadCapabilities.NominalRotationRate != 0x0000 && + ataReport.ReadCapabilities.NominalRotationRate != 0xFFFF) + ataOneValue.Add(ataReport.ReadCapabilities.NominalRotationRate == 0x0001 ? "Device does not rotate." + : $"Device rotates at {ataReport.ReadCapabilities.NominalRotationRate} rpm"); + + if(!atapi) + { + if(ataReport.ReadCapabilities.BlockSize != null) + { + ataTwoValue.Add("Logical sector size", $"{ataReport.ReadCapabilities.BlockSize} bytes"); + logicalSectorSize = ataReport.ReadCapabilities.BlockSize.Value; + } + + if(ataReport.ReadCapabilities.PhysicalBlockSize != null) + ataTwoValue.Add("Physical sector size", + $"{ataReport.ReadCapabilities.PhysicalBlockSize} bytes"); + + if(ataReport.ReadCapabilities.LongBlockSize != null) + ataTwoValue.Add("READ LONG sector size", $"{ataReport.ReadCapabilities.LongBlockSize} bytes"); + + if(ataReport.ReadCapabilities.BlockSize != null && + ataReport.ReadCapabilities.PhysicalBlockSize != null && + ataReport.ReadCapabilities.BlockSize.Value != + ataReport.ReadCapabilities.PhysicalBlockSize.Value && + (ataReport.ReadCapabilities.LogicalAlignment & 0x8000) == 0x0000 && + (ataReport.ReadCapabilities.LogicalAlignment & 0x4000) == 0x4000) + ataOneValue. + Add($"Logical sector starts at offset {ataReport.ReadCapabilities.LogicalAlignment & 0x3FFF} from physical sector"); + + if(ataReport.ReadCapabilities.CHS != null && + ataReport.ReadCapabilities.CurrentCHS != null) + { + int currentSectors = ataReport.ReadCapabilities.CurrentCHS.Cylinders * + ataReport.ReadCapabilities.CurrentCHS.Heads * + ataReport.ReadCapabilities.CurrentCHS.Sectors; + + ataTwoValue.Add("Cylinders", + $"{ataReport.ReadCapabilities.CHS.Cylinders} max., {ataReport.ReadCapabilities.CurrentCHS.Cylinders} current"); + + ataTwoValue.Add("Heads", + $"{ataReport.ReadCapabilities.CHS.Heads} max., {ataReport.ReadCapabilities.CurrentCHS.Heads} current"); + + ataTwoValue.Add("Sectors per track", + $"{ataReport.ReadCapabilities.CHS.Sectors} max., {ataReport.ReadCapabilities.CurrentCHS.Sectors} current"); + + ataTwoValue.Add("Sectors addressable in CHS mode", + $"{ataReport.ReadCapabilities.CHS.Cylinders * ataReport.ReadCapabilities.CHS.Heads * ataReport.ReadCapabilities.CHS.Sectors} max., {currentSectors} current"); + + ataTwoValue.Add("Device size in CHS mode", + $"{(ulong)currentSectors * logicalSectorSize} bytes, {(ulong)currentSectors * logicalSectorSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); + } + else if(ataReport.ReadCapabilities.CHS != null) + { + int currentSectors = ataReport.ReadCapabilities.CHS.Cylinders * + ataReport.ReadCapabilities.CHS.Heads * + ataReport.ReadCapabilities.CHS.Sectors; + + ataTwoValue.Add("Cylinders", $"{ataReport.ReadCapabilities.CHS.Cylinders}"); + ataTwoValue.Add("Heads", $"{ataReport.ReadCapabilities.CHS.Heads}"); + ataTwoValue.Add("Sectors per track", $"{ataReport.ReadCapabilities.CHS.Sectors}"); + ataTwoValue.Add("Sectors addressable in CHS mode", $"{currentSectors}"); + + ataTwoValue.Add("Device size in CHS mode", + $"{(ulong)currentSectors * logicalSectorSize} bytes, {(ulong)currentSectors * logicalSectorSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); + } + + if(ataReport.ReadCapabilities.LBASectors != null) + { + ataTwoValue.Add("Sectors addressable in sectors in 28-bit LBA mode", + $"{ataReport.ReadCapabilities.LBASectors}"); + + if((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1024 / 1024 > 1000000) + ataTwoValue.Add("Device size in 28-bit LBA mode", + $"{(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize} bytes, {(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); + else if((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1024 / 1024 > 1000) + ataTwoValue.Add("Device size in 28-bit LBA mode", + $"{(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize} bytes, {(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1000 / 1000 / 1000} Gb, {(double)((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize) / 1024 / 1024 / 1024:F2} GiB"); + else + ataTwoValue.Add("Device size in 28-bit LBA mode", + $"{(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize} bytes, {(ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize / 1000 / 1000} Mb, {(double)((ulong)ataReport.ReadCapabilities.LBASectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); + } + + if(ataReport.ReadCapabilities.LBA48Sectors != null) + { + ataTwoValue.Add("Sectors addressable in sectors in 48-bit LBA mode", + $"{ataReport.ReadCapabilities.LBA48Sectors}"); + + if(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1024 / 1024 > 1000000) + ataTwoValue.Add("Device size in 48-bit LBA mode", + $"{ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize} bytes, {ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); + else if(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1024 / 1024 > 1000) + ataTwoValue.Add("Device size in 48-bit LBA mode", + $"{ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize} bytes, {ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1000 / 1000 / 1000} Gb, {(double)(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize) / 1024 / 1024 / 1024:F2} GiB"); + else + ataTwoValue.Add("Device size in 48-bit LBA mode", + $"{ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize} bytes, {ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize / 1000 / 1000} Mb, {(double)(ataReport.ReadCapabilities.LBA48Sectors * logicalSectorSize) / 1024 / 1024:F2} MiB"); + } + + if(ata1 || cfa) + { + if(ataReport.ReadCapabilities.UnformattedBPT > 0) + ataTwoValue.Add("Bytes per unformatted track", + $"{ataReport.ReadCapabilities.UnformattedBPT}"); + + if(ataReport.ReadCapabilities.UnformattedBPS > 0) + ataTwoValue.Add("Bytes per unformatted sector", + $"{ataReport.ReadCapabilities.UnformattedBPS}"); + } + } + + if(ataReport.ReadCapabilities.SupportsReadSectors == true) + ataOneValue.Add("Device supports READ SECTOR(S) command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsReadRetry == true) + ataOneValue.Add("Device supports READ SECTOR(S) RETRY command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsReadDma == true) + ataOneValue.Add("Device supports READ DMA command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsReadDmaRetry == true) + ataOneValue.Add("Device supports READ DMA RETRY command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsReadLong == true) + ataOneValue.Add("Device supports READ LONG command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsReadLongRetry == true) + ataOneValue.Add("Device supports READ LONG RETRY command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsReadLba == true) + ataOneValue.Add("Device supports READ SECTOR(S) command in 28-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadRetryLba == true) + ataOneValue.Add("Device supports READ SECTOR(S) RETRY command in 28-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadDmaLba == true) + ataOneValue.Add("Device supports READ DMA command in 28-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadDmaRetryLba == true) + ataOneValue.Add("Device supports READ DMA RETRY command in 28-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadLongLba == true) + ataOneValue.Add("Device supports READ LONG command in 28-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadLongRetryLba == true) + ataOneValue.Add("Device supports READ LONG RETRY command in 28-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadLba48 == true) + ataOneValue.Add("Device supports READ SECTOR(S) command in 48-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsReadDmaLba48 == true) + ataOneValue.Add("Device supports READ DMA command in 48-bit LBA mode"); + + if(ataReport.ReadCapabilities.SupportsSeek == true) + ataOneValue.Add("Device supports SEEK command in CHS mode"); + + if(ataReport.ReadCapabilities.SupportsSeekLba == true) + ataOneValue.Add("Device supports SEEK command in 28-bit LBA mode"); + } + else + { + testedMedia = ataReport.RemovableMedias; } } } \ No newline at end of file diff --git a/Aaru.Server/Core/Hash.cs b/Aaru.Server/Core/Hash.cs index 17445087..87a26f33 100644 --- a/Aaru.Server/Core/Hash.cs +++ b/Aaru.Server/Core/Hash.cs @@ -1,36 +1,35 @@ using System.Security.Cryptography; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class Hash { - public static class Hash + public static string Sha512(byte[] data) { - public static string Sha512(byte[] data) + byte[] hash; + + using(var sha = new SHA512Managed()) { - byte[] hash; - - using(var sha = new SHA512Managed()) - { - sha.Initialize(); - hash = sha.ComputeHash(data); - } - - char[] chars = new char[hash.Length * 2]; - - int j = 0; - - foreach(byte b in hash) - { - int nibble1 = (b & 0xF0) >> 4; - int nibble2 = b & 0x0F; - - nibble1 += nibble1 > 9 ? 0x57 : 0x30; - nibble2 += nibble2 > 9 ? 0x57 : 0x30; - - chars[j++] = (char)nibble1; - chars[j++] = (char)nibble2; - } - - return new string(chars); + sha.Initialize(); + hash = sha.ComputeHash(data); } + + char[] chars = new char[hash.Length * 2]; + + int j = 0; + + foreach(byte b in hash) + { + int nibble1 = (b & 0xF0) >> 4; + int nibble2 = b & 0x0F; + + nibble1 += nibble1 > 9 ? 0x57 : 0x30; + nibble2 += nibble2 > 9 ? 0x57 : 0x30; + + chars[j++] = (char)nibble1; + chars[j++] = (char)nibble2; + } + + return new string(chars); } } \ No newline at end of file diff --git a/Aaru.Server/Core/HtmlHelpers.cs b/Aaru.Server/Core/HtmlHelpers.cs index 1602fe67..0e8a3ad2 100644 --- a/Aaru.Server/Core/HtmlHelpers.cs +++ b/Aaru.Server/Core/HtmlHelpers.cs @@ -2,24 +2,23 @@ using System.Text.RegularExpressions; using Aaru.CommonTypes.Metadata; using Microsoft.AspNetCore.Mvc.Rendering; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class HtmlHelpers { - public static class HtmlHelpers - { - public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => - string.IsNullOrEmpty(text) ? string.Empty - : Regex.Replace(helper.Encode(text), " | | ", "
"); + public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => + string.IsNullOrEmpty(text) ? string.Empty + : Regex.Replace(helper.Encode(text), " | | ", "
"); - public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => - string.IsNullOrEmpty(text) ? string.Empty - : Regex.Replace(helper.Encode(text), " | | ", "
"); + public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => + string.IsNullOrEmpty(text) ? string.Empty + : Regex.Replace(helper.Encode(text), " | | ", "
"); - public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => - string.IsNullOrEmpty(text) ? string.Empty - : Regex.Replace(helper.Encode(text), " | | ", "
"); + public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => + string.IsNullOrEmpty(text) ? string.Empty + : Regex.Replace(helper.Encode(text), " | | ", "
"); - public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => - string.IsNullOrEmpty(text) ? string.Empty - : Regex.Replace(helper.Encode(text), " | | ", "
"); - } + public static string EncodedMultiLineText(this IHtmlHelper helper, string text) => + string.IsNullOrEmpty(text) ? string.Empty + : Regex.Replace(helper.Encode(text), " | | ", "
"); } \ No newline at end of file diff --git a/Aaru.Server/Core/ScsiEvpd.cs b/Aaru.Server/Core/ScsiEvpd.cs index a1b0d07e..532d7b3e 100644 --- a/Aaru.Server/Core/ScsiEvpd.cs +++ b/Aaru.Server/Core/ScsiEvpd.cs @@ -34,80 +34,79 @@ using System.Collections.Generic; using Aaru.CommonTypes.Metadata; using Aaru.Decoders.SCSI; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class ScsiEvpd { - public static class ScsiEvpd + /// + /// Takes the SCSI EVPD part of a device report and prints it as a list key=value pairs to be sequenced by ASP.NET + /// in the rendering + /// + /// EVPD pages + /// SCSI vendor string + /// List to put the key=value pairs on + public static void Report(IEnumerable pages, string vendor, ref Dictionary evpdPages) { - /// - /// Takes the SCSI EVPD part of a device report and prints it as a list key=value pairs to be sequenced by ASP.NET - /// in the rendering - /// - /// EVPD pages - /// SCSI vendor string - /// List to put the key=value pairs on - public static void Report(IEnumerable pages, string vendor, ref Dictionary evpdPages) + foreach(ScsiPage evpd in pages) { - foreach(ScsiPage evpd in pages) - { - string decoded; + string decoded; - if(evpd.page >= 0x01 && - evpd.page <= 0x7F) - decoded = EVPD.DecodeASCIIPage(evpd.value); - else if(evpd.page == 0x81) - decoded = EVPD.PrettifyPage_81(evpd.value); - else if(evpd.page == 0x82) - decoded = EVPD.DecodePage82(evpd.value); - else if(evpd.page == 0x83) - decoded = EVPD.PrettifyPage_83(evpd.value); - else if(evpd.page == 0x84) - decoded = EVPD.PrettifyPage_84(evpd.value); - else if(evpd.page == 0x85) - decoded = EVPD.PrettifyPage_85(evpd.value); - else if(evpd.page == 0x86) - decoded = EVPD.PrettifyPage_86(evpd.value); - else if(evpd.page == 0x89) - decoded = EVPD.PrettifyPage_89(evpd.value); - else if(evpd.page == 0xB0) - decoded = EVPD.PrettifyPage_B0(evpd.value); - else if(evpd.page == 0xB2) - decoded = $"TapeAlert Supported Flags Bitmap: 0x{EVPD.DecodePageB2(evpd.value):X16}
"; - else if(evpd.page == 0xB4) - decoded = EVPD.DecodePageB4(evpd.value); - else if(evpd.page == 0xC0 && - vendor.Trim() == "quantum") - decoded = EVPD.PrettifyPage_C0_Quantum(evpd.value); - else if(evpd.page == 0xC0 && - vendor.Trim() == "seagate") - decoded = EVPD.PrettifyPage_C0_Seagate(evpd.value); - else if(evpd.page == 0xC0 && - vendor.Trim() == "ibm") - decoded = EVPD.PrettifyPage_C0_IBM(evpd.value); - else if(evpd.page == 0xC1 && - vendor.Trim() == "ibm") - decoded = EVPD.PrettifyPage_C1_IBM(evpd.value); - else if((evpd.page == 0xC0 || evpd.page == 0xC1) && - vendor.Trim() == "certance") - decoded = EVPD.PrettifyPage_C0_C1_Certance(evpd.value); - else if((evpd.page == 0xC2 || evpd.page == 0xC3 || evpd.page == 0xC4 || evpd.page == 0xC5 || - evpd.page == 0xC6) && - vendor.Trim() == "certance") - decoded = EVPD.PrettifyPage_C2_C3_C4_C5_C6_Certance(evpd.value); - else if((evpd.page == 0xC0 || evpd.page == 0xC1 || evpd.page == 0xC2 || evpd.page == 0xC3 || - evpd.page == 0xC4 || evpd.page == 0xC5) && - vendor.Trim() == "hp") - decoded = EVPD.PrettifyPage_C0_to_C5_HP(evpd.value); - else if(evpd.page == 0xDF && - vendor.Trim() == "certance") - decoded = EVPD.PrettifyPage_DF_Certance(evpd.value); - else - decoded = "Undecoded"; + if(evpd.page >= 0x01 && + evpd.page <= 0x7F) + decoded = EVPD.DecodeASCIIPage(evpd.value); + else if(evpd.page == 0x81) + decoded = EVPD.PrettifyPage_81(evpd.value); + else if(evpd.page == 0x82) + decoded = EVPD.DecodePage82(evpd.value); + else if(evpd.page == 0x83) + decoded = EVPD.PrettifyPage_83(evpd.value); + else if(evpd.page == 0x84) + decoded = EVPD.PrettifyPage_84(evpd.value); + else if(evpd.page == 0x85) + decoded = EVPD.PrettifyPage_85(evpd.value); + else if(evpd.page == 0x86) + decoded = EVPD.PrettifyPage_86(evpd.value); + else if(evpd.page == 0x89) + decoded = EVPD.PrettifyPage_89(evpd.value); + else if(evpd.page == 0xB0) + decoded = EVPD.PrettifyPage_B0(evpd.value); + else if(evpd.page == 0xB2) + decoded = $"TapeAlert Supported Flags Bitmap: 0x{EVPD.DecodePageB2(evpd.value):X16}
"; + else if(evpd.page == 0xB4) + decoded = EVPD.DecodePageB4(evpd.value); + else if(evpd.page == 0xC0 && + vendor.Trim() == "quantum") + decoded = EVPD.PrettifyPage_C0_Quantum(evpd.value); + else if(evpd.page == 0xC0 && + vendor.Trim() == "seagate") + decoded = EVPD.PrettifyPage_C0_Seagate(evpd.value); + else if(evpd.page == 0xC0 && + vendor.Trim() == "ibm") + decoded = EVPD.PrettifyPage_C0_IBM(evpd.value); + else if(evpd.page == 0xC1 && + vendor.Trim() == "ibm") + decoded = EVPD.PrettifyPage_C1_IBM(evpd.value); + else if((evpd.page == 0xC0 || evpd.page == 0xC1) && + vendor.Trim() == "certance") + decoded = EVPD.PrettifyPage_C0_C1_Certance(evpd.value); + else if((evpd.page == 0xC2 || evpd.page == 0xC3 || evpd.page == 0xC4 || evpd.page == 0xC5 || + evpd.page == 0xC6) && + vendor.Trim() == "certance") + decoded = EVPD.PrettifyPage_C2_C3_C4_C5_C6_Certance(evpd.value); + else if((evpd.page == 0xC0 || evpd.page == 0xC1 || evpd.page == 0xC2 || evpd.page == 0xC3 || + evpd.page == 0xC4 || evpd.page == 0xC5) && + vendor.Trim() == "hp") + decoded = EVPD.PrettifyPage_C0_to_C5_HP(evpd.value); + else if(evpd.page == 0xDF && + vendor.Trim() == "certance") + decoded = EVPD.PrettifyPage_DF_Certance(evpd.value); + else + decoded = "Undecoded"; - if(!string.IsNullOrEmpty(decoded)) - decoded = decoded.Replace("\n", "
"); + if(!string.IsNullOrEmpty(decoded)) + decoded = decoded.Replace("\n", "
"); - evpdPages.Add($"EVPD page {evpd.page:X2}h", decoded); - } + evpdPages.Add($"EVPD page {evpd.page:X2}h", decoded); } } } \ No newline at end of file diff --git a/Aaru.Server/Core/ScsiInquiry.cs b/Aaru.Server/Core/ScsiInquiry.cs index 073d5b3e..85145489 100644 --- a/Aaru.Server/Core/ScsiInquiry.cs +++ b/Aaru.Server/Core/ScsiInquiry.cs @@ -33,2236 +33,2235 @@ using System.Collections.Generic; using Aaru.CommonTypes.Structs.Devices.SCSI; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +internal static class ScsiInquiry { - internal static class ScsiInquiry + /// + /// Takes the SCSI INQUIRY part of a device report and prints it as a list of values to be sequenced by ASP.NET in + /// the rendering + /// + /// INQUIRY part of the report + /// List of values + internal static IEnumerable Report(Inquiry? inquiryNullable) { - /// - /// Takes the SCSI INQUIRY part of a device report and prints it as a list of values to be sequenced by ASP.NET in - /// the rendering - /// - /// INQUIRY part of the report - /// List of values - internal static IEnumerable Report(Inquiry? inquiryNullable) - { - List scsiOneValue = new(); - - if(!inquiryNullable.HasValue) - return scsiOneValue; - - Inquiry inquiry = inquiryNullable.Value; - - switch((PeripheralQualifiers)inquiry.PeripheralQualifier) - { - case PeripheralQualifiers.Supported: - scsiOneValue.Add("Device is connected and supported."); - - break; - case PeripheralQualifiers.Unconnected: - scsiOneValue.Add("Device is supported but not connected."); - - break; - case PeripheralQualifiers.Reserved: - scsiOneValue.Add("Reserved value set in Peripheral Qualifier field."); - - break; - case PeripheralQualifiers.Unsupported: - scsiOneValue.Add("Device is connected but unsupported."); - - break; - default: - scsiOneValue.Add($"Vendor value {inquiry.PeripheralQualifier} set in Peripheral Qualifier field."); - - break; - } - - switch((PeripheralDeviceTypes)inquiry.PeripheralDeviceType) - { - case PeripheralDeviceTypes.DirectAccess: //0x00, - scsiOneValue.Add("Direct-access device"); - - break; - case PeripheralDeviceTypes.SequentialAccess: //0x01, - scsiOneValue.Add("Sequential-access device"); - - break; - case PeripheralDeviceTypes.PrinterDevice: //0x02, - scsiOneValue.Add("Printer device"); - - break; - case PeripheralDeviceTypes.ProcessorDevice: //0x03, - scsiOneValue.Add("Processor device"); - - break; - case PeripheralDeviceTypes.WriteOnceDevice: //0x04, - scsiOneValue.Add("Write-once device"); - - break; - case PeripheralDeviceTypes.MultiMediaDevice: //0x05, - scsiOneValue.Add("CD-ROM/DVD/etc device"); - - break; - case PeripheralDeviceTypes.ScannerDevice: //0x06, - scsiOneValue.Add("Scanner device"); - - break; - case PeripheralDeviceTypes.OpticalDevice: //0x07, - scsiOneValue.Add("Optical memory device"); - - break; - case PeripheralDeviceTypes.MediumChangerDevice: //0x08, - scsiOneValue.Add("Medium change device"); - - break; - case PeripheralDeviceTypes.CommsDevice: //0x09, - scsiOneValue.Add("Communications device"); - - break; - case PeripheralDeviceTypes.PrePressDevice1: //0x0A, - scsiOneValue.Add("Graphics arts pre-press device (defined in ASC IT8)"); - - break; - case PeripheralDeviceTypes.PrePressDevice2: //0x0B, - scsiOneValue.Add("Graphics arts pre-press device (defined in ASC IT8)"); - - break; - case PeripheralDeviceTypes.ArrayControllerDevice: //0x0C, - scsiOneValue.Add("Array controller device"); - - break; - case PeripheralDeviceTypes.EnclosureServiceDevice: //0x0D, - scsiOneValue.Add("Enclosure services device"); - - break; - case PeripheralDeviceTypes.SimplifiedDevice: //0x0E, - scsiOneValue.Add("Simplified direct-access device"); - - break; - case PeripheralDeviceTypes.OCRWDevice: //0x0F, - scsiOneValue.Add("Optical card reader/writer device"); - - break; - case PeripheralDeviceTypes.BridgingExpander: //0x10, - scsiOneValue.Add("Bridging Expanders"); - - break; - case PeripheralDeviceTypes.ObjectDevice: //0x11, - scsiOneValue.Add("Object-based Storage Device"); - - break; - case PeripheralDeviceTypes.ADCDevice: //0x12, - scsiOneValue.Add("Automation/Drive Interface"); - - break; - case PeripheralDeviceTypes.SCSISecurityManagerDevice: //0x13, - scsiOneValue.Add("Security Manager Device"); - - break; - case PeripheralDeviceTypes.SCSIZonedBlockDevice: //0x14 - scsiOneValue.Add("Host managed zoned block device"); - - break; - case PeripheralDeviceTypes.WellKnownDevice: //0x1E, - scsiOneValue.Add("Well known logical unit"); - - break; - case PeripheralDeviceTypes.UnknownDevice: //0x1F - scsiOneValue.Add("Unknown or no device type"); - - break; - default: - scsiOneValue.Add($"Unknown device type field value 0x{inquiry.PeripheralDeviceType:X2}"); - - break; - } - - switch((ANSIVersions)inquiry.ANSIVersion) - { - case ANSIVersions.ANSINoVersion: - scsiOneValue.Add("Device does not claim to comply with any SCSI ANSI standard"); - - break; - case ANSIVersions.ANSI1986Version: - scsiOneValue.Add("Device claims to comply with ANSI X3.131:1986 (SCSI-1)"); - - break; - case ANSIVersions.ANSI1994Version: - scsiOneValue.Add("Device claims to comply with ANSI X3.131:1994 (SCSI-2)"); - - break; - case ANSIVersions.ANSI1997Version: - scsiOneValue.Add("Device claims to comply with ANSI X3.301:1997 (SPC-1)"); - - break; - case ANSIVersions.ANSI2001Version: - scsiOneValue.Add("Device claims to comply with ANSI X3.351:2001 (SPC-2)"); - - break; - case ANSIVersions.ANSI2005Version: - scsiOneValue.Add("Device claims to comply with ANSI X3.408:2005 (SPC-3)"); - - break; - case ANSIVersions.ANSI2008Version: - scsiOneValue.Add("Device claims to comply with ANSI X3.408:2005 (SPC-4)"); - - break; - default: - scsiOneValue. - Add($"Device claims to comply with unknown SCSI ANSI standard value 0x{inquiry.ANSIVersion:X2})"); - - break; - } - - switch((ECMAVersions)inquiry.ECMAVersion) - { - case ECMAVersions.ECMANoVersion: - scsiOneValue.Add("Device does not claim to comply with any SCSI ECMA standard"); - - break; - case ECMAVersions.ECMA111: - scsiOneValue.Add("Device claims to comply ECMA-111: Small Computer System Interface SCSI"); - - break; - default: - scsiOneValue. - Add($"Device claims to comply with unknown SCSI ECMA standard value 0x{inquiry.ECMAVersion:X2})"); - - break; - } - - switch((ISOVersions)inquiry.ISOVersion) - { - case ISOVersions.ISONoVersion: - scsiOneValue.Add("Device does not claim to comply with any SCSI ISO/IEC standard"); - - break; - case ISOVersions.ISO1995Version: - scsiOneValue.Add("Device claims to comply with ISO/IEC 9316:1995"); - - break; - default: - scsiOneValue. - Add($"Device claims to comply with unknown SCSI ISO/IEC standard value 0x{inquiry.ISOVersion:X2})"); - - break; - } - - if(inquiry.RMB) - scsiOneValue.Add("Device is removable"); - - if(inquiry.AERC) - scsiOneValue.Add("Device supports Asynchronous Event Reporting Capability"); - - if(inquiry.TrmTsk) - scsiOneValue.Add("Device supports TERMINATE TASK command"); - - if(inquiry.NormACA) - scsiOneValue.Add("Device supports setting Normal ACA"); - - if(inquiry.HiSup) - scsiOneValue.Add("Device supports LUN hierarchical addressing"); - - if(inquiry.SCCS) - scsiOneValue.Add("Device contains an embedded storage array controller"); - - if(inquiry.ACC) - scsiOneValue.Add("Device contains an Access Control Coordinator"); - - if(inquiry.ThreePC) - scsiOneValue.Add("Device supports third-party copy commands"); - - if(inquiry.Protect) - scsiOneValue.Add("Device supports protection information"); - - if(inquiry.BQue) - scsiOneValue.Add("Device supports basic queueing"); - - if(inquiry.EncServ) - scsiOneValue.Add("Device contains an embedded enclosure services component"); - - if(inquiry.MultiP) - scsiOneValue.Add("Multi-port device"); - - if(inquiry.MChngr) - scsiOneValue.Add("Device contains or is attached to a medium changer"); - - if(inquiry.ACKREQQ) - scsiOneValue.Add("Device supports request and acknowledge handshakes"); - - if(inquiry.Addr32) - scsiOneValue.Add("Device supports 32-bit wide SCSI addresses"); - - if(inquiry.Addr16) - scsiOneValue.Add("Device supports 16-bit wide SCSI addresses"); - - if(inquiry.RelAddr) - scsiOneValue.Add("Device supports relative addressing"); - - if(inquiry.WBus32) - scsiOneValue.Add("Device supports 32-bit wide data transfers"); - - if(inquiry.WBus16) - scsiOneValue.Add("Device supports 16-bit wide data transfers"); - - if(inquiry.Sync) - scsiOneValue.Add("Device supports synchronous data transfer"); - - if(inquiry.Linked) - scsiOneValue.Add("Device supports linked commands"); - - if(inquiry.TranDis) - scsiOneValue.Add("Device supports CONTINUE TASK and TARGET TRANSFER DISABLE commands"); - - if(inquiry.QAS) - scsiOneValue.Add("Device supports Quick Arbitration and Selection"); - - if(inquiry.CmdQue) - scsiOneValue.Add("Device supports TCQ queue"); - - if(inquiry.IUS) - scsiOneValue.Add("Device supports information unit transfers"); - - if(inquiry.SftRe) - scsiOneValue.Add("Device implements RESET as a soft reset"); - - switch((TGPSValues)inquiry.TPGS) - { - case TGPSValues.NotSupported: - scsiOneValue.Add("Device does not support asymmetrical access"); - - break; - case TGPSValues.OnlyImplicit: - scsiOneValue.Add("Device only supports implicit asymmetrical access"); - - break; - case TGPSValues.OnlyExplicit: - scsiOneValue.Add("Device only supports explicit asymmetrical access"); - - break; - case TGPSValues.Both: - scsiOneValue.Add("Device supports implicit and explicit asymmetrical access"); - - break; - default: - scsiOneValue.Add($"Unknown value in TPGS field 0x{inquiry.TPGS:X2}"); - - break; - } - - switch((SPIClocking)inquiry.Clocking) - { - case SPIClocking.ST: - scsiOneValue.Add("Device supports only ST clocking"); - - break; - case SPIClocking.DT: - scsiOneValue.Add("Device supports only DT clocking"); - - break; - case SPIClocking.Reserved: - scsiOneValue.Add("Reserved value 0x02 found in SPI clocking field"); - - break; - case SPIClocking.STandDT: - scsiOneValue.Add("Device supports ST and DT clocking"); - - break; - default: - scsiOneValue.Add($"Unknown value in SPI clocking field 0x{inquiry.Clocking:X2}"); - - break; - } - - if(inquiry.VersionDescriptors == null) - return scsiOneValue; - - foreach(ushort versionDescriptor in inquiry.VersionDescriptors) - switch(versionDescriptor) - { - case 0xFFFF: - case 0x0000: break; - case 0x0020: - scsiOneValue.Add("Device complies with SAM (no version claimed)"); - - break; - case 0x003B: - scsiOneValue.Add("Device complies with SAM T10/0994-D revision 18"); - - break; - case 0x003C: - scsiOneValue.Add("Device complies with SAM ANSI INCITS 270-1996"); - - break; - case 0x0040: - scsiOneValue.Add("Device complies with SAM-2 (no version claimed)"); - - break; - case 0x0054: - scsiOneValue.Add("Device complies with SAM-2 T10/1157-D revision 23"); - - break; - case 0x0055: - scsiOneValue.Add("Device complies with SAM-2 T10/1157-D revision 24"); - - break; - case 0x005C: - scsiOneValue.Add("Device complies with SAM-2 ANSI INCITS 366-2003"); - - break; - case 0x005E: - scsiOneValue.Add("Device complies with SAM-2 ISO/IEC 14776-412"); - - break; - case 0x0060: - scsiOneValue.Add("Device complies with SAM-3 (no version claimed)"); - - break; - case 0x0062: - scsiOneValue.Add("Device complies with SAM-3 T10/1561-D revision 7"); - - break; - case 0x0075: - scsiOneValue.Add("Device complies with SAM-3 T10/1561-D revision 13"); - - break; - case 0x0076: - scsiOneValue.Add("Device complies with SAM-3 T10/1561-D revision 14"); - - break; - case 0x0077: - scsiOneValue.Add("Device complies with SAM-3 ANSI INCITS 402-2005"); - - break; - case 0x0080: - scsiOneValue.Add("Device complies with SAM-4 (no version claimed)"); - - break; - case 0x0087: - scsiOneValue.Add("Device complies with SAM-4 T10/1683-D revision 13"); - - break; - case 0x008B: - scsiOneValue.Add("Device complies with SAM-4 T10/1683-D revision 14"); - - break; - case 0x0090: - scsiOneValue.Add("Device complies with SAM-4 ANSI INCITS 447-2008"); - - break; - case 0x0092: - scsiOneValue.Add("Device complies with SAM-4 ISO/IEC 14776-414"); - - break; - case 0x00A0: - scsiOneValue.Add("Device complies with SAM-5 (no version claimed)"); - - break; - case 0x00A2: - scsiOneValue.Add("Device complies with SAM-5 T10/2104-D revision 4"); - - break; - case 0x00A4: - scsiOneValue.Add("Device complies with SAM-5 T10/2104-D revision 20"); - - break; - case 0x00A6: - scsiOneValue.Add("Device complies with SAM-5 T10/2104-D revision 21"); - - break; - case 0x00C0: - scsiOneValue.Add("Device complies with SAM-6 (no version claimed)"); - - break; - case 0x0120: - scsiOneValue.Add("Device complies with SPC (no version claimed)"); - - break; - case 0x013B: - scsiOneValue.Add("Device complies with SPC T10/0995-D revision 11a"); - - break; - case 0x013C: - scsiOneValue.Add("Device complies with SPC ANSI INCITS 301-1997"); - - break; - case 0x0140: - scsiOneValue.Add("Device complies with MMC (no version claimed)"); - - break; - case 0x015B: - scsiOneValue.Add("Device complies with MMC T10/1048-D revision 10a"); - - break; - case 0x015C: - scsiOneValue.Add("Device complies with MMC ANSI INCITS 304-1997"); - - break; - case 0x0160: - scsiOneValue.Add("Device complies with SCC (no version claimed)"); - - break; - case 0x017B: - scsiOneValue.Add("Device complies with SCC T10/1047-D revision 06c"); - - break; - case 0x017C: - scsiOneValue.Add("Device complies with SCC ANSI INCITS 276-1997"); - - break; - case 0x0180: - scsiOneValue.Add("Device complies with SBC (no version claimed)"); - - break; - case 0x019B: - scsiOneValue.Add("Device complies with SBC T10/0996-D revision 08c"); - - break; - case 0x019C: - scsiOneValue.Add("Device complies with SBC ANSI INCITS 306-1998"); - - break; - case 0x01A0: - scsiOneValue.Add("Device complies with SMC (no version claimed)"); - - break; - case 0x01BB: - scsiOneValue.Add("Device complies with SMC T10/0999-D revision 10a"); - - break; - case 0x01BC: - scsiOneValue.Add("Device complies with SMC ANSI INCITS 314-1998"); - - break; - case 0x01BE: - scsiOneValue.Add("Device complies with SMC ISO/IEC 14776-351"); - - break; - case 0x01C0: - scsiOneValue.Add("Device complies with SES (no version claimed)"); - - break; - case 0x01DB: - scsiOneValue.Add("Device complies with SES T10/1212-D revision 08b"); - - break; - case 0x01DC: - scsiOneValue.Add("Device complies with SES ANSI INCITS 305-1998"); - - break; - case 0x01DD: - scsiOneValue. - Add("Device complies with SES T10/1212 revision 08b w/ Amendment ANSI INCITS.305/AM1-2000"); - - break; - case 0x01DE: - scsiOneValue. - Add("Device complies with SES ANSI INCITS 305-1998 w/ Amendment ANSI INCITS.305/AM1-2000"); - - break; - case 0x01E0: - scsiOneValue.Add("Device complies with SCC-2 (no version claimed)"); - - break; - case 0x01FB: - scsiOneValue.Add("Device complies with SCC-2 T10/1125-D revision 04"); - - break; - case 0x01FC: - scsiOneValue.Add("Device complies with SCC-2 ANSI INCITS 318-1998"); - - break; - case 0x0200: - scsiOneValue.Add("Device complies with SSC (no version claimed)"); - - break; - case 0x0201: - scsiOneValue.Add("Device complies with SSC T10/0997-D revision 17"); - - break; - case 0x0207: - scsiOneValue.Add("Device complies with SSC T10/0997-D revision 22"); - - break; - case 0x021C: - scsiOneValue.Add("Device complies with SSC ANSI INCITS 335-2000"); - - break; - case 0x0220: - scsiOneValue.Add("Device complies with RBC (no version claimed)"); - - break; - case 0x0238: - scsiOneValue.Add("Device complies with RBC T10/1240-D revision 10a"); - - break; - case 0x023C: - scsiOneValue.Add("Device complies with RBC ANSI INCITS 330-2000"); - - break; - case 0x0240: - scsiOneValue.Add("Device complies with MMC-2 (no version claimed)"); - - break; - case 0x0255: - scsiOneValue.Add("Device complies with MMC-2 T10/1228-D revision 11"); - - break; - case 0x025B: - scsiOneValue.Add("Device complies with MMC-2 T10/1228-D revision 11a"); - - break; - case 0x025C: - scsiOneValue.Add("Device complies with MMC-2 ANSI INCITS 333-2000"); - - break; - case 0x0260: - scsiOneValue.Add("Device complies with SPC-2 (no version claimed)"); - - break; - case 0x0267: - scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 12"); - - break; - case 0x0269: - scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 18"); - - break; - case 0x0275: - scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 19"); - - break; - case 0x0276: - scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 20"); - - break; - case 0x0277: - scsiOneValue.Add("Device complies with SPC-2 ANSI INCITS 351-2001"); - - break; - case 0x0278: - scsiOneValue.Add("Device complies with SPC-2 ISO/IEC 14776-452"); - - break; - case 0x0280: - scsiOneValue.Add("Device complies with OCRW (no version claimed)"); - - break; - case 0x029E: - scsiOneValue.Add("Device complies with OCRW ISO/IEC 14776-381"); - - break; - case 0x02A0: - scsiOneValue.Add("Device complies with MMC-3 (no version claimed)"); - - break; - case 0x02B5: - scsiOneValue.Add("Device complies with MMC-3 T10/1363-D revision 9"); - - break; - case 0x02B6: - scsiOneValue.Add("Device complies with MMC-3 T10/1363-D revision 10g"); - - break; - case 0x02B8: - scsiOneValue.Add("Device complies with MMC-3 ANSI INCITS 360-2002"); - - break; - case 0x02E0: - scsiOneValue.Add("Device complies with SMC-2 (no version claimed)"); - - break; - case 0x02F5: - scsiOneValue.Add("Device complies with SMC-2 T10/1383-D revision 5"); - - break; - case 0x02FC: - scsiOneValue.Add("Device complies with SMC-2 T10/1383-D revision 6"); - - break; - case 0x02FD: - scsiOneValue.Add("Device complies with SMC-2 T10/1383-D revision 7"); - - break; - case 0x02FE: - scsiOneValue.Add("Device complies with SMC-2 ANSI INCITS 382-2004"); - - break; - case 0x0300: - scsiOneValue.Add("Device complies with SPC-3 (no version claimed)"); - - break; - case 0x0301: - scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 7"); - - break; - case 0x0307: - scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 21"); - - break; - case 0x030F: - scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 22"); - - break; - case 0x0312: - scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 23"); - - break; - case 0x0314: - scsiOneValue.Add("Device complies with SPC-3 ANSI INCITS 408-2005"); - - break; - case 0x0316: - scsiOneValue.Add("Device complies with SPC-3 ISO/IEC 14776-453"); - - break; - case 0x0320: - scsiOneValue.Add("Device complies with SBC-2 (no version claimed)"); - - break; - case 0x0322: - scsiOneValue.Add("Device complies with SBC-2 T10/1417-D revision 5a"); - - break; - case 0x0324: - scsiOneValue.Add("Device complies with SBC-2 T10/1417-D revision 15"); - - break; - case 0x033B: - scsiOneValue.Add("Device complies with SBC-2 T10/1417-D revision 16"); - - break; - case 0x033D: - scsiOneValue.Add("Device complies with SBC-2 ANSI INCITS 405-2005"); - - break; - case 0x033E: - scsiOneValue.Add("Device complies with SBC-2 ISO/IEC 14776-322"); - - break; - case 0x0340: - scsiOneValue.Add("Device complies with OSD (no version claimed)"); - - break; - case 0x0341: - scsiOneValue.Add("Device complies with OSD T10/1355-D revision 0"); - - break; - case 0x0342: - scsiOneValue.Add("Device complies with OSD T10/1355-D revision 7a"); - - break; - case 0x0343: - scsiOneValue.Add("Device complies with OSD T10/1355-D revision 8"); - - break; - case 0x0344: - scsiOneValue.Add("Device complies with OSD T10/1355-D revision 9"); - - break; - case 0x0355: - scsiOneValue.Add("Device complies with OSD T10/1355-D revision 10"); - - break; - case 0x0356: - scsiOneValue.Add("Device complies with OSD ANSI INCITS 400-2004"); - - break; - case 0x0360: - scsiOneValue.Add("Device complies with SSC-2 (no version claimed)"); - - break; - case 0x0374: - scsiOneValue.Add("Device complies with SSC-2 T10/1434-D revision 7"); - - break; - case 0x0375: - scsiOneValue.Add("Device complies with SSC-2 T10/1434-D revision 9"); - - break; - case 0x037D: - scsiOneValue.Add("Device complies with SSC-2 ANSI INCITS 380-2003"); - - break; - case 0x0380: - scsiOneValue.Add("Device complies with BCC (no version claimed)"); - - break; - case 0x03A0: - scsiOneValue.Add("Device complies with MMC-4 (no version claimed)"); - - break; - case 0x03B0: - scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 5"); - - break; - case 0x03B1: - scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 5a"); - - break; - case 0x03BD: - scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 3"); - - break; - case 0x03BE: - scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 3d"); - - break; - case 0x03BF: - scsiOneValue.Add("Device complies with MMC-4 ANSI INCITS 401-2005"); - - break; - case 0x03C0: - scsiOneValue.Add("Device complies with ADC (no version claimed)"); - - break; - case 0x03D5: - scsiOneValue.Add("Device complies with ADC T10/1558-D revision 6"); - - break; - case 0x03D6: - scsiOneValue.Add("Device complies with ADC T10/1558-D revision 7"); - - break; - case 0x03D7: - scsiOneValue.Add("Device complies with ADC ANSI INCITS 403-2005"); - - break; - case 0x03E0: - scsiOneValue.Add("Device complies with SES-2 (no version claimed)"); - - break; - case 0x03E1: - scsiOneValue.Add("Device complies with SES-2 T10/1559-D revision 16"); - - break; - case 0x03E7: - scsiOneValue.Add("Device complies with SES-2 T10/1559-D revision 19"); - - break; - case 0x03EB: - scsiOneValue.Add("Device complies with SES-2 T10/1559-D revision 20"); - - break; - case 0x03F0: - scsiOneValue.Add("Device complies with SES-2 ANSI INCITS 448-2008"); - - break; - case 0x03F2: - scsiOneValue.Add("Device complies with SES-2 ISO/IEC 14776-372"); - - break; - case 0x0400: - scsiOneValue.Add("Device complies with SSC-3 (no version claimed)"); - - break; - case 0x0403: - scsiOneValue.Add("Device complies with SSC-3 T10/1611-D revision 04a"); - - break; - case 0x0407: - scsiOneValue.Add("Device complies with SSC-3 T10/1611-D revision 05"); - - break; - case 0x0409: - scsiOneValue.Add("Device complies with SSC-3 ANSI INCITS 467-2011"); - - break; - case 0x040B: - scsiOneValue.Add("Device complies with SSC-3 ISO/IEC 14776-333:2013"); - - break; - case 0x0420: - scsiOneValue.Add("Device complies with MMC-5 (no version claimed)"); - - break; - case 0x042F: - scsiOneValue.Add("Device complies with MMC-5 T10/1675-D revision 03"); - - break; - case 0x0431: - scsiOneValue.Add("Device complies with MMC-5 T10/1675-D revision 03b"); - - break; - case 0x0432: - scsiOneValue.Add("Device complies with MMC-5 T10/1675-D revision 04"); - - break; - case 0x0434: - scsiOneValue.Add("Device complies with MMC-5 ANSI INCITS 430-2007"); - - break; - case 0x0440: - scsiOneValue.Add("Device complies with OSD-2 (no version claimed)"); - - break; - case 0x0444: - scsiOneValue.Add("Device complies with OSD-2 T10/1729-D revision 4"); - - break; - case 0x0446: - scsiOneValue.Add("Device complies with OSD-2 T10/1729-D revision 5"); - - break; - case 0x0448: - scsiOneValue.Add("Device complies with OSD-2 ANSI INCITS 458-2011"); - - break; - case 0x0460: - scsiOneValue.Add("Device complies with SPC-4 (no version claimed)"); - - break; - case 0x0461: - scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 16"); - - break; - case 0x0462: - scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 18"); - - break; - case 0x0463: - scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 23"); - - break; - case 0x0466: - scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 36"); - - break; - case 0x0468: - scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 37"); - - break; - case 0x0469: - scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 37a"); - - break; - case 0x046C: - scsiOneValue.Add("Device complies with SPC-4 ANSI INCITS 513-2015"); - - break; - case 0x0480: - scsiOneValue.Add("Device complies with SMC-3 (no version claimed)"); - - break; - case 0x0482: - scsiOneValue.Add("Device complies with SMC-3 T10/1730-D revision 15"); - - break; - case 0x0484: - scsiOneValue.Add("Device complies with SMC-3 T10/1730-D revision 16"); - - break; - case 0x0486: - scsiOneValue.Add("Device complies with SMC-3 ANSI INCITS 484-2012"); - - break; - case 0x04A0: - scsiOneValue.Add("Device complies with ADC-2 (no version claimed)"); - - break; - case 0x04A7: - scsiOneValue.Add("Device complies with ADC-2 T10/1741-D revision 7"); - - break; - case 0x04AA: - scsiOneValue.Add("Device complies with ADC-2 T10/1741-D revision 8"); - - break; - case 0x04AC: - scsiOneValue.Add("Device complies with ADC-2 ANSI INCITS 441-2008"); - - break; - case 0x04C0: - scsiOneValue.Add("Device complies with SBC-3 (no version claimed)"); - - break; - case 0x04C3: - scsiOneValue.Add("Device complies with SBC-3 T10/BSR INCITS 514 revision 35"); - - break; - case 0x04C5: - scsiOneValue.Add("Device complies with SBC-3 T10/BSR INCITS 514 revision 36"); - - break; - case 0x04C8: - scsiOneValue.Add("Device complies with SBC-3 ANSI INCITS 514-2014"); - - break; - case 0x04E0: - scsiOneValue.Add("Device complies with MMC-6 (no version claimed)"); - - break; - case 0x04E3: - scsiOneValue.Add("Device complies with MMC-6 T10/1836-D revision 02b"); - - break; - case 0x04E5: - scsiOneValue.Add("Device complies with MMC-6 T10/1836-D revision 02g"); - - break; - case 0x04E6: - scsiOneValue.Add("Device complies with MMC-6 ANSI INCITS 468-2010"); - - break; - case 0x04E7: - scsiOneValue. - Add("Device complies with MMC-6 ANSI INCITS 468-2010 + MMC-6/AM1 ANSI INCITS 468-2010/AM 1"); - - break; - case 0x0500: - scsiOneValue.Add("Device complies with ADC-3 (no version claimed)"); - - break; - case 0x0502: - scsiOneValue.Add("Device complies with ADC-3 T10/1895-D revision 04"); - - break; - case 0x0504: - scsiOneValue.Add("Device complies with ADC-3 T10/1895-D revision 05"); - - break; - case 0x0506: - scsiOneValue.Add("Device complies with ADC-3 T10/1895-D revision 05a"); - - break; - case 0x050A: - scsiOneValue.Add("Device complies with ADC-3 ANSI INCITS 497-2012"); - - break; - case 0x0520: - scsiOneValue.Add("Device complies with SSC-4 (no version claimed)"); - - break; - case 0x0523: - scsiOneValue.Add("Device complies with SSC-4 T10/BSR INCITS 516 revision 2"); - - break; - case 0x0525: - scsiOneValue.Add("Device complies with SSC-4 T10/BSR INCITS 516 revision 3"); - - break; - case 0x0527: - scsiOneValue.Add("Device complies with SSC-4 ANSI INCITS 516-2013"); - - break; - case 0x0560: - scsiOneValue.Add("Device complies with OSD-3 (no version claimed)"); - - break; - case 0x0580: - scsiOneValue.Add("Device complies with SES-3 (no version claimed)"); - - break; - case 0x05A0: - scsiOneValue.Add("Device complies with SSC-5 (no version claimed)"); - - break; - case 0x05C0: - scsiOneValue.Add("Device complies with SPC-5 (no version claimed)"); - - break; - case 0x05E0: - scsiOneValue.Add("Device complies with SFSC (no version claimed)"); - - break; - case 0x05E3: - scsiOneValue.Add("Device complies with SFSC BSR INCITS 501 revision 01"); - - break; - case 0x0600: - scsiOneValue.Add("Device complies with SBC-4 (no version claimed)"); - - break; - case 0x0620: - scsiOneValue.Add("Device complies with ZBC (no version claimed)"); - - break; - case 0x0622: - scsiOneValue.Add("Device complies with ZBC BSR INCITS 536 revision 02"); - - break; - case 0x0640: - scsiOneValue.Add("Device complies with ADC-4 (no version claimed)"); - - break; - case 0x0820: - scsiOneValue.Add("Device complies with SSA-TL2 (no version claimed)"); - - break; - case 0x083B: - scsiOneValue.Add("Device complies with SSA-TL2 T10.1/1147-D revision 05b"); - - break; - case 0x083C: - scsiOneValue.Add("Device complies with SSA-TL2 ANSI INCITS 308-1998"); - - break; - case 0x0840: - scsiOneValue.Add("Device complies with SSA-TL1 (no version claimed)"); - - break; - case 0x085B: - scsiOneValue.Add("Device complies with SSA-TL1 T10.1/0989-D revision 10b"); - - break; - case 0x085C: - scsiOneValue.Add("Device complies with SSA-TL1 ANSI INCITS 295-1996"); - - break; - case 0x0860: - scsiOneValue.Add("Device complies with SSA-S3P (no version claimed)"); - - break; - case 0x087B: - scsiOneValue.Add("Device complies with SSA-S3P T10.1/1051-D revision 05b"); - - break; - case 0x087C: - scsiOneValue.Add("Device complies with SSA-S3P ANSI INCITS 309-1998"); - - break; - case 0x0880: - scsiOneValue.Add("Device complies with SSA-S2P (no version claimed)"); - - break; - case 0x089B: - scsiOneValue.Add("Device complies with SSA-S2P T10.1/1121-D revision 07b"); - - break; - case 0x089C: - scsiOneValue.Add("Device complies with SSA-S2P ANSI INCITS 294-1996"); - - break; - case 0x08A0: - scsiOneValue.Add("Device complies with SIP (no version claimed)"); - - break; - case 0x08BB: - scsiOneValue.Add("Device complies with SIP T10/0856-D revision 10"); - - break; - case 0x08BC: - scsiOneValue.Add("Device complies with SIP ANSI INCITS 292-1997"); - - break; - case 0x08C0: - scsiOneValue.Add("Device complies with FCP (no version claimed)"); - - break; - case 0x08DB: - scsiOneValue.Add("Device complies with FCP T10/0993-D revision 12"); - - break; - case 0x08DC: - scsiOneValue.Add("Device complies with FCP ANSI INCITS 269-1996"); - - break; - case 0x08E0: - scsiOneValue.Add("Device complies with SBP-2 (no version claimed)"); - - break; - case 0x08FB: - scsiOneValue.Add("Device complies with SBP-2 T10/1155-D revision 04"); - - break; - case 0x08FC: - scsiOneValue.Add("Device complies with SBP-2 ANSI INCITS 325-1998"); - - break; - case 0x0900: - scsiOneValue.Add("Device complies with FCP-2 (no version claimed)"); - - break; - case 0x0901: - scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 4"); - - break; - case 0x0915: - scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 7"); - - break; - case 0x0916: - scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 7a"); - - break; - case 0x0917: - scsiOneValue.Add("Device complies with FCP-2 ANSI INCITS 350-2003"); - - break; - case 0x0918: - scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 8"); - - break; - case 0x0920: - scsiOneValue.Add("Device complies with SST (no version claimed)"); - - break; - case 0x0935: - scsiOneValue.Add("Device complies with SST T10/1380-D revision 8b"); - - break; - case 0x0940: - scsiOneValue.Add("Device complies with SRP (no version claimed)"); - - break; - case 0x0954: - scsiOneValue.Add("Device complies with SRP T10/1415-D revision 10"); - - break; - case 0x0955: - scsiOneValue.Add("Device complies with SRP T10/1415-D revision 16a"); - - break; - case 0x095C: - scsiOneValue.Add("Device complies with SRP ANSI INCITS 365-2002"); - - break; - case 0x0960: - scsiOneValue.Add("Device complies with iSCSI (no version claimed)"); - - break; - case 0x0961: - case 0x0962: - case 0x0963: - case 0x0964: - case 0x0965: - case 0x0966: - case 0x0967: - case 0x0968: - case 0x0969: - case 0x096A: - case 0x096B: - case 0x096C: - case 0x096D: - case 0x096E: - case 0x096F: - case 0x0970: - case 0x0971: - case 0x0972: - case 0x0973: - case 0x0974: - case 0x0975: - case 0x0976: - case 0x0977: - case 0x0978: - case 0x0979: - case 0x097A: - case 0x097B: - case 0x097C: - case 0x097D: - case 0x097E: - case 0x097F: - scsiOneValue.Add($"Device complies with iSCSI revision {versionDescriptor & 0x1F}"); - - break; - case 0x0980: - scsiOneValue.Add("Device complies with SBP-3 (no version claimed)"); - - break; - case 0x0982: - scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 1f"); - - break; - case 0x0994: - scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 3"); - - break; - case 0x099A: - scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 4"); - - break; - case 0x099B: - scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 5"); - - break; - case 0x099C: - scsiOneValue.Add("Device complies with SBP-3 ANSI INCITS 375-2004"); - - break; - case 0x09C0: - scsiOneValue.Add("Device complies with ADP (no version claimed)"); - - break; - case 0x09E0: - scsiOneValue.Add("Device complies with ADT (no version claimed)"); - - break; - case 0x09F9: - scsiOneValue.Add("Device complies with ADT T10/1557-D revision 11"); - - break; - case 0x09FA: - scsiOneValue.Add("Device complies with ADT T10/1557-D revision 14"); - - break; - case 0x09FD: - scsiOneValue.Add("Device complies with ADT ANSI INCITS 406-2005"); - - break; - case 0x0A00: - scsiOneValue.Add("Device complies with FCP-3 (no version claimed)"); - - break; - case 0x0A07: - scsiOneValue.Add("Device complies with FCP-3 T10/1560-D revision 3f"); - - break; - case 0x0A0F: - scsiOneValue.Add("Device complies with FCP-3 T10/1560-D revision 4"); - - break; - case 0x0A11: - scsiOneValue.Add("Device complies with FCP-3 ANSI INCITS 416-2006"); - - break; - case 0x0A1C: - scsiOneValue.Add("Device complies with FCP-3 ISO/IEC 14776-223"); - - break; - case 0x0A20: - scsiOneValue.Add("Device complies with ADT-2 (no version claimed)"); - - break; - case 0x0A22: - scsiOneValue.Add("Device complies with ADT-2 T10/1742-D revision 06"); - - break; - case 0x0A27: - scsiOneValue.Add("Device complies with ADT-2 T10/1742-D revision 08"); - - break; - case 0x0A28: - scsiOneValue.Add("Device complies with ADT-2 T10/1742-D revision 09"); - - break; - case 0x0A2B: - scsiOneValue.Add("Device complies with ADT-2 ANSI INCITS 472-2011"); - - break; - case 0x0A40: - scsiOneValue.Add("Device complies with FCP-4 (no version claimed)"); - - break; - case 0x0A42: - scsiOneValue.Add("Device complies with FCP-4 T10/1828-D revision 01"); - - break; - case 0x0A44: - scsiOneValue.Add("Device complies with FCP-4 T10/1828-D revision 02"); - - break; - case 0x0A45: - scsiOneValue.Add("Device complies with FCP-4 T10/1828-D revision 02b"); - - break; - case 0x0A46: - scsiOneValue.Add("Device complies with FCP-4 ANSI INCITS 481-2012"); - - break; - case 0x0A60: - scsiOneValue.Add("Device complies with ADT-3 (no version claimed)"); - - break; - case 0x0AA0: - scsiOneValue.Add("Device complies with SPI (no version claimed)"); - - break; - case 0x0AB9: - scsiOneValue.Add("Device complies with SPI T10/0855-D revision 15a"); - - break; - case 0x0ABA: - scsiOneValue.Add("Device complies with SPI ANSI INCITS 253-1995"); - - break; - case 0x0ABB: - scsiOneValue.Add("Device complies with SPI T10/0855-D revision 15a with SPI Amnd revision 3a"); - - break; - case 0x0ABC: - scsiOneValue. - Add("Device complies with SPI ANSI INCITS 253-1995 with SPI Amnd ANSI INCITS 253/AM1-1998"); - - break; - case 0x0AC0: - scsiOneValue.Add("Device complies with Fast-20 (no version claimed)"); - - break; - case 0x0ADB: - scsiOneValue.Add("Device complies with Fast-20 T10/1071 revision 06"); - - break; - case 0x0ADC: - scsiOneValue.Add("Device complies with Fast-20 ANSI INCITS 277-1996"); - - break; - case 0x0AE0: - scsiOneValue.Add("Device complies with SPI-2 (no version claimed)"); - - break; - case 0x0AFB: - scsiOneValue.Add("Device complies with SPI-2 T10/1142-D revision 20b"); - - break; - case 0x0AFC: - scsiOneValue.Add("Device complies with SPI-2 ANSI INCITS 302-1999"); - - break; - case 0x0B00: - scsiOneValue.Add("Device complies with SPI-3 (no version claimed)"); - - break; - case 0x0B18: - scsiOneValue.Add("Device complies with SPI-3 T10/1302-D revision 10"); - - break; - case 0x0B19: - scsiOneValue.Add("Device complies with SPI-3 T10/1302-D revision 13a"); - - break; - case 0x0B1A: - scsiOneValue.Add("Device complies with SPI-3 T10/1302-D revision 14"); - - break; - case 0x0B1C: - scsiOneValue.Add("Device complies with SPI-3 ANSI INCITS 336-2000"); - - break; - case 0x0B20: - scsiOneValue.Add("Device complies with EPI (no version claimed)"); - - break; - case 0x0B3B: - scsiOneValue.Add("Device complies with EPI T10/1134 revision 16"); - - break; - case 0x0B3C: - scsiOneValue.Add("Device complies with EPI ANSI INCITS TR-23 1999"); - - break; - case 0x0B40: - scsiOneValue.Add("Device complies with SPI-4 (no version claimed)"); - - break; - case 0x0B54: - scsiOneValue.Add("Device complies with SPI-4 T10/1365-D revision 7"); - - break; - case 0x0B55: - scsiOneValue.Add("Device complies with SPI-4 T10/1365-D revision 9"); - - break; - case 0x0B56: - scsiOneValue.Add("Device complies with SPI-4 ANSI INCITS 362-2002"); - - break; - case 0x0B59: - scsiOneValue.Add("Device complies with SPI-4 T10/1365-D revision 10"); - - break; - case 0x0B60: - scsiOneValue.Add("Device complies with SPI-5 (no version claimed)"); - - break; - case 0x0B79: - scsiOneValue.Add("Device complies with SPI-5 T10/1525-D revision 3"); - - break; - case 0x0B7A: - scsiOneValue.Add("Device complies with SPI-5 T10/1525-D revision 5"); - - break; - case 0x0B7B: - scsiOneValue.Add("Device complies with SPI-5 T10/1525-D revision 6"); - - break; - case 0x0B7C: - scsiOneValue.Add("Device complies with SPI-5 ANSI INCITS 367-2003"); - - break; - case 0x0BE0: - scsiOneValue.Add("Device complies with SAS (no version claimed)"); - - break; - case 0x0BE1: - scsiOneValue.Add("Device complies with SAS T10/1562-D revision 01"); - - break; - case 0x0BF5: - scsiOneValue.Add("Device complies with SAS T10/1562-D revision 03"); - - break; - case 0x0BFA: - scsiOneValue.Add("Device complies with SAS T10/1562-D revision 04"); - - break; - case 0x0BFB: - scsiOneValue.Add("Device complies with SAS T10/1562-D revision 04"); - - break; - case 0x0BFC: - scsiOneValue.Add("Device complies with SAS T10/1562-D revision 05"); - - break; - case 0x0BFD: - scsiOneValue.Add("Device complies with SAS ANSI INCITS 376-2003"); - - break; - case 0x0C00: - scsiOneValue.Add("Device complies with SAS-1.1 (no version claimed)"); - - break; - case 0x0C07: - scsiOneValue.Add("Device complies with SAS-1.1 T10/1601-D revision 9"); - - break; - case 0x0C0F: - scsiOneValue.Add("Device complies with SAS-1.1 T10/1601-D revision 10"); - - break; - case 0x0C11: - scsiOneValue.Add("Device complies with SAS-1.1 ANSI INCITS 417-2006"); - - break; - case 0x0C12: - scsiOneValue.Add("Device complies with SAS-1.1 ISO/IEC 14776-151"); - - break; - case 0x0C20: - scsiOneValue.Add("Device complies with SAS-2 (no version claimed)"); - - break; - case 0x0C23: - scsiOneValue.Add("Device complies with SAS-2 T10/1760-D revision 14"); - - break; - case 0x0C27: - scsiOneValue.Add("Device complies with SAS-2 T10/1760-D revision 15"); - - break; - case 0x0C28: - scsiOneValue.Add("Device complies with SAS-2 T10/1760-D revision 16"); - - break; - case 0x0C2A: - scsiOneValue.Add("Device complies with SAS-2 ANSI INCITS 457-2010"); - - break; - case 0x0C40: - scsiOneValue.Add("Device complies with SAS-2.1 (no version claimed)"); - - break; - case 0x0C48: - scsiOneValue.Add("Device complies with SAS-2.1 T10/2125-D revision 04"); - - break; - case 0x0C4A: - scsiOneValue.Add("Device complies with SAS-2.1 T10/2125-D revision 06"); - - break; - case 0x0C4B: - scsiOneValue.Add("Device complies with SAS-2.1 T10/2125-D revision 07"); - - break; - case 0x0C4E: - scsiOneValue.Add("Device complies with SAS-2.1 ANSI INCITS 478-2011"); - - break; - case 0x0C4F: - scsiOneValue. - Add("Device complies with SAS-2.1 ANSI INCITS 478-2011 w/ Amnd 1 ANSI INCITS 478/AM1-2014"); - - break; - case 0x0C52: - scsiOneValue.Add("Device complies with SAS-2.1 ISO/IEC 14776-153"); - - break; - case 0x0C60: - scsiOneValue.Add("Device complies with SAS-3 (no version claimed)"); - - break; - case 0x0C63: - scsiOneValue.Add("Device complies with SAS-3 T10/BSR INCITS 519 revision 05a"); - - break; - case 0x0C65: - scsiOneValue.Add("Device complies with SAS-3 T10/BSR INCITS 519 revision 06"); - - break; - case 0x0C68: - scsiOneValue.Add("Device complies with SAS-3 ANSI INCITS 519-2014"); - - break; - case 0x0C80: - scsiOneValue.Add("Device complies with SAS-4 (no version claimed)"); - - break; - case 0x0D20: - scsiOneValue.Add("Device complies with FC-PH (no version claimed)"); - - break; - case 0x0D3B: - scsiOneValue.Add("Device complies with FC-PH ANSI INCITS 230-1994"); - - break; - case 0x0D3C: - scsiOneValue. - Add("Device complies with FC-PH ANSI INCITS 230-1994 with Amnd 1 ANSI INCITS 230/AM1-1996"); - - break; - case 0x0D40: - scsiOneValue.Add("Device complies with FC-AL (no version claimed)"); - - break; - case 0x0D5C: - scsiOneValue.Add("Device complies with FC-AL ANSI INCITS 272-1996"); - - break; - case 0x0D60: - scsiOneValue.Add("Device complies with FC-AL-2 (no version claimed)"); - - break; - case 0x0D61: - scsiOneValue.Add("Device complies with FC-AL-2 T11/1133-D revision 7.0"); - - break; - case 0x0D63: - scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999 with AM1-2003 & AM2-2006"); - - break; - case 0x0D64: - scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999 with Amnd 2 AM2-2006"); - - break; - case 0x0D65: - scsiOneValue.Add("Device complies with FC-AL-2 ISO/IEC 14165-122 with AM1 & AM2"); - - break; - case 0x0D7C: - scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999"); - - break; - case 0x0D7D: - scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999 with Amnd 1 AM1-2003"); - - break; - case 0x0D80: - scsiOneValue.Add("Device complies with FC-PH-3 (no version claimed)"); - - break; - case 0x0D9C: - scsiOneValue.Add("Device complies with FC-PH-3 ANSI INCITS 303-1998"); - - break; - case 0x0DA0: - scsiOneValue.Add("Device complies with FC-FS (no version claimed)"); - - break; - case 0x0DB7: - scsiOneValue.Add("Device complies with FC-FS T11/1331-D revision 1.2"); - - break; - case 0x0DB8: - scsiOneValue.Add("Device complies with FC-FS T11/1331-D revision 1.7"); - - break; - case 0x0DBC: - scsiOneValue.Add("Device complies with FC-FS ANSI INCITS 373-2003"); - - break; - case 0x0DBD: - scsiOneValue.Add("Device complies with FC-FS ISO/IEC 14165-251"); - - break; - case 0x0DC0: - scsiOneValue.Add("Device complies with FC-PI (no version claimed)"); - - break; - case 0x0DDC: - scsiOneValue.Add("Device complies with FC-PI ANSI INCITS 352-2002"); - - break; - case 0x0DE0: - scsiOneValue.Add("Device complies with FC-PI-2 (no version claimed)"); - - break; - case 0x0DE2: - scsiOneValue.Add("Device complies with FC-PI-2 T11/1506-D revision 5.0"); - - break; - case 0x0DE4: - scsiOneValue.Add("Device complies with FC-PI-2 ANSI INCITS 404-2006"); - - break; - case 0x0E00: - scsiOneValue.Add("Device complies with FC-FS-2 (no version claimed)"); - - break; - case 0x0E02: - scsiOneValue.Add("Device complies with FC-FS-2 ANSI INCITS 242-2007"); - - break; - case 0x0E03: - scsiOneValue. - Add("Device complies with FC-FS-2 ANSI INCITS 242-2007 with AM1 ANSI INCITS 242/AM1-2007"); - - break; - case 0x0E20: - scsiOneValue.Add("Device complies with FC-LS (no version claimed)"); - - break; - case 0x0E21: - scsiOneValue.Add("Device complies with FC-LS T11/1620-D revision 1.62"); - - break; - case 0x0E29: - scsiOneValue.Add("Device complies with FC-LS ANSI INCITS 433-2007"); - - break; - case 0x0E40: - scsiOneValue.Add("Device complies with FC-SP (no version claimed)"); - - break; - case 0x0E42: - scsiOneValue.Add("Device complies with FC-SP T11/1570-D revision 1.6"); - - break; - case 0x0E45: - scsiOneValue.Add("Device complies with FC-SP ANSI INCITS 426-2007"); - - break; - case 0x0E60: - scsiOneValue.Add("Device complies with FC-PI-3 (no version claimed)"); - - break; - case 0x0E62: - scsiOneValue.Add("Device complies with FC-PI-3 T11/1625-D revision 2.0"); - - break; - case 0x0E68: - scsiOneValue.Add("Device complies with FC-PI-3 T11/1625-D revision 2.1"); - - break; - case 0x0E6A: - scsiOneValue.Add("Device complies with FC-PI-3 T11/1625-D revision 4.0"); - - break; - case 0x0E6E: - scsiOneValue.Add("Device complies with FC-PI-3 ANSI INCITS 460-2011"); - - break; - case 0x0E80: - scsiOneValue.Add("Device complies with FC-PI-4 (no version claimed)"); - - break; - case 0x0E82: - scsiOneValue.Add("Device complies with FC-PI-4 T11/1647-D revision 8.0"); - - break; - case 0x0E88: - scsiOneValue.Add("Device complies with FC-PI-4 ANSI INCITS 450-2009"); - - break; - case 0x0EA0: - scsiOneValue.Add("Device complies with FC 10GFC (no version claimed)"); - - break; - case 0x0EA2: - scsiOneValue.Add("Device complies with FC 10GFC ANSI INCITS 364-2003"); - - break; - case 0x0EA3: - scsiOneValue.Add("Device complies with FC 10GFC ISO/IEC 14165-116"); - - break; - case 0x0EA5: - scsiOneValue.Add("Device complies with FC 10GFC ISO/IEC 14165-116 with AM1"); - - break; - case 0x0EA6: - scsiOneValue. - Add("Device complies with FC 10GFC ANSI INCITS 364-2003 with AM1 ANSI INCITS 364/AM1-2007"); - - break; - case 0x0EC0: - scsiOneValue.Add("Device complies with FC-SP-2 (no version claimed)"); - - break; - case 0x0EE0: - scsiOneValue.Add("Device complies with FC-FS-3 (no version claimed)"); - - break; - case 0x0EE2: - scsiOneValue.Add("Device complies with FC-FS-3 T11/1861-D revision 0.9"); - - break; - case 0x0EE7: - scsiOneValue.Add("Device complies with FC-FS-3 T11/1861-D revision 1.0"); - - break; - case 0x0EE9: - scsiOneValue.Add("Device complies with FC-FS-3 T11/1861-D revision 1.10"); - - break; - case 0x0EEB: - scsiOneValue.Add("Device complies with FC-FS-3 ANSI INCITS 470-2011"); - - break; - case 0x0F00: - scsiOneValue.Add("Device complies with FC-LS-2 (no version claimed)"); - - break; - case 0x0F03: - scsiOneValue.Add("Device complies with FC-LS-2 T11/2103-D revision 2.11"); - - break; - case 0x0F05: - scsiOneValue.Add("Device complies with FC-LS-2 T11/2103-D revision 2.21"); - - break; - case 0x0F07: - scsiOneValue.Add("Device complies with FC-LS-2 ANSI INCITS 477-2011"); - - break; - case 0x0F20: - scsiOneValue.Add("Device complies with FC-PI-5 (no version claimed)"); - - break; - case 0x0F27: - scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 2.00"); - - break; - case 0x0F28: - scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 3.00"); - - break; - case 0x0F2A: - scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 6.00"); - - break; - case 0x0F2B: - scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 6.10"); - - break; - case 0x0F2E: - scsiOneValue.Add("Device complies with FC-PI-5 ANSI INCITS 479-2011"); - - break; - case 0x0F40: - scsiOneValue.Add("Device complies with FC-PI-6 (no version claimed)"); - - break; - case 0x0F60: - scsiOneValue.Add("Device complies with FC-FS-4 (no version claimed)"); - - break; - case 0x0F80: - scsiOneValue.Add("Device complies with FC-LS-3 (no version claimed)"); - - break; - case 0x12A0: - scsiOneValue.Add("Device complies with FC-SCM (no version claimed)"); - - break; - case 0x12A3: - scsiOneValue.Add("Device complies with FC-SCM T11/1824DT revision 1.0"); - - break; - case 0x12A5: - scsiOneValue.Add("Device complies with FC-SCM T11/1824DT revision 1.1"); - - break; - case 0x12A7: - scsiOneValue.Add("Device complies with FC-SCM T11/1824DT revision 1.4"); - - break; - case 0x12AA: - scsiOneValue.Add("Device complies with FC-SCM INCITS TR-47 2012"); - - break; - case 0x12C0: - scsiOneValue.Add("Device complies with FC-DA-2 (no version claimed)"); - - break; - case 0x12C3: - scsiOneValue.Add("Device complies with FC-DA-2 T11/1870DT revision 1.04"); - - break; - case 0x12C5: - scsiOneValue.Add("Device complies with FC-DA-2 T11/1870DT revision 1.06"); - - break; - case 0x12C9: - scsiOneValue.Add("Device complies with FC-DA-2 INCITS TR-49 2012"); - - break; - case 0x12E0: - scsiOneValue.Add("Device complies with FC-DA (no version claimed)"); - - break; - case 0x12E2: - scsiOneValue.Add("Device complies with FC-DA T11/1513-DT revision 3.1"); - - break; - case 0x12E8: - scsiOneValue.Add("Device complies with FC-DA ANSI INCITS TR-36 2004"); - - break; - case 0x12E9: - scsiOneValue.Add("Device complies with FC-DA ISO/IEC 14165-341"); - - break; - case 0x1300: - scsiOneValue.Add("Device complies with FC-Tape (no version claimed)"); - - break; - case 0x1301: - scsiOneValue.Add("Device complies with FC-Tape T11/1315 revision 1.16"); - - break; - case 0x131B: - scsiOneValue.Add("Device complies with FC-Tape T11/1315 revision 1.17"); - - break; - case 0x131C: - scsiOneValue.Add("Device complies with FC-Tape ANSI INCITS TR-24 1999"); - - break; - case 0x1320: - scsiOneValue.Add("Device complies with FC-FLA (no version claimed)"); - - break; - case 0x133B: - scsiOneValue.Add("Device complies with FC-FLA T11/1235 revision 7"); - - break; - case 0x133C: - scsiOneValue.Add("Device complies with FC-FLA ANSI INCITS TR-20 1998"); - - break; - case 0x1340: - scsiOneValue.Add("Device complies with FC-PLDA (no version claimed)"); - - break; - case 0x135B: - scsiOneValue.Add("Device complies with FC-PLDA T11/1162 revision 2.1"); - - break; - case 0x135C: - scsiOneValue.Add("Device complies with FC-PLDA ANSI INCITS TR-19 1998"); - - break; - case 0x1360: - scsiOneValue.Add("Device complies with SSA-PH2 (no version claimed)"); - - break; - case 0x137B: - scsiOneValue.Add("Device complies with SSA-PH2 T10.1/1145-D revision 09c"); - - break; - case 0x137C: - scsiOneValue.Add("Device complies with SSA-PH2 ANSI INCITS 293-1996"); - - break; - case 0x1380: - scsiOneValue.Add("Device complies with SSA-PH3 (no version claimed)"); - - break; - case 0x139B: - scsiOneValue.Add("Device complies with SSA-PH3 T10.1/1146-D revision 05b"); - - break; - case 0x139C: - scsiOneValue.Add("Device complies with SSA-PH3 ANSI INCITS 307-1998"); - - break; - case 0x14A0: - scsiOneValue.Add("Device complies with IEEE 1394 (no version claimed)"); - - break; - case 0x14BD: - scsiOneValue.Add("Device complies with ANSI IEEE 1394-1995"); - - break; - case 0x14C0: - scsiOneValue.Add("Device complies with IEEE 1394a (no version claimed)"); - - break; - case 0x14E0: - scsiOneValue.Add("Device complies with IEEE 1394b (no version claimed)"); - - break; - case 0x15E0: - scsiOneValue.Add("Device complies with ATA/ATAPI-6 (no version claimed)"); - - break; - case 0x15FD: - scsiOneValue.Add("Device complies with ATA/ATAPI-6 ANSI INCITS 361-2002"); - - break; - case 0x1600: - scsiOneValue.Add("Device complies with ATA/ATAPI-7 (no version claimed)"); - - break; - case 0x1602: - scsiOneValue.Add("Device complies with ATA/ATAPI-7 T13/1532-D revision 3"); - - break; - case 0x161C: - scsiOneValue.Add("Device complies with ATA/ATAPI-7 ANSI INCITS 397-2005"); - - break; - case 0x161E: - scsiOneValue.Add("Device complies with ATA/ATAPI-7 ISO/IEC 24739"); - - break; - case 0x1620: - scsiOneValue.Add("Device complies with ATA/ATAPI-8 ATA8-AAM (no version claimed)"); - - break; - case 0x1621: - scsiOneValue. - Add("Device complies with ATA/ATAPI-8 ATA8-APT Parallel Transport (no version claimed)"); - - break; - case 0x1622: - scsiOneValue. - Add("Device complies with ATA/ATAPI-8 ATA8-AST Serial Transport (no version claimed)"); - - break; - case 0x1623: - scsiOneValue. - Add("Device complies with ATA/ATAPI-8 ATA8-ACS ATA/ATAPI Command Set (no version claimed)"); - - break; - case 0x1628: - scsiOneValue.Add("Device complies with ATA/ATAPI-8 ATA8-AAM ANSI INCITS 451-2008"); - - break; - case 0x162A: - scsiOneValue. - Add("Device complies with ATA/ATAPI-8 ATA8-ACS ANSI INCITS 452-2009 w/ Amendment 1"); - - break; - case 0x1728: - scsiOneValue.Add("Device complies with Universal Serial Bus Specification, Revision 1.1"); - - break; - case 0x1729: - scsiOneValue.Add("Device complies with Universal Serial Bus Specification, Revision 2.0"); - - break; - case 0x1730: - scsiOneValue. - Add("Device complies with USB Mass Storage Class Bulk-Only Transport, Revision 1.0"); - - break; - case 0x1740: - scsiOneValue.Add("Device complies with UAS (no version claimed)"); - - break; - case 0x1743: - scsiOneValue.Add("Device complies with UAS T10/2095-D revision 02"); - - break; - case 0x1747: - scsiOneValue.Add("Device complies with UAS T10/2095-D revision 04"); - - break; - case 0x1748: - scsiOneValue.Add("Device complies with UAS ANSI INCITS 471-2010"); - - break; - case 0x1749: - scsiOneValue.Add("Device complies with UAS ISO/IEC 14776-251:2014"); - - break; - case 0x1761: - scsiOneValue.Add("Device complies with ACS-2 (no version claimed)"); - - break; - case 0x1762: - scsiOneValue.Add("Device complies with ACS-2 ANSI INCITS 482-2013"); - - break; - case 0x1765: - scsiOneValue.Add("Device complies with ACS-3 (no version claimed)"); - - break; - case 0x1780: - scsiOneValue.Add("Device complies with UAS-2 (no version claimed)"); - - break; - case 0x1EA0: - scsiOneValue.Add("Device complies with SAT (no version claimed)"); - - break; - case 0x1EA7: - scsiOneValue.Add("Device complies with SAT T10/1711-D revision 8"); - - break; - case 0x1EAB: - scsiOneValue.Add("Device complies with SAT T10/1711-D revision 9"); - - break; - case 0x1EAD: - scsiOneValue.Add("Device complies with SAT ANSI INCITS 431-2007"); - - break; - case 0x1EC0: - scsiOneValue.Add("Device complies with SAT-2 (no version claimed)"); - - break; - case 0x1EC4: - scsiOneValue.Add("Device complies with SAT-2 T10/1826-D revision 06"); - - break; - case 0x1EC8: - scsiOneValue.Add("Device complies with SAT-2 T10/1826-D revision 09"); - - break; - case 0x1ECA: - scsiOneValue.Add("Device complies with SAT-2 ANSI INCITS 465-2010"); - - break; - case 0x1EE0: - scsiOneValue.Add("Device complies with SAT-3 (no version claimed)"); - - break; - case 0x1EE2: - scsiOneValue.Add("Device complies with SAT-3 T10/BSR INCITS 517 revision 4"); - - break; - case 0x1EE4: - scsiOneValue.Add("Device complies with SAT-3 T10/BSR INCITS 517 revision 7"); - - break; - case 0x1EE8: - scsiOneValue.Add("Device complies with SAT-3 ANSI INCITS 517-2015"); - - break; - case 0x1F00: - scsiOneValue.Add("Device complies with SAT-4 (no version claimed)"); - - break; - case 0x20A0: - scsiOneValue.Add("Device complies with SPL (no version claimed)"); - - break; - case 0x20A3: - scsiOneValue.Add("Device complies with SPL T10/2124-D revision 6a"); - - break; - case 0x20A5: - scsiOneValue.Add("Device complies with SPL T10/2124-D revision 7"); - - break; - case 0x20A7: - scsiOneValue.Add("Device complies with SPL ANSI INCITS 476-2011"); - - break; - case 0x20A8: - scsiOneValue.Add("Device complies with SPL ANSI INCITS 476-2011 + SPL AM1 INCITS 476/AM1 2012"); - - break; - case 0x20AA: - scsiOneValue.Add("Device complies with SPL ISO/IEC 14776-261:2012"); - - break; - case 0x20C0: - scsiOneValue.Add("Device complies with SPL-2 (no version claimed)"); - - break; - case 0x20C2: - scsiOneValue.Add("Device complies with SPL-2 T10/BSR INCITS 505 revision 4"); - - break; - case 0x20C4: - scsiOneValue.Add("Device complies with SPL-2 T10/BSR INCITS 505 revision 5"); - - break; - case 0x20C8: - scsiOneValue.Add("Device complies with SPL-2 ANSI INCITS 505-2013"); - - break; - case 0x20E0: - scsiOneValue.Add("Device complies with SPL-3 (no version claimed)"); - - break; - case 0x20E4: - scsiOneValue.Add("Device complies with SPL-3 T10/BSR INCITS 492 revision 6"); - - break; - case 0x20E6: - scsiOneValue.Add("Device complies with SPL-3 T10/BSR INCITS 492 revision 7"); - - break; - case 0x20E8: - scsiOneValue.Add("Device complies with SPL-3 ANSI INCITS 492-2015"); - - break; - case 0x2100: - scsiOneValue.Add("Device complies with SPL-4 (no version claimed)"); - - break; - case 0x21E0: - scsiOneValue.Add("Device complies with SOP (no version claimed)"); - - break; - case 0x21E4: - scsiOneValue.Add("Device complies with SOP T10/BSR INCITS 489 revision 4"); - - break; - case 0x21E6: - scsiOneValue.Add("Device complies with SOP T10/BSR INCITS 489 revision 5"); - - break; - case 0x21E8: - scsiOneValue.Add("Device complies with SOP ANSI INCITS 489-2014"); - - break; - case 0x2200: - scsiOneValue.Add("Device complies with PQI (no version claimed)"); - - break; - case 0x2204: - scsiOneValue.Add("Device complies with PQI T10/BSR INCITS 490 revision 6"); - - break; - case 0x2206: - scsiOneValue.Add("Device complies with PQI T10/BSR INCITS 490 revision 7"); - - break; - case 0x2208: - scsiOneValue.Add("Device complies with PQI ANSI INCITS 490-2014"); - - break; - case 0x2220: - scsiOneValue.Add("Device complies with SOP-2 (no version claimed)"); - - break; - case 0x2240: - scsiOneValue.Add("Device complies with PQI-2 (no version claimed)"); - - break; - case 0xFFC0: - scsiOneValue.Add("Device complies with IEEE 1667 (no version claimed)"); - - break; - case 0xFFC1: - scsiOneValue.Add("Device complies with IEEE 1667-2006"); - - break; - case 0xFFC2: - scsiOneValue.Add("Device complies with IEEE 1667-2009"); - - break; - default: - scsiOneValue.Add($"Device complies with unknown standard code 0x{versionDescriptor:X4}"); - - break; - } + List scsiOneValue = new(); + if(!inquiryNullable.HasValue) return scsiOneValue; + + Inquiry inquiry = inquiryNullable.Value; + + switch((PeripheralQualifiers)inquiry.PeripheralQualifier) + { + case PeripheralQualifiers.Supported: + scsiOneValue.Add("Device is connected and supported."); + + break; + case PeripheralQualifiers.Unconnected: + scsiOneValue.Add("Device is supported but not connected."); + + break; + case PeripheralQualifiers.Reserved: + scsiOneValue.Add("Reserved value set in Peripheral Qualifier field."); + + break; + case PeripheralQualifiers.Unsupported: + scsiOneValue.Add("Device is connected but unsupported."); + + break; + default: + scsiOneValue.Add($"Vendor value {inquiry.PeripheralQualifier} set in Peripheral Qualifier field."); + + break; } + + switch((PeripheralDeviceTypes)inquiry.PeripheralDeviceType) + { + case PeripheralDeviceTypes.DirectAccess: //0x00, + scsiOneValue.Add("Direct-access device"); + + break; + case PeripheralDeviceTypes.SequentialAccess: //0x01, + scsiOneValue.Add("Sequential-access device"); + + break; + case PeripheralDeviceTypes.PrinterDevice: //0x02, + scsiOneValue.Add("Printer device"); + + break; + case PeripheralDeviceTypes.ProcessorDevice: //0x03, + scsiOneValue.Add("Processor device"); + + break; + case PeripheralDeviceTypes.WriteOnceDevice: //0x04, + scsiOneValue.Add("Write-once device"); + + break; + case PeripheralDeviceTypes.MultiMediaDevice: //0x05, + scsiOneValue.Add("CD-ROM/DVD/etc device"); + + break; + case PeripheralDeviceTypes.ScannerDevice: //0x06, + scsiOneValue.Add("Scanner device"); + + break; + case PeripheralDeviceTypes.OpticalDevice: //0x07, + scsiOneValue.Add("Optical memory device"); + + break; + case PeripheralDeviceTypes.MediumChangerDevice: //0x08, + scsiOneValue.Add("Medium change device"); + + break; + case PeripheralDeviceTypes.CommsDevice: //0x09, + scsiOneValue.Add("Communications device"); + + break; + case PeripheralDeviceTypes.PrePressDevice1: //0x0A, + scsiOneValue.Add("Graphics arts pre-press device (defined in ASC IT8)"); + + break; + case PeripheralDeviceTypes.PrePressDevice2: //0x0B, + scsiOneValue.Add("Graphics arts pre-press device (defined in ASC IT8)"); + + break; + case PeripheralDeviceTypes.ArrayControllerDevice: //0x0C, + scsiOneValue.Add("Array controller device"); + + break; + case PeripheralDeviceTypes.EnclosureServiceDevice: //0x0D, + scsiOneValue.Add("Enclosure services device"); + + break; + case PeripheralDeviceTypes.SimplifiedDevice: //0x0E, + scsiOneValue.Add("Simplified direct-access device"); + + break; + case PeripheralDeviceTypes.OCRWDevice: //0x0F, + scsiOneValue.Add("Optical card reader/writer device"); + + break; + case PeripheralDeviceTypes.BridgingExpander: //0x10, + scsiOneValue.Add("Bridging Expanders"); + + break; + case PeripheralDeviceTypes.ObjectDevice: //0x11, + scsiOneValue.Add("Object-based Storage Device"); + + break; + case PeripheralDeviceTypes.ADCDevice: //0x12, + scsiOneValue.Add("Automation/Drive Interface"); + + break; + case PeripheralDeviceTypes.SCSISecurityManagerDevice: //0x13, + scsiOneValue.Add("Security Manager Device"); + + break; + case PeripheralDeviceTypes.SCSIZonedBlockDevice: //0x14 + scsiOneValue.Add("Host managed zoned block device"); + + break; + case PeripheralDeviceTypes.WellKnownDevice: //0x1E, + scsiOneValue.Add("Well known logical unit"); + + break; + case PeripheralDeviceTypes.UnknownDevice: //0x1F + scsiOneValue.Add("Unknown or no device type"); + + break; + default: + scsiOneValue.Add($"Unknown device type field value 0x{inquiry.PeripheralDeviceType:X2}"); + + break; + } + + switch((ANSIVersions)inquiry.ANSIVersion) + { + case ANSIVersions.ANSINoVersion: + scsiOneValue.Add("Device does not claim to comply with any SCSI ANSI standard"); + + break; + case ANSIVersions.ANSI1986Version: + scsiOneValue.Add("Device claims to comply with ANSI X3.131:1986 (SCSI-1)"); + + break; + case ANSIVersions.ANSI1994Version: + scsiOneValue.Add("Device claims to comply with ANSI X3.131:1994 (SCSI-2)"); + + break; + case ANSIVersions.ANSI1997Version: + scsiOneValue.Add("Device claims to comply with ANSI X3.301:1997 (SPC-1)"); + + break; + case ANSIVersions.ANSI2001Version: + scsiOneValue.Add("Device claims to comply with ANSI X3.351:2001 (SPC-2)"); + + break; + case ANSIVersions.ANSI2005Version: + scsiOneValue.Add("Device claims to comply with ANSI X3.408:2005 (SPC-3)"); + + break; + case ANSIVersions.ANSI2008Version: + scsiOneValue.Add("Device claims to comply with ANSI X3.408:2005 (SPC-4)"); + + break; + default: + scsiOneValue. + Add($"Device claims to comply with unknown SCSI ANSI standard value 0x{inquiry.ANSIVersion:X2})"); + + break; + } + + switch((ECMAVersions)inquiry.ECMAVersion) + { + case ECMAVersions.ECMANoVersion: + scsiOneValue.Add("Device does not claim to comply with any SCSI ECMA standard"); + + break; + case ECMAVersions.ECMA111: + scsiOneValue.Add("Device claims to comply ECMA-111: Small Computer System Interface SCSI"); + + break; + default: + scsiOneValue. + Add($"Device claims to comply with unknown SCSI ECMA standard value 0x{inquiry.ECMAVersion:X2})"); + + break; + } + + switch((ISOVersions)inquiry.ISOVersion) + { + case ISOVersions.ISONoVersion: + scsiOneValue.Add("Device does not claim to comply with any SCSI ISO/IEC standard"); + + break; + case ISOVersions.ISO1995Version: + scsiOneValue.Add("Device claims to comply with ISO/IEC 9316:1995"); + + break; + default: + scsiOneValue. + Add($"Device claims to comply with unknown SCSI ISO/IEC standard value 0x{inquiry.ISOVersion:X2})"); + + break; + } + + if(inquiry.RMB) + scsiOneValue.Add("Device is removable"); + + if(inquiry.AERC) + scsiOneValue.Add("Device supports Asynchronous Event Reporting Capability"); + + if(inquiry.TrmTsk) + scsiOneValue.Add("Device supports TERMINATE TASK command"); + + if(inquiry.NormACA) + scsiOneValue.Add("Device supports setting Normal ACA"); + + if(inquiry.HiSup) + scsiOneValue.Add("Device supports LUN hierarchical addressing"); + + if(inquiry.SCCS) + scsiOneValue.Add("Device contains an embedded storage array controller"); + + if(inquiry.ACC) + scsiOneValue.Add("Device contains an Access Control Coordinator"); + + if(inquiry.ThreePC) + scsiOneValue.Add("Device supports third-party copy commands"); + + if(inquiry.Protect) + scsiOneValue.Add("Device supports protection information"); + + if(inquiry.BQue) + scsiOneValue.Add("Device supports basic queueing"); + + if(inquiry.EncServ) + scsiOneValue.Add("Device contains an embedded enclosure services component"); + + if(inquiry.MultiP) + scsiOneValue.Add("Multi-port device"); + + if(inquiry.MChngr) + scsiOneValue.Add("Device contains or is attached to a medium changer"); + + if(inquiry.ACKREQQ) + scsiOneValue.Add("Device supports request and acknowledge handshakes"); + + if(inquiry.Addr32) + scsiOneValue.Add("Device supports 32-bit wide SCSI addresses"); + + if(inquiry.Addr16) + scsiOneValue.Add("Device supports 16-bit wide SCSI addresses"); + + if(inquiry.RelAddr) + scsiOneValue.Add("Device supports relative addressing"); + + if(inquiry.WBus32) + scsiOneValue.Add("Device supports 32-bit wide data transfers"); + + if(inquiry.WBus16) + scsiOneValue.Add("Device supports 16-bit wide data transfers"); + + if(inquiry.Sync) + scsiOneValue.Add("Device supports synchronous data transfer"); + + if(inquiry.Linked) + scsiOneValue.Add("Device supports linked commands"); + + if(inquiry.TranDis) + scsiOneValue.Add("Device supports CONTINUE TASK and TARGET TRANSFER DISABLE commands"); + + if(inquiry.QAS) + scsiOneValue.Add("Device supports Quick Arbitration and Selection"); + + if(inquiry.CmdQue) + scsiOneValue.Add("Device supports TCQ queue"); + + if(inquiry.IUS) + scsiOneValue.Add("Device supports information unit transfers"); + + if(inquiry.SftRe) + scsiOneValue.Add("Device implements RESET as a soft reset"); + + switch((TGPSValues)inquiry.TPGS) + { + case TGPSValues.NotSupported: + scsiOneValue.Add("Device does not support asymmetrical access"); + + break; + case TGPSValues.OnlyImplicit: + scsiOneValue.Add("Device only supports implicit asymmetrical access"); + + break; + case TGPSValues.OnlyExplicit: + scsiOneValue.Add("Device only supports explicit asymmetrical access"); + + break; + case TGPSValues.Both: + scsiOneValue.Add("Device supports implicit and explicit asymmetrical access"); + + break; + default: + scsiOneValue.Add($"Unknown value in TPGS field 0x{inquiry.TPGS:X2}"); + + break; + } + + switch((SPIClocking)inquiry.Clocking) + { + case SPIClocking.ST: + scsiOneValue.Add("Device supports only ST clocking"); + + break; + case SPIClocking.DT: + scsiOneValue.Add("Device supports only DT clocking"); + + break; + case SPIClocking.Reserved: + scsiOneValue.Add("Reserved value 0x02 found in SPI clocking field"); + + break; + case SPIClocking.STandDT: + scsiOneValue.Add("Device supports ST and DT clocking"); + + break; + default: + scsiOneValue.Add($"Unknown value in SPI clocking field 0x{inquiry.Clocking:X2}"); + + break; + } + + if(inquiry.VersionDescriptors == null) + return scsiOneValue; + + foreach(ushort versionDescriptor in inquiry.VersionDescriptors) + switch(versionDescriptor) + { + case 0xFFFF: + case 0x0000: break; + case 0x0020: + scsiOneValue.Add("Device complies with SAM (no version claimed)"); + + break; + case 0x003B: + scsiOneValue.Add("Device complies with SAM T10/0994-D revision 18"); + + break; + case 0x003C: + scsiOneValue.Add("Device complies with SAM ANSI INCITS 270-1996"); + + break; + case 0x0040: + scsiOneValue.Add("Device complies with SAM-2 (no version claimed)"); + + break; + case 0x0054: + scsiOneValue.Add("Device complies with SAM-2 T10/1157-D revision 23"); + + break; + case 0x0055: + scsiOneValue.Add("Device complies with SAM-2 T10/1157-D revision 24"); + + break; + case 0x005C: + scsiOneValue.Add("Device complies with SAM-2 ANSI INCITS 366-2003"); + + break; + case 0x005E: + scsiOneValue.Add("Device complies with SAM-2 ISO/IEC 14776-412"); + + break; + case 0x0060: + scsiOneValue.Add("Device complies with SAM-3 (no version claimed)"); + + break; + case 0x0062: + scsiOneValue.Add("Device complies with SAM-3 T10/1561-D revision 7"); + + break; + case 0x0075: + scsiOneValue.Add("Device complies with SAM-3 T10/1561-D revision 13"); + + break; + case 0x0076: + scsiOneValue.Add("Device complies with SAM-3 T10/1561-D revision 14"); + + break; + case 0x0077: + scsiOneValue.Add("Device complies with SAM-3 ANSI INCITS 402-2005"); + + break; + case 0x0080: + scsiOneValue.Add("Device complies with SAM-4 (no version claimed)"); + + break; + case 0x0087: + scsiOneValue.Add("Device complies with SAM-4 T10/1683-D revision 13"); + + break; + case 0x008B: + scsiOneValue.Add("Device complies with SAM-4 T10/1683-D revision 14"); + + break; + case 0x0090: + scsiOneValue.Add("Device complies with SAM-4 ANSI INCITS 447-2008"); + + break; + case 0x0092: + scsiOneValue.Add("Device complies with SAM-4 ISO/IEC 14776-414"); + + break; + case 0x00A0: + scsiOneValue.Add("Device complies with SAM-5 (no version claimed)"); + + break; + case 0x00A2: + scsiOneValue.Add("Device complies with SAM-5 T10/2104-D revision 4"); + + break; + case 0x00A4: + scsiOneValue.Add("Device complies with SAM-5 T10/2104-D revision 20"); + + break; + case 0x00A6: + scsiOneValue.Add("Device complies with SAM-5 T10/2104-D revision 21"); + + break; + case 0x00C0: + scsiOneValue.Add("Device complies with SAM-6 (no version claimed)"); + + break; + case 0x0120: + scsiOneValue.Add("Device complies with SPC (no version claimed)"); + + break; + case 0x013B: + scsiOneValue.Add("Device complies with SPC T10/0995-D revision 11a"); + + break; + case 0x013C: + scsiOneValue.Add("Device complies with SPC ANSI INCITS 301-1997"); + + break; + case 0x0140: + scsiOneValue.Add("Device complies with MMC (no version claimed)"); + + break; + case 0x015B: + scsiOneValue.Add("Device complies with MMC T10/1048-D revision 10a"); + + break; + case 0x015C: + scsiOneValue.Add("Device complies with MMC ANSI INCITS 304-1997"); + + break; + case 0x0160: + scsiOneValue.Add("Device complies with SCC (no version claimed)"); + + break; + case 0x017B: + scsiOneValue.Add("Device complies with SCC T10/1047-D revision 06c"); + + break; + case 0x017C: + scsiOneValue.Add("Device complies with SCC ANSI INCITS 276-1997"); + + break; + case 0x0180: + scsiOneValue.Add("Device complies with SBC (no version claimed)"); + + break; + case 0x019B: + scsiOneValue.Add("Device complies with SBC T10/0996-D revision 08c"); + + break; + case 0x019C: + scsiOneValue.Add("Device complies with SBC ANSI INCITS 306-1998"); + + break; + case 0x01A0: + scsiOneValue.Add("Device complies with SMC (no version claimed)"); + + break; + case 0x01BB: + scsiOneValue.Add("Device complies with SMC T10/0999-D revision 10a"); + + break; + case 0x01BC: + scsiOneValue.Add("Device complies with SMC ANSI INCITS 314-1998"); + + break; + case 0x01BE: + scsiOneValue.Add("Device complies with SMC ISO/IEC 14776-351"); + + break; + case 0x01C0: + scsiOneValue.Add("Device complies with SES (no version claimed)"); + + break; + case 0x01DB: + scsiOneValue.Add("Device complies with SES T10/1212-D revision 08b"); + + break; + case 0x01DC: + scsiOneValue.Add("Device complies with SES ANSI INCITS 305-1998"); + + break; + case 0x01DD: + scsiOneValue. + Add("Device complies with SES T10/1212 revision 08b w/ Amendment ANSI INCITS.305/AM1-2000"); + + break; + case 0x01DE: + scsiOneValue. + Add("Device complies with SES ANSI INCITS 305-1998 w/ Amendment ANSI INCITS.305/AM1-2000"); + + break; + case 0x01E0: + scsiOneValue.Add("Device complies with SCC-2 (no version claimed)"); + + break; + case 0x01FB: + scsiOneValue.Add("Device complies with SCC-2 T10/1125-D revision 04"); + + break; + case 0x01FC: + scsiOneValue.Add("Device complies with SCC-2 ANSI INCITS 318-1998"); + + break; + case 0x0200: + scsiOneValue.Add("Device complies with SSC (no version claimed)"); + + break; + case 0x0201: + scsiOneValue.Add("Device complies with SSC T10/0997-D revision 17"); + + break; + case 0x0207: + scsiOneValue.Add("Device complies with SSC T10/0997-D revision 22"); + + break; + case 0x021C: + scsiOneValue.Add("Device complies with SSC ANSI INCITS 335-2000"); + + break; + case 0x0220: + scsiOneValue.Add("Device complies with RBC (no version claimed)"); + + break; + case 0x0238: + scsiOneValue.Add("Device complies with RBC T10/1240-D revision 10a"); + + break; + case 0x023C: + scsiOneValue.Add("Device complies with RBC ANSI INCITS 330-2000"); + + break; + case 0x0240: + scsiOneValue.Add("Device complies with MMC-2 (no version claimed)"); + + break; + case 0x0255: + scsiOneValue.Add("Device complies with MMC-2 T10/1228-D revision 11"); + + break; + case 0x025B: + scsiOneValue.Add("Device complies with MMC-2 T10/1228-D revision 11a"); + + break; + case 0x025C: + scsiOneValue.Add("Device complies with MMC-2 ANSI INCITS 333-2000"); + + break; + case 0x0260: + scsiOneValue.Add("Device complies with SPC-2 (no version claimed)"); + + break; + case 0x0267: + scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 12"); + + break; + case 0x0269: + scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 18"); + + break; + case 0x0275: + scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 19"); + + break; + case 0x0276: + scsiOneValue.Add("Device complies with SPC-2 T10/1236-D revision 20"); + + break; + case 0x0277: + scsiOneValue.Add("Device complies with SPC-2 ANSI INCITS 351-2001"); + + break; + case 0x0278: + scsiOneValue.Add("Device complies with SPC-2 ISO/IEC 14776-452"); + + break; + case 0x0280: + scsiOneValue.Add("Device complies with OCRW (no version claimed)"); + + break; + case 0x029E: + scsiOneValue.Add("Device complies with OCRW ISO/IEC 14776-381"); + + break; + case 0x02A0: + scsiOneValue.Add("Device complies with MMC-3 (no version claimed)"); + + break; + case 0x02B5: + scsiOneValue.Add("Device complies with MMC-3 T10/1363-D revision 9"); + + break; + case 0x02B6: + scsiOneValue.Add("Device complies with MMC-3 T10/1363-D revision 10g"); + + break; + case 0x02B8: + scsiOneValue.Add("Device complies with MMC-3 ANSI INCITS 360-2002"); + + break; + case 0x02E0: + scsiOneValue.Add("Device complies with SMC-2 (no version claimed)"); + + break; + case 0x02F5: + scsiOneValue.Add("Device complies with SMC-2 T10/1383-D revision 5"); + + break; + case 0x02FC: + scsiOneValue.Add("Device complies with SMC-2 T10/1383-D revision 6"); + + break; + case 0x02FD: + scsiOneValue.Add("Device complies with SMC-2 T10/1383-D revision 7"); + + break; + case 0x02FE: + scsiOneValue.Add("Device complies with SMC-2 ANSI INCITS 382-2004"); + + break; + case 0x0300: + scsiOneValue.Add("Device complies with SPC-3 (no version claimed)"); + + break; + case 0x0301: + scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 7"); + + break; + case 0x0307: + scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 21"); + + break; + case 0x030F: + scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 22"); + + break; + case 0x0312: + scsiOneValue.Add("Device complies with SPC-3 T10/1416-D revision 23"); + + break; + case 0x0314: + scsiOneValue.Add("Device complies with SPC-3 ANSI INCITS 408-2005"); + + break; + case 0x0316: + scsiOneValue.Add("Device complies with SPC-3 ISO/IEC 14776-453"); + + break; + case 0x0320: + scsiOneValue.Add("Device complies with SBC-2 (no version claimed)"); + + break; + case 0x0322: + scsiOneValue.Add("Device complies with SBC-2 T10/1417-D revision 5a"); + + break; + case 0x0324: + scsiOneValue.Add("Device complies with SBC-2 T10/1417-D revision 15"); + + break; + case 0x033B: + scsiOneValue.Add("Device complies with SBC-2 T10/1417-D revision 16"); + + break; + case 0x033D: + scsiOneValue.Add("Device complies with SBC-2 ANSI INCITS 405-2005"); + + break; + case 0x033E: + scsiOneValue.Add("Device complies with SBC-2 ISO/IEC 14776-322"); + + break; + case 0x0340: + scsiOneValue.Add("Device complies with OSD (no version claimed)"); + + break; + case 0x0341: + scsiOneValue.Add("Device complies with OSD T10/1355-D revision 0"); + + break; + case 0x0342: + scsiOneValue.Add("Device complies with OSD T10/1355-D revision 7a"); + + break; + case 0x0343: + scsiOneValue.Add("Device complies with OSD T10/1355-D revision 8"); + + break; + case 0x0344: + scsiOneValue.Add("Device complies with OSD T10/1355-D revision 9"); + + break; + case 0x0355: + scsiOneValue.Add("Device complies with OSD T10/1355-D revision 10"); + + break; + case 0x0356: + scsiOneValue.Add("Device complies with OSD ANSI INCITS 400-2004"); + + break; + case 0x0360: + scsiOneValue.Add("Device complies with SSC-2 (no version claimed)"); + + break; + case 0x0374: + scsiOneValue.Add("Device complies with SSC-2 T10/1434-D revision 7"); + + break; + case 0x0375: + scsiOneValue.Add("Device complies with SSC-2 T10/1434-D revision 9"); + + break; + case 0x037D: + scsiOneValue.Add("Device complies with SSC-2 ANSI INCITS 380-2003"); + + break; + case 0x0380: + scsiOneValue.Add("Device complies with BCC (no version claimed)"); + + break; + case 0x03A0: + scsiOneValue.Add("Device complies with MMC-4 (no version claimed)"); + + break; + case 0x03B0: + scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 5"); + + break; + case 0x03B1: + scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 5a"); + + break; + case 0x03BD: + scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 3"); + + break; + case 0x03BE: + scsiOneValue.Add("Device complies with MMC-4 T10/1545-D revision 3d"); + + break; + case 0x03BF: + scsiOneValue.Add("Device complies with MMC-4 ANSI INCITS 401-2005"); + + break; + case 0x03C0: + scsiOneValue.Add("Device complies with ADC (no version claimed)"); + + break; + case 0x03D5: + scsiOneValue.Add("Device complies with ADC T10/1558-D revision 6"); + + break; + case 0x03D6: + scsiOneValue.Add("Device complies with ADC T10/1558-D revision 7"); + + break; + case 0x03D7: + scsiOneValue.Add("Device complies with ADC ANSI INCITS 403-2005"); + + break; + case 0x03E0: + scsiOneValue.Add("Device complies with SES-2 (no version claimed)"); + + break; + case 0x03E1: + scsiOneValue.Add("Device complies with SES-2 T10/1559-D revision 16"); + + break; + case 0x03E7: + scsiOneValue.Add("Device complies with SES-2 T10/1559-D revision 19"); + + break; + case 0x03EB: + scsiOneValue.Add("Device complies with SES-2 T10/1559-D revision 20"); + + break; + case 0x03F0: + scsiOneValue.Add("Device complies with SES-2 ANSI INCITS 448-2008"); + + break; + case 0x03F2: + scsiOneValue.Add("Device complies with SES-2 ISO/IEC 14776-372"); + + break; + case 0x0400: + scsiOneValue.Add("Device complies with SSC-3 (no version claimed)"); + + break; + case 0x0403: + scsiOneValue.Add("Device complies with SSC-3 T10/1611-D revision 04a"); + + break; + case 0x0407: + scsiOneValue.Add("Device complies with SSC-3 T10/1611-D revision 05"); + + break; + case 0x0409: + scsiOneValue.Add("Device complies with SSC-3 ANSI INCITS 467-2011"); + + break; + case 0x040B: + scsiOneValue.Add("Device complies with SSC-3 ISO/IEC 14776-333:2013"); + + break; + case 0x0420: + scsiOneValue.Add("Device complies with MMC-5 (no version claimed)"); + + break; + case 0x042F: + scsiOneValue.Add("Device complies with MMC-5 T10/1675-D revision 03"); + + break; + case 0x0431: + scsiOneValue.Add("Device complies with MMC-5 T10/1675-D revision 03b"); + + break; + case 0x0432: + scsiOneValue.Add("Device complies with MMC-5 T10/1675-D revision 04"); + + break; + case 0x0434: + scsiOneValue.Add("Device complies with MMC-5 ANSI INCITS 430-2007"); + + break; + case 0x0440: + scsiOneValue.Add("Device complies with OSD-2 (no version claimed)"); + + break; + case 0x0444: + scsiOneValue.Add("Device complies with OSD-2 T10/1729-D revision 4"); + + break; + case 0x0446: + scsiOneValue.Add("Device complies with OSD-2 T10/1729-D revision 5"); + + break; + case 0x0448: + scsiOneValue.Add("Device complies with OSD-2 ANSI INCITS 458-2011"); + + break; + case 0x0460: + scsiOneValue.Add("Device complies with SPC-4 (no version claimed)"); + + break; + case 0x0461: + scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 16"); + + break; + case 0x0462: + scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 18"); + + break; + case 0x0463: + scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 23"); + + break; + case 0x0466: + scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 36"); + + break; + case 0x0468: + scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 37"); + + break; + case 0x0469: + scsiOneValue.Add("Device complies with SPC-4 T10/BSR INCITS 513 revision 37a"); + + break; + case 0x046C: + scsiOneValue.Add("Device complies with SPC-4 ANSI INCITS 513-2015"); + + break; + case 0x0480: + scsiOneValue.Add("Device complies with SMC-3 (no version claimed)"); + + break; + case 0x0482: + scsiOneValue.Add("Device complies with SMC-3 T10/1730-D revision 15"); + + break; + case 0x0484: + scsiOneValue.Add("Device complies with SMC-3 T10/1730-D revision 16"); + + break; + case 0x0486: + scsiOneValue.Add("Device complies with SMC-3 ANSI INCITS 484-2012"); + + break; + case 0x04A0: + scsiOneValue.Add("Device complies with ADC-2 (no version claimed)"); + + break; + case 0x04A7: + scsiOneValue.Add("Device complies with ADC-2 T10/1741-D revision 7"); + + break; + case 0x04AA: + scsiOneValue.Add("Device complies with ADC-2 T10/1741-D revision 8"); + + break; + case 0x04AC: + scsiOneValue.Add("Device complies with ADC-2 ANSI INCITS 441-2008"); + + break; + case 0x04C0: + scsiOneValue.Add("Device complies with SBC-3 (no version claimed)"); + + break; + case 0x04C3: + scsiOneValue.Add("Device complies with SBC-3 T10/BSR INCITS 514 revision 35"); + + break; + case 0x04C5: + scsiOneValue.Add("Device complies with SBC-3 T10/BSR INCITS 514 revision 36"); + + break; + case 0x04C8: + scsiOneValue.Add("Device complies with SBC-3 ANSI INCITS 514-2014"); + + break; + case 0x04E0: + scsiOneValue.Add("Device complies with MMC-6 (no version claimed)"); + + break; + case 0x04E3: + scsiOneValue.Add("Device complies with MMC-6 T10/1836-D revision 02b"); + + break; + case 0x04E5: + scsiOneValue.Add("Device complies with MMC-6 T10/1836-D revision 02g"); + + break; + case 0x04E6: + scsiOneValue.Add("Device complies with MMC-6 ANSI INCITS 468-2010"); + + break; + case 0x04E7: + scsiOneValue. + Add("Device complies with MMC-6 ANSI INCITS 468-2010 + MMC-6/AM1 ANSI INCITS 468-2010/AM 1"); + + break; + case 0x0500: + scsiOneValue.Add("Device complies with ADC-3 (no version claimed)"); + + break; + case 0x0502: + scsiOneValue.Add("Device complies with ADC-3 T10/1895-D revision 04"); + + break; + case 0x0504: + scsiOneValue.Add("Device complies with ADC-3 T10/1895-D revision 05"); + + break; + case 0x0506: + scsiOneValue.Add("Device complies with ADC-3 T10/1895-D revision 05a"); + + break; + case 0x050A: + scsiOneValue.Add("Device complies with ADC-3 ANSI INCITS 497-2012"); + + break; + case 0x0520: + scsiOneValue.Add("Device complies with SSC-4 (no version claimed)"); + + break; + case 0x0523: + scsiOneValue.Add("Device complies with SSC-4 T10/BSR INCITS 516 revision 2"); + + break; + case 0x0525: + scsiOneValue.Add("Device complies with SSC-4 T10/BSR INCITS 516 revision 3"); + + break; + case 0x0527: + scsiOneValue.Add("Device complies with SSC-4 ANSI INCITS 516-2013"); + + break; + case 0x0560: + scsiOneValue.Add("Device complies with OSD-3 (no version claimed)"); + + break; + case 0x0580: + scsiOneValue.Add("Device complies with SES-3 (no version claimed)"); + + break; + case 0x05A0: + scsiOneValue.Add("Device complies with SSC-5 (no version claimed)"); + + break; + case 0x05C0: + scsiOneValue.Add("Device complies with SPC-5 (no version claimed)"); + + break; + case 0x05E0: + scsiOneValue.Add("Device complies with SFSC (no version claimed)"); + + break; + case 0x05E3: + scsiOneValue.Add("Device complies with SFSC BSR INCITS 501 revision 01"); + + break; + case 0x0600: + scsiOneValue.Add("Device complies with SBC-4 (no version claimed)"); + + break; + case 0x0620: + scsiOneValue.Add("Device complies with ZBC (no version claimed)"); + + break; + case 0x0622: + scsiOneValue.Add("Device complies with ZBC BSR INCITS 536 revision 02"); + + break; + case 0x0640: + scsiOneValue.Add("Device complies with ADC-4 (no version claimed)"); + + break; + case 0x0820: + scsiOneValue.Add("Device complies with SSA-TL2 (no version claimed)"); + + break; + case 0x083B: + scsiOneValue.Add("Device complies with SSA-TL2 T10.1/1147-D revision 05b"); + + break; + case 0x083C: + scsiOneValue.Add("Device complies with SSA-TL2 ANSI INCITS 308-1998"); + + break; + case 0x0840: + scsiOneValue.Add("Device complies with SSA-TL1 (no version claimed)"); + + break; + case 0x085B: + scsiOneValue.Add("Device complies with SSA-TL1 T10.1/0989-D revision 10b"); + + break; + case 0x085C: + scsiOneValue.Add("Device complies with SSA-TL1 ANSI INCITS 295-1996"); + + break; + case 0x0860: + scsiOneValue.Add("Device complies with SSA-S3P (no version claimed)"); + + break; + case 0x087B: + scsiOneValue.Add("Device complies with SSA-S3P T10.1/1051-D revision 05b"); + + break; + case 0x087C: + scsiOneValue.Add("Device complies with SSA-S3P ANSI INCITS 309-1998"); + + break; + case 0x0880: + scsiOneValue.Add("Device complies with SSA-S2P (no version claimed)"); + + break; + case 0x089B: + scsiOneValue.Add("Device complies with SSA-S2P T10.1/1121-D revision 07b"); + + break; + case 0x089C: + scsiOneValue.Add("Device complies with SSA-S2P ANSI INCITS 294-1996"); + + break; + case 0x08A0: + scsiOneValue.Add("Device complies with SIP (no version claimed)"); + + break; + case 0x08BB: + scsiOneValue.Add("Device complies with SIP T10/0856-D revision 10"); + + break; + case 0x08BC: + scsiOneValue.Add("Device complies with SIP ANSI INCITS 292-1997"); + + break; + case 0x08C0: + scsiOneValue.Add("Device complies with FCP (no version claimed)"); + + break; + case 0x08DB: + scsiOneValue.Add("Device complies with FCP T10/0993-D revision 12"); + + break; + case 0x08DC: + scsiOneValue.Add("Device complies with FCP ANSI INCITS 269-1996"); + + break; + case 0x08E0: + scsiOneValue.Add("Device complies with SBP-2 (no version claimed)"); + + break; + case 0x08FB: + scsiOneValue.Add("Device complies with SBP-2 T10/1155-D revision 04"); + + break; + case 0x08FC: + scsiOneValue.Add("Device complies with SBP-2 ANSI INCITS 325-1998"); + + break; + case 0x0900: + scsiOneValue.Add("Device complies with FCP-2 (no version claimed)"); + + break; + case 0x0901: + scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 4"); + + break; + case 0x0915: + scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 7"); + + break; + case 0x0916: + scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 7a"); + + break; + case 0x0917: + scsiOneValue.Add("Device complies with FCP-2 ANSI INCITS 350-2003"); + + break; + case 0x0918: + scsiOneValue.Add("Device complies with FCP-2 T10/1144-D revision 8"); + + break; + case 0x0920: + scsiOneValue.Add("Device complies with SST (no version claimed)"); + + break; + case 0x0935: + scsiOneValue.Add("Device complies with SST T10/1380-D revision 8b"); + + break; + case 0x0940: + scsiOneValue.Add("Device complies with SRP (no version claimed)"); + + break; + case 0x0954: + scsiOneValue.Add("Device complies with SRP T10/1415-D revision 10"); + + break; + case 0x0955: + scsiOneValue.Add("Device complies with SRP T10/1415-D revision 16a"); + + break; + case 0x095C: + scsiOneValue.Add("Device complies with SRP ANSI INCITS 365-2002"); + + break; + case 0x0960: + scsiOneValue.Add("Device complies with iSCSI (no version claimed)"); + + break; + case 0x0961: + case 0x0962: + case 0x0963: + case 0x0964: + case 0x0965: + case 0x0966: + case 0x0967: + case 0x0968: + case 0x0969: + case 0x096A: + case 0x096B: + case 0x096C: + case 0x096D: + case 0x096E: + case 0x096F: + case 0x0970: + case 0x0971: + case 0x0972: + case 0x0973: + case 0x0974: + case 0x0975: + case 0x0976: + case 0x0977: + case 0x0978: + case 0x0979: + case 0x097A: + case 0x097B: + case 0x097C: + case 0x097D: + case 0x097E: + case 0x097F: + scsiOneValue.Add($"Device complies with iSCSI revision {versionDescriptor & 0x1F}"); + + break; + case 0x0980: + scsiOneValue.Add("Device complies with SBP-3 (no version claimed)"); + + break; + case 0x0982: + scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 1f"); + + break; + case 0x0994: + scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 3"); + + break; + case 0x099A: + scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 4"); + + break; + case 0x099B: + scsiOneValue.Add("Device complies with SBP-3 T10/1467-D revision 5"); + + break; + case 0x099C: + scsiOneValue.Add("Device complies with SBP-3 ANSI INCITS 375-2004"); + + break; + case 0x09C0: + scsiOneValue.Add("Device complies with ADP (no version claimed)"); + + break; + case 0x09E0: + scsiOneValue.Add("Device complies with ADT (no version claimed)"); + + break; + case 0x09F9: + scsiOneValue.Add("Device complies with ADT T10/1557-D revision 11"); + + break; + case 0x09FA: + scsiOneValue.Add("Device complies with ADT T10/1557-D revision 14"); + + break; + case 0x09FD: + scsiOneValue.Add("Device complies with ADT ANSI INCITS 406-2005"); + + break; + case 0x0A00: + scsiOneValue.Add("Device complies with FCP-3 (no version claimed)"); + + break; + case 0x0A07: + scsiOneValue.Add("Device complies with FCP-3 T10/1560-D revision 3f"); + + break; + case 0x0A0F: + scsiOneValue.Add("Device complies with FCP-3 T10/1560-D revision 4"); + + break; + case 0x0A11: + scsiOneValue.Add("Device complies with FCP-3 ANSI INCITS 416-2006"); + + break; + case 0x0A1C: + scsiOneValue.Add("Device complies with FCP-3 ISO/IEC 14776-223"); + + break; + case 0x0A20: + scsiOneValue.Add("Device complies with ADT-2 (no version claimed)"); + + break; + case 0x0A22: + scsiOneValue.Add("Device complies with ADT-2 T10/1742-D revision 06"); + + break; + case 0x0A27: + scsiOneValue.Add("Device complies with ADT-2 T10/1742-D revision 08"); + + break; + case 0x0A28: + scsiOneValue.Add("Device complies with ADT-2 T10/1742-D revision 09"); + + break; + case 0x0A2B: + scsiOneValue.Add("Device complies with ADT-2 ANSI INCITS 472-2011"); + + break; + case 0x0A40: + scsiOneValue.Add("Device complies with FCP-4 (no version claimed)"); + + break; + case 0x0A42: + scsiOneValue.Add("Device complies with FCP-4 T10/1828-D revision 01"); + + break; + case 0x0A44: + scsiOneValue.Add("Device complies with FCP-4 T10/1828-D revision 02"); + + break; + case 0x0A45: + scsiOneValue.Add("Device complies with FCP-4 T10/1828-D revision 02b"); + + break; + case 0x0A46: + scsiOneValue.Add("Device complies with FCP-4 ANSI INCITS 481-2012"); + + break; + case 0x0A60: + scsiOneValue.Add("Device complies with ADT-3 (no version claimed)"); + + break; + case 0x0AA0: + scsiOneValue.Add("Device complies with SPI (no version claimed)"); + + break; + case 0x0AB9: + scsiOneValue.Add("Device complies with SPI T10/0855-D revision 15a"); + + break; + case 0x0ABA: + scsiOneValue.Add("Device complies with SPI ANSI INCITS 253-1995"); + + break; + case 0x0ABB: + scsiOneValue.Add("Device complies with SPI T10/0855-D revision 15a with SPI Amnd revision 3a"); + + break; + case 0x0ABC: + scsiOneValue. + Add("Device complies with SPI ANSI INCITS 253-1995 with SPI Amnd ANSI INCITS 253/AM1-1998"); + + break; + case 0x0AC0: + scsiOneValue.Add("Device complies with Fast-20 (no version claimed)"); + + break; + case 0x0ADB: + scsiOneValue.Add("Device complies with Fast-20 T10/1071 revision 06"); + + break; + case 0x0ADC: + scsiOneValue.Add("Device complies with Fast-20 ANSI INCITS 277-1996"); + + break; + case 0x0AE0: + scsiOneValue.Add("Device complies with SPI-2 (no version claimed)"); + + break; + case 0x0AFB: + scsiOneValue.Add("Device complies with SPI-2 T10/1142-D revision 20b"); + + break; + case 0x0AFC: + scsiOneValue.Add("Device complies with SPI-2 ANSI INCITS 302-1999"); + + break; + case 0x0B00: + scsiOneValue.Add("Device complies with SPI-3 (no version claimed)"); + + break; + case 0x0B18: + scsiOneValue.Add("Device complies with SPI-3 T10/1302-D revision 10"); + + break; + case 0x0B19: + scsiOneValue.Add("Device complies with SPI-3 T10/1302-D revision 13a"); + + break; + case 0x0B1A: + scsiOneValue.Add("Device complies with SPI-3 T10/1302-D revision 14"); + + break; + case 0x0B1C: + scsiOneValue.Add("Device complies with SPI-3 ANSI INCITS 336-2000"); + + break; + case 0x0B20: + scsiOneValue.Add("Device complies with EPI (no version claimed)"); + + break; + case 0x0B3B: + scsiOneValue.Add("Device complies with EPI T10/1134 revision 16"); + + break; + case 0x0B3C: + scsiOneValue.Add("Device complies with EPI ANSI INCITS TR-23 1999"); + + break; + case 0x0B40: + scsiOneValue.Add("Device complies with SPI-4 (no version claimed)"); + + break; + case 0x0B54: + scsiOneValue.Add("Device complies with SPI-4 T10/1365-D revision 7"); + + break; + case 0x0B55: + scsiOneValue.Add("Device complies with SPI-4 T10/1365-D revision 9"); + + break; + case 0x0B56: + scsiOneValue.Add("Device complies with SPI-4 ANSI INCITS 362-2002"); + + break; + case 0x0B59: + scsiOneValue.Add("Device complies with SPI-4 T10/1365-D revision 10"); + + break; + case 0x0B60: + scsiOneValue.Add("Device complies with SPI-5 (no version claimed)"); + + break; + case 0x0B79: + scsiOneValue.Add("Device complies with SPI-5 T10/1525-D revision 3"); + + break; + case 0x0B7A: + scsiOneValue.Add("Device complies with SPI-5 T10/1525-D revision 5"); + + break; + case 0x0B7B: + scsiOneValue.Add("Device complies with SPI-5 T10/1525-D revision 6"); + + break; + case 0x0B7C: + scsiOneValue.Add("Device complies with SPI-5 ANSI INCITS 367-2003"); + + break; + case 0x0BE0: + scsiOneValue.Add("Device complies with SAS (no version claimed)"); + + break; + case 0x0BE1: + scsiOneValue.Add("Device complies with SAS T10/1562-D revision 01"); + + break; + case 0x0BF5: + scsiOneValue.Add("Device complies with SAS T10/1562-D revision 03"); + + break; + case 0x0BFA: + scsiOneValue.Add("Device complies with SAS T10/1562-D revision 04"); + + break; + case 0x0BFB: + scsiOneValue.Add("Device complies with SAS T10/1562-D revision 04"); + + break; + case 0x0BFC: + scsiOneValue.Add("Device complies with SAS T10/1562-D revision 05"); + + break; + case 0x0BFD: + scsiOneValue.Add("Device complies with SAS ANSI INCITS 376-2003"); + + break; + case 0x0C00: + scsiOneValue.Add("Device complies with SAS-1.1 (no version claimed)"); + + break; + case 0x0C07: + scsiOneValue.Add("Device complies with SAS-1.1 T10/1601-D revision 9"); + + break; + case 0x0C0F: + scsiOneValue.Add("Device complies with SAS-1.1 T10/1601-D revision 10"); + + break; + case 0x0C11: + scsiOneValue.Add("Device complies with SAS-1.1 ANSI INCITS 417-2006"); + + break; + case 0x0C12: + scsiOneValue.Add("Device complies with SAS-1.1 ISO/IEC 14776-151"); + + break; + case 0x0C20: + scsiOneValue.Add("Device complies with SAS-2 (no version claimed)"); + + break; + case 0x0C23: + scsiOneValue.Add("Device complies with SAS-2 T10/1760-D revision 14"); + + break; + case 0x0C27: + scsiOneValue.Add("Device complies with SAS-2 T10/1760-D revision 15"); + + break; + case 0x0C28: + scsiOneValue.Add("Device complies with SAS-2 T10/1760-D revision 16"); + + break; + case 0x0C2A: + scsiOneValue.Add("Device complies with SAS-2 ANSI INCITS 457-2010"); + + break; + case 0x0C40: + scsiOneValue.Add("Device complies with SAS-2.1 (no version claimed)"); + + break; + case 0x0C48: + scsiOneValue.Add("Device complies with SAS-2.1 T10/2125-D revision 04"); + + break; + case 0x0C4A: + scsiOneValue.Add("Device complies with SAS-2.1 T10/2125-D revision 06"); + + break; + case 0x0C4B: + scsiOneValue.Add("Device complies with SAS-2.1 T10/2125-D revision 07"); + + break; + case 0x0C4E: + scsiOneValue.Add("Device complies with SAS-2.1 ANSI INCITS 478-2011"); + + break; + case 0x0C4F: + scsiOneValue. + Add("Device complies with SAS-2.1 ANSI INCITS 478-2011 w/ Amnd 1 ANSI INCITS 478/AM1-2014"); + + break; + case 0x0C52: + scsiOneValue.Add("Device complies with SAS-2.1 ISO/IEC 14776-153"); + + break; + case 0x0C60: + scsiOneValue.Add("Device complies with SAS-3 (no version claimed)"); + + break; + case 0x0C63: + scsiOneValue.Add("Device complies with SAS-3 T10/BSR INCITS 519 revision 05a"); + + break; + case 0x0C65: + scsiOneValue.Add("Device complies with SAS-3 T10/BSR INCITS 519 revision 06"); + + break; + case 0x0C68: + scsiOneValue.Add("Device complies with SAS-3 ANSI INCITS 519-2014"); + + break; + case 0x0C80: + scsiOneValue.Add("Device complies with SAS-4 (no version claimed)"); + + break; + case 0x0D20: + scsiOneValue.Add("Device complies with FC-PH (no version claimed)"); + + break; + case 0x0D3B: + scsiOneValue.Add("Device complies with FC-PH ANSI INCITS 230-1994"); + + break; + case 0x0D3C: + scsiOneValue. + Add("Device complies with FC-PH ANSI INCITS 230-1994 with Amnd 1 ANSI INCITS 230/AM1-1996"); + + break; + case 0x0D40: + scsiOneValue.Add("Device complies with FC-AL (no version claimed)"); + + break; + case 0x0D5C: + scsiOneValue.Add("Device complies with FC-AL ANSI INCITS 272-1996"); + + break; + case 0x0D60: + scsiOneValue.Add("Device complies with FC-AL-2 (no version claimed)"); + + break; + case 0x0D61: + scsiOneValue.Add("Device complies with FC-AL-2 T11/1133-D revision 7.0"); + + break; + case 0x0D63: + scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999 with AM1-2003 & AM2-2006"); + + break; + case 0x0D64: + scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999 with Amnd 2 AM2-2006"); + + break; + case 0x0D65: + scsiOneValue.Add("Device complies with FC-AL-2 ISO/IEC 14165-122 with AM1 & AM2"); + + break; + case 0x0D7C: + scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999"); + + break; + case 0x0D7D: + scsiOneValue.Add("Device complies with FC-AL-2 ANSI INCITS 332-1999 with Amnd 1 AM1-2003"); + + break; + case 0x0D80: + scsiOneValue.Add("Device complies with FC-PH-3 (no version claimed)"); + + break; + case 0x0D9C: + scsiOneValue.Add("Device complies with FC-PH-3 ANSI INCITS 303-1998"); + + break; + case 0x0DA0: + scsiOneValue.Add("Device complies with FC-FS (no version claimed)"); + + break; + case 0x0DB7: + scsiOneValue.Add("Device complies with FC-FS T11/1331-D revision 1.2"); + + break; + case 0x0DB8: + scsiOneValue.Add("Device complies with FC-FS T11/1331-D revision 1.7"); + + break; + case 0x0DBC: + scsiOneValue.Add("Device complies with FC-FS ANSI INCITS 373-2003"); + + break; + case 0x0DBD: + scsiOneValue.Add("Device complies with FC-FS ISO/IEC 14165-251"); + + break; + case 0x0DC0: + scsiOneValue.Add("Device complies with FC-PI (no version claimed)"); + + break; + case 0x0DDC: + scsiOneValue.Add("Device complies with FC-PI ANSI INCITS 352-2002"); + + break; + case 0x0DE0: + scsiOneValue.Add("Device complies with FC-PI-2 (no version claimed)"); + + break; + case 0x0DE2: + scsiOneValue.Add("Device complies with FC-PI-2 T11/1506-D revision 5.0"); + + break; + case 0x0DE4: + scsiOneValue.Add("Device complies with FC-PI-2 ANSI INCITS 404-2006"); + + break; + case 0x0E00: + scsiOneValue.Add("Device complies with FC-FS-2 (no version claimed)"); + + break; + case 0x0E02: + scsiOneValue.Add("Device complies with FC-FS-2 ANSI INCITS 242-2007"); + + break; + case 0x0E03: + scsiOneValue. + Add("Device complies with FC-FS-2 ANSI INCITS 242-2007 with AM1 ANSI INCITS 242/AM1-2007"); + + break; + case 0x0E20: + scsiOneValue.Add("Device complies with FC-LS (no version claimed)"); + + break; + case 0x0E21: + scsiOneValue.Add("Device complies with FC-LS T11/1620-D revision 1.62"); + + break; + case 0x0E29: + scsiOneValue.Add("Device complies with FC-LS ANSI INCITS 433-2007"); + + break; + case 0x0E40: + scsiOneValue.Add("Device complies with FC-SP (no version claimed)"); + + break; + case 0x0E42: + scsiOneValue.Add("Device complies with FC-SP T11/1570-D revision 1.6"); + + break; + case 0x0E45: + scsiOneValue.Add("Device complies with FC-SP ANSI INCITS 426-2007"); + + break; + case 0x0E60: + scsiOneValue.Add("Device complies with FC-PI-3 (no version claimed)"); + + break; + case 0x0E62: + scsiOneValue.Add("Device complies with FC-PI-3 T11/1625-D revision 2.0"); + + break; + case 0x0E68: + scsiOneValue.Add("Device complies with FC-PI-3 T11/1625-D revision 2.1"); + + break; + case 0x0E6A: + scsiOneValue.Add("Device complies with FC-PI-3 T11/1625-D revision 4.0"); + + break; + case 0x0E6E: + scsiOneValue.Add("Device complies with FC-PI-3 ANSI INCITS 460-2011"); + + break; + case 0x0E80: + scsiOneValue.Add("Device complies with FC-PI-4 (no version claimed)"); + + break; + case 0x0E82: + scsiOneValue.Add("Device complies with FC-PI-4 T11/1647-D revision 8.0"); + + break; + case 0x0E88: + scsiOneValue.Add("Device complies with FC-PI-4 ANSI INCITS 450-2009"); + + break; + case 0x0EA0: + scsiOneValue.Add("Device complies with FC 10GFC (no version claimed)"); + + break; + case 0x0EA2: + scsiOneValue.Add("Device complies with FC 10GFC ANSI INCITS 364-2003"); + + break; + case 0x0EA3: + scsiOneValue.Add("Device complies with FC 10GFC ISO/IEC 14165-116"); + + break; + case 0x0EA5: + scsiOneValue.Add("Device complies with FC 10GFC ISO/IEC 14165-116 with AM1"); + + break; + case 0x0EA6: + scsiOneValue. + Add("Device complies with FC 10GFC ANSI INCITS 364-2003 with AM1 ANSI INCITS 364/AM1-2007"); + + break; + case 0x0EC0: + scsiOneValue.Add("Device complies with FC-SP-2 (no version claimed)"); + + break; + case 0x0EE0: + scsiOneValue.Add("Device complies with FC-FS-3 (no version claimed)"); + + break; + case 0x0EE2: + scsiOneValue.Add("Device complies with FC-FS-3 T11/1861-D revision 0.9"); + + break; + case 0x0EE7: + scsiOneValue.Add("Device complies with FC-FS-3 T11/1861-D revision 1.0"); + + break; + case 0x0EE9: + scsiOneValue.Add("Device complies with FC-FS-3 T11/1861-D revision 1.10"); + + break; + case 0x0EEB: + scsiOneValue.Add("Device complies with FC-FS-3 ANSI INCITS 470-2011"); + + break; + case 0x0F00: + scsiOneValue.Add("Device complies with FC-LS-2 (no version claimed)"); + + break; + case 0x0F03: + scsiOneValue.Add("Device complies with FC-LS-2 T11/2103-D revision 2.11"); + + break; + case 0x0F05: + scsiOneValue.Add("Device complies with FC-LS-2 T11/2103-D revision 2.21"); + + break; + case 0x0F07: + scsiOneValue.Add("Device complies with FC-LS-2 ANSI INCITS 477-2011"); + + break; + case 0x0F20: + scsiOneValue.Add("Device complies with FC-PI-5 (no version claimed)"); + + break; + case 0x0F27: + scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 2.00"); + + break; + case 0x0F28: + scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 3.00"); + + break; + case 0x0F2A: + scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 6.00"); + + break; + case 0x0F2B: + scsiOneValue.Add("Device complies with FC-PI-5 T11/2118-D revision 6.10"); + + break; + case 0x0F2E: + scsiOneValue.Add("Device complies with FC-PI-5 ANSI INCITS 479-2011"); + + break; + case 0x0F40: + scsiOneValue.Add("Device complies with FC-PI-6 (no version claimed)"); + + break; + case 0x0F60: + scsiOneValue.Add("Device complies with FC-FS-4 (no version claimed)"); + + break; + case 0x0F80: + scsiOneValue.Add("Device complies with FC-LS-3 (no version claimed)"); + + break; + case 0x12A0: + scsiOneValue.Add("Device complies with FC-SCM (no version claimed)"); + + break; + case 0x12A3: + scsiOneValue.Add("Device complies with FC-SCM T11/1824DT revision 1.0"); + + break; + case 0x12A5: + scsiOneValue.Add("Device complies with FC-SCM T11/1824DT revision 1.1"); + + break; + case 0x12A7: + scsiOneValue.Add("Device complies with FC-SCM T11/1824DT revision 1.4"); + + break; + case 0x12AA: + scsiOneValue.Add("Device complies with FC-SCM INCITS TR-47 2012"); + + break; + case 0x12C0: + scsiOneValue.Add("Device complies with FC-DA-2 (no version claimed)"); + + break; + case 0x12C3: + scsiOneValue.Add("Device complies with FC-DA-2 T11/1870DT revision 1.04"); + + break; + case 0x12C5: + scsiOneValue.Add("Device complies with FC-DA-2 T11/1870DT revision 1.06"); + + break; + case 0x12C9: + scsiOneValue.Add("Device complies with FC-DA-2 INCITS TR-49 2012"); + + break; + case 0x12E0: + scsiOneValue.Add("Device complies with FC-DA (no version claimed)"); + + break; + case 0x12E2: + scsiOneValue.Add("Device complies with FC-DA T11/1513-DT revision 3.1"); + + break; + case 0x12E8: + scsiOneValue.Add("Device complies with FC-DA ANSI INCITS TR-36 2004"); + + break; + case 0x12E9: + scsiOneValue.Add("Device complies with FC-DA ISO/IEC 14165-341"); + + break; + case 0x1300: + scsiOneValue.Add("Device complies with FC-Tape (no version claimed)"); + + break; + case 0x1301: + scsiOneValue.Add("Device complies with FC-Tape T11/1315 revision 1.16"); + + break; + case 0x131B: + scsiOneValue.Add("Device complies with FC-Tape T11/1315 revision 1.17"); + + break; + case 0x131C: + scsiOneValue.Add("Device complies with FC-Tape ANSI INCITS TR-24 1999"); + + break; + case 0x1320: + scsiOneValue.Add("Device complies with FC-FLA (no version claimed)"); + + break; + case 0x133B: + scsiOneValue.Add("Device complies with FC-FLA T11/1235 revision 7"); + + break; + case 0x133C: + scsiOneValue.Add("Device complies with FC-FLA ANSI INCITS TR-20 1998"); + + break; + case 0x1340: + scsiOneValue.Add("Device complies with FC-PLDA (no version claimed)"); + + break; + case 0x135B: + scsiOneValue.Add("Device complies with FC-PLDA T11/1162 revision 2.1"); + + break; + case 0x135C: + scsiOneValue.Add("Device complies with FC-PLDA ANSI INCITS TR-19 1998"); + + break; + case 0x1360: + scsiOneValue.Add("Device complies with SSA-PH2 (no version claimed)"); + + break; + case 0x137B: + scsiOneValue.Add("Device complies with SSA-PH2 T10.1/1145-D revision 09c"); + + break; + case 0x137C: + scsiOneValue.Add("Device complies with SSA-PH2 ANSI INCITS 293-1996"); + + break; + case 0x1380: + scsiOneValue.Add("Device complies with SSA-PH3 (no version claimed)"); + + break; + case 0x139B: + scsiOneValue.Add("Device complies with SSA-PH3 T10.1/1146-D revision 05b"); + + break; + case 0x139C: + scsiOneValue.Add("Device complies with SSA-PH3 ANSI INCITS 307-1998"); + + break; + case 0x14A0: + scsiOneValue.Add("Device complies with IEEE 1394 (no version claimed)"); + + break; + case 0x14BD: + scsiOneValue.Add("Device complies with ANSI IEEE 1394-1995"); + + break; + case 0x14C0: + scsiOneValue.Add("Device complies with IEEE 1394a (no version claimed)"); + + break; + case 0x14E0: + scsiOneValue.Add("Device complies with IEEE 1394b (no version claimed)"); + + break; + case 0x15E0: + scsiOneValue.Add("Device complies with ATA/ATAPI-6 (no version claimed)"); + + break; + case 0x15FD: + scsiOneValue.Add("Device complies with ATA/ATAPI-6 ANSI INCITS 361-2002"); + + break; + case 0x1600: + scsiOneValue.Add("Device complies with ATA/ATAPI-7 (no version claimed)"); + + break; + case 0x1602: + scsiOneValue.Add("Device complies with ATA/ATAPI-7 T13/1532-D revision 3"); + + break; + case 0x161C: + scsiOneValue.Add("Device complies with ATA/ATAPI-7 ANSI INCITS 397-2005"); + + break; + case 0x161E: + scsiOneValue.Add("Device complies with ATA/ATAPI-7 ISO/IEC 24739"); + + break; + case 0x1620: + scsiOneValue.Add("Device complies with ATA/ATAPI-8 ATA8-AAM (no version claimed)"); + + break; + case 0x1621: + scsiOneValue. + Add("Device complies with ATA/ATAPI-8 ATA8-APT Parallel Transport (no version claimed)"); + + break; + case 0x1622: + scsiOneValue. + Add("Device complies with ATA/ATAPI-8 ATA8-AST Serial Transport (no version claimed)"); + + break; + case 0x1623: + scsiOneValue. + Add("Device complies with ATA/ATAPI-8 ATA8-ACS ATA/ATAPI Command Set (no version claimed)"); + + break; + case 0x1628: + scsiOneValue.Add("Device complies with ATA/ATAPI-8 ATA8-AAM ANSI INCITS 451-2008"); + + break; + case 0x162A: + scsiOneValue. + Add("Device complies with ATA/ATAPI-8 ATA8-ACS ANSI INCITS 452-2009 w/ Amendment 1"); + + break; + case 0x1728: + scsiOneValue.Add("Device complies with Universal Serial Bus Specification, Revision 1.1"); + + break; + case 0x1729: + scsiOneValue.Add("Device complies with Universal Serial Bus Specification, Revision 2.0"); + + break; + case 0x1730: + scsiOneValue. + Add("Device complies with USB Mass Storage Class Bulk-Only Transport, Revision 1.0"); + + break; + case 0x1740: + scsiOneValue.Add("Device complies with UAS (no version claimed)"); + + break; + case 0x1743: + scsiOneValue.Add("Device complies with UAS T10/2095-D revision 02"); + + break; + case 0x1747: + scsiOneValue.Add("Device complies with UAS T10/2095-D revision 04"); + + break; + case 0x1748: + scsiOneValue.Add("Device complies with UAS ANSI INCITS 471-2010"); + + break; + case 0x1749: + scsiOneValue.Add("Device complies with UAS ISO/IEC 14776-251:2014"); + + break; + case 0x1761: + scsiOneValue.Add("Device complies with ACS-2 (no version claimed)"); + + break; + case 0x1762: + scsiOneValue.Add("Device complies with ACS-2 ANSI INCITS 482-2013"); + + break; + case 0x1765: + scsiOneValue.Add("Device complies with ACS-3 (no version claimed)"); + + break; + case 0x1780: + scsiOneValue.Add("Device complies with UAS-2 (no version claimed)"); + + break; + case 0x1EA0: + scsiOneValue.Add("Device complies with SAT (no version claimed)"); + + break; + case 0x1EA7: + scsiOneValue.Add("Device complies with SAT T10/1711-D revision 8"); + + break; + case 0x1EAB: + scsiOneValue.Add("Device complies with SAT T10/1711-D revision 9"); + + break; + case 0x1EAD: + scsiOneValue.Add("Device complies with SAT ANSI INCITS 431-2007"); + + break; + case 0x1EC0: + scsiOneValue.Add("Device complies with SAT-2 (no version claimed)"); + + break; + case 0x1EC4: + scsiOneValue.Add("Device complies with SAT-2 T10/1826-D revision 06"); + + break; + case 0x1EC8: + scsiOneValue.Add("Device complies with SAT-2 T10/1826-D revision 09"); + + break; + case 0x1ECA: + scsiOneValue.Add("Device complies with SAT-2 ANSI INCITS 465-2010"); + + break; + case 0x1EE0: + scsiOneValue.Add("Device complies with SAT-3 (no version claimed)"); + + break; + case 0x1EE2: + scsiOneValue.Add("Device complies with SAT-3 T10/BSR INCITS 517 revision 4"); + + break; + case 0x1EE4: + scsiOneValue.Add("Device complies with SAT-3 T10/BSR INCITS 517 revision 7"); + + break; + case 0x1EE8: + scsiOneValue.Add("Device complies with SAT-3 ANSI INCITS 517-2015"); + + break; + case 0x1F00: + scsiOneValue.Add("Device complies with SAT-4 (no version claimed)"); + + break; + case 0x20A0: + scsiOneValue.Add("Device complies with SPL (no version claimed)"); + + break; + case 0x20A3: + scsiOneValue.Add("Device complies with SPL T10/2124-D revision 6a"); + + break; + case 0x20A5: + scsiOneValue.Add("Device complies with SPL T10/2124-D revision 7"); + + break; + case 0x20A7: + scsiOneValue.Add("Device complies with SPL ANSI INCITS 476-2011"); + + break; + case 0x20A8: + scsiOneValue.Add("Device complies with SPL ANSI INCITS 476-2011 + SPL AM1 INCITS 476/AM1 2012"); + + break; + case 0x20AA: + scsiOneValue.Add("Device complies with SPL ISO/IEC 14776-261:2012"); + + break; + case 0x20C0: + scsiOneValue.Add("Device complies with SPL-2 (no version claimed)"); + + break; + case 0x20C2: + scsiOneValue.Add("Device complies with SPL-2 T10/BSR INCITS 505 revision 4"); + + break; + case 0x20C4: + scsiOneValue.Add("Device complies with SPL-2 T10/BSR INCITS 505 revision 5"); + + break; + case 0x20C8: + scsiOneValue.Add("Device complies with SPL-2 ANSI INCITS 505-2013"); + + break; + case 0x20E0: + scsiOneValue.Add("Device complies with SPL-3 (no version claimed)"); + + break; + case 0x20E4: + scsiOneValue.Add("Device complies with SPL-3 T10/BSR INCITS 492 revision 6"); + + break; + case 0x20E6: + scsiOneValue.Add("Device complies with SPL-3 T10/BSR INCITS 492 revision 7"); + + break; + case 0x20E8: + scsiOneValue.Add("Device complies with SPL-3 ANSI INCITS 492-2015"); + + break; + case 0x2100: + scsiOneValue.Add("Device complies with SPL-4 (no version claimed)"); + + break; + case 0x21E0: + scsiOneValue.Add("Device complies with SOP (no version claimed)"); + + break; + case 0x21E4: + scsiOneValue.Add("Device complies with SOP T10/BSR INCITS 489 revision 4"); + + break; + case 0x21E6: + scsiOneValue.Add("Device complies with SOP T10/BSR INCITS 489 revision 5"); + + break; + case 0x21E8: + scsiOneValue.Add("Device complies with SOP ANSI INCITS 489-2014"); + + break; + case 0x2200: + scsiOneValue.Add("Device complies with PQI (no version claimed)"); + + break; + case 0x2204: + scsiOneValue.Add("Device complies with PQI T10/BSR INCITS 490 revision 6"); + + break; + case 0x2206: + scsiOneValue.Add("Device complies with PQI T10/BSR INCITS 490 revision 7"); + + break; + case 0x2208: + scsiOneValue.Add("Device complies with PQI ANSI INCITS 490-2014"); + + break; + case 0x2220: + scsiOneValue.Add("Device complies with SOP-2 (no version claimed)"); + + break; + case 0x2240: + scsiOneValue.Add("Device complies with PQI-2 (no version claimed)"); + + break; + case 0xFFC0: + scsiOneValue.Add("Device complies with IEEE 1667 (no version claimed)"); + + break; + case 0xFFC1: + scsiOneValue.Add("Device complies with IEEE 1667-2006"); + + break; + case 0xFFC2: + scsiOneValue.Add("Device complies with IEEE 1667-2009"); + + break; + default: + scsiOneValue.Add($"Device complies with unknown standard code 0x{versionDescriptor:X4}"); + + break; + } + + return scsiOneValue; } } \ No newline at end of file diff --git a/Aaru.Server/Core/ScsiMmcFeatures.cs b/Aaru.Server/Core/ScsiMmcFeatures.cs index 6ab88dac..900a8b7d 100644 --- a/Aaru.Server/Core/ScsiMmcFeatures.cs +++ b/Aaru.Server/Core/ScsiMmcFeatures.cs @@ -34,489 +34,488 @@ using System.Collections.Generic; using Aaru.CommonTypes.Metadata; using Aaru.CommonTypes.Structs.Devices.SCSI; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class ScsiMmcFeatures { - public static class ScsiMmcFeatures + /// + /// Takes the MMC FEATURES part of a device report and prints it as a list of values to be sequenced by ASP.NET in + /// the rendering + /// + /// FEATURES part of the report + /// List to put the values on + public static void Report(MmcFeatures ftr, ref List mmcOneValue) { - /// - /// Takes the MMC FEATURES part of a device report and prints it as a list of values to be sequenced by ASP.NET in - /// the rendering - /// - /// FEATURES part of the report - /// List to put the values on - public static void Report(MmcFeatures ftr, ref List mmcOneValue) + if(ftr.SupportsAACS && + ftr.AACSVersion.HasValue) + mmcOneValue.Add($"Drive supports AACS version {ftr.AACSVersion}"); + else if(ftr.SupportsAACS) + mmcOneValue.Add("Drive supports AACS"); + + if(ftr.AGIDs.HasValue) + mmcOneValue.Add($"Drive supports {ftr.AGIDs} AGIDs concurrently"); + + if(ftr.CanGenerateBindingNonce) { - if(ftr.SupportsAACS && - ftr.AACSVersion.HasValue) - mmcOneValue.Add($"Drive supports AACS version {ftr.AACSVersion}"); - else if(ftr.SupportsAACS) - mmcOneValue.Add("Drive supports AACS"); + mmcOneValue.Add("Drive supports generating the binding nonce"); - if(ftr.AGIDs.HasValue) - mmcOneValue.Add($"Drive supports {ftr.AGIDs} AGIDs concurrently"); - - if(ftr.CanGenerateBindingNonce) - { - mmcOneValue.Add("Drive supports generating the binding nonce"); - - if(ftr.BindingNonceBlocks.HasValue) - mmcOneValue.Add($"{ftr.BindingNonceBlocks} media blocks are required for the binding nonce"); - } - - if(ftr.BlocksPerReadableUnit > 1) - mmcOneValue.Add($"{ftr.BlocksPerReadableUnit} logical blocks per media writable unit"); - - if(ftr.BufferUnderrunFreeInDVD) - mmcOneValue.Add("Drive supports zero loss linking writing DVDs"); - - if(ftr.BufferUnderrunFreeInSAO) - mmcOneValue.Add("Drive supports zero loss linking in Session at Once Mode"); - - if(ftr.BufferUnderrunFreeInTAO) - mmcOneValue.Add("Drive supports zero loss linking in Track at Once Mode"); - - if(ftr.CanAudioScan) - mmcOneValue.Add("Drive supports the SCAN command"); - - if(ftr.CanEject) - mmcOneValue.Add("Drive can eject media"); - - if(ftr.CanEraseSector) - mmcOneValue.Add("Drive supports media that require erasing before writing"); - - if(ftr.CanExpandBDRESpareArea) - mmcOneValue.Add("Drive can expand the spare area on a formatted BD-RE disc"); - - if(ftr.CanFormat) - mmcOneValue.Add("Drive can format media into logical blocks"); - - if(ftr.CanFormatBDREWithoutSpare) - mmcOneValue.Add("Drive can format BD-RE with no spares allocated"); - - if(ftr.CanFormatQCert) - mmcOneValue.Add("Drive can format BD-RE discs with quick certification"); - - if(ftr.CanFormatCert) - mmcOneValue.Add("Drive can format BD-RE discs with full certification"); - - if(ftr.CanFormatFRF) - mmcOneValue.Add("Drive can fast re-format BD-RE discs"); - - if(ftr.CanFormatRRM) - mmcOneValue.Add("Drive can format BD-R discs with RRM format"); - - if(ftr.CanLoad) - mmcOneValue.Add("Drive can load media"); - - if(ftr.CanMuteSeparateChannels) - mmcOneValue.Add("Drive is able to mute channels separately"); - - if(ftr.CanOverwriteSAOTrack) - mmcOneValue.Add("Drive can overwrite a SAO track with another in CD-RWs"); - - if(ftr.CanOverwriteTAOTrack) - mmcOneValue.Add("Drive can overwrite a TAO track with another in CD-RWs"); - - if(ftr.CanPlayCDAudio) - mmcOneValue.Add("Drive has an analogue audio output"); - - if(ftr.CanPseudoOverwriteBDR) - mmcOneValue.Add("Drive can write BD-R on Pseudo-OverWrite SRM mode"); - - if(ftr.CanReadAllDualR) - mmcOneValue.Add("Drive can read DVD-R DL from all recording modes"); - - if(ftr.CanReadAllDualRW) - mmcOneValue.Add("Drive can read DVD-RW DL from all recording modes"); - - if(ftr.CanReadBD) - mmcOneValue.Add("Drive can read BD-ROM"); - - if(ftr.CanReadBDR) - mmcOneValue.Add("Drive can read BD-R Ver.1"); - - if(ftr.CanReadBDRE1) - mmcOneValue.Add("Drive can read BD-RE Ver.1"); - - if(ftr.CanReadBDRE2) - mmcOneValue.Add("Drive can read BD-RE Ver.2"); - - if(ftr.CanReadBDROM) - mmcOneValue.Add("Drive can read BD-ROM Ver.1"); - - if(ftr.CanReadBluBCA) - mmcOneValue.Add("Drive can read BD's Burst Cutting Area"); - - if(ftr.CanReadCD) - mmcOneValue.Add("Drive can read CD-ROM"); - - if(ftr.CanWriteCDMRW && - ftr.CanReadDVDPlusMRW && - ftr.CanWriteDVDPlusMRW) - mmcOneValue.Add("Drive can read and write CD-MRW and DVD+MRW"); - else if(ftr.CanReadDVDPlusMRW && - ftr.CanWriteDVDPlusMRW) - mmcOneValue.Add("Drive can read and write DVD+MRW"); - else if(ftr.CanWriteCDMRW && - ftr.CanReadDVDPlusMRW) - mmcOneValue.Add("Drive and read DVD+MRW and read and write CD-MRW"); - else if(ftr.CanWriteCDMRW) - mmcOneValue.Add("Drive can read and write CD-MRW"); - else if(ftr.CanReadDVDPlusMRW) - mmcOneValue.Add("Drive can read CD-MRW and DVD+MRW"); - else if(ftr.CanReadCDMRW) - mmcOneValue.Add("Drive can read CD-MRW"); - - if(ftr.CanReadCPRM_MKB) - mmcOneValue.Add("Drive supports reading Media Key Block of CPRM"); - - if(ftr.CanReadDDCD) - mmcOneValue.Add("Drive can read DDCDs"); - - if(ftr.CanReadDVD) - mmcOneValue.Add("Drive can read DVD"); - - if(ftr.CanWriteDVDPlusRW) - mmcOneValue.Add("Drive can read and write DVD+RW"); - else if(ftr.CanReadDVDPlusRW) - mmcOneValue.Add("Drive can read DVD+RW"); - - if(ftr.CanWriteDVDPlusR) - mmcOneValue.Add("Drive can read and write DVD+R"); - else if(ftr.CanReadDVDPlusR) - mmcOneValue.Add("Drive can read DVD+R"); - - if(ftr.CanWriteDVDPlusRDL) - mmcOneValue.Add("Drive can read and write DVD+R DL"); - else if(ftr.CanReadDVDPlusRDL) - mmcOneValue.Add("Drive can read DVD+R DL"); - - if(ftr.CanReadDriveAACSCertificate) - mmcOneValue.Add("Drive supports reading the Drive Certificate"); - - if(ftr.CanReadHDDVD && - ftr.CanReadHDDVDR && - ftr.CanReadHDDVDRAM) - mmcOneValue.Add("Drive can read HD DVD-ROM, HD DVD-RW, HD DVD-R and HD DVD-RAM"); - else if(ftr.CanReadHDDVD && - ftr.CanReadHDDVDR) - mmcOneValue.Add("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-R"); - else if(ftr.CanReadHDDVD && - ftr.CanReadHDDVDRAM) - mmcOneValue.Add("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-RAM"); - else if(ftr.CanReadHDDVD) - mmcOneValue.Add("Drive can read HD DVD-ROM and HD DVD-RW"); - - if(ftr.CanReadLeadInCDText) - mmcOneValue.Add("Drive can return CD-Text from Lead-In"); - - if(ftr.CanReadOldBDR) - mmcOneValue.Add("Drive can read BD-R pre-1.0"); - - if(ftr.CanReadOldBDRE) - mmcOneValue.Add("Drive can read BD-RE pre-1.0"); - - if(ftr.CanReadOldBDROM) - mmcOneValue.Add("Drive can read BD-ROM pre-1.0"); - - if(ftr.CanReadSpareAreaInformation) - mmcOneValue.Add("Drive can return Spare Area Information"); - - if(ftr.CanReportDriveSerial) - mmcOneValue.Add("Drive is to report drive serial number"); - - if(ftr.CanReportMediaSerial) - mmcOneValue.Add("Drive is to read media serial number"); - - if(ftr.CanTestWriteDDCDR) - mmcOneValue.Add("Drive can do a test writing with DDCD-R"); - - if(ftr.CanTestWriteDVD) - mmcOneValue.Add("Drive can do a test writing with DVDs"); - - if(ftr.CanTestWriteInSAO) - mmcOneValue.Add("Drive can do a test writing in Session at Once Mode"); - - if(ftr.CanTestWriteInTAO) - mmcOneValue.Add("Drive can do a test writing in Track at Once Mode"); - - if(ftr.CanUpgradeFirmware) - mmcOneValue.Add("Drive supports Microcode Upgrade"); - - if(ftr.ErrorRecoveryPage) - mmcOneValue.Add("Drive shall report Read/Write Error Recovery mode page"); - - if(ftr.Locked) - mmcOneValue.Add("Drive can lock media"); - - if(ftr.LogicalBlockSize > 0) - mmcOneValue.Add($"{ftr.LogicalBlockSize} bytes per logical block"); - - if(ftr.MultiRead) - mmcOneValue. - Add("Drive claims capability to read all CD formats according to OSTA Multi-Read Specification"); - - if(ftr.PhysicalInterfaceStandard.HasValue) - switch(ftr.PhysicalInterfaceStandard) - { - case PhysicalInterfaces.Unspecified: - mmcOneValue.Add("Drive uses an unspecified physical interface"); - - break; - case PhysicalInterfaces.SCSI: - mmcOneValue.Add("Drive uses SCSI interface"); - - break; - case PhysicalInterfaces.ATAPI: - mmcOneValue.Add("Drive uses ATAPI interface"); - - break; - case PhysicalInterfaces.IEEE1394: - mmcOneValue.Add("Drive uses IEEE-1394 interface"); - - break; - case PhysicalInterfaces.IEEE1394A: - mmcOneValue.Add("Drive uses IEEE-1394A interface"); - - break; - case PhysicalInterfaces.FC: - mmcOneValue.Add("Drive uses Fibre Channel interface"); - - break; - case PhysicalInterfaces.IEEE1394B: - mmcOneValue.Add("Drive uses IEEE-1394B interface"); - - break; - case PhysicalInterfaces.SerialATAPI: - mmcOneValue.Add("Drive uses Serial ATAPI interface"); - - break; - case PhysicalInterfaces.USB: - mmcOneValue.Add("Drive uses USB interface"); - - break; - case PhysicalInterfaces.Vendor: - mmcOneValue.Add("Drive uses a vendor unique interface"); - - break; - default: - mmcOneValue. - Add($"Drive uses an unknown interface with code {(uint)ftr.PhysicalInterfaceStandard}"); - - break; - } - - if(ftr.PreventJumper) - mmcOneValue.Add("Drive power ups locked"); - - if(ftr.SupportsBusEncryption) - mmcOneValue.Add("Drive supports bus encryption"); - - if(ftr.CanWriteBD) - mmcOneValue.Add("Drive can write BD-R or BD-RE"); - - if(ftr.CanWriteBDR) - mmcOneValue.Add("Drive can write BD-R Ver.1"); - - if(ftr.CanWriteBDRE1) - mmcOneValue.Add("Drive can write BD-RE Ver.1"); - - if(ftr.CanWriteBDRE2) - mmcOneValue.Add("Drive can write BD-RE Ver.2"); - - if(ftr.CanWriteBusEncryptedBlocks) - mmcOneValue.Add("Drive supports writing with bus encryption"); - - if(ftr.CanWriteCDRW) - mmcOneValue.Add("Drive can write CD-RW"); - - if(ftr.CanWriteCDRWCAV) - mmcOneValue.Add("Drive can write High-Speed CD-RW"); - - if(ftr.CanWriteCDSAO && - !ftr.CanWriteRaw) - mmcOneValue.Add("Drive can write CDs in Session at Once Mode:"); - else if(!ftr.CanWriteCDSAO && - ftr.CanWriteRaw) - mmcOneValue.Add("Drive can write CDs in raw Mode:"); - else if(ftr.CanWriteCDSAO && - ftr.CanWriteRaw) - mmcOneValue.Add("Drive can write CDs in Session at Once and in Raw Modes:"); - - if(ftr.CanWriteCDTAO) - mmcOneValue.Add("Drive can write CDs in Track at Once Mode:"); - - if(ftr.CanWriteCSSManagedDVD) - mmcOneValue.Add("Drive can write CSS managed DVDs"); - - if(ftr.CanWriteDDCDR) - mmcOneValue.Add("Drive supports writing DDCD-R"); - - if(ftr.CanWriteDDCDRW) - mmcOneValue.Add("Drive supports writing DDCD-RW"); - - if(ftr.CanWriteDVDPlusRWDL) - mmcOneValue.Add("Drive can read and write DVD+RW DL"); - else if(ftr.CanReadDVDPlusRWDL) - mmcOneValue.Add("Drive can read DVD+RW DL"); - - if(ftr.CanWriteDVDR && - ftr.CanWriteDVDRW && - ftr.CanWriteDVDRDL) - mmcOneValue.Add("Drive supports writing DVD-R, DVD-RW and DVD-R DL"); - else if(ftr.CanWriteDVDR && - ftr.CanWriteDVDRDL) - mmcOneValue.Add("Drive supports writing DVD-R and DVD-R DL"); - else if(ftr.CanWriteDVDR && - ftr.CanWriteDVDRW) - mmcOneValue.Add("Drive supports writing DVD-R and DVD-RW"); - else if(ftr.CanWriteDVDR) - mmcOneValue.Add("Drive supports writing DVD-R"); - - if(ftr.CanWriteHDDVDR && - ftr.CanWriteHDDVDRAM) - mmcOneValue.Add("Drive can write HD DVD-RW, HD DVD-R and HD DVD-RAM"); - else if(ftr.CanWriteHDDVDR) - mmcOneValue.Add("Drive can write HD DVD-RW and HD DVD-R"); - else if(ftr.CanWriteHDDVDRAM) - mmcOneValue.Add("Drive can write HD DVD-RW and HD DVD-RAM"); - - // TODO: Write HD DVD-RW - /* - else - mmcOneValue.Add("Drive can write HD DVD-RW"); - */ - if(ftr.CanWriteOldBDR) - mmcOneValue.Add("Drive can write BD-R pre-1.0"); - - if(ftr.CanWriteOldBDRE) - mmcOneValue.Add("Drive can write BD-RE pre-1.0"); - - if(ftr.CanWriteRWSubchannelInTAO) - { - mmcOneValue.Add("Drive can write user provided data in the R-W subchannels in Track at Once Mode"); - - if(ftr.CanWriteRawSubchannelInTAO) - mmcOneValue.Add("Drive accepts RAW R-W subchannel data in Track at Once Mode"); - - if(ftr.CanWritePackedSubchannelInTAO) - mmcOneValue.Add("Drive accepts Packed R-W subchannel data in Track at Once Mode"); - } - - if(ftr.CanWriteRWSubchannelInSAO) - mmcOneValue.Add("Drive can write user provided data in the R-W subchannels in Session at Once Mode"); - - if(ftr.CanWriteRaw && - ftr.CanWriteRawMultiSession) - mmcOneValue.Add("Drive can write multi-session CDs in raw mode"); - - if(ftr.EmbeddedChanger) - { - mmcOneValue.Add("Drive contains an embedded changer"); - - if(ftr.ChangerIsSideChangeCapable) - mmcOneValue.Add("Drive can change disc side"); - - if(ftr.ChangerSupportsDiscPresent) - mmcOneValue.Add("Drive is able to report slots contents after a reset or change"); - - mmcOneValue.Add($"Drive has {ftr.ChangerSlots + 1} slots"); - } - - if(ftr.SupportsCSS && - ftr.CSSVersion.HasValue) - mmcOneValue.Add($"Drive supports DVD CSS/CPPM version {ftr.CSSVersion}"); - else if(ftr.SupportsCSS) - mmcOneValue.Add("Drive supports DVD CSS/CPRM"); - - if(ftr.SupportsCPRM && - ftr.CPRMVersion.HasValue) - mmcOneValue.Add($"Drive supports DVD CPRM version {ftr.CPRMVersion}"); - else if(ftr.SupportsCPRM) - mmcOneValue.Add("Drive supports DVD CPRM"); - - if(ftr.DBML) - mmcOneValue.Add("Drive reports Device Busy Class events during medium loading/unloading"); - - if(ftr.DVDMultiRead) - mmcOneValue.Add("Drive conforms to DVD Multi Drive Read-only Specifications"); - - if(ftr.FirmwareDate.HasValue) - mmcOneValue.Add($"Drive firmware is dated {ftr.FirmwareDate}"); - - if(ftr.SupportsC2) - mmcOneValue.Add("Drive supports C2 Error Pointers"); - - if(ftr.SupportsDAP) - mmcOneValue.Add("Drive supports the DAP bit in the READ CD and READ CD MSF commands"); - - if(ftr.SupportsDeviceBusyEvent) - mmcOneValue.Add("Drive supports Device Busy events"); - - if(ftr.LoadingMechanismType.HasValue) - switch(ftr.LoadingMechanismType) - { - case 0: - mmcOneValue.Add("Drive uses media caddy"); - - break; - case 1: - mmcOneValue.Add("Drive uses a tray"); - - break; - case 2: - mmcOneValue.Add("Drive is pop-up"); - - break; - case 4: - mmcOneValue.Add("Drive is a changer with individually changeable discs"); - - break; - case 5: - mmcOneValue.Add("Drive is a changer using cartridges"); - - break; - default: - mmcOneValue.Add($"Drive uses unknown loading mechanism type {ftr.LoadingMechanismType}"); - - break; - } - - if(ftr.SupportsHybridDiscs) - mmcOneValue.Add("Drive is able to access Hybrid discs"); - - if(ftr.SupportsModePage1Ch) - mmcOneValue.Add("Drive supports the Informational Exceptions Control mode page 1Ch"); - - if(ftr.SupportsOSSC) - mmcOneValue.Add("Drive supports the Trusted Computing Group Optical Security Subsystem Class"); - - if(ftr.SupportsPWP) - mmcOneValue.Add("Drive supports set/release of PWP status"); - - if(ftr.SupportsSWPP) - mmcOneValue.Add("Drive supports the SWPP bit of the Timeout and Protect mode page"); - - if(ftr.SupportsSecurDisc) - mmcOneValue.Add("Drive supports SecurDisc"); - - if(ftr.SupportsSeparateVolume) - mmcOneValue.Add("Drive supports separate volume per channel"); - - if(ftr.SupportsVCPS) - mmcOneValue.Add("Drive supports VCPS"); - - if(ftr.VolumeLevels.HasValue) - mmcOneValue.Add($"Drive has {ftr.VolumeLevels + 1} volume levels"); - - if(ftr.SupportsWriteProtectPAC) - mmcOneValue.Add("Drive supports reading/writing the Disc Write Protect PAC on BD-R/-RE media"); - - if(ftr.SupportsWriteInhibitDCB) - mmcOneValue.Add("Drive supports writing the Write Inhibit DCB on DVD+RW media"); - - mmcOneValue.Sort(); - mmcOneValue.Add(""); + if(ftr.BindingNonceBlocks.HasValue) + mmcOneValue.Add($"{ftr.BindingNonceBlocks} media blocks are required for the binding nonce"); } + + if(ftr.BlocksPerReadableUnit > 1) + mmcOneValue.Add($"{ftr.BlocksPerReadableUnit} logical blocks per media writable unit"); + + if(ftr.BufferUnderrunFreeInDVD) + mmcOneValue.Add("Drive supports zero loss linking writing DVDs"); + + if(ftr.BufferUnderrunFreeInSAO) + mmcOneValue.Add("Drive supports zero loss linking in Session at Once Mode"); + + if(ftr.BufferUnderrunFreeInTAO) + mmcOneValue.Add("Drive supports zero loss linking in Track at Once Mode"); + + if(ftr.CanAudioScan) + mmcOneValue.Add("Drive supports the SCAN command"); + + if(ftr.CanEject) + mmcOneValue.Add("Drive can eject media"); + + if(ftr.CanEraseSector) + mmcOneValue.Add("Drive supports media that require erasing before writing"); + + if(ftr.CanExpandBDRESpareArea) + mmcOneValue.Add("Drive can expand the spare area on a formatted BD-RE disc"); + + if(ftr.CanFormat) + mmcOneValue.Add("Drive can format media into logical blocks"); + + if(ftr.CanFormatBDREWithoutSpare) + mmcOneValue.Add("Drive can format BD-RE with no spares allocated"); + + if(ftr.CanFormatQCert) + mmcOneValue.Add("Drive can format BD-RE discs with quick certification"); + + if(ftr.CanFormatCert) + mmcOneValue.Add("Drive can format BD-RE discs with full certification"); + + if(ftr.CanFormatFRF) + mmcOneValue.Add("Drive can fast re-format BD-RE discs"); + + if(ftr.CanFormatRRM) + mmcOneValue.Add("Drive can format BD-R discs with RRM format"); + + if(ftr.CanLoad) + mmcOneValue.Add("Drive can load media"); + + if(ftr.CanMuteSeparateChannels) + mmcOneValue.Add("Drive is able to mute channels separately"); + + if(ftr.CanOverwriteSAOTrack) + mmcOneValue.Add("Drive can overwrite a SAO track with another in CD-RWs"); + + if(ftr.CanOverwriteTAOTrack) + mmcOneValue.Add("Drive can overwrite a TAO track with another in CD-RWs"); + + if(ftr.CanPlayCDAudio) + mmcOneValue.Add("Drive has an analogue audio output"); + + if(ftr.CanPseudoOverwriteBDR) + mmcOneValue.Add("Drive can write BD-R on Pseudo-OverWrite SRM mode"); + + if(ftr.CanReadAllDualR) + mmcOneValue.Add("Drive can read DVD-R DL from all recording modes"); + + if(ftr.CanReadAllDualRW) + mmcOneValue.Add("Drive can read DVD-RW DL from all recording modes"); + + if(ftr.CanReadBD) + mmcOneValue.Add("Drive can read BD-ROM"); + + if(ftr.CanReadBDR) + mmcOneValue.Add("Drive can read BD-R Ver.1"); + + if(ftr.CanReadBDRE1) + mmcOneValue.Add("Drive can read BD-RE Ver.1"); + + if(ftr.CanReadBDRE2) + mmcOneValue.Add("Drive can read BD-RE Ver.2"); + + if(ftr.CanReadBDROM) + mmcOneValue.Add("Drive can read BD-ROM Ver.1"); + + if(ftr.CanReadBluBCA) + mmcOneValue.Add("Drive can read BD's Burst Cutting Area"); + + if(ftr.CanReadCD) + mmcOneValue.Add("Drive can read CD-ROM"); + + if(ftr.CanWriteCDMRW && + ftr.CanReadDVDPlusMRW && + ftr.CanWriteDVDPlusMRW) + mmcOneValue.Add("Drive can read and write CD-MRW and DVD+MRW"); + else if(ftr.CanReadDVDPlusMRW && + ftr.CanWriteDVDPlusMRW) + mmcOneValue.Add("Drive can read and write DVD+MRW"); + else if(ftr.CanWriteCDMRW && + ftr.CanReadDVDPlusMRW) + mmcOneValue.Add("Drive and read DVD+MRW and read and write CD-MRW"); + else if(ftr.CanWriteCDMRW) + mmcOneValue.Add("Drive can read and write CD-MRW"); + else if(ftr.CanReadDVDPlusMRW) + mmcOneValue.Add("Drive can read CD-MRW and DVD+MRW"); + else if(ftr.CanReadCDMRW) + mmcOneValue.Add("Drive can read CD-MRW"); + + if(ftr.CanReadCPRM_MKB) + mmcOneValue.Add("Drive supports reading Media Key Block of CPRM"); + + if(ftr.CanReadDDCD) + mmcOneValue.Add("Drive can read DDCDs"); + + if(ftr.CanReadDVD) + mmcOneValue.Add("Drive can read DVD"); + + if(ftr.CanWriteDVDPlusRW) + mmcOneValue.Add("Drive can read and write DVD+RW"); + else if(ftr.CanReadDVDPlusRW) + mmcOneValue.Add("Drive can read DVD+RW"); + + if(ftr.CanWriteDVDPlusR) + mmcOneValue.Add("Drive can read and write DVD+R"); + else if(ftr.CanReadDVDPlusR) + mmcOneValue.Add("Drive can read DVD+R"); + + if(ftr.CanWriteDVDPlusRDL) + mmcOneValue.Add("Drive can read and write DVD+R DL"); + else if(ftr.CanReadDVDPlusRDL) + mmcOneValue.Add("Drive can read DVD+R DL"); + + if(ftr.CanReadDriveAACSCertificate) + mmcOneValue.Add("Drive supports reading the Drive Certificate"); + + if(ftr.CanReadHDDVD && + ftr.CanReadHDDVDR && + ftr.CanReadHDDVDRAM) + mmcOneValue.Add("Drive can read HD DVD-ROM, HD DVD-RW, HD DVD-R and HD DVD-RAM"); + else if(ftr.CanReadHDDVD && + ftr.CanReadHDDVDR) + mmcOneValue.Add("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-R"); + else if(ftr.CanReadHDDVD && + ftr.CanReadHDDVDRAM) + mmcOneValue.Add("Drive can read HD DVD-ROM, HD DVD-RW and HD DVD-RAM"); + else if(ftr.CanReadHDDVD) + mmcOneValue.Add("Drive can read HD DVD-ROM and HD DVD-RW"); + + if(ftr.CanReadLeadInCDText) + mmcOneValue.Add("Drive can return CD-Text from Lead-In"); + + if(ftr.CanReadOldBDR) + mmcOneValue.Add("Drive can read BD-R pre-1.0"); + + if(ftr.CanReadOldBDRE) + mmcOneValue.Add("Drive can read BD-RE pre-1.0"); + + if(ftr.CanReadOldBDROM) + mmcOneValue.Add("Drive can read BD-ROM pre-1.0"); + + if(ftr.CanReadSpareAreaInformation) + mmcOneValue.Add("Drive can return Spare Area Information"); + + if(ftr.CanReportDriveSerial) + mmcOneValue.Add("Drive is to report drive serial number"); + + if(ftr.CanReportMediaSerial) + mmcOneValue.Add("Drive is to read media serial number"); + + if(ftr.CanTestWriteDDCDR) + mmcOneValue.Add("Drive can do a test writing with DDCD-R"); + + if(ftr.CanTestWriteDVD) + mmcOneValue.Add("Drive can do a test writing with DVDs"); + + if(ftr.CanTestWriteInSAO) + mmcOneValue.Add("Drive can do a test writing in Session at Once Mode"); + + if(ftr.CanTestWriteInTAO) + mmcOneValue.Add("Drive can do a test writing in Track at Once Mode"); + + if(ftr.CanUpgradeFirmware) + mmcOneValue.Add("Drive supports Microcode Upgrade"); + + if(ftr.ErrorRecoveryPage) + mmcOneValue.Add("Drive shall report Read/Write Error Recovery mode page"); + + if(ftr.Locked) + mmcOneValue.Add("Drive can lock media"); + + if(ftr.LogicalBlockSize > 0) + mmcOneValue.Add($"{ftr.LogicalBlockSize} bytes per logical block"); + + if(ftr.MultiRead) + mmcOneValue. + Add("Drive claims capability to read all CD formats according to OSTA Multi-Read Specification"); + + if(ftr.PhysicalInterfaceStandard.HasValue) + switch(ftr.PhysicalInterfaceStandard) + { + case PhysicalInterfaces.Unspecified: + mmcOneValue.Add("Drive uses an unspecified physical interface"); + + break; + case PhysicalInterfaces.SCSI: + mmcOneValue.Add("Drive uses SCSI interface"); + + break; + case PhysicalInterfaces.ATAPI: + mmcOneValue.Add("Drive uses ATAPI interface"); + + break; + case PhysicalInterfaces.IEEE1394: + mmcOneValue.Add("Drive uses IEEE-1394 interface"); + + break; + case PhysicalInterfaces.IEEE1394A: + mmcOneValue.Add("Drive uses IEEE-1394A interface"); + + break; + case PhysicalInterfaces.FC: + mmcOneValue.Add("Drive uses Fibre Channel interface"); + + break; + case PhysicalInterfaces.IEEE1394B: + mmcOneValue.Add("Drive uses IEEE-1394B interface"); + + break; + case PhysicalInterfaces.SerialATAPI: + mmcOneValue.Add("Drive uses Serial ATAPI interface"); + + break; + case PhysicalInterfaces.USB: + mmcOneValue.Add("Drive uses USB interface"); + + break; + case PhysicalInterfaces.Vendor: + mmcOneValue.Add("Drive uses a vendor unique interface"); + + break; + default: + mmcOneValue. + Add($"Drive uses an unknown interface with code {(uint)ftr.PhysicalInterfaceStandard}"); + + break; + } + + if(ftr.PreventJumper) + mmcOneValue.Add("Drive power ups locked"); + + if(ftr.SupportsBusEncryption) + mmcOneValue.Add("Drive supports bus encryption"); + + if(ftr.CanWriteBD) + mmcOneValue.Add("Drive can write BD-R or BD-RE"); + + if(ftr.CanWriteBDR) + mmcOneValue.Add("Drive can write BD-R Ver.1"); + + if(ftr.CanWriteBDRE1) + mmcOneValue.Add("Drive can write BD-RE Ver.1"); + + if(ftr.CanWriteBDRE2) + mmcOneValue.Add("Drive can write BD-RE Ver.2"); + + if(ftr.CanWriteBusEncryptedBlocks) + mmcOneValue.Add("Drive supports writing with bus encryption"); + + if(ftr.CanWriteCDRW) + mmcOneValue.Add("Drive can write CD-RW"); + + if(ftr.CanWriteCDRWCAV) + mmcOneValue.Add("Drive can write High-Speed CD-RW"); + + if(ftr.CanWriteCDSAO && + !ftr.CanWriteRaw) + mmcOneValue.Add("Drive can write CDs in Session at Once Mode:"); + else if(!ftr.CanWriteCDSAO && + ftr.CanWriteRaw) + mmcOneValue.Add("Drive can write CDs in raw Mode:"); + else if(ftr.CanWriteCDSAO && + ftr.CanWriteRaw) + mmcOneValue.Add("Drive can write CDs in Session at Once and in Raw Modes:"); + + if(ftr.CanWriteCDTAO) + mmcOneValue.Add("Drive can write CDs in Track at Once Mode:"); + + if(ftr.CanWriteCSSManagedDVD) + mmcOneValue.Add("Drive can write CSS managed DVDs"); + + if(ftr.CanWriteDDCDR) + mmcOneValue.Add("Drive supports writing DDCD-R"); + + if(ftr.CanWriteDDCDRW) + mmcOneValue.Add("Drive supports writing DDCD-RW"); + + if(ftr.CanWriteDVDPlusRWDL) + mmcOneValue.Add("Drive can read and write DVD+RW DL"); + else if(ftr.CanReadDVDPlusRWDL) + mmcOneValue.Add("Drive can read DVD+RW DL"); + + if(ftr.CanWriteDVDR && + ftr.CanWriteDVDRW && + ftr.CanWriteDVDRDL) + mmcOneValue.Add("Drive supports writing DVD-R, DVD-RW and DVD-R DL"); + else if(ftr.CanWriteDVDR && + ftr.CanWriteDVDRDL) + mmcOneValue.Add("Drive supports writing DVD-R and DVD-R DL"); + else if(ftr.CanWriteDVDR && + ftr.CanWriteDVDRW) + mmcOneValue.Add("Drive supports writing DVD-R and DVD-RW"); + else if(ftr.CanWriteDVDR) + mmcOneValue.Add("Drive supports writing DVD-R"); + + if(ftr.CanWriteHDDVDR && + ftr.CanWriteHDDVDRAM) + mmcOneValue.Add("Drive can write HD DVD-RW, HD DVD-R and HD DVD-RAM"); + else if(ftr.CanWriteHDDVDR) + mmcOneValue.Add("Drive can write HD DVD-RW and HD DVD-R"); + else if(ftr.CanWriteHDDVDRAM) + mmcOneValue.Add("Drive can write HD DVD-RW and HD DVD-RAM"); + + // TODO: Write HD DVD-RW + /* + else + mmcOneValue.Add("Drive can write HD DVD-RW"); + */ + if(ftr.CanWriteOldBDR) + mmcOneValue.Add("Drive can write BD-R pre-1.0"); + + if(ftr.CanWriteOldBDRE) + mmcOneValue.Add("Drive can write BD-RE pre-1.0"); + + if(ftr.CanWriteRWSubchannelInTAO) + { + mmcOneValue.Add("Drive can write user provided data in the R-W subchannels in Track at Once Mode"); + + if(ftr.CanWriteRawSubchannelInTAO) + mmcOneValue.Add("Drive accepts RAW R-W subchannel data in Track at Once Mode"); + + if(ftr.CanWritePackedSubchannelInTAO) + mmcOneValue.Add("Drive accepts Packed R-W subchannel data in Track at Once Mode"); + } + + if(ftr.CanWriteRWSubchannelInSAO) + mmcOneValue.Add("Drive can write user provided data in the R-W subchannels in Session at Once Mode"); + + if(ftr.CanWriteRaw && + ftr.CanWriteRawMultiSession) + mmcOneValue.Add("Drive can write multi-session CDs in raw mode"); + + if(ftr.EmbeddedChanger) + { + mmcOneValue.Add("Drive contains an embedded changer"); + + if(ftr.ChangerIsSideChangeCapable) + mmcOneValue.Add("Drive can change disc side"); + + if(ftr.ChangerSupportsDiscPresent) + mmcOneValue.Add("Drive is able to report slots contents after a reset or change"); + + mmcOneValue.Add($"Drive has {ftr.ChangerSlots + 1} slots"); + } + + if(ftr.SupportsCSS && + ftr.CSSVersion.HasValue) + mmcOneValue.Add($"Drive supports DVD CSS/CPPM version {ftr.CSSVersion}"); + else if(ftr.SupportsCSS) + mmcOneValue.Add("Drive supports DVD CSS/CPRM"); + + if(ftr.SupportsCPRM && + ftr.CPRMVersion.HasValue) + mmcOneValue.Add($"Drive supports DVD CPRM version {ftr.CPRMVersion}"); + else if(ftr.SupportsCPRM) + mmcOneValue.Add("Drive supports DVD CPRM"); + + if(ftr.DBML) + mmcOneValue.Add("Drive reports Device Busy Class events during medium loading/unloading"); + + if(ftr.DVDMultiRead) + mmcOneValue.Add("Drive conforms to DVD Multi Drive Read-only Specifications"); + + if(ftr.FirmwareDate.HasValue) + mmcOneValue.Add($"Drive firmware is dated {ftr.FirmwareDate}"); + + if(ftr.SupportsC2) + mmcOneValue.Add("Drive supports C2 Error Pointers"); + + if(ftr.SupportsDAP) + mmcOneValue.Add("Drive supports the DAP bit in the READ CD and READ CD MSF commands"); + + if(ftr.SupportsDeviceBusyEvent) + mmcOneValue.Add("Drive supports Device Busy events"); + + if(ftr.LoadingMechanismType.HasValue) + switch(ftr.LoadingMechanismType) + { + case 0: + mmcOneValue.Add("Drive uses media caddy"); + + break; + case 1: + mmcOneValue.Add("Drive uses a tray"); + + break; + case 2: + mmcOneValue.Add("Drive is pop-up"); + + break; + case 4: + mmcOneValue.Add("Drive is a changer with individually changeable discs"); + + break; + case 5: + mmcOneValue.Add("Drive is a changer using cartridges"); + + break; + default: + mmcOneValue.Add($"Drive uses unknown loading mechanism type {ftr.LoadingMechanismType}"); + + break; + } + + if(ftr.SupportsHybridDiscs) + mmcOneValue.Add("Drive is able to access Hybrid discs"); + + if(ftr.SupportsModePage1Ch) + mmcOneValue.Add("Drive supports the Informational Exceptions Control mode page 1Ch"); + + if(ftr.SupportsOSSC) + mmcOneValue.Add("Drive supports the Trusted Computing Group Optical Security Subsystem Class"); + + if(ftr.SupportsPWP) + mmcOneValue.Add("Drive supports set/release of PWP status"); + + if(ftr.SupportsSWPP) + mmcOneValue.Add("Drive supports the SWPP bit of the Timeout and Protect mode page"); + + if(ftr.SupportsSecurDisc) + mmcOneValue.Add("Drive supports SecurDisc"); + + if(ftr.SupportsSeparateVolume) + mmcOneValue.Add("Drive supports separate volume per channel"); + + if(ftr.SupportsVCPS) + mmcOneValue.Add("Drive supports VCPS"); + + if(ftr.VolumeLevels.HasValue) + mmcOneValue.Add($"Drive has {ftr.VolumeLevels + 1} volume levels"); + + if(ftr.SupportsWriteProtectPAC) + mmcOneValue.Add("Drive supports reading/writing the Disc Write Protect PAC on BD-R/-RE media"); + + if(ftr.SupportsWriteInhibitDCB) + mmcOneValue.Add("Drive supports writing the Write Inhibit DCB on DVD+RW media"); + + mmcOneValue.Sort(); + mmcOneValue.Add(""); } } \ No newline at end of file diff --git a/Aaru.Server/Core/ScsiMmcMode.cs b/Aaru.Server/Core/ScsiMmcMode.cs index 3e7b32c7..f1a7ecce 100644 --- a/Aaru.Server/Core/ScsiMmcMode.cs +++ b/Aaru.Server/Core/ScsiMmcMode.cs @@ -34,196 +34,195 @@ using System.Collections.Generic; using System.Linq; using Aaru.CommonTypes.Structs.Devices.SCSI.Modes; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class ScsiMmcMode { - public static class ScsiMmcMode + /// + /// Takes the MODE PAGE 2Ah part of a device report and prints it as a list of values to be sequenced by ASP.NET + /// in the rendering + /// + /// MODE PAGE 2Ah part of the report + /// List to put the values on + public static void Report(ModePage_2A mode, ref List mmcOneValue) { - /// - /// Takes the MODE PAGE 2Ah part of a device report and prints it as a list of values to be sequenced by ASP.NET - /// in the rendering - /// - /// MODE PAGE 2Ah part of the report - /// List to put the values on - public static void Report(ModePage_2A mode, ref List mmcOneValue) + if(mode.AudioPlay) + mmcOneValue.Add("Drive can play audio"); + + if(mode.Mode2Form1) + mmcOneValue.Add("Drive can read sectors in Mode 2 Form 1 format"); + + if(mode.Mode2Form2) + mmcOneValue.Add("Drive can read sectors in Mode 2 Form 2 format"); + + if(mode.MultiSession) + mmcOneValue.Add("Drive supports multi-session discs and/or Photo-CD"); + + if(mode.CDDACommand) + mmcOneValue.Add("Drive can read digital audio"); + + if(mode.AccurateCDDA) + mmcOneValue.Add("Drive can continue from streaming loss"); + + if(mode.Subchannel) + mmcOneValue.Add("Drive can read uncorrected and interleaved R-W subchannels"); + + if(mode.DeinterlaveSubchannel) + mmcOneValue.Add("Drive can read, deinterleave and correct R-W subchannels"); + + if(mode.C2Pointer) + mmcOneValue.Add("Drive supports C2 pointers"); + + if(mode.UPC) + mmcOneValue.Add("Drive can read Media Catalogue Number"); + + if(mode.ISRC) + mmcOneValue.Add("Drive can read ISRC"); + + switch(mode.LoadingMechanism) { - if(mode.AudioPlay) - mmcOneValue.Add("Drive can play audio"); + case 0: + mmcOneValue.Add("Drive uses media caddy"); - if(mode.Mode2Form1) - mmcOneValue.Add("Drive can read sectors in Mode 2 Form 1 format"); + break; + case 1: + mmcOneValue.Add("Drive uses a tray"); - if(mode.Mode2Form2) - mmcOneValue.Add("Drive can read sectors in Mode 2 Form 2 format"); + break; + case 2: + mmcOneValue.Add("Drive is pop-up"); - if(mode.MultiSession) - mmcOneValue.Add("Drive supports multi-session discs and/or Photo-CD"); + break; + case 4: + mmcOneValue.Add("Drive is a changer with individually changeable discs"); - if(mode.CDDACommand) - mmcOneValue.Add("Drive can read digital audio"); + break; + case 5: + mmcOneValue.Add("Drive is a changer using cartridges"); - if(mode.AccurateCDDA) - mmcOneValue.Add("Drive can continue from streaming loss"); + break; + default: + mmcOneValue.Add($"Drive uses unknown loading mechanism type {mode.LoadingMechanism}"); - if(mode.Subchannel) - mmcOneValue.Add("Drive can read uncorrected and interleaved R-W subchannels"); - - if(mode.DeinterlaveSubchannel) - mmcOneValue.Add("Drive can read, deinterleave and correct R-W subchannels"); - - if(mode.C2Pointer) - mmcOneValue.Add("Drive supports C2 pointers"); - - if(mode.UPC) - mmcOneValue.Add("Drive can read Media Catalogue Number"); - - if(mode.ISRC) - mmcOneValue.Add("Drive can read ISRC"); - - switch(mode.LoadingMechanism) - { - case 0: - mmcOneValue.Add("Drive uses media caddy"); - - break; - case 1: - mmcOneValue.Add("Drive uses a tray"); - - break; - case 2: - mmcOneValue.Add("Drive is pop-up"); - - break; - case 4: - mmcOneValue.Add("Drive is a changer with individually changeable discs"); - - break; - case 5: - mmcOneValue.Add("Drive is a changer using cartridges"); - - break; - default: - mmcOneValue.Add($"Drive uses unknown loading mechanism type {mode.LoadingMechanism}"); - - break; - } - - if(mode.Lock) - mmcOneValue.Add("Drive can lock media"); - - if(mode.PreventJumper) - { - mmcOneValue.Add("Drive power ups locked"); - - mmcOneValue.Add(mode.LockState ? "Drive is locked, media cannot be ejected or inserted" - : "Drive is not locked, media can be ejected and inserted"); - } - else - { - mmcOneValue.Add(mode.LockState - ? "Drive is locked, media cannot be ejected, but if empty, can be inserted" - : "Drive is not locked, media can be ejected and inserted"); - } - - if(mode.Eject) - mmcOneValue.Add("Drive can eject media"); - - if(mode.SeparateChannelMute) - mmcOneValue.Add("Each channel can be muted independently"); - - if(mode.SeparateChannelVolume) - mmcOneValue.Add("Each channel's volume can be controlled independently"); - - if(mode.SupportedVolumeLevels > 0) - mmcOneValue.Add($"Drive supports {mode.SupportedVolumeLevels} volume levels"); - - if(mode.BufferSize > 0) - mmcOneValue.Add($"Drive has {mode.BufferSize} Kbyte of buffer"); - - if(mode.MaximumSpeed > 0) - mmcOneValue.Add($"Drive's maximum reading speed is {mode.MaximumSpeed} Kbyte/sec."); - - if(mode.CurrentSpeed > 0) - mmcOneValue.Add($"Drive's current reading speed is {mode.CurrentSpeed} Kbyte/sec."); - - if(mode.ReadCDR) - { - mmcOneValue.Add(mode.WriteCDR ? "Drive can read and write CD-R" : "Drive can read CD-R"); - - if(mode.Method2) - mmcOneValue.Add("Drive supports reading CD-R packet media"); - } - - if(mode.ReadCDRW) - mmcOneValue.Add(mode.WriteCDRW ? "Drive can read and write CD-RW" : "Drive can read CD-RW"); - - if(mode.ReadDVDROM) - mmcOneValue.Add("Drive can read DVD-ROM"); - - if(mode.ReadDVDR) - mmcOneValue.Add(mode.WriteDVDR ? "Drive can read and write DVD-R" : "Drive can read DVD-R"); - - if(mode.ReadDVDRAM) - mmcOneValue.Add(mode.WriteDVDRAM ? "Drive can read and write DVD-RAM" : "Drive can read DVD-RAM"); - - if(mode.Composite) - mmcOneValue.Add("Drive can deliver a composite audio and video data stream"); - - if(mode.DigitalPort1) - mmcOneValue.Add("Drive supports IEC-958 digital output on port 1"); - - if(mode.DigitalPort2) - mmcOneValue.Add("Drive supports IEC-958 digital output on port 2"); - - if(mode.SDP) - mmcOneValue.Add("Drive contains a changer that can report the exact contents of the slots"); - - if(mode.CurrentWriteSpeedSelected > 0) - { - if(mode.RotationControlSelected == 0) - mmcOneValue. - Add($"Drive's current writing speed is {mode.CurrentWriteSpeedSelected} Kbyte/sec. in CLV mode"); - else if(mode.RotationControlSelected == 1) - mmcOneValue. - Add($"Drive's current writing speed is {mode.CurrentWriteSpeedSelected} Kbyte/sec. in pure CAV mode"); - } - else - { - if(mode.MaxWriteSpeed > 0) - mmcOneValue.Add($"Drive's maximum writing speed is {mode.MaxWriteSpeed} Kbyte/sec."); - - if(mode.CurrentWriteSpeed > 0) - mmcOneValue.Add($"Drive's current writing speed is {mode.CurrentWriteSpeed} Kbyte/sec."); - } - - if(mode.WriteSpeedPerformanceDescriptors != null) - foreach(ModePage_2A_WriteDescriptor descriptor in - mode.WriteSpeedPerformanceDescriptors.Where(descriptor => descriptor.WriteSpeed > 0)) - if(descriptor.RotationControl == 0) - mmcOneValue.Add($"Drive supports writing at {descriptor.WriteSpeed} Kbyte/sec. in CLV mode"); - else if(descriptor.RotationControl == 1) - mmcOneValue. - Add($"Drive supports writing at is {descriptor.WriteSpeed} Kbyte/sec. in pure CAV mode"); - - if(mode.TestWrite) - mmcOneValue.Add("Drive supports test writing"); - - if(mode.ReadBarcode) - mmcOneValue.Add("Drive can read barcode"); - - if(mode.SCC) - mmcOneValue.Add("Drive can read both sides of a disc"); - - if(mode.LeadInPW) - mmcOneValue.Add("Drive an read raw R-W subchannel from the Lead-In"); - - if(mode.CMRSupported == 1) - mmcOneValue.Add("Drive supports DVD CSS and/or DVD CPPM"); - - if(mode.BUF) - mmcOneValue.Add("Drive supports buffer under-run free recording"); - - mmcOneValue.Sort(); - mmcOneValue.Add(""); + break; } + + if(mode.Lock) + mmcOneValue.Add("Drive can lock media"); + + if(mode.PreventJumper) + { + mmcOneValue.Add("Drive power ups locked"); + + mmcOneValue.Add(mode.LockState ? "Drive is locked, media cannot be ejected or inserted" + : "Drive is not locked, media can be ejected and inserted"); + } + else + { + mmcOneValue.Add(mode.LockState + ? "Drive is locked, media cannot be ejected, but if empty, can be inserted" + : "Drive is not locked, media can be ejected and inserted"); + } + + if(mode.Eject) + mmcOneValue.Add("Drive can eject media"); + + if(mode.SeparateChannelMute) + mmcOneValue.Add("Each channel can be muted independently"); + + if(mode.SeparateChannelVolume) + mmcOneValue.Add("Each channel's volume can be controlled independently"); + + if(mode.SupportedVolumeLevels > 0) + mmcOneValue.Add($"Drive supports {mode.SupportedVolumeLevels} volume levels"); + + if(mode.BufferSize > 0) + mmcOneValue.Add($"Drive has {mode.BufferSize} Kbyte of buffer"); + + if(mode.MaximumSpeed > 0) + mmcOneValue.Add($"Drive's maximum reading speed is {mode.MaximumSpeed} Kbyte/sec."); + + if(mode.CurrentSpeed > 0) + mmcOneValue.Add($"Drive's current reading speed is {mode.CurrentSpeed} Kbyte/sec."); + + if(mode.ReadCDR) + { + mmcOneValue.Add(mode.WriteCDR ? "Drive can read and write CD-R" : "Drive can read CD-R"); + + if(mode.Method2) + mmcOneValue.Add("Drive supports reading CD-R packet media"); + } + + if(mode.ReadCDRW) + mmcOneValue.Add(mode.WriteCDRW ? "Drive can read and write CD-RW" : "Drive can read CD-RW"); + + if(mode.ReadDVDROM) + mmcOneValue.Add("Drive can read DVD-ROM"); + + if(mode.ReadDVDR) + mmcOneValue.Add(mode.WriteDVDR ? "Drive can read and write DVD-R" : "Drive can read DVD-R"); + + if(mode.ReadDVDRAM) + mmcOneValue.Add(mode.WriteDVDRAM ? "Drive can read and write DVD-RAM" : "Drive can read DVD-RAM"); + + if(mode.Composite) + mmcOneValue.Add("Drive can deliver a composite audio and video data stream"); + + if(mode.DigitalPort1) + mmcOneValue.Add("Drive supports IEC-958 digital output on port 1"); + + if(mode.DigitalPort2) + mmcOneValue.Add("Drive supports IEC-958 digital output on port 2"); + + if(mode.SDP) + mmcOneValue.Add("Drive contains a changer that can report the exact contents of the slots"); + + if(mode.CurrentWriteSpeedSelected > 0) + { + if(mode.RotationControlSelected == 0) + mmcOneValue. + Add($"Drive's current writing speed is {mode.CurrentWriteSpeedSelected} Kbyte/sec. in CLV mode"); + else if(mode.RotationControlSelected == 1) + mmcOneValue. + Add($"Drive's current writing speed is {mode.CurrentWriteSpeedSelected} Kbyte/sec. in pure CAV mode"); + } + else + { + if(mode.MaxWriteSpeed > 0) + mmcOneValue.Add($"Drive's maximum writing speed is {mode.MaxWriteSpeed} Kbyte/sec."); + + if(mode.CurrentWriteSpeed > 0) + mmcOneValue.Add($"Drive's current writing speed is {mode.CurrentWriteSpeed} Kbyte/sec."); + } + + if(mode.WriteSpeedPerformanceDescriptors != null) + foreach(ModePage_2A_WriteDescriptor descriptor in + mode.WriteSpeedPerformanceDescriptors.Where(descriptor => descriptor.WriteSpeed > 0)) + if(descriptor.RotationControl == 0) + mmcOneValue.Add($"Drive supports writing at {descriptor.WriteSpeed} Kbyte/sec. in CLV mode"); + else if(descriptor.RotationControl == 1) + mmcOneValue. + Add($"Drive supports writing at is {descriptor.WriteSpeed} Kbyte/sec. in pure CAV mode"); + + if(mode.TestWrite) + mmcOneValue.Add("Drive supports test writing"); + + if(mode.ReadBarcode) + mmcOneValue.Add("Drive can read barcode"); + + if(mode.SCC) + mmcOneValue.Add("Drive can read both sides of a disc"); + + if(mode.LeadInPW) + mmcOneValue.Add("Drive an read raw R-W subchannel from the Lead-In"); + + if(mode.CMRSupported == 1) + mmcOneValue.Add("Drive supports DVD CSS and/or DVD CPPM"); + + if(mode.BUF) + mmcOneValue.Add("Drive supports buffer under-run free recording"); + + mmcOneValue.Sort(); + mmcOneValue.Add(""); } } \ No newline at end of file diff --git a/Aaru.Server/Core/ScsiModeSense.cs b/Aaru.Server/Core/ScsiModeSense.cs index 425d3d63..6a1a7dde 100644 --- a/Aaru.Server/Core/ScsiModeSense.cs +++ b/Aaru.Server/Core/ScsiModeSense.cs @@ -35,396 +35,395 @@ using Aaru.CommonTypes.Metadata; using Aaru.CommonTypes.Structs.Devices.SCSI; using Aaru.Decoders.SCSI; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class ScsiModeSense { - public static class ScsiModeSense + /// + /// Takes the MODE PAGEs part of a device report and prints it as a list of values and another list of key=value + /// pairs to be sequenced by ASP.NET in the rendering + /// + /// MODE PAGEs part of a device report + /// SCSI vendor string + /// SCSI peripheral device type + /// List to put values on + /// List to put key=value pairs on + public static void Report(ScsiMode modeSense, string vendor, PeripheralDeviceTypes deviceType, + ref List scsiOneValue, ref Dictionary modePages) { - /// - /// Takes the MODE PAGEs part of a device report and prints it as a list of values and another list of key=value - /// pairs to be sequenced by ASP.NET in the rendering - /// - /// MODE PAGEs part of a device report - /// SCSI vendor string - /// SCSI peripheral device type - /// List to put values on - /// List to put key=value pairs on - public static void Report(ScsiMode modeSense, string vendor, PeripheralDeviceTypes deviceType, - ref List scsiOneValue, ref Dictionary modePages) - { - if(modeSense.MediumType.HasValue) - scsiOneValue.Add($"Medium type is {modeSense.MediumType:X2}h"); + if(modeSense.MediumType.HasValue) + scsiOneValue.Add($"Medium type is {modeSense.MediumType:X2}h"); - if(modeSense.WriteProtected) - scsiOneValue.Add("Device is write protected."); + if(modeSense.WriteProtected) + scsiOneValue.Add("Device is write protected."); - if(modeSense.BlockDescriptors != null) - foreach(BlockDescriptor descriptor in modeSense.BlockDescriptors) - if(descriptor.Blocks.HasValue && - descriptor.BlockLength.HasValue) - scsiOneValue. - Add($"Density code {descriptor.Density:X2}h has {descriptor.Blocks} blocks of {descriptor.BlockLength} bytes each"); + if(modeSense.BlockDescriptors != null) + foreach(BlockDescriptor descriptor in modeSense.BlockDescriptors) + if(descriptor.Blocks.HasValue && + descriptor.BlockLength.HasValue) + scsiOneValue. + Add($"Density code {descriptor.Density:X2}h has {descriptor.Blocks} blocks of {descriptor.BlockLength} bytes each"); + else + scsiOneValue.Add($"Density code {descriptor.Density:X2}h"); + + if(modeSense.DPOandFUA) + scsiOneValue.Add("Drive supports DPO and FUA bits"); + + if(modeSense.BlankCheckEnabled) + scsiOneValue.Add("Blank checking during write is enabled"); + + if(modeSense.BufferedMode.HasValue) + switch(modeSense.BufferedMode) + { + case 0: + scsiOneValue.Add("Device writes directly to media"); + + break; + case 1: + scsiOneValue.Add("Device uses a write cache"); + + break; + case 2: + scsiOneValue.Add("Device uses a write cache but doesn't return until cache is flushed"); + + break; + default: + scsiOneValue.Add($"Unknown buffered mode code 0x{modeSense.BufferedMode:X2}"); + + break; + } + + if(modeSense.ModePages == null) + return; + + foreach(ScsiPage page in modeSense.ModePages) + switch(page.page) + { + case 0x00: + { + if(deviceType == PeripheralDeviceTypes.MultiMediaDevice && + page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_00_SFF(page.value)); else - scsiOneValue.Add($"Density code {descriptor.Density:X2}h"); - - if(modeSense.DPOandFUA) - scsiOneValue.Add("Drive supports DPO and FUA bits"); - - if(modeSense.BlankCheckEnabled) - scsiOneValue.Add("Blank checking during write is enabled"); - - if(modeSense.BufferedMode.HasValue) - switch(modeSense.BufferedMode) - { - case 0: - scsiOneValue.Add("Device writes directly to media"); - - break; - case 1: - scsiOneValue.Add("Device uses a write cache"); - - break; - case 2: - scsiOneValue.Add("Device uses a write cache but doesn't return until cache is flushed"); - - break; - default: - scsiOneValue.Add($"Unknown buffered mode code 0x{modeSense.BufferedMode:X2}"); - - break; - } - - if(modeSense.ModePages == null) - return; - - foreach(ScsiPage page in modeSense.ModePages) - switch(page.page) - { - case 0x00: - { - if(deviceType == PeripheralDeviceTypes.MultiMediaDevice && - page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_00_SFF(page.value)); - else - modePages. - Add(page.subpage != 0 ? $"MODE page {page.page:X2}h subpage {page.subpage:X2}h" : $"MODE page {page.page:X2}h", - "Unknown vendor mode page"); - - break; - } - case 0x01: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", - deviceType == PeripheralDeviceTypes.MultiMediaDevice - ? Modes.PrettifyModePage_01_MMC(page.value) - : Modes.PrettifyModePage_01(page.value)); - else - goto default; - - break; - } - case 0x02: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_02(page.value)); - else - goto default; - - break; - } - case 0x03: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_03(page.value)); - else - goto default; - - break; - } - case 0x04: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_04(page.value)); - else - goto default; - - break; - } - case 0x05: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_05(page.value)); - else - goto default; - - break; - } - case 0x06: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_06(page.value)); - else - goto default; - - break; - } - case 0x07: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", - deviceType == PeripheralDeviceTypes.MultiMediaDevice - ? Modes.PrettifyModePage_07_MMC(page.value) - : Modes.PrettifyModePage_07(page.value)); - else - goto default; - - break; - } - case 0x08: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_08(page.value)); - else - goto default; - - break; - } - case 0x0A: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0A(page.value)); - else if(page.subpage == 1) - modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h", - Modes.PrettifyModePage_0A_S01(page.value)); - else - goto default; - - break; - } - case 0x0B: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0B(page.value)); - else - goto default; - - break; - } - case 0x0D: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0D(page.value)); - else - goto default; - - break; - } - case 0x0E: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0E(page.value)); - else - goto default; - - break; - } - case 0x0F: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0F(page.value)); - else - goto default; - - break; - } - case 0x10: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", - deviceType == PeripheralDeviceTypes.SequentialAccess - ? Modes.PrettifyModePage_10_SSC(page.value) - : Modes.PrettifyModePage_10(page.value)); - else - goto default; - - break; - } - case 0x11: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_11(page.value)); - else - goto default; - - break; - } - case 0x12: - case 0x13: - case 0x14: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_12_13_14(page.value)); - else - goto default; - - break; - } - case 0x1A: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1A(page.value)); - else if(page.subpage == 1) - modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h", - Modes.PrettifyModePage_1A_S01(page.value)); - else - goto default; - - break; - } - case 0x1B: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1B(page.value)); - else - goto default; - - break; - } - case 0x1C: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", - deviceType == PeripheralDeviceTypes.MultiMediaDevice - ? Modes.PrettifyModePage_1C_SFF(page.value) - : Modes.PrettifyModePage_1C(page.value)); - else if(page.subpage == 1) - modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h", - Modes.PrettifyModePage_1C_S01(page.value)); - else - goto default; - - break; - } - case 0x1D: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1D(page.value)); - else - goto default; - - break; - } - case 0x21: - { - if(vendor == "CERTANCE") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyCertanceModePage_21(page.value)); - else - goto default; - - break; - } - case 0x22: - { - if(vendor == "CERTANCE") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyCertanceModePage_22(page.value)); - else - goto default; - - break; - } - case 0x24: - { - if(vendor == "IBM") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_24(page.value)); - else - goto default; - - break; - } - case 0x2A: - { - if(page.subpage == 0) - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_2A(page.value)); - else - goto default; - - break; - } - case 0x2F: - { - if(vendor == "IBM") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_2F(page.value)); - else - goto default; - - break; - } - case 0x30: - { - if(Modes.IsAppleModePage_30(page.value)) - modePages.Add("MODE page 30h", "Drive identifies as an Apple OEM drive"); - else - goto default; - - break; - } - case 0x3B: - { - if(vendor == "HP") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3B(page.value)); - else - goto default; - - break; - } - case 0x3C: - { - if(vendor == "HP") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3C(page.value)); - else - goto default; - - break; - } - case 0x3D: - { - if(vendor == "IBM") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_3D(page.value)); - else if(vendor == "HP") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3D(page.value)); - else - goto default; - - break; - } - case 0x3E: - { - if(vendor == "FUJITSU") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyFujitsuModePage_3E(page.value)); - else if(vendor == "HP") - modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3E(page.value)); - else - goto default; - - break; - } - default: - { modePages. Add(page.subpage != 0 ? $"MODE page {page.page:X2}h subpage {page.subpage:X2}h" : $"MODE page {page.page:X2}h", - "Unknown mode page"); - } + "Unknown vendor mode page"); - break; + break; + } + case 0x01: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", + deviceType == PeripheralDeviceTypes.MultiMediaDevice + ? Modes.PrettifyModePage_01_MMC(page.value) + : Modes.PrettifyModePage_01(page.value)); + else + goto default; + + break; + } + case 0x02: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_02(page.value)); + else + goto default; + + break; + } + case 0x03: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_03(page.value)); + else + goto default; + + break; + } + case 0x04: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_04(page.value)); + else + goto default; + + break; + } + case 0x05: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_05(page.value)); + else + goto default; + + break; + } + case 0x06: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_06(page.value)); + else + goto default; + + break; + } + case 0x07: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", + deviceType == PeripheralDeviceTypes.MultiMediaDevice + ? Modes.PrettifyModePage_07_MMC(page.value) + : Modes.PrettifyModePage_07(page.value)); + else + goto default; + + break; + } + case 0x08: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_08(page.value)); + else + goto default; + + break; + } + case 0x0A: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0A(page.value)); + else if(page.subpage == 1) + modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h", + Modes.PrettifyModePage_0A_S01(page.value)); + else + goto default; + + break; + } + case 0x0B: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0B(page.value)); + else + goto default; + + break; + } + case 0x0D: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0D(page.value)); + else + goto default; + + break; + } + case 0x0E: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0E(page.value)); + else + goto default; + + break; + } + case 0x0F: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_0F(page.value)); + else + goto default; + + break; + } + case 0x10: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", + deviceType == PeripheralDeviceTypes.SequentialAccess + ? Modes.PrettifyModePage_10_SSC(page.value) + : Modes.PrettifyModePage_10(page.value)); + else + goto default; + + break; + } + case 0x11: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_11(page.value)); + else + goto default; + + break; + } + case 0x12: + case 0x13: + case 0x14: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_12_13_14(page.value)); + else + goto default; + + break; + } + case 0x1A: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1A(page.value)); + else if(page.subpage == 1) + modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h", + Modes.PrettifyModePage_1A_S01(page.value)); + else + goto default; + + break; + } + case 0x1B: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1B(page.value)); + else + goto default; + + break; + } + case 0x1C: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", + deviceType == PeripheralDeviceTypes.MultiMediaDevice + ? Modes.PrettifyModePage_1C_SFF(page.value) + : Modes.PrettifyModePage_1C(page.value)); + else if(page.subpage == 1) + modePages.Add($"MODE page {page.page:X2}h subpage {page.subpage:X2}h", + Modes.PrettifyModePage_1C_S01(page.value)); + else + goto default; + + break; + } + case 0x1D: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_1D(page.value)); + else + goto default; + + break; + } + case 0x21: + { + if(vendor == "CERTANCE") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyCertanceModePage_21(page.value)); + else + goto default; + + break; + } + case 0x22: + { + if(vendor == "CERTANCE") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyCertanceModePage_22(page.value)); + else + goto default; + + break; + } + case 0x24: + { + if(vendor == "IBM") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_24(page.value)); + else + goto default; + + break; + } + case 0x2A: + { + if(page.subpage == 0) + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyModePage_2A(page.value)); + else + goto default; + + break; + } + case 0x2F: + { + if(vendor == "IBM") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_2F(page.value)); + else + goto default; + + break; + } + case 0x30: + { + if(Modes.IsAppleModePage_30(page.value)) + modePages.Add("MODE page 30h", "Drive identifies as an Apple OEM drive"); + else + goto default; + + break; + } + case 0x3B: + { + if(vendor == "HP") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3B(page.value)); + else + goto default; + + break; + } + case 0x3C: + { + if(vendor == "HP") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3C(page.value)); + else + goto default; + + break; + } + case 0x3D: + { + if(vendor == "IBM") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyIBMModePage_3D(page.value)); + else if(vendor == "HP") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3D(page.value)); + else + goto default; + + break; + } + case 0x3E: + { + if(vendor == "FUJITSU") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyFujitsuModePage_3E(page.value)); + else if(vendor == "HP") + modePages.Add($"MODE page {page.page:X2}h", Modes.PrettifyHPModePage_3E(page.value)); + else + goto default; + + break; + } + default: + { + modePages. + Add(page.subpage != 0 ? $"MODE page {page.page:X2}h subpage {page.subpage:X2}h" : $"MODE page {page.page:X2}h", + "Unknown mode page"); } - Dictionary newModePages = new(); + break; + } - foreach(KeyValuePair kvp in modePages) - newModePages.Add(kvp.Key, - string.IsNullOrWhiteSpace(kvp.Value) ? "Undecoded" : kvp.Value.Replace("\n", "
")); + Dictionary newModePages = new(); - modePages = newModePages; - } + foreach(KeyValuePair kvp in modePages) + newModePages.Add(kvp.Key, + string.IsNullOrWhiteSpace(kvp.Value) ? "Undecoded" : kvp.Value.Replace("\n", "
")); + + modePages = newModePages; } } \ No newline at end of file diff --git a/Aaru.Server/Core/SscTestedMedia.cs b/Aaru.Server/Core/SscTestedMedia.cs index 142a0a93..c6c4e70b 100644 --- a/Aaru.Server/Core/SscTestedMedia.cs +++ b/Aaru.Server/Core/SscTestedMedia.cs @@ -33,50 +33,49 @@ using System.Collections.Generic; using Aaru.CommonTypes.Metadata; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class SscTestedMedia { - public static class SscTestedMedia + /// Takes the tested media from SCSI Streaming devices of a device report and prints it as a list of values + /// List to put values on + /// List of tested media + public static void Report(IEnumerable testedMedia, ref List mediaOneValue) { - /// Takes the tested media from SCSI Streaming devices of a device report and prints it as a list of values - /// List to put values on - /// List of tested media - public static void Report(IEnumerable testedMedia, ref List mediaOneValue) + foreach(TestedSequentialMedia media in testedMedia) { - foreach(TestedSequentialMedia media in testedMedia) + if(!string.IsNullOrWhiteSpace(media.MediumTypeName)) { - if(!string.IsNullOrWhiteSpace(media.MediumTypeName)) - { - mediaOneValue.Add($"Information for medium named \"{media.MediumTypeName}\""); + mediaOneValue.Add($"Information for medium named \"{media.MediumTypeName}\""); - if(media.MediumType.HasValue) - mediaOneValue.Add($"Medium type code: {media.MediumType:X2}h"); - } - else if(media.MediumType.HasValue) - { - mediaOneValue.Add($"Information for medium type {media.MediumType:X2}h"); - } - else - { - mediaOneValue.Add("Information for unknown medium type"); - } - - if(!string.IsNullOrWhiteSpace(media.Manufacturer)) - mediaOneValue.Add($"Medium manufactured by: {media.Manufacturer}"); - - if(!string.IsNullOrWhiteSpace(media.Model)) - mediaOneValue.Add($"Medium model: {media.Model}"); - - if(media.Density.HasValue) - mediaOneValue.Add($"Medium has density code {media.Density:X2}h"); - - if(media.CanReadMediaSerial == true) - mediaOneValue.Add("Drive can read medium serial number."); - - if(media.MediaIsRecognized) - mediaOneValue.Add("Drive recognizes this medium."); - - mediaOneValue.Add(""); + if(media.MediumType.HasValue) + mediaOneValue.Add($"Medium type code: {media.MediumType:X2}h"); } + else if(media.MediumType.HasValue) + { + mediaOneValue.Add($"Information for medium type {media.MediumType:X2}h"); + } + else + { + mediaOneValue.Add("Information for unknown medium type"); + } + + if(!string.IsNullOrWhiteSpace(media.Manufacturer)) + mediaOneValue.Add($"Medium manufactured by: {media.Manufacturer}"); + + if(!string.IsNullOrWhiteSpace(media.Model)) + mediaOneValue.Add($"Medium model: {media.Model}"); + + if(media.Density.HasValue) + mediaOneValue.Add($"Medium has density code {media.Density:X2}h"); + + if(media.CanReadMediaSerial == true) + mediaOneValue.Add("Drive can read medium serial number."); + + if(media.MediaIsRecognized) + mediaOneValue.Add("Drive recognizes this medium."); + + mediaOneValue.Add(""); } } } \ No newline at end of file diff --git a/Aaru.Server/Core/StatsConverter.cs b/Aaru.Server/Core/StatsConverter.cs index 42d343fb..0ed901e3 100644 --- a/Aaru.Server/Core/StatsConverter.cs +++ b/Aaru.Server/Core/StatsConverter.cs @@ -35,489 +35,488 @@ using Aaru.CommonTypes.Metadata; using Aaru.Server.Models; using Version = Aaru.Server.Models.Version; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class StatsConverter { - public static class StatsConverter + public static void Convert(Stats newStats) { - public static void Convert(Stats newStats) + var ctx = new AaruServerContext(); + + if(newStats.Commands?.Analyze > 0) { - var ctx = new AaruServerContext(); + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info"); - if(newStats.Commands?.Analyze > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "fs-info"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Analyze, - Name = "fs-info" - }); - else - existing.Count += newStats.Commands.Analyze; - } - - if(newStats.Commands?.Benchmark > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "benchmark"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Benchmark, - Name = "benchmark" - }); - else - existing.Count += newStats.Commands.Benchmark; - } - - if(newStats.Commands?.Checksum > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "checksum"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Checksum, - Name = "checksum" - }); - else - existing.Count += newStats.Commands.Checksum; - } - - if(newStats.Commands?.Compare > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "compare"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Compare, - Name = "compare" - }); - else - existing.Count += newStats.Commands.Compare; - } - - if(newStats.Commands?.CreateSidecar > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.CreateSidecar, - Name = "create-sidecar" - }); - else - existing.Count += newStats.Commands.CreateSidecar; - } - - if(newStats.Commands?.Decode > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "decode"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Decode, - Name = "decode" - }); - else - existing.Count += newStats.Commands.Decode; - } - - if(newStats.Commands?.DeviceInfo > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-info"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.DeviceInfo, - Name = "device-info" - }); - else - existing.Count += newStats.Commands.DeviceInfo; - } - - if(newStats.Commands?.DeviceReport > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-report"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.DeviceReport, - Name = "device-report" - }); - else - existing.Count += newStats.Commands.DeviceReport; - } - - if(newStats.Commands?.DumpMedia > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "dump-media"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.DumpMedia, - Name = "dump-media" - }); - else - existing.Count += newStats.Commands.DumpMedia; - } - - if(newStats.Commands?.Entropy > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "entropy"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Entropy, - Name = "entropy" - }); - else - existing.Count += newStats.Commands.Entropy; - } - - if(newStats.Commands?.Formats > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "formats"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Formats, - Name = "formats" - }); - else - existing.Count += newStats.Commands.Formats; - } - - if(newStats.Commands?.MediaInfo > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-info"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.MediaInfo, - Name = "media-info" - }); - else - existing.Count += newStats.Commands.MediaInfo; - } - - if(newStats.Commands?.MediaScan > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-scan"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.MediaScan, - Name = "media-scan" - }); - else - existing.Count += newStats.Commands.MediaScan; - } - - if(newStats.Commands?.PrintHex > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "printhex"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.PrintHex, - Name = "printhex" - }); - else - existing.Count += newStats.Commands.PrintHex; - } - - if(newStats.Commands?.Verify > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "verify"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Verify, - Name = "verify" - }); - else - existing.Count += newStats.Commands.Verify; - } - - if(newStats.Commands?.Ls > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "ls"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.Ls, - Name = "ls" - }); - else - existing.Count += newStats.Commands.Ls; - } - - if(newStats.Commands?.ExtractFiles > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "extract-files"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.ExtractFiles, - Name = "extract-files" - }); - else - existing.Count += newStats.Commands.ExtractFiles; - } - - if(newStats.Commands?.ListDevices > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-devices"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.ListDevices, - Name = "list-devices" - }); - else - existing.Count += newStats.Commands.ListDevices; - } - - if(newStats.Commands?.ListEncodings > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.ListEncodings, - Name = "list-encodings" - }); - else - existing.Count += newStats.Commands.ListEncodings; - } - - if(newStats.Commands?.ConvertImage > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "convert-image"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.ConvertImage, - Name = "convert-image" - }); - else - existing.Count += newStats.Commands.ConvertImage; - } - - if(newStats.Commands?.ImageInfo > 0) - { - Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "image-info"); - - if(existing == null) - ctx.Commands.Add(new() - { - Count = newStats.Commands.ImageInfo, - Name = "image-info" - }); - else - existing.Count += newStats.Commands.ImageInfo; - } - - if(newStats.OperatingSystems != null) - { - foreach(OsStats operatingSystem in newStats.OperatingSystems) + if(existing == null) + ctx.Commands.Add(new() { - if(string.IsNullOrWhiteSpace(operatingSystem.name) || - string.IsNullOrWhiteSpace(operatingSystem.version)) - continue; - - OperatingSystem existing = - ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name && - c.Version == operatingSystem.version); - - if(existing == null) - ctx.OperatingSystems.Add(new() - { - Count = operatingSystem.Value, - Name = operatingSystem.name, - Version = operatingSystem.version - }); - else - existing.Count += operatingSystem.Value; - } - } + Count = newStats.Commands.Analyze, + Name = "fs-info" + }); else + existing.Count += newStats.Commands.Analyze; + } + + if(newStats.Commands?.Benchmark > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "benchmark"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Benchmark, + Name = "benchmark" + }); + else + existing.Count += newStats.Commands.Benchmark; + } + + if(newStats.Commands?.Checksum > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "checksum"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Checksum, + Name = "checksum" + }); + else + existing.Count += newStats.Commands.Checksum; + } + + if(newStats.Commands?.Compare > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "compare"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Compare, + Name = "compare" + }); + else + existing.Count += newStats.Commands.Compare; + } + + if(newStats.Commands?.CreateSidecar > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.CreateSidecar, + Name = "create-sidecar" + }); + else + existing.Count += newStats.Commands.CreateSidecar; + } + + if(newStats.Commands?.Decode > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "decode"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Decode, + Name = "decode" + }); + else + existing.Count += newStats.Commands.Decode; + } + + if(newStats.Commands?.DeviceInfo > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-info"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.DeviceInfo, + Name = "device-info" + }); + else + existing.Count += newStats.Commands.DeviceInfo; + } + + if(newStats.Commands?.DeviceReport > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-report"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.DeviceReport, + Name = "device-report" + }); + else + existing.Count += newStats.Commands.DeviceReport; + } + + if(newStats.Commands?.DumpMedia > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "dump-media"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.DumpMedia, + Name = "dump-media" + }); + else + existing.Count += newStats.Commands.DumpMedia; + } + + if(newStats.Commands?.Entropy > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "entropy"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Entropy, + Name = "entropy" + }); + else + existing.Count += newStats.Commands.Entropy; + } + + if(newStats.Commands?.Formats > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "formats"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Formats, + Name = "formats" + }); + else + existing.Count += newStats.Commands.Formats; + } + + if(newStats.Commands?.MediaInfo > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-info"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.MediaInfo, + Name = "media-info" + }); + else + existing.Count += newStats.Commands.MediaInfo; + } + + if(newStats.Commands?.MediaScan > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-scan"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.MediaScan, + Name = "media-scan" + }); + else + existing.Count += newStats.Commands.MediaScan; + } + + if(newStats.Commands?.PrintHex > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "printhex"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.PrintHex, + Name = "printhex" + }); + else + existing.Count += newStats.Commands.PrintHex; + } + + if(newStats.Commands?.Verify > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "verify"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Verify, + Name = "verify" + }); + else + existing.Count += newStats.Commands.Verify; + } + + if(newStats.Commands?.Ls > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "ls"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.Ls, + Name = "ls" + }); + else + existing.Count += newStats.Commands.Ls; + } + + if(newStats.Commands?.ExtractFiles > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "extract-files"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.ExtractFiles, + Name = "extract-files" + }); + else + existing.Count += newStats.Commands.ExtractFiles; + } + + if(newStats.Commands?.ListDevices > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-devices"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.ListDevices, + Name = "list-devices" + }); + else + existing.Count += newStats.Commands.ListDevices; + } + + if(newStats.Commands?.ListEncodings > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.ListEncodings, + Name = "list-encodings" + }); + else + existing.Count += newStats.Commands.ListEncodings; + } + + if(newStats.Commands?.ConvertImage > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "convert-image"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.ConvertImage, + Name = "convert-image" + }); + else + existing.Count += newStats.Commands.ConvertImage; + } + + if(newStats.Commands?.ImageInfo > 0) + { + Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "image-info"); + + if(existing == null) + ctx.Commands.Add(new() + { + Count = newStats.Commands.ImageInfo, + Name = "image-info" + }); + else + existing.Count += newStats.Commands.ImageInfo; + } + + if(newStats.OperatingSystems != null) + { + foreach(OsStats operatingSystem in newStats.OperatingSystems) { + if(string.IsNullOrWhiteSpace(operatingSystem.name) || + string.IsNullOrWhiteSpace(operatingSystem.version)) + continue; + OperatingSystem existing = - ctx.OperatingSystems.FirstOrDefault(c => c.Name == "Linux" && c.Version == null); + ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name && + c.Version == operatingSystem.version); if(existing == null) ctx.OperatingSystems.Add(new() { - Count = 1, - Name = "Linux" + Count = operatingSystem.Value, + Name = operatingSystem.name, + Version = operatingSystem.version }); else - existing.Count++; + existing.Count += operatingSystem.Value; } + } + else + { + OperatingSystem existing = + ctx.OperatingSystems.FirstOrDefault(c => c.Name == "Linux" && c.Version == null); - if(newStats.Versions != null) - { - foreach(NameValueStats nvs in newStats.Versions) + if(existing == null) + ctx.OperatingSystems.Add(new() { - if(string.IsNullOrWhiteSpace(nvs.name)) - continue; - - Version existing = ctx.Versions.FirstOrDefault(c => c.Name == nvs.name); - - if(existing == null) - ctx.Versions.Add(new() - { - Count = nvs.Value, - Name = nvs.name - }); - else - existing.Count += nvs.Value; - } - } + Count = 1, + Name = "Linux" + }); else + existing.Count++; + } + + if(newStats.Versions != null) + { + foreach(NameValueStats nvs in newStats.Versions) { - Version existing = ctx.Versions.FirstOrDefault(c => c.Name == "previous"); + if(string.IsNullOrWhiteSpace(nvs.name)) + continue; + + Version existing = ctx.Versions.FirstOrDefault(c => c.Name == nvs.name); if(existing == null) ctx.Versions.Add(new() { - Count = 1, - Name = "previous" + Count = nvs.Value, + Name = nvs.name }); else - existing.Count++; + existing.Count += nvs.Value; + } + } + else + { + Version existing = ctx.Versions.FirstOrDefault(c => c.Name == "previous"); + + if(existing == null) + ctx.Versions.Add(new() + { + Count = 1, + Name = "previous" + }); + else + existing.Count++; + } + + if(newStats.Filesystems != null) + foreach(NameValueStats nvs in newStats.Filesystems) + { + if(string.IsNullOrWhiteSpace(nvs.name)) + continue; + + Filesystem existing = ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name); + + if(existing == null) + ctx.Filesystems.Add(new() + { + Count = nvs.Value, + Name = nvs.name + }); + else + existing.Count += nvs.Value; } - if(newStats.Filesystems != null) - foreach(NameValueStats nvs in newStats.Filesystems) - { - if(string.IsNullOrWhiteSpace(nvs.name)) - continue; + if(newStats.Partitions != null) + foreach(NameValueStats nvs in newStats.Partitions) + { + if(string.IsNullOrWhiteSpace(nvs.name)) + continue; - Filesystem existing = ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name); + Partition existing = ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name); - if(existing == null) - ctx.Filesystems.Add(new() - { - Count = nvs.Value, - Name = nvs.name - }); - else - existing.Count += nvs.Value; - } - - if(newStats.Partitions != null) - foreach(NameValueStats nvs in newStats.Partitions) - { - if(string.IsNullOrWhiteSpace(nvs.name)) - continue; - - Partition existing = ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name); - - if(existing == null) - ctx.Partitions.Add(new() - { - Count = nvs.Value, - Name = nvs.name - }); - else - existing.Count += nvs.Value; - } - - if(newStats.MediaImages != null) - foreach(NameValueStats nvs in newStats.MediaImages) - { - if(string.IsNullOrWhiteSpace(nvs.name)) - continue; - - MediaFormat existing = ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name); - - if(existing == null) - ctx.MediaFormats.Add(new() - { - Count = nvs.Value, - Name = nvs.name - }); - else - existing.Count += nvs.Value; - } - - if(newStats.Filters != null) - foreach(NameValueStats nvs in newStats.Filters) - { - if(string.IsNullOrWhiteSpace(nvs.name)) - continue; - - Filter existing = ctx.Filters.FirstOrDefault(c => c.Name == nvs.name); - - if(existing == null) - ctx.Filters.Add(new() - { - Count = nvs.Value, - Name = nvs.name - }); - else - existing.Count += nvs.Value; - } - - if(newStats.Devices != null) - foreach(DeviceStats device in newStats.Devices. - Where(device => !string.IsNullOrWhiteSpace(device.Model)). - Where(device => !ctx.DeviceStats.Any(c => c.Bus == device.Bus && - c.Manufacturer == - device.Manufacturer && - c.Model == device.Model && - c.Revision == device.Revision))) - { - ctx.DeviceStats.Add(new() + if(existing == null) + ctx.Partitions.Add(new() { - Bus = device.Bus, - Manufacturer = device.Manufacturer, - Model = device.Model, - Revision = device.Revision + Count = nvs.Value, + Name = nvs.name }); - } + else + existing.Count += nvs.Value; + } - if(newStats.Medias != null) - foreach(MediaStats media in newStats.Medias) + if(newStats.MediaImages != null) + foreach(NameValueStats nvs in newStats.MediaImages) + { + if(string.IsNullOrWhiteSpace(nvs.name)) + continue; + + MediaFormat existing = ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name); + + if(existing == null) + ctx.MediaFormats.Add(new() + { + Count = nvs.Value, + Name = nvs.name + }); + else + existing.Count += nvs.Value; + } + + if(newStats.Filters != null) + foreach(NameValueStats nvs in newStats.Filters) + { + if(string.IsNullOrWhiteSpace(nvs.name)) + continue; + + Filter existing = ctx.Filters.FirstOrDefault(c => c.Name == nvs.name); + + if(existing == null) + ctx.Filters.Add(new() + { + Count = nvs.Value, + Name = nvs.name + }); + else + existing.Count += nvs.Value; + } + + if(newStats.Devices != null) + foreach(DeviceStats device in newStats.Devices. + Where(device => !string.IsNullOrWhiteSpace(device.Model)). + Where(device => !ctx.DeviceStats.Any(c => c.Bus == device.Bus && + c.Manufacturer == + device.Manufacturer && + c.Model == device.Model && + c.Revision == device.Revision))) + { + ctx.DeviceStats.Add(new() { - if(string.IsNullOrWhiteSpace(media.type)) - continue; + Bus = device.Bus, + Manufacturer = device.Manufacturer, + Model = device.Model, + Revision = device.Revision + }); + } - Media existing = ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real); + if(newStats.Medias != null) + foreach(MediaStats media in newStats.Medias) + { + if(string.IsNullOrWhiteSpace(media.type)) + continue; - if(existing == null) - ctx.Medias.Add(new() - { - Count = media.Value, - Real = media.real, - Type = media.type - }); - else - existing.Count += media.Value; - } + Media existing = ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real); - ctx.SaveChanges(); - } + if(existing == null) + ctx.Medias.Add(new() + { + Count = media.Value, + Real = media.real, + Type = media.type + }); + else + existing.Count += media.Value; + } + + ctx.SaveChanges(); } } \ No newline at end of file diff --git a/Aaru.Server/Core/TestedMedia.cs b/Aaru.Server/Core/TestedMedia.cs index eb32e730..b5845a37 100644 --- a/Aaru.Server/Core/TestedMedia.cs +++ b/Aaru.Server/Core/TestedMedia.cs @@ -32,364 +32,363 @@ using System.Collections.Generic; -namespace Aaru.Server.Core +namespace Aaru.Server.Core; + +public static class TestedMedia { - public static class TestedMedia + /// Takes the tested media from a device report and prints it as a list of values + /// List to put values on + /// List of tested media + public static void Report(List testedMedias, ref List mediaOneValue) { - /// Takes the tested media from a device report and prints it as a list of values - /// List to put values on - /// List of tested media - public static void Report(List testedMedias, ref List mediaOneValue) + foreach(CommonTypes.Metadata.TestedMedia testedMedia in testedMedias) { - foreach(CommonTypes.Metadata.TestedMedia testedMedia in testedMedias) + if(!string.IsNullOrWhiteSpace(testedMedia.MediumTypeName)) { - if(!string.IsNullOrWhiteSpace(testedMedia.MediumTypeName)) - { - mediaOneValue.Add($"Information for medium named \"{testedMedia.MediumTypeName}\""); + mediaOneValue.Add($"Information for medium named \"{testedMedia.MediumTypeName}\""); - if(testedMedia.MediumType != null) - mediaOneValue.Add($"Medium type code: {testedMedia.MediumType:X2}h"); - } - else if(testedMedia.MediumType != null) - { - mediaOneValue.Add($"Information for medium type {testedMedia.MediumType:X2}h"); - } - else - { - mediaOneValue.Add("Information for unknown medium type"); - } - - mediaOneValue.Add(testedMedia.MediaIsRecognized ? "Drive recognizes this medium." - : "Drive does not recognize this medium."); - - if(!string.IsNullOrWhiteSpace(testedMedia.Manufacturer)) - mediaOneValue.Add($"Medium manufactured by: {testedMedia.Manufacturer}"); - - if(!string.IsNullOrWhiteSpace(testedMedia.Model)) - mediaOneValue.Add($"Medium model: {testedMedia.Model}"); - - if(testedMedia.Density != null) - mediaOneValue.Add($"Density code: {testedMedia.Density:X2}h"); - - if(testedMedia.BlockSize != null) - mediaOneValue.Add($"Logical sector size: {testedMedia.BlockSize} bytes"); - - if(testedMedia.PhysicalBlockSize != null) - mediaOneValue.Add($"Physical sector size: {testedMedia.PhysicalBlockSize} bytes"); - - if(testedMedia.LongBlockSize != null) - mediaOneValue.Add($"READ LONG sector size: {testedMedia.LongBlockSize} bytes"); - - if(testedMedia.Blocks != null && - testedMedia.BlockSize != null) - { - mediaOneValue.Add($"Medium has {testedMedia.Blocks} blocks of {testedMedia.BlockSize} bytes each"); - - if(testedMedia.Blocks * testedMedia.BlockSize / 1024 / 1024 > 1000000) - mediaOneValue. - Add($"Medium size: {testedMedia.Blocks * testedMedia.BlockSize} bytes, {testedMedia.Blocks * testedMedia.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(testedMedia.Blocks * testedMedia.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); - else if(testedMedia.Blocks * testedMedia.BlockSize / 1024 / 1024 > 1000) - mediaOneValue. - Add($"Medium size: {testedMedia.Blocks * testedMedia.BlockSize} bytes, {testedMedia.Blocks * testedMedia.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(testedMedia.Blocks * testedMedia.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); - else - mediaOneValue. - Add($"Medium size: {testedMedia.Blocks * testedMedia.BlockSize} bytes, {testedMedia.Blocks * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)(testedMedia.Blocks * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); - } - - if(testedMedia.CHS != null && - testedMedia.CurrentCHS != null) - { - int currentSectors = testedMedia.CurrentCHS.Cylinders * testedMedia.CurrentCHS.Heads * - testedMedia.CurrentCHS.Sectors; - - mediaOneValue. - Add($"Cylinders: {testedMedia.CHS.Cylinders} max., {testedMedia.CurrentCHS.Cylinders} current"); - - mediaOneValue.Add($"Heads: {testedMedia.CHS.Heads} max., {testedMedia.CurrentCHS.Heads} current"); - - mediaOneValue. - Add($"Sectors per track: {testedMedia.CHS.Sectors} max., {testedMedia.CurrentCHS.Sectors} current"); - - mediaOneValue. - Add($"Sectors addressable in CHS mode: {testedMedia.CHS.Cylinders * testedMedia.CHS.Heads * testedMedia.CHS.Sectors} max., {currentSectors} current"); - - mediaOneValue. - Add($"Medium size in CHS mode: {(ulong)currentSectors * testedMedia.BlockSize} bytes, {(ulong)currentSectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); - } - else if(testedMedia.CHS != null) - { - int currentSectors = testedMedia.CHS.Cylinders * testedMedia.CHS.Heads * testedMedia.CHS.Sectors; - mediaOneValue.Add($"Cylinders: {testedMedia.CHS.Cylinders}"); - mediaOneValue.Add($"Heads: {testedMedia.CHS.Heads}"); - mediaOneValue.Add($"Sectors per track: {testedMedia.CHS.Sectors}"); - mediaOneValue.Add($"Sectors addressable in CHS mode: {currentSectors}"); - - mediaOneValue. - Add($"Medium size in CHS mode: {(ulong)currentSectors * testedMedia.BlockSize} bytes, {(ulong)currentSectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); - } - - if(testedMedia.LBASectors != null) - { - mediaOneValue.Add($"Sectors addressable in sectors in 28-bit LBA mode: {testedMedia.LBASectors}"); - - if((ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1024 / 1024 > 1000000) - mediaOneValue. - Add($"Medium size in 28-bit LBA mode: {(ulong)testedMedia.LBASectors * testedMedia.BlockSize} bytes, {(ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)((ulong)testedMedia.LBASectors * testedMedia.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); - else if((ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1024 / 1024 > 1000) - mediaOneValue. - Add($"Medium size in 28-bit LBA mode: {(ulong)testedMedia.LBASectors * testedMedia.BlockSize} bytes, {(ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1000 / 1000 / 1000} Gb, {(double)((ulong)testedMedia.LBASectors * testedMedia.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); - else - mediaOneValue. - Add($"Medium size in 28-bit LBA mode: {(ulong)testedMedia.LBASectors * testedMedia.BlockSize} bytes, {(ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)((ulong)testedMedia.LBASectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); - } - - if(testedMedia.LBA48Sectors != null) - { - mediaOneValue.Add($"Sectors addressable in sectors in 48-bit LBA mode: {testedMedia.LBA48Sectors}"); - - if(testedMedia.LBA48Sectors * testedMedia.BlockSize / 1024 / 1024 > 1000000) - mediaOneValue. - Add($"Medium size in 48-bit LBA mode: {testedMedia.LBA48Sectors * testedMedia.BlockSize} bytes, {testedMedia.LBA48Sectors * testedMedia.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(testedMedia.LBA48Sectors * testedMedia.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); - else if(testedMedia.LBA48Sectors * testedMedia.BlockSize / 1024 / 1024 > 1000) - mediaOneValue. - Add($"Medium size in 48-bit LBA mode: {testedMedia.LBA48Sectors * testedMedia.BlockSize} bytes, {testedMedia.LBA48Sectors * testedMedia.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(testedMedia.LBA48Sectors * testedMedia.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); - else - mediaOneValue. - Add($"Medium size in 48-bit LBA mode: {testedMedia.LBA48Sectors * testedMedia.BlockSize} bytes, {testedMedia.LBA48Sectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)(testedMedia.LBA48Sectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); - } - - if(testedMedia.NominalRotationRate != null && - testedMedia.NominalRotationRate != 0x0000 && - testedMedia.NominalRotationRate != 0xFFFF) - mediaOneValue.Add(testedMedia.NominalRotationRate == 0x0001 ? "Medium does not rotate." - : $"Medium rotates at {testedMedia.NominalRotationRate} rpm"); - - if(testedMedia.BlockSize != null && - testedMedia.PhysicalBlockSize != null && - testedMedia.BlockSize.Value != testedMedia.PhysicalBlockSize.Value && - (testedMedia.LogicalAlignment & 0x8000) == 0x0000 && - (testedMedia.LogicalAlignment & 0x4000) == 0x4000) - mediaOneValue. - Add($"Logical sector starts at offset {testedMedia.LogicalAlignment & 0x3FFF} from physical sector"); - - if(testedMedia.SupportsReadSectors == true) - mediaOneValue.Add("Device can use the READ SECTOR(S) command in CHS mode with this medium"); - - if(testedMedia.SupportsReadRetry == true) - mediaOneValue.Add("Device can use the READ SECTOR(S) RETRY command in CHS mode with this medium"); - - if(testedMedia.SupportsReadDma == true) - mediaOneValue.Add("Device can use the READ DMA command in CHS mode with this medium"); - - if(testedMedia.SupportsReadDmaRetry == true) - mediaOneValue.Add("Device can use the READ DMA RETRY command in CHS mode with this medium"); - - if(testedMedia.SupportsReadLong == true) - mediaOneValue.Add("Device can use the READ LONG command in CHS mode with this medium"); - - if(testedMedia.SupportsReadLongRetry == true) - mediaOneValue.Add("Device can use the READ LONG RETRY command in CHS mode with this medium"); - - if(testedMedia.SupportsReadLba == true) - mediaOneValue.Add("Device can use the READ SECTOR(S) command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadRetryLba == true) - mediaOneValue. - Add("Device can use the READ SECTOR(S) RETRY command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadDmaLba == true) - mediaOneValue.Add("Device can use the READ DMA command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadDmaRetryLba == true) - mediaOneValue.Add("Device can use the READ DMA RETRY command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadLongLba == true) - mediaOneValue.Add("Device can use the READ LONG command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadLongRetryLba == true) - mediaOneValue.Add("Device can use the READ LONG RETRY command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadLba48 == true) - mediaOneValue.Add("Device can use the READ SECTOR(S) command in 48-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadDmaLba48 == true) - mediaOneValue.Add("Device can use the READ DMA command in 48-bit LBA mode with this medium"); - - if(testedMedia.SupportsSeek == true) - mediaOneValue.Add("Device can use the SEEK command in CHS mode with this medium"); - - if(testedMedia.SupportsSeekLba == true) - mediaOneValue.Add("Device can use the SEEK command in 28-bit LBA mode with this medium"); - - if(testedMedia.SupportsReadCapacity == true) - mediaOneValue.Add("Device can use the READ CAPACITY (10) command with this medium"); - - if(testedMedia.SupportsReadCapacity16 == true) - mediaOneValue.Add("Device can use the READ CAPACITY (16) command with this medium"); - - if(testedMedia.SupportsRead6 == true) - mediaOneValue.Add("Device can use the READ (6) command with this medium"); - - if(testedMedia.SupportsRead10 == true) - mediaOneValue.Add("Device can use the READ (10) command with this medium"); - - if(testedMedia.SupportsRead12 == true) - mediaOneValue.Add("Device can use the READ (12) command with this medium"); - - if(testedMedia.SupportsRead16 == true) - mediaOneValue.Add("Device can use the READ (16) command with this medium"); - - if(testedMedia.SupportsReadLong == true) - mediaOneValue.Add("Device can use the READ LONG (10) command with this medium"); - - if(testedMedia.SupportsReadLong16 == true) - mediaOneValue.Add("Device can use the READ LONG (16) command with this medium"); - - if(testedMedia.SupportsReadCd == true) - mediaOneValue.Add("Device can use the READ CD command with LBA addressing with this medium"); - - if(testedMedia.SupportsReadCdMsf == true) - mediaOneValue.Add("Device can use the READ CD command with MM:SS:FF addressing with this medium"); - - if(testedMedia.SupportsReadCdRaw == true) - mediaOneValue. - Add("Device can use the READ CD command with LBA addressing with this medium to read raw sector"); - - if(testedMedia.SupportsReadCdMsfRaw == true) - mediaOneValue. - Add("Device can use the READ CD command with MM:SS:FF addressing with this medium read raw sector"); - - if(testedMedia.SupportsHLDTSTReadRawDVD == true) - mediaOneValue.Add("Device can use the HL-DT-ST vendor READ DVD (RAW) command with this medium"); - - if(testedMedia.SupportsNECReadCDDA == true) - mediaOneValue.Add("Device can use the NEC vendor READ CD-DA command with this medium"); - - if(testedMedia.SupportsPioneerReadCDDA == true) - mediaOneValue.Add("Device can use the PIONEER vendor READ CD-DA command with this medium"); - - if(testedMedia.SupportsPioneerReadCDDAMSF == true) - mediaOneValue.Add("Device can use the PIONEER vendor READ CD-DA MSF command with this medium"); - - if(testedMedia.SupportsPlextorReadCDDA == true) - mediaOneValue.Add("Device can use the PLEXTOR vendor READ CD-DA command with this medium"); - - if(testedMedia.SupportsPlextorReadRawDVD == true) - mediaOneValue.Add("Device can use the PLEXTOR vendor READ DVD (RAW) command with this medium"); - - if(testedMedia.CanReadAACS == true) - mediaOneValue.Add("Device can read the Advanced Access Content System from this medium"); - - if(testedMedia.CanReadADIP == true) - mediaOneValue.Add("Device can read the DVD ADress-In-Pregroove from this medium"); - - if(testedMedia.CanReadATIP == true) - mediaOneValue.Add("Device can read the CD Absolute-Time-In-Pregroove from this medium"); - - if(testedMedia.CanReadBCA == true) - mediaOneValue.Add("Device can read the Burst Cutting Area from this medium"); - - if(testedMedia.CanReadC2Pointers == true) - mediaOneValue.Add("Device can report the C2 pointers when reading from this medium"); - - if(testedMedia.CanReadCMI == true) - mediaOneValue.Add("Device can read the Copyright Management Information from this medium"); - - if(testedMedia.CanReadCorrectedSubchannel == true) - mediaOneValue.Add("Device can correct subchannels when reading from this medium"); - - if(testedMedia.CanReadCorrectedSubchannelWithC2 == true) - mediaOneValue. - Add("Device can correct subchannels and report the C2 pointers when reading from this medium"); - - if(testedMedia.CanReadDCB == true) - mediaOneValue.Add("Device can read the Disc Control Blocks from this medium"); - - if(testedMedia.CanReadDDS == true) - mediaOneValue.Add("Device can read the Disc Definition Structure from this medium"); - - if(testedMedia.CanReadDMI == true) - mediaOneValue.Add("Device can read the Disc Manufacturer Information from this medium"); - - if(testedMedia.CanReadDiscInformation == true) - mediaOneValue.Add("Device can read the Disc Information from this medium"); - - if(testedMedia.CanReadFullTOC == true) - mediaOneValue.Add("Device can read the Table of Contents from this medium, without processing it"); - - if(testedMedia.CanReadHDCMI == true) - mediaOneValue.Add("Device can read the HD DVD Copyright Management Information from this medium"); - - if(testedMedia.CanReadLayerCapacity == true) - mediaOneValue.Add("Device can read the layer capacity from this medium"); - - if(testedMedia.CanReadFirstTrackPreGap == true) - mediaOneValue.Add("Device can read the first track's pregap data"); - - if(testedMedia.CanReadLeadIn == true) - mediaOneValue.Add("Device can read the Lead-In from this medium"); - - if(testedMedia.CanReadLeadOut == true) - mediaOneValue.Add("Device can read the Lead-Out from this medium"); - - if(testedMedia.CanReadMediaID == true) - mediaOneValue.Add("Device can read the Media ID from this medium"); - - if(testedMedia.CanReadMediaSerial == true) - mediaOneValue.Add("Device can read the Media Serial Number from this medium"); - - if(testedMedia.CanReadPAC == true) - mediaOneValue.Add("Device can read the PAC from this medium"); - - if(testedMedia.CanReadPFI == true) - mediaOneValue.Add("Device can read the Physical Format Information from this medium"); - - if(testedMedia.CanReadPMA == true) - mediaOneValue.Add("Device can read the Power Management Area from this medium"); - - if(testedMedia.CanReadPQSubchannel == true) - mediaOneValue.Add("Device can read the P to Q subchannels from this medium"); - - if(testedMedia.CanReadPQSubchannelWithC2 == true) - mediaOneValue. - Add("Device can read the P to Q subchannels from this medium reporting the C2 pointers"); - - if(testedMedia.CanReadPRI == true) - mediaOneValue.Add("Device can read the Pre-Recorded Information from this medium"); - - if(testedMedia.CanReadRWSubchannel == true) - mediaOneValue.Add("Device can read the R to W subchannels from this medium"); - - if(testedMedia.CanReadRWSubchannelWithC2 == true) - mediaOneValue. - Add("Device can read the R to W subchannels from this medium reporting the C2 pointers"); - - if(testedMedia.CanReadRecordablePFI == true) - mediaOneValue.Add("Device can read the Physical Format Information from Lead-In from this medium"); - - if(testedMedia.CanReadSpareAreaInformation == true) - mediaOneValue.Add("Device can read the Spare Area Information from this medium"); - - if(testedMedia.CanReadTOC == true) - mediaOneValue.Add("Device can read the Table of Contents from this medium"); - - if(testedMedia.CanReadingIntersessionLeadIn == true) - mediaOneValue.Add("Device can read Lead-In between sessions"); - - if(testedMedia.CanReadingIntersessionLeadOut == true) - mediaOneValue.Add("Device can read Lead-Out between sessions"); - - if(testedMedia.CanReadCdScrambled == true) - mediaOneValue.Add("Device can read scrambled sectors using standard READ CD command"); - - if(testedMedia.CanReadF1_06 == true) - mediaOneValue.Add("Device can read from cache using F1h command with subcommand 06h"); - - if(testedMedia.CanReadF1_06LeadOut == true) - mediaOneValue.Add("Device can read Lead-Out from cache using F1h command with subcommand 06h"); - - mediaOneValue.Add(""); + if(testedMedia.MediumType != null) + mediaOneValue.Add($"Medium type code: {testedMedia.MediumType:X2}h"); } + else if(testedMedia.MediumType != null) + { + mediaOneValue.Add($"Information for medium type {testedMedia.MediumType:X2}h"); + } + else + { + mediaOneValue.Add("Information for unknown medium type"); + } + + mediaOneValue.Add(testedMedia.MediaIsRecognized ? "Drive recognizes this medium." + : "Drive does not recognize this medium."); + + if(!string.IsNullOrWhiteSpace(testedMedia.Manufacturer)) + mediaOneValue.Add($"Medium manufactured by: {testedMedia.Manufacturer}"); + + if(!string.IsNullOrWhiteSpace(testedMedia.Model)) + mediaOneValue.Add($"Medium model: {testedMedia.Model}"); + + if(testedMedia.Density != null) + mediaOneValue.Add($"Density code: {testedMedia.Density:X2}h"); + + if(testedMedia.BlockSize != null) + mediaOneValue.Add($"Logical sector size: {testedMedia.BlockSize} bytes"); + + if(testedMedia.PhysicalBlockSize != null) + mediaOneValue.Add($"Physical sector size: {testedMedia.PhysicalBlockSize} bytes"); + + if(testedMedia.LongBlockSize != null) + mediaOneValue.Add($"READ LONG sector size: {testedMedia.LongBlockSize} bytes"); + + if(testedMedia.Blocks != null && + testedMedia.BlockSize != null) + { + mediaOneValue.Add($"Medium has {testedMedia.Blocks} blocks of {testedMedia.BlockSize} bytes each"); + + if(testedMedia.Blocks * testedMedia.BlockSize / 1024 / 1024 > 1000000) + mediaOneValue. + Add($"Medium size: {testedMedia.Blocks * testedMedia.BlockSize} bytes, {testedMedia.Blocks * testedMedia.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(testedMedia.Blocks * testedMedia.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); + else if(testedMedia.Blocks * testedMedia.BlockSize / 1024 / 1024 > 1000) + mediaOneValue. + Add($"Medium size: {testedMedia.Blocks * testedMedia.BlockSize} bytes, {testedMedia.Blocks * testedMedia.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(testedMedia.Blocks * testedMedia.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); + else + mediaOneValue. + Add($"Medium size: {testedMedia.Blocks * testedMedia.BlockSize} bytes, {testedMedia.Blocks * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)(testedMedia.Blocks * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); + } + + if(testedMedia.CHS != null && + testedMedia.CurrentCHS != null) + { + int currentSectors = testedMedia.CurrentCHS.Cylinders * testedMedia.CurrentCHS.Heads * + testedMedia.CurrentCHS.Sectors; + + mediaOneValue. + Add($"Cylinders: {testedMedia.CHS.Cylinders} max., {testedMedia.CurrentCHS.Cylinders} current"); + + mediaOneValue.Add($"Heads: {testedMedia.CHS.Heads} max., {testedMedia.CurrentCHS.Heads} current"); + + mediaOneValue. + Add($"Sectors per track: {testedMedia.CHS.Sectors} max., {testedMedia.CurrentCHS.Sectors} current"); + + mediaOneValue. + Add($"Sectors addressable in CHS mode: {testedMedia.CHS.Cylinders * testedMedia.CHS.Heads * testedMedia.CHS.Sectors} max., {currentSectors} current"); + + mediaOneValue. + Add($"Medium size in CHS mode: {(ulong)currentSectors * testedMedia.BlockSize} bytes, {(ulong)currentSectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); + } + else if(testedMedia.CHS != null) + { + int currentSectors = testedMedia.CHS.Cylinders * testedMedia.CHS.Heads * testedMedia.CHS.Sectors; + mediaOneValue.Add($"Cylinders: {testedMedia.CHS.Cylinders}"); + mediaOneValue.Add($"Heads: {testedMedia.CHS.Heads}"); + mediaOneValue.Add($"Sectors per track: {testedMedia.CHS.Sectors}"); + mediaOneValue.Add($"Sectors addressable in CHS mode: {currentSectors}"); + + mediaOneValue. + Add($"Medium size in CHS mode: {(ulong)currentSectors * testedMedia.BlockSize} bytes, {(ulong)currentSectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)((ulong)currentSectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); + } + + if(testedMedia.LBASectors != null) + { + mediaOneValue.Add($"Sectors addressable in sectors in 28-bit LBA mode: {testedMedia.LBASectors}"); + + if((ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1024 / 1024 > 1000000) + mediaOneValue. + Add($"Medium size in 28-bit LBA mode: {(ulong)testedMedia.LBASectors * testedMedia.BlockSize} bytes, {(ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)((ulong)testedMedia.LBASectors * testedMedia.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); + else if((ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1024 / 1024 > 1000) + mediaOneValue. + Add($"Medium size in 28-bit LBA mode: {(ulong)testedMedia.LBASectors * testedMedia.BlockSize} bytes, {(ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1000 / 1000 / 1000} Gb, {(double)((ulong)testedMedia.LBASectors * testedMedia.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); + else + mediaOneValue. + Add($"Medium size in 28-bit LBA mode: {(ulong)testedMedia.LBASectors * testedMedia.BlockSize} bytes, {(ulong)testedMedia.LBASectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)((ulong)testedMedia.LBASectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); + } + + if(testedMedia.LBA48Sectors != null) + { + mediaOneValue.Add($"Sectors addressable in sectors in 48-bit LBA mode: {testedMedia.LBA48Sectors}"); + + if(testedMedia.LBA48Sectors * testedMedia.BlockSize / 1024 / 1024 > 1000000) + mediaOneValue. + Add($"Medium size in 48-bit LBA mode: {testedMedia.LBA48Sectors * testedMedia.BlockSize} bytes, {testedMedia.LBA48Sectors * testedMedia.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(testedMedia.LBA48Sectors * testedMedia.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB"); + else if(testedMedia.LBA48Sectors * testedMedia.BlockSize / 1024 / 1024 > 1000) + mediaOneValue. + Add($"Medium size in 48-bit LBA mode: {testedMedia.LBA48Sectors * testedMedia.BlockSize} bytes, {testedMedia.LBA48Sectors * testedMedia.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(testedMedia.LBA48Sectors * testedMedia.BlockSize) / 1024 / 1024 / 1024:F2} GiB"); + else + mediaOneValue. + Add($"Medium size in 48-bit LBA mode: {testedMedia.LBA48Sectors * testedMedia.BlockSize} bytes, {testedMedia.LBA48Sectors * testedMedia.BlockSize / 1000 / 1000} Mb, {(double)(testedMedia.LBA48Sectors * testedMedia.BlockSize) / 1024 / 1024:F2} MiB"); + } + + if(testedMedia.NominalRotationRate != null && + testedMedia.NominalRotationRate != 0x0000 && + testedMedia.NominalRotationRate != 0xFFFF) + mediaOneValue.Add(testedMedia.NominalRotationRate == 0x0001 ? "Medium does not rotate." + : $"Medium rotates at {testedMedia.NominalRotationRate} rpm"); + + if(testedMedia.BlockSize != null && + testedMedia.PhysicalBlockSize != null && + testedMedia.BlockSize.Value != testedMedia.PhysicalBlockSize.Value && + (testedMedia.LogicalAlignment & 0x8000) == 0x0000 && + (testedMedia.LogicalAlignment & 0x4000) == 0x4000) + mediaOneValue. + Add($"Logical sector starts at offset {testedMedia.LogicalAlignment & 0x3FFF} from physical sector"); + + if(testedMedia.SupportsReadSectors == true) + mediaOneValue.Add("Device can use the READ SECTOR(S) command in CHS mode with this medium"); + + if(testedMedia.SupportsReadRetry == true) + mediaOneValue.Add("Device can use the READ SECTOR(S) RETRY command in CHS mode with this medium"); + + if(testedMedia.SupportsReadDma == true) + mediaOneValue.Add("Device can use the READ DMA command in CHS mode with this medium"); + + if(testedMedia.SupportsReadDmaRetry == true) + mediaOneValue.Add("Device can use the READ DMA RETRY command in CHS mode with this medium"); + + if(testedMedia.SupportsReadLong == true) + mediaOneValue.Add("Device can use the READ LONG command in CHS mode with this medium"); + + if(testedMedia.SupportsReadLongRetry == true) + mediaOneValue.Add("Device can use the READ LONG RETRY command in CHS mode with this medium"); + + if(testedMedia.SupportsReadLba == true) + mediaOneValue.Add("Device can use the READ SECTOR(S) command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadRetryLba == true) + mediaOneValue. + Add("Device can use the READ SECTOR(S) RETRY command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadDmaLba == true) + mediaOneValue.Add("Device can use the READ DMA command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadDmaRetryLba == true) + mediaOneValue.Add("Device can use the READ DMA RETRY command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadLongLba == true) + mediaOneValue.Add("Device can use the READ LONG command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadLongRetryLba == true) + mediaOneValue.Add("Device can use the READ LONG RETRY command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadLba48 == true) + mediaOneValue.Add("Device can use the READ SECTOR(S) command in 48-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadDmaLba48 == true) + mediaOneValue.Add("Device can use the READ DMA command in 48-bit LBA mode with this medium"); + + if(testedMedia.SupportsSeek == true) + mediaOneValue.Add("Device can use the SEEK command in CHS mode with this medium"); + + if(testedMedia.SupportsSeekLba == true) + mediaOneValue.Add("Device can use the SEEK command in 28-bit LBA mode with this medium"); + + if(testedMedia.SupportsReadCapacity == true) + mediaOneValue.Add("Device can use the READ CAPACITY (10) command with this medium"); + + if(testedMedia.SupportsReadCapacity16 == true) + mediaOneValue.Add("Device can use the READ CAPACITY (16) command with this medium"); + + if(testedMedia.SupportsRead6 == true) + mediaOneValue.Add("Device can use the READ (6) command with this medium"); + + if(testedMedia.SupportsRead10 == true) + mediaOneValue.Add("Device can use the READ (10) command with this medium"); + + if(testedMedia.SupportsRead12 == true) + mediaOneValue.Add("Device can use the READ (12) command with this medium"); + + if(testedMedia.SupportsRead16 == true) + mediaOneValue.Add("Device can use the READ (16) command with this medium"); + + if(testedMedia.SupportsReadLong == true) + mediaOneValue.Add("Device can use the READ LONG (10) command with this medium"); + + if(testedMedia.SupportsReadLong16 == true) + mediaOneValue.Add("Device can use the READ LONG (16) command with this medium"); + + if(testedMedia.SupportsReadCd == true) + mediaOneValue.Add("Device can use the READ CD command with LBA addressing with this medium"); + + if(testedMedia.SupportsReadCdMsf == true) + mediaOneValue.Add("Device can use the READ CD command with MM:SS:FF addressing with this medium"); + + if(testedMedia.SupportsReadCdRaw == true) + mediaOneValue. + Add("Device can use the READ CD command with LBA addressing with this medium to read raw sector"); + + if(testedMedia.SupportsReadCdMsfRaw == true) + mediaOneValue. + Add("Device can use the READ CD command with MM:SS:FF addressing with this medium read raw sector"); + + if(testedMedia.SupportsHLDTSTReadRawDVD == true) + mediaOneValue.Add("Device can use the HL-DT-ST vendor READ DVD (RAW) command with this medium"); + + if(testedMedia.SupportsNECReadCDDA == true) + mediaOneValue.Add("Device can use the NEC vendor READ CD-DA command with this medium"); + + if(testedMedia.SupportsPioneerReadCDDA == true) + mediaOneValue.Add("Device can use the PIONEER vendor READ CD-DA command with this medium"); + + if(testedMedia.SupportsPioneerReadCDDAMSF == true) + mediaOneValue.Add("Device can use the PIONEER vendor READ CD-DA MSF command with this medium"); + + if(testedMedia.SupportsPlextorReadCDDA == true) + mediaOneValue.Add("Device can use the PLEXTOR vendor READ CD-DA command with this medium"); + + if(testedMedia.SupportsPlextorReadRawDVD == true) + mediaOneValue.Add("Device can use the PLEXTOR vendor READ DVD (RAW) command with this medium"); + + if(testedMedia.CanReadAACS == true) + mediaOneValue.Add("Device can read the Advanced Access Content System from this medium"); + + if(testedMedia.CanReadADIP == true) + mediaOneValue.Add("Device can read the DVD ADress-In-Pregroove from this medium"); + + if(testedMedia.CanReadATIP == true) + mediaOneValue.Add("Device can read the CD Absolute-Time-In-Pregroove from this medium"); + + if(testedMedia.CanReadBCA == true) + mediaOneValue.Add("Device can read the Burst Cutting Area from this medium"); + + if(testedMedia.CanReadC2Pointers == true) + mediaOneValue.Add("Device can report the C2 pointers when reading from this medium"); + + if(testedMedia.CanReadCMI == true) + mediaOneValue.Add("Device can read the Copyright Management Information from this medium"); + + if(testedMedia.CanReadCorrectedSubchannel == true) + mediaOneValue.Add("Device can correct subchannels when reading from this medium"); + + if(testedMedia.CanReadCorrectedSubchannelWithC2 == true) + mediaOneValue. + Add("Device can correct subchannels and report the C2 pointers when reading from this medium"); + + if(testedMedia.CanReadDCB == true) + mediaOneValue.Add("Device can read the Disc Control Blocks from this medium"); + + if(testedMedia.CanReadDDS == true) + mediaOneValue.Add("Device can read the Disc Definition Structure from this medium"); + + if(testedMedia.CanReadDMI == true) + mediaOneValue.Add("Device can read the Disc Manufacturer Information from this medium"); + + if(testedMedia.CanReadDiscInformation == true) + mediaOneValue.Add("Device can read the Disc Information from this medium"); + + if(testedMedia.CanReadFullTOC == true) + mediaOneValue.Add("Device can read the Table of Contents from this medium, without processing it"); + + if(testedMedia.CanReadHDCMI == true) + mediaOneValue.Add("Device can read the HD DVD Copyright Management Information from this medium"); + + if(testedMedia.CanReadLayerCapacity == true) + mediaOneValue.Add("Device can read the layer capacity from this medium"); + + if(testedMedia.CanReadFirstTrackPreGap == true) + mediaOneValue.Add("Device can read the first track's pregap data"); + + if(testedMedia.CanReadLeadIn == true) + mediaOneValue.Add("Device can read the Lead-In from this medium"); + + if(testedMedia.CanReadLeadOut == true) + mediaOneValue.Add("Device can read the Lead-Out from this medium"); + + if(testedMedia.CanReadMediaID == true) + mediaOneValue.Add("Device can read the Media ID from this medium"); + + if(testedMedia.CanReadMediaSerial == true) + mediaOneValue.Add("Device can read the Media Serial Number from this medium"); + + if(testedMedia.CanReadPAC == true) + mediaOneValue.Add("Device can read the PAC from this medium"); + + if(testedMedia.CanReadPFI == true) + mediaOneValue.Add("Device can read the Physical Format Information from this medium"); + + if(testedMedia.CanReadPMA == true) + mediaOneValue.Add("Device can read the Power Management Area from this medium"); + + if(testedMedia.CanReadPQSubchannel == true) + mediaOneValue.Add("Device can read the P to Q subchannels from this medium"); + + if(testedMedia.CanReadPQSubchannelWithC2 == true) + mediaOneValue. + Add("Device can read the P to Q subchannels from this medium reporting the C2 pointers"); + + if(testedMedia.CanReadPRI == true) + mediaOneValue.Add("Device can read the Pre-Recorded Information from this medium"); + + if(testedMedia.CanReadRWSubchannel == true) + mediaOneValue.Add("Device can read the R to W subchannels from this medium"); + + if(testedMedia.CanReadRWSubchannelWithC2 == true) + mediaOneValue. + Add("Device can read the R to W subchannels from this medium reporting the C2 pointers"); + + if(testedMedia.CanReadRecordablePFI == true) + mediaOneValue.Add("Device can read the Physical Format Information from Lead-In from this medium"); + + if(testedMedia.CanReadSpareAreaInformation == true) + mediaOneValue.Add("Device can read the Spare Area Information from this medium"); + + if(testedMedia.CanReadTOC == true) + mediaOneValue.Add("Device can read the Table of Contents from this medium"); + + if(testedMedia.CanReadingIntersessionLeadIn == true) + mediaOneValue.Add("Device can read Lead-In between sessions"); + + if(testedMedia.CanReadingIntersessionLeadOut == true) + mediaOneValue.Add("Device can read Lead-Out between sessions"); + + if(testedMedia.CanReadCdScrambled == true) + mediaOneValue.Add("Device can read scrambled sectors using standard READ CD command"); + + if(testedMedia.CanReadF1_06 == true) + mediaOneValue.Add("Device can read from cache using F1h command with subcommand 06h"); + + if(testedMedia.CanReadF1_06LeadOut == true) + mediaOneValue.Add("Device can read Lead-Out from cache using F1h command with subcommand 06h"); + + mediaOneValue.Add(""); } } } \ No newline at end of file diff --git a/Aaru.Server/Models/BaseModel.cs b/Aaru.Server/Models/BaseModel.cs index bafc4b95..9fe48ce4 100644 --- a/Aaru.Server/Models/BaseModel.cs +++ b/Aaru.Server/Models/BaseModel.cs @@ -1,10 +1,9 @@ using System.ComponentModel.DataAnnotations; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public abstract class BaseModel { - public abstract class BaseModel - { - [Key] - public T Id { get; set; } - } + [Key] + public T Id { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/BaseOperatingSystem.cs b/Aaru.Server/Models/BaseOperatingSystem.cs index ec93a508..1a688534 100644 --- a/Aaru.Server/Models/BaseOperatingSystem.cs +++ b/Aaru.Server/Models/BaseOperatingSystem.cs @@ -30,12 +30,11 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public abstract class BaseOperatingSystem : BaseModel { - public abstract class BaseOperatingSystem : BaseModel - { - public string Name { get; set; } - public string Version { get; set; } - public long Count { get; set; } - } + public string Name { get; set; } + public string Version { get; set; } + public long Count { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/CdOffset.cs b/Aaru.Server/Models/CdOffset.cs index aebc8d77..3f3ce735 100644 --- a/Aaru.Server/Models/CdOffset.cs +++ b/Aaru.Server/Models/CdOffset.cs @@ -35,37 +35,36 @@ using System.Collections.Generic; using System.ComponentModel; using Aaru.CommonTypes.Metadata; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class CompactDiscOffset : CdOffset { - public class CompactDiscOffset : CdOffset + public CompactDiscOffset() {} + + public CompactDiscOffset(string manufacturer, string model, short offset, int submissions, float agreement) { - public CompactDiscOffset() {} - - public CompactDiscOffset(string manufacturer, string model, short offset, int submissions, float agreement) - { - Manufacturer = manufacturer; - Model = model; - Offset = offset; - Submissions = submissions; - Agreement = agreement; - AddedWhen = ModifiedWhen = DateTime.UtcNow; - } - - public CompactDiscOffset(CdOffset offset) - { - Manufacturer = offset.Manufacturer; - Model = offset.Model; - Offset = offset.Offset; - Submissions = offset.Submissions; - Agreement = offset.Agreement; - AddedWhen = ModifiedWhen = DateTime.UtcNow; - } - - public int Id { get; set; } - [DisplayName("Added date")] - public DateTime AddedWhen { get; set; } - [DisplayName("Modification date")] - public DateTime ModifiedWhen { get; set; } - public virtual ICollection Devices { get; set; } + Manufacturer = manufacturer; + Model = model; + Offset = offset; + Submissions = submissions; + Agreement = agreement; + AddedWhen = ModifiedWhen = DateTime.UtcNow; } + + public CompactDiscOffset(CdOffset offset) + { + Manufacturer = offset.Manufacturer; + Model = offset.Model; + Offset = offset.Offset; + Submissions = offset.Submissions; + Agreement = offset.Agreement; + AddedWhen = ModifiedWhen = DateTime.UtcNow; + } + + public int Id { get; set; } + [DisplayName("Added date")] + public DateTime AddedWhen { get; set; } + [DisplayName("Modification date")] + public DateTime ModifiedWhen { get; set; } + public virtual ICollection Devices { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/ChsModel.cs b/Aaru.Server/Models/ChsModel.cs index 31186b7e..6c4252f5 100644 --- a/Aaru.Server/Models/ChsModel.cs +++ b/Aaru.Server/Models/ChsModel.cs @@ -1,17 +1,16 @@ using System.Collections.Generic; -namespace Aaru.Server.Models -{ - public class ChsModel - { - public ushort Cylinders { get; set; } - public ushort Heads { get; set; } - public ushort Sectors { get; set; } - } +namespace Aaru.Server.Models; - public class ChsModelForView - { - public List List { get; set; } - public string Json { get; set; } - } +public class ChsModel +{ + public ushort Cylinders { get; set; } + public ushort Heads { get; set; } + public ushort Sectors { get; set; } +} + +public class ChsModelForView +{ + public List List { get; set; } + public string Json { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/Command.cs b/Aaru.Server/Models/Command.cs index c9009a61..9f1f561f 100644 --- a/Aaru.Server/Models/Command.cs +++ b/Aaru.Server/Models/Command.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class Command : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class Command : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Models/CompareModel.cs b/Aaru.Server/Models/CompareModel.cs index 2355e90e..d467c4d3 100644 --- a/Aaru.Server/Models/CompareModel.cs +++ b/Aaru.Server/Models/CompareModel.cs @@ -1,16 +1,15 @@ using System.Collections.Generic; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class CompareModel { - public class CompareModel - { - public int LeftId { get; set; } - public int RightId { get; set; } - public List ValueNames { get; set; } - public List LeftValues { get; set; } - public List RightValues { get; set; } - public bool HasError { get; set; } - public string ErrorMessage { get; set; } - public bool AreEqual { get; set; } - } + public int LeftId { get; set; } + public int RightId { get; set; } + public List ValueNames { get; set; } + public List LeftValues { get; set; } + public List RightValues { get; set; } + public bool HasError { get; set; } + public string ErrorMessage { get; set; } + public bool AreEqual { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/Context.cs b/Aaru.Server/Models/Context.cs index bb8cab05..cd8d32e0 100644 --- a/Aaru.Server/Models/Context.cs +++ b/Aaru.Server/Models/Context.cs @@ -37,235 +37,234 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public sealed class AaruServerContext : IdentityDbContext { - public sealed class AaruServerContext : IdentityDbContext + public AaruServerContext() {} + + public AaruServerContext(DbContextOptions options) : base(options) {} + + public DbSet Devices { get; set; } + public DbSet Reports { get; set; } + public DbSet Commands { get; set; } + public DbSet DeviceStats { get; set; } + public DbSet Filesystems { get; set; } + public DbSet Filters { get; set; } + public DbSet Medias { get; set; } + public DbSet MediaFormats { get; set; } + public DbSet OperatingSystems { get; set; } + public DbSet Partitions { get; set; } + public DbSet Versions { get; set; } + public DbSet UsbVendors { get; set; } + public DbSet UsbProducts { get; set; } + public DbSet CdOffsets { get; set; } + public DbSet Ata { get; set; } + public DbSet BlockDescriptor { get; set; } + public DbSet Chs { get; set; } + public DbSet FireWire { get; set; } + public DbSet Mmc { get; set; } + public DbSet MmcSd { get; set; } + public DbSet MmcFeatures { get; set; } + public DbSet Pcmcia { get; set; } + public DbSet Scsi { get; set; } + public DbSet ScsiMode { get; set; } + public DbSet ScsiPage { get; set; } + public DbSet Ssc { get; set; } + public DbSet SupportedDensity { get; set; } + public DbSet TestedMedia { get; set; } + public DbSet TestedSequentialMedia { get; set; } + public DbSet Usb { get; set; } + public DbSet RemoteApplications { get; set; } + public DbSet RemoteArchitectures { get; set; } + public DbSet RemoteOperatingSystems { get; set; } + public DbSet GdRomSwapDiscCapabilities { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - public AaruServerContext() {} + if(optionsBuilder.IsConfigured) + return; - public AaruServerContext(DbContextOptions options) : base(options) {} + IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); + IConfigurationRoot configuration = builder.Build(); - public DbSet Devices { get; set; } - public DbSet Reports { get; set; } - public DbSet Commands { get; set; } - public DbSet DeviceStats { get; set; } - public DbSet Filesystems { get; set; } - public DbSet Filters { get; set; } - public DbSet Medias { get; set; } - public DbSet MediaFormats { get; set; } - public DbSet OperatingSystems { get; set; } - public DbSet Partitions { get; set; } - public DbSet Versions { get; set; } - public DbSet UsbVendors { get; set; } - public DbSet UsbProducts { get; set; } - public DbSet CdOffsets { get; set; } - public DbSet Ata { get; set; } - public DbSet BlockDescriptor { get; set; } - public DbSet Chs { get; set; } - public DbSet FireWire { get; set; } - public DbSet Mmc { get; set; } - public DbSet MmcSd { get; set; } - public DbSet MmcFeatures { get; set; } - public DbSet Pcmcia { get; set; } - public DbSet Scsi { get; set; } - public DbSet ScsiMode { get; set; } - public DbSet ScsiPage { get; set; } - public DbSet Ssc { get; set; } - public DbSet SupportedDensity { get; set; } - public DbSet TestedMedia { get; set; } - public DbSet TestedSequentialMedia { get; set; } - public DbSet Usb { get; set; } - public DbSet RemoteApplications { get; set; } - public DbSet RemoteArchitectures { get; set; } - public DbSet RemoteOperatingSystems { get; set; } - public DbSet GdRomSwapDiscCapabilities { get; set; } + optionsBuilder. + UseMySql(configuration.GetConnectionString("DefaultConnection"), + new MariaDbServerVersion(new System.Version(10, 4, 0))).UseLazyLoadingProxies(); + } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.Ata", + b => b.HasOne("Aaru.CommonTypes.Metadata.TestedMedia", "ReadCapabilities").WithMany(). + HasForeignKey("ReadCapabilitiesId").OnDelete(DeleteBehavior.SetNull)); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.BlockDescriptor", + b => b.HasOne("Aaru.CommonTypes.Metadata.ScsiMode", null).WithMany("BlockDescriptors"). + HasForeignKey("ScsiModeId").OnDelete(DeleteBehavior.Cascade)); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.DensityCode", + b => b.HasOne("Aaru.CommonTypes.Metadata.SscSupportedMedia", null). + WithMany("DensityCodes").HasForeignKey("SscSupportedMediaId"). + OnDelete(DeleteBehavior.Cascade)); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.Mmc", + b => b.HasOne("Aaru.CommonTypes.Metadata.MmcFeatures", "Features").WithMany(). + HasForeignKey("FeaturesId").OnDelete(DeleteBehavior.SetNull)); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.Scsi", b => { - if(optionsBuilder.IsConfigured) - return; + b.HasOne("Aaru.CommonTypes.Metadata.ScsiMode", "ModeSense").WithMany().HasForeignKey("ModeSenseId"). + OnDelete(DeleteBehavior.SetNull); - IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); - IConfigurationRoot configuration = builder.Build(); + b.HasOne("Aaru.CommonTypes.Metadata.Mmc", "MultiMediaDevice").WithMany(). + HasForeignKey("MultiMediaDeviceId").OnDelete(DeleteBehavior.SetNull); - optionsBuilder. - UseMySql(configuration.GetConnectionString("DefaultConnection"), - new MariaDbServerVersion(new System.Version(10, 4, 0))).UseLazyLoadingProxies(); - } + b.HasOne("Aaru.CommonTypes.Metadata.TestedMedia", "ReadCapabilities").WithMany(). + HasForeignKey("ReadCapabilitiesId").OnDelete(DeleteBehavior.SetNull); - protected override void OnModelCreating(ModelBuilder modelBuilder) + b.HasOne("Aaru.CommonTypes.Metadata.Ssc", "SequentialDevice").WithMany(). + HasForeignKey("SequentialDeviceId").OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.ScsiPage", b => { - base.OnModelCreating(modelBuilder); + b.HasOne("Aaru.CommonTypes.Metadata.Scsi", null).WithMany("EVPDPages").HasForeignKey("ScsiId"). + OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity("Aaru.CommonTypes.Metadata.Ata", - b => b.HasOne("Aaru.CommonTypes.Metadata.TestedMedia", "ReadCapabilities").WithMany(). - HasForeignKey("ReadCapabilitiesId").OnDelete(DeleteBehavior.SetNull)); + b.HasOne("Aaru.CommonTypes.Metadata.ScsiMode", null).WithMany("ModePages").HasForeignKey("ScsiModeId"). + OnDelete(DeleteBehavior.SetNull); + }); - modelBuilder.Entity("Aaru.CommonTypes.Metadata.BlockDescriptor", - b => b.HasOne("Aaru.CommonTypes.Metadata.ScsiMode", null).WithMany("BlockDescriptors"). - HasForeignKey("ScsiModeId").OnDelete(DeleteBehavior.Cascade)); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.DensityCode", - b => b.HasOne("Aaru.CommonTypes.Metadata.SscSupportedMedia", null). - WithMany("DensityCodes").HasForeignKey("SscSupportedMediaId"). - OnDelete(DeleteBehavior.Cascade)); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.Mmc", - b => b.HasOne("Aaru.CommonTypes.Metadata.MmcFeatures", "Features").WithMany(). - HasForeignKey("FeaturesId").OnDelete(DeleteBehavior.SetNull)); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.Scsi", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.ScsiMode", "ModeSense").WithMany().HasForeignKey("ModeSenseId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Mmc", "MultiMediaDevice").WithMany(). - HasForeignKey("MultiMediaDeviceId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.TestedMedia", "ReadCapabilities").WithMany(). - HasForeignKey("ReadCapabilitiesId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Ssc", "SequentialDevice").WithMany(). - HasForeignKey("SequentialDeviceId").OnDelete(DeleteBehavior.SetNull); - }); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.ScsiPage", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.Scsi", null).WithMany("EVPDPages").HasForeignKey("ScsiId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.ScsiMode", null).WithMany("ModePages").HasForeignKey("ScsiModeId"). - OnDelete(DeleteBehavior.SetNull); - }); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.SscSupportedMedia", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.Ssc", null).WithMany("SupportedMediaTypes").HasForeignKey("SscId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.TestedSequentialMedia", null).WithMany("SupportedMediaTypes"). - HasForeignKey("TestedSequentialMediaId").OnDelete(DeleteBehavior.SetNull); - }); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.SupportedDensity", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.Ssc", null).WithMany("SupportedDensities").HasForeignKey("SscId"). - OnDelete(DeleteBehavior.Cascade); - - b.HasOne("Aaru.CommonTypes.Metadata.TestedSequentialMedia", null).WithMany("SupportedDensities"). - HasForeignKey("TestedSequentialMediaId").OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.TestedMedia", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.Ata", null).WithMany("RemovableMedias").HasForeignKey("AtaId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Chs", "CHS").WithMany().HasForeignKey("CHSId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Chs", "CurrentCHS").WithMany().HasForeignKey("CurrentCHSId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Mmc", null).WithMany("TestedMedia").HasForeignKey("MmcId"). - OnDelete(DeleteBehavior.Cascade); - - b.HasOne("Aaru.CommonTypes.Metadata.Scsi", null).WithMany("RemovableMedias").HasForeignKey("ScsiId"). - OnDelete(DeleteBehavior.SetNull); - }); - - modelBuilder.Entity("Aaru.CommonTypes.Metadata.TestedSequentialMedia", - b => b.HasOne("Aaru.CommonTypes.Metadata.Ssc", null).WithMany("TestedMedia"). - HasForeignKey("SscId").OnDelete(DeleteBehavior.SetNull)); - - modelBuilder.Entity("Aaru.Server.Models.Device", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATA").WithMany().HasForeignKey("ATAId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATAPI").WithMany().HasForeignKey("ATAPIId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.Server.Models.CompactDiscOffset", "CdOffset").WithMany("Devices"). - HasForeignKey("CdOffsetId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany(). - HasForeignKey("MultiMediaCardId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany(). - HasForeignKey("SecureDigitalId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId"). - OnDelete(DeleteBehavior.SetNull); - }); - - modelBuilder.Entity("Aaru.Server.Models.DeviceStat", - b => b.HasOne("Aaru.Server.Models.Device", "Report").WithMany(). - HasForeignKey("ReportId").OnDelete(DeleteBehavior.SetNull)); - - modelBuilder.Entity("Aaru.Server.Models.UploadedReport", b => - { - b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATA").WithMany().HasForeignKey("ATAId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATAPI").WithMany().HasForeignKey("ATAPIId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany(). - HasForeignKey("MultiMediaCardId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId"). - OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany(). - HasForeignKey("SecureDigitalId").OnDelete(DeleteBehavior.SetNull); - - b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId"). - OnDelete(DeleteBehavior.SetNull); - }); - - modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); - - modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); - - modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); - modelBuilder.Entity().HasIndex(b => b.ProductId); - modelBuilder.Entity().HasIndex(b => b.VendorId); - - modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); - modelBuilder.Entity().HasIndex(b => b.VendorId).IsUnique(); - } - - internal static bool TableExists(string tableName) + modelBuilder.Entity("Aaru.CommonTypes.Metadata.SscSupportedMedia", b => { - using var db = new AaruServerContext(); + b.HasOne("Aaru.CommonTypes.Metadata.Ssc", null).WithMany("SupportedMediaTypes").HasForeignKey("SscId"). + OnDelete(DeleteBehavior.SetNull); - DbConnection connection = db.Database.GetDbConnection(); - connection.Open(); + b.HasOne("Aaru.CommonTypes.Metadata.TestedSequentialMedia", null).WithMany("SupportedMediaTypes"). + HasForeignKey("TestedSequentialMediaId").OnDelete(DeleteBehavior.SetNull); + }); - DbCommand command = connection.CreateCommand(); + modelBuilder.Entity("Aaru.CommonTypes.Metadata.SupportedDensity", b => + { + b.HasOne("Aaru.CommonTypes.Metadata.Ssc", null).WithMany("SupportedDensities").HasForeignKey("SscId"). + OnDelete(DeleteBehavior.Cascade); - command.CommandText = - $"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=\"{tableName}\""; + b.HasOne("Aaru.CommonTypes.Metadata.TestedSequentialMedia", null).WithMany("SupportedDensities"). + HasForeignKey("TestedSequentialMediaId").OnDelete(DeleteBehavior.Cascade); + }); - long result = (long)command.ExecuteScalar(); + modelBuilder.Entity("Aaru.CommonTypes.Metadata.TestedMedia", b => + { + b.HasOne("Aaru.CommonTypes.Metadata.Ata", null).WithMany("RemovableMedias").HasForeignKey("AtaId"). + OnDelete(DeleteBehavior.SetNull); - return result != 0; - } + b.HasOne("Aaru.CommonTypes.Metadata.Chs", "CHS").WithMany().HasForeignKey("CHSId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Chs", "CurrentCHS").WithMany().HasForeignKey("CurrentCHSId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Mmc", null).WithMany("TestedMedia").HasForeignKey("MmcId"). + OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Aaru.CommonTypes.Metadata.Scsi", null).WithMany("RemovableMedias").HasForeignKey("ScsiId"). + OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity("Aaru.CommonTypes.Metadata.TestedSequentialMedia", + b => b.HasOne("Aaru.CommonTypes.Metadata.Ssc", null).WithMany("TestedMedia"). + HasForeignKey("SscId").OnDelete(DeleteBehavior.SetNull)); + + modelBuilder.Entity("Aaru.Server.Models.Device", b => + { + b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATA").WithMany().HasForeignKey("ATAId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATAPI").WithMany().HasForeignKey("ATAPIId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.Server.Models.CompactDiscOffset", "CdOffset").WithMany("Devices"). + HasForeignKey("CdOffsetId").OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany(). + HasForeignKey("MultiMediaCardId").OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany(). + HasForeignKey("SecureDigitalId").OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId"). + OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity("Aaru.Server.Models.DeviceStat", + b => b.HasOne("Aaru.Server.Models.Device", "Report").WithMany(). + HasForeignKey("ReportId").OnDelete(DeleteBehavior.SetNull)); + + modelBuilder.Entity("Aaru.Server.Models.UploadedReport", b => + { + b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATA").WithMany().HasForeignKey("ATAId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Ata", "ATAPI").WithMany().HasForeignKey("ATAPIId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany(). + HasForeignKey("MultiMediaCardId").OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId"). + OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany(). + HasForeignKey("SecureDigitalId").OnDelete(DeleteBehavior.SetNull); + + b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId"). + OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); + + modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); + + modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); + modelBuilder.Entity().HasIndex(b => b.ProductId); + modelBuilder.Entity().HasIndex(b => b.VendorId); + + modelBuilder.Entity().HasIndex(b => b.ModifiedWhen); + modelBuilder.Entity().HasIndex(b => b.VendorId).IsUnique(); + } + + internal static bool TableExists(string tableName) + { + using var db = new AaruServerContext(); + + DbConnection connection = db.Database.GetDbConnection(); + connection.Open(); + + DbCommand command = connection.CreateCommand(); + + command.CommandText = + $"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=\"{tableName}\""; + + long result = (long)command.ExecuteScalar(); + + return result != 0; } } \ No newline at end of file diff --git a/Aaru.Server/Models/Device.cs b/Aaru.Server/Models/Device.cs index ff02727c..c294943b 100644 --- a/Aaru.Server/Models/Device.cs +++ b/Aaru.Server/Models/Device.cs @@ -35,74 +35,73 @@ using System.ComponentModel; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Metadata; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class Device : DeviceReportV2 { - public class Device : DeviceReportV2 + public Device() => AddedWhen = DateTime.UtcNow; + + public Device(DeviceReportV2 report) { - public Device() => AddedWhen = DateTime.UtcNow; - - public Device(DeviceReportV2 report) - { - ATA = report.ATA; - ATAPI = report.ATAPI; - CompactFlash = report.CompactFlash; - FireWire = report.FireWire; - AddedWhen = DateTime.UtcNow; - ModifiedWhen = DateTime.UtcNow; - MultiMediaCard = report.MultiMediaCard; - PCMCIA = report.PCMCIA; - SCSI = report.SCSI; - SecureDigital = report.SecureDigital; - USB = report.USB; - Manufacturer = report.Manufacturer; - Model = report.Model; - Revision = report.Revision; - Type = report.Type; - GdRomSwapDiscCapabilities = report.GdRomSwapDiscCapabilities; - } - - public Device(int? ataId, int? atapiId, int? firewireId, int? multimediacardId, int? pcmciaId, - int? securedigitalId, int? scsiId, int? usbId, DateTime uploadedWhen, string manufacturer, - string model, string revision, bool compactFlash, DeviceType type, - int? gdRomSwapDiscCapabilitiesId) - { - ATAId = ataId; - ATAPIId = atapiId; - FireWireId = firewireId; - MultiMediaCardId = multimediacardId; - PCMCIAId = pcmciaId; - SecureDigitalId = securedigitalId; - SCSIId = scsiId; - USBId = usbId; - AddedWhen = uploadedWhen; - ModifiedWhen = DateTime.UtcNow; - Manufacturer = manufacturer; - Model = model; - Revision = revision; - CompactFlash = compactFlash; - Type = type; - GdRomSwapDiscCapabilitiesId = gdRomSwapDiscCapabilitiesId; - } - - [DisplayName("Added when")] - public DateTime AddedWhen { get; set; } - [DisplayName("Modified when")] - public DateTime? ModifiedWhen { get; set; } - public virtual CompactDiscOffset CdOffset { get; set; } - - [DefaultValue(0), DisplayName("Optimal no. of sectors to be read at once")] - public int OptimalMultipleSectorsRead { get; set; } - [DefaultValue(null), DisplayName("Can read GD-ROM using swap disc trick")] - public bool? CanReadGdRomUsingSwapDisc { get; set; } - - public int? ATAId { get; set; } - public int? ATAPIId { get; set; } - public int? FireWireId { get; set; } - public int? MultiMediaCardId { get; set; } - public int? PCMCIAId { get; set; } - public int? SecureDigitalId { get; set; } - public int? SCSIId { get; set; } - public int? USBId { get; set; } - public int? GdRomSwapDiscCapabilitiesId { get; set; } + ATA = report.ATA; + ATAPI = report.ATAPI; + CompactFlash = report.CompactFlash; + FireWire = report.FireWire; + AddedWhen = DateTime.UtcNow; + ModifiedWhen = DateTime.UtcNow; + MultiMediaCard = report.MultiMediaCard; + PCMCIA = report.PCMCIA; + SCSI = report.SCSI; + SecureDigital = report.SecureDigital; + USB = report.USB; + Manufacturer = report.Manufacturer; + Model = report.Model; + Revision = report.Revision; + Type = report.Type; + GdRomSwapDiscCapabilities = report.GdRomSwapDiscCapabilities; } + + public Device(int? ataId, int? atapiId, int? firewireId, int? multimediacardId, int? pcmciaId, + int? securedigitalId, int? scsiId, int? usbId, DateTime uploadedWhen, string manufacturer, + string model, string revision, bool compactFlash, DeviceType type, + int? gdRomSwapDiscCapabilitiesId) + { + ATAId = ataId; + ATAPIId = atapiId; + FireWireId = firewireId; + MultiMediaCardId = multimediacardId; + PCMCIAId = pcmciaId; + SecureDigitalId = securedigitalId; + SCSIId = scsiId; + USBId = usbId; + AddedWhen = uploadedWhen; + ModifiedWhen = DateTime.UtcNow; + Manufacturer = manufacturer; + Model = model; + Revision = revision; + CompactFlash = compactFlash; + Type = type; + GdRomSwapDiscCapabilitiesId = gdRomSwapDiscCapabilitiesId; + } + + [DisplayName("Added when")] + public DateTime AddedWhen { get; set; } + [DisplayName("Modified when")] + public DateTime? ModifiedWhen { get; set; } + public virtual CompactDiscOffset CdOffset { get; set; } + + [DefaultValue(0), DisplayName("Optimal no. of sectors to be read at once")] + public int OptimalMultipleSectorsRead { get; set; } + [DefaultValue(null), DisplayName("Can read GD-ROM using swap disc trick")] + public bool? CanReadGdRomUsingSwapDisc { get; set; } + + public int? ATAId { get; set; } + public int? ATAPIId { get; set; } + public int? FireWireId { get; set; } + public int? MultiMediaCardId { get; set; } + public int? PCMCIAId { get; set; } + public int? SecureDigitalId { get; set; } + public int? SCSIId { get; set; } + public int? USBId { get; set; } + public int? GdRomSwapDiscCapabilitiesId { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/DeviceDetails.cs b/Aaru.Server/Models/DeviceDetails.cs index f6abe442..e96f1e1f 100644 --- a/Aaru.Server/Models/DeviceDetails.cs +++ b/Aaru.Server/Models/DeviceDetails.cs @@ -1,19 +1,18 @@ using System.Collections.Generic; using Aaru.CommonTypes.Metadata; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class DeviceDetails { - public class DeviceDetails - { - public Device Report { get; set; } - public List SameAll { get; set; } - public List SameButManufacturer { get; set; } - public List ReportAll { get; set; } - public List ReportButManufacturer { get; set; } - public List StatsAll { get; set; } - public List StatsButManufacturer { get; set; } - public int ReadCapabilitiesId { get; set; } - public List TestedMedias { get; set; } - public List TestedSequentialMedias { get; set; } - } + public Device Report { get; set; } + public List SameAll { get; set; } + public List SameButManufacturer { get; set; } + public List ReportAll { get; set; } + public List ReportButManufacturer { get; set; } + public List StatsAll { get; set; } + public List StatsButManufacturer { get; set; } + public int ReadCapabilitiesId { get; set; } + public List TestedMedias { get; set; } + public List TestedSequentialMedias { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/DeviceItem.cs b/Aaru.Server/Models/DeviceItem.cs index 9745fabb..b85a12e8 100644 --- a/Aaru.Server/Models/DeviceItem.cs +++ b/Aaru.Server/Models/DeviceItem.cs @@ -30,14 +30,13 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class DeviceItem { - public class DeviceItem - { - public string Manufacturer { get; set; } - public string Model { get; set; } - public string Revision { get; set; } - public string Bus { get; set; } - public int ReportId { get; set; } - } + public string Manufacturer { get; set; } + public string Model { get; set; } + public string Revision { get; set; } + public string Bus { get; set; } + public int ReportId { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/DeviceStat.cs b/Aaru.Server/Models/DeviceStat.cs index 1f99a471..35eccc15 100644 --- a/Aaru.Server/Models/DeviceStat.cs +++ b/Aaru.Server/Models/DeviceStat.cs @@ -30,14 +30,13 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class DeviceStat : BaseModel { - public class DeviceStat : BaseModel - { - public string Manufacturer { get; set; } - public string Model { get; set; } - public string Revision { get; set; } - public string Bus { get; set; } - public virtual Device Report { get; set; } - } + public string Manufacturer { get; set; } + public string Model { get; set; } + public string Revision { get; set; } + public string Bus { get; set; } + public virtual Device Report { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/ErrorViewModel.cs b/Aaru.Server/Models/ErrorViewModel.cs index 2a61bcfb..31726820 100644 --- a/Aaru.Server/Models/ErrorViewModel.cs +++ b/Aaru.Server/Models/ErrorViewModel.cs @@ -1,9 +1,8 @@ -namespace Aaru.Server.Models -{ - public class ErrorViewModel - { - public string RequestId { get; set; } +namespace Aaru.Server.Models; - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } +public class ErrorViewModel +{ + public string RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); } \ No newline at end of file diff --git a/Aaru.Server/Models/Filesystem.cs b/Aaru.Server/Models/Filesystem.cs index 794a0b9b..98b054b8 100644 --- a/Aaru.Server/Models/Filesystem.cs +++ b/Aaru.Server/Models/Filesystem.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class Filesystem : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class Filesystem : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Models/Filter.cs b/Aaru.Server/Models/Filter.cs index 6d726e4c..fa93e0be 100644 --- a/Aaru.Server/Models/Filter.cs +++ b/Aaru.Server/Models/Filter.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class Filter : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class Filter : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Models/FindReportModel.cs b/Aaru.Server/Models/FindReportModel.cs index d2b1942a..8b7583d4 100644 --- a/Aaru.Server/Models/FindReportModel.cs +++ b/Aaru.Server/Models/FindReportModel.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class FindReportModel : BaseModel { - public class FindReportModel : BaseModel - { - public string Manufacturer { get; set; } - public string Model { get; set; } - public string Revision { get; set; } - public string Bus { get; set; } - public List LikeDevices { get; set; } - } + public string Manufacturer { get; set; } + public string Model { get; set; } + public string Revision { get; set; } + public string Bus { get; set; } + public List LikeDevices { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/FireWireModel.cs b/Aaru.Server/Models/FireWireModel.cs index dd0b1bce..de1c56e8 100644 --- a/Aaru.Server/Models/FireWireModel.cs +++ b/Aaru.Server/Models/FireWireModel.cs @@ -2,25 +2,24 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace Aaru.Server.Models -{ - public class FireWireModel - { - [DisplayName("Vendor ID"), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "0x{0:X8}")] - public uint VendorID { get; set; } - [DisplayName("Product ID"), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "0x{0:X8}")] - public uint ProductID { get; set; } - [DisplayFormat(NullDisplayText = "Unknown")] - public string Manufacturer { get; set; } - [DisplayFormat(NullDisplayText = "Unknown")] - public string Product { get; set; } - [DisplayName("Is media removable?")] - public bool RemovableMedia { get; set; } - } +namespace Aaru.Server.Models; - public class FireWireModelForView - { - public List List { get; set; } - public string Json { get; set; } - } +public class FireWireModel +{ + [DisplayName("Vendor ID"), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "0x{0:X8}")] + public uint VendorID { get; set; } + [DisplayName("Product ID"), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "0x{0:X8}")] + public uint ProductID { get; set; } + [DisplayFormat(NullDisplayText = "Unknown")] + public string Manufacturer { get; set; } + [DisplayFormat(NullDisplayText = "Unknown")] + public string Product { get; set; } + [DisplayName("Is media removable?")] + public bool RemovableMedia { get; set; } +} + +public class FireWireModelForView +{ + public List List { get; set; } + public string Json { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/IdHashModel.cs b/Aaru.Server/Models/IdHashModel.cs index a40b5f0d..97d0a3c5 100644 --- a/Aaru.Server/Models/IdHashModel.cs +++ b/Aaru.Server/Models/IdHashModel.cs @@ -1,15 +1,14 @@ -namespace Aaru.Server.Models -{ - public class IdHashModel : BaseModel - { - public IdHashModel(int id, string hash) - { - Id = id; - Hash = hash; - } +namespace Aaru.Server.Models; - public string Hash { get; set; } - public string Description { get; set; } - public int[] Duplicates { get; set; } +public class IdHashModel : BaseModel +{ + public IdHashModel(int id, string hash) + { + Id = id; + Hash = hash; } + + public string Hash { get; set; } + public string Description { get; set; } + public int[] Duplicates { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/IdHashModelForView.cs b/Aaru.Server/Models/IdHashModelForView.cs index 14724a29..e469b5a6 100644 --- a/Aaru.Server/Models/IdHashModelForView.cs +++ b/Aaru.Server/Models/IdHashModelForView.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class IdHashModelForView { - public class IdHashModelForView - { - public List List { get; set; } - public string Json { get; set; } - } + public List List { get; set; } + public string Json { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/Media.cs b/Aaru.Server/Models/Media.cs index 03ca4602..b7e26ac0 100644 --- a/Aaru.Server/Models/Media.cs +++ b/Aaru.Server/Models/Media.cs @@ -35,44 +35,43 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using Aaru.CommonTypes; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class Media : BaseModel { - public class Media : BaseModel + [NotMapped] + (string type, string subType) _mediaType; + + public string Type { get; set; } + public bool Real { get; set; } + public long Count { get; set; } + + [NotMapped] + (string type, string subType) MediaType { - [NotMapped] - (string type, string subType) _mediaType; - - public string Type { get; set; } - public bool Real { get; set; } - public long Count { get; set; } - - [NotMapped] - (string type, string subType) MediaType + get { - get - { - if(_mediaType != default) - return _mediaType; - - try - { - if(Enum.TryParse(Type, out MediaType enumMediaType)) - _mediaType = CommonTypes.Metadata.MediaType.MediaTypeToString(enumMediaType); - else if(int.TryParse(Type, out int asInt)) - _mediaType = CommonTypes.Metadata.MediaType.MediaTypeToString((MediaType)asInt); - } - catch - { - // Could not get media type/subtype pair from type, so just leave it as is - } - + if(_mediaType != default) return _mediaType; - } - } - [NotMapped, DisplayName("Physical type")] - public string PhysicalType => MediaType.type; - [NotMapped, DisplayName("Logical type")] - public string LogicalType => MediaType.subType; + try + { + if(Enum.TryParse(Type, out MediaType enumMediaType)) + _mediaType = CommonTypes.Metadata.MediaType.MediaTypeToString(enumMediaType); + else if(int.TryParse(Type, out int asInt)) + _mediaType = CommonTypes.Metadata.MediaType.MediaTypeToString((MediaType)asInt); + } + catch + { + // Could not get media type/subtype pair from type, so just leave it as is + } + + return _mediaType; + } } + + [NotMapped, DisplayName("Physical type")] + public string PhysicalType => MediaType.type; + [NotMapped, DisplayName("Logical type")] + public string LogicalType => MediaType.subType; } \ No newline at end of file diff --git a/Aaru.Server/Models/MediaFormat.cs b/Aaru.Server/Models/MediaFormat.cs index 86b5ca99..e2d7c7ed 100644 --- a/Aaru.Server/Models/MediaFormat.cs +++ b/Aaru.Server/Models/MediaFormat.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class MediaFormat : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class MediaFormat : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Models/MediaItem.cs b/Aaru.Server/Models/MediaItem.cs index eb83e59b..917ab645 100644 --- a/Aaru.Server/Models/MediaItem.cs +++ b/Aaru.Server/Models/MediaItem.cs @@ -30,12 +30,11 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class MediaItem { - public class MediaItem - { - public string Type { get; set; } - public string SubType { get; set; } - public long Count { get; set; } - } + public string Type { get; set; } + public string SubType { get; set; } + public long Count { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/MmcModelForView.cs b/Aaru.Server/Models/MmcModelForView.cs index 0fa62b06..a305a283 100644 --- a/Aaru.Server/Models/MmcModelForView.cs +++ b/Aaru.Server/Models/MmcModelForView.cs @@ -1,13 +1,12 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class MmcModelForView : BaseModel { - public class MmcModelForView : BaseModel - { - [DisplayFormat(NullDisplayText = "none"), DisplayName("MMC FEATURES ID")] - public int? FeaturesId { get; set; } - [DisplayName("Response length (bytes)")] - public int DataLength { get; set; } - } + [DisplayFormat(NullDisplayText = "none"), DisplayName("MMC FEATURES ID")] + public int? FeaturesId { get; set; } + [DisplayName("Response length (bytes)")] + public int DataLength { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/NameCountModel.cs b/Aaru.Server/Models/NameCountModel.cs index 84532fc9..bf0e5a3f 100644 --- a/Aaru.Server/Models/NameCountModel.cs +++ b/Aaru.Server/Models/NameCountModel.cs @@ -1,8 +1,7 @@ -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public abstract class NameCountModel : BaseModel { - public abstract class NameCountModel : BaseModel - { - public string Name { get; set; } - public long Count { get; set; } - } + public string Name { get; set; } + public long Count { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/OperatingSystem.cs b/Aaru.Server/Models/OperatingSystem.cs index 310f5734..efc6cec8 100644 --- a/Aaru.Server/Models/OperatingSystem.cs +++ b/Aaru.Server/Models/OperatingSystem.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class OperatingSystem : BaseOperatingSystem {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class OperatingSystem : BaseOperatingSystem {} \ No newline at end of file diff --git a/Aaru.Server/Models/Partition.cs b/Aaru.Server/Models/Partition.cs index 2d04c887..9b1800a2 100644 --- a/Aaru.Server/Models/Partition.cs +++ b/Aaru.Server/Models/Partition.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class Partition : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class Partition : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Models/RemoteApplication.cs b/Aaru.Server/Models/RemoteApplication.cs index 9cb70f75..8f83cf95 100644 --- a/Aaru.Server/Models/RemoteApplication.cs +++ b/Aaru.Server/Models/RemoteApplication.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class RemoteApplication : BaseOperatingSystem {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class RemoteApplication : BaseOperatingSystem {} \ No newline at end of file diff --git a/Aaru.Server/Models/RemoteArchitecture.cs b/Aaru.Server/Models/RemoteArchitecture.cs index 306ece5e..f17ff142 100644 --- a/Aaru.Server/Models/RemoteArchitecture.cs +++ b/Aaru.Server/Models/RemoteArchitecture.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class RemoteArchitecture : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class RemoteArchitecture : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Models/RemoteOperatingSystem.cs b/Aaru.Server/Models/RemoteOperatingSystem.cs index 95839360..59a1fc3a 100644 --- a/Aaru.Server/Models/RemoteOperatingSystem.cs +++ b/Aaru.Server/Models/RemoteOperatingSystem.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class RemoteOperatingSystem : BaseOperatingSystem {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class RemoteOperatingSystem : BaseOperatingSystem {} \ No newline at end of file diff --git a/Aaru.Server/Models/SscModel.cs b/Aaru.Server/Models/SscModel.cs index fac16488..eb995c03 100644 --- a/Aaru.Server/Models/SscModel.cs +++ b/Aaru.Server/Models/SscModel.cs @@ -1,17 +1,16 @@ using System.Collections.Generic; -namespace Aaru.Server.Models -{ - public class SscModel - { - public byte? BlockSizeGranularity { get; set; } - public uint? MaxBlockLength { get; set; } - public uint? MinBlockLength { get; set; } - } +namespace Aaru.Server.Models; - public class SscModelForView - { - public List List { get; set; } - public string Json { get; set; } - } +public class SscModel +{ + public byte? BlockSizeGranularity { get; set; } + public uint? MaxBlockLength { get; set; } + public uint? MinBlockLength { get; set; } +} + +public class SscModelForView +{ + public List List { get; set; } + public string Json { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/TestedMediaDataModel.cs b/Aaru.Server/Models/TestedMediaDataModel.cs index 940785ed..3fbc3b54 100644 --- a/Aaru.Server/Models/TestedMediaDataModel.cs +++ b/Aaru.Server/Models/TestedMediaDataModel.cs @@ -1,10 +1,9 @@ -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class TestedMediaDataModel { - public class TestedMediaDataModel - { - public int TestedMediaId { get; set; } - public string DataName { get; set; } - public string RawDataAsHex { get; set; } - public string Decoded { get; set; } - } + public int TestedMediaId { get; set; } + public string DataName { get; set; } + public string RawDataAsHex { get; set; } + public string Decoded { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UploadedReport.cs b/Aaru.Server/Models/UploadedReport.cs index 5170ef21..a6dc3419 100644 --- a/Aaru.Server/Models/UploadedReport.cs +++ b/Aaru.Server/Models/UploadedReport.cs @@ -34,42 +34,41 @@ using System; using System.ComponentModel; using Aaru.CommonTypes.Metadata; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class UploadedReport : DeviceReportV2 { - public class UploadedReport : DeviceReportV2 + public UploadedReport() => UploadedWhen = DateTime.UtcNow; + + public UploadedReport(DeviceReportV2 report) { - public UploadedReport() => UploadedWhen = DateTime.UtcNow; - - public UploadedReport(DeviceReportV2 report) - { - ATA = report.ATA; - ATAPI = report.ATAPI; - CompactFlash = report.CompactFlash; - FireWire = report.FireWire; - UploadedWhen = DateTime.UtcNow; - MultiMediaCard = report.MultiMediaCard; - PCMCIA = report.PCMCIA; - SCSI = report.SCSI; - SecureDigital = report.SecureDigital; - USB = report.USB; - Manufacturer = report.Manufacturer; - Model = report.Model; - Revision = report.Revision; - Type = report.Type; - GdRomSwapDiscCapabilities = report.GdRomSwapDiscCapabilities; - } - - [DisplayName("Uploaded when")] - public DateTime UploadedWhen { get; set; } - - public int? ATAId { get; set; } - public int? ATAPIId { get; set; } - public int? FireWireId { get; set; } - public int? MultiMediaCardId { get; set; } - public int? PCMCIAId { get; set; } - public int? SecureDigitalId { get; set; } - public int? SCSIId { get; set; } - public int? USBId { get; set; } - public int? GdRomSwapDiscCapabilitiesId { get; set; } + ATA = report.ATA; + ATAPI = report.ATAPI; + CompactFlash = report.CompactFlash; + FireWire = report.FireWire; + UploadedWhen = DateTime.UtcNow; + MultiMediaCard = report.MultiMediaCard; + PCMCIA = report.PCMCIA; + SCSI = report.SCSI; + SecureDigital = report.SecureDigital; + USB = report.USB; + Manufacturer = report.Manufacturer; + Model = report.Model; + Revision = report.Revision; + Type = report.Type; + GdRomSwapDiscCapabilities = report.GdRomSwapDiscCapabilities; } + + [DisplayName("Uploaded when")] + public DateTime UploadedWhen { get; set; } + + public int? ATAId { get; set; } + public int? ATAPIId { get; set; } + public int? FireWireId { get; set; } + public int? MultiMediaCardId { get; set; } + public int? PCMCIAId { get; set; } + public int? SecureDigitalId { get; set; } + public int? SCSIId { get; set; } + public int? USBId { get; set; } + public int? GdRomSwapDiscCapabilitiesId { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UploadedReportDetails.cs b/Aaru.Server/Models/UploadedReportDetails.cs index f5f7dc37..437ea5cd 100644 --- a/Aaru.Server/Models/UploadedReportDetails.cs +++ b/Aaru.Server/Models/UploadedReportDetails.cs @@ -1,17 +1,16 @@ using System.Collections.Generic; using Aaru.CommonTypes.Metadata; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class UploadedReportDetails { - public class UploadedReportDetails - { - public UploadedReport Report { get; set; } - public List SameAll { get; set; } - public List SameButManufacturer { get; set; } - public List ReportAll { get; set; } - public List ReportButManufacturer { get; set; } - public int ReadCapabilitiesId { get; set; } - public List TestedMedias { get; set; } - public List TestedSequentialMedias { get; set; } - } + public UploadedReport Report { get; set; } + public List SameAll { get; set; } + public List SameButManufacturer { get; set; } + public List ReportAll { get; set; } + public List ReportButManufacturer { get; set; } + public int ReadCapabilitiesId { get; set; } + public List TestedMedias { get; set; } + public List TestedSequentialMedias { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UsbModel.cs b/Aaru.Server/Models/UsbModel.cs index 4a72d0b1..0c136bc8 100644 --- a/Aaru.Server/Models/UsbModel.cs +++ b/Aaru.Server/Models/UsbModel.cs @@ -1,18 +1,17 @@ using System.Collections.Generic; -namespace Aaru.Server.Models -{ - public class UsbModel - { - public string Manufacturer { get; set; } - public string Product { get; set; } - public ushort VendorID { get; set; } - public ushort ProductID { get; set; } - } +namespace Aaru.Server.Models; - public class UsbModelForView - { - public List List { get; set; } - public string Json { get; set; } - } +public class UsbModel +{ + public string Manufacturer { get; set; } + public string Product { get; set; } + public ushort VendorID { get; set; } + public ushort ProductID { get; set; } +} + +public class UsbModelForView +{ + public List List { get; set; } + public string Json { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UsbProduct.cs b/Aaru.Server/Models/UsbProduct.cs index 2b86e3b4..ba79a5d6 100644 --- a/Aaru.Server/Models/UsbProduct.cs +++ b/Aaru.Server/Models/UsbProduct.cs @@ -33,27 +33,26 @@ using System; using Newtonsoft.Json; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class UsbProduct : BaseModel { - public class UsbProduct : BaseModel + public UsbProduct() {} + + public UsbProduct(UsbVendor vendor, ushort id, string product) { - public UsbProduct() {} - - public UsbProduct(UsbVendor vendor, ushort id, string product) - { - ProductId = id; - Product = product; - AddedWhen = ModifiedWhen = DateTime.UtcNow; - Vendor = vendor; - } - - public ushort ProductId { get; set; } - public string Product { get; set; } - public DateTime AddedWhen { get; set; } - public DateTime ModifiedWhen { get; set; } - public int VendorId { get; set; } - - [JsonIgnore] - public virtual UsbVendor Vendor { get; set; } + ProductId = id; + Product = product; + AddedWhen = ModifiedWhen = DateTime.UtcNow; + Vendor = vendor; } + + public ushort ProductId { get; set; } + public string Product { get; set; } + public DateTime AddedWhen { get; set; } + public DateTime ModifiedWhen { get; set; } + public int VendorId { get; set; } + + [JsonIgnore] + public virtual UsbVendor Vendor { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UsbProductModel.cs b/Aaru.Server/Models/UsbProductModel.cs index 6b6f9bb9..5c4ae861 100644 --- a/Aaru.Server/Models/UsbProductModel.cs +++ b/Aaru.Server/Models/UsbProductModel.cs @@ -1,16 +1,15 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class UsbProductModel { - public class UsbProductModel - { - [DisplayName("Manufacturer")] - public string VendorName { get; set; } - public int VendorId { get; set; } - [DisplayName("Product")] - public string ProductName { get; set; } - [DisplayName("Product ID"), DisplayFormat(DataFormatString = "0x{0:X4}")] - public ushort ProductId { get; set; } - } + [DisplayName("Manufacturer")] + public string VendorName { get; set; } + public int VendorId { get; set; } + [DisplayName("Product")] + public string ProductName { get; set; } + [DisplayName("Product ID"), DisplayFormat(DataFormatString = "0x{0:X4}")] + public ushort ProductId { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UsbVendor.cs b/Aaru.Server/Models/UsbVendor.cs index 136ccf8f..94e90de7 100644 --- a/Aaru.Server/Models/UsbVendor.cs +++ b/Aaru.Server/Models/UsbVendor.cs @@ -36,27 +36,26 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class UsbVendor : BaseModel { - public class UsbVendor : BaseModel + public UsbVendor() {} + + public UsbVendor(ushort id, string vendor) { - public UsbVendor() {} - - public UsbVendor(ushort id, string vendor) - { - VendorId = id; - Vendor = vendor; - AddedWhen = ModifiedWhen = DateTime.UtcNow; - } - - [DisplayName("Manufacturer ID"), DisplayFormat(DataFormatString = "0x{0:X4}")] - public ushort VendorId { get; set; } - [DisplayName("Manufacturer")] - public string Vendor { get; set; } - public DateTime AddedWhen { get; set; } - public DateTime ModifiedWhen { get; set; } - - [JsonIgnore] - public virtual ICollection Products { get; set; } + VendorId = id; + Vendor = vendor; + AddedWhen = ModifiedWhen = DateTime.UtcNow; } + + [DisplayName("Manufacturer ID"), DisplayFormat(DataFormatString = "0x{0:X4}")] + public ushort VendorId { get; set; } + [DisplayName("Manufacturer")] + public string Vendor { get; set; } + public DateTime AddedWhen { get; set; } + public DateTime ModifiedWhen { get; set; } + + [JsonIgnore] + public virtual ICollection Products { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/UsbVendorModel.cs b/Aaru.Server/Models/UsbVendorModel.cs index ee3e56fe..a7c9523b 100644 --- a/Aaru.Server/Models/UsbVendorModel.cs +++ b/Aaru.Server/Models/UsbVendorModel.cs @@ -2,14 +2,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace Aaru.Server.Models +namespace Aaru.Server.Models; + +public class UsbVendorModel { - public class UsbVendorModel - { - [DisplayName("Manufacturer")] - public string Vendor { get; set; } - [DisplayName("Vendor ID"), DisplayFormat(DataFormatString = "0x{0:X4}")] - public ushort VendorId { get; set; } - public List Products { get; set; } - } + [DisplayName("Manufacturer")] + public string Vendor { get; set; } + [DisplayName("Vendor ID"), DisplayFormat(DataFormatString = "0x{0:X4}")] + public ushort VendorId { get; set; } + public List Products { get; set; } } \ No newline at end of file diff --git a/Aaru.Server/Models/Version.cs b/Aaru.Server/Models/Version.cs index 1801561e..96d5e0d5 100644 --- a/Aaru.Server/Models/Version.cs +++ b/Aaru.Server/Models/Version.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Server.Models -{ - public class Version : NameCountModel {} -} \ No newline at end of file +namespace Aaru.Server.Models; + +public class Version : NameCountModel {} \ No newline at end of file diff --git a/Aaru.Server/Program.cs b/Aaru.Server/Program.cs index 31156d94..cdb4c07f 100644 --- a/Aaru.Server/Program.cs +++ b/Aaru.Server/Program.cs @@ -12,171 +12,170 @@ using Microsoft.Extensions.Hosting; using Prometheus; using Version = Aaru.CommonTypes.Interop.Version; -namespace Aaru.Server +namespace Aaru.Server; + +public sealed class Program { - public sealed class Program + public static void Main(string[] args) { - public static void Main(string[] args) - { - DateTime start; - DateTime end; + DateTime start; + DateTime end; - System.Console.Clear(); + System.Console.Clear(); - System.Console.Write( - "\u001b[32m . ,,\n" + - "\u001b[32m ;,. '0d.\n" + - "\u001b[32m oc oWd \u001b[31m" + - @"__/\\\\\\\\\\\\_____/\\\\\\\\\\\________/\\\\\\\\\_ " + "\n\u001b[0m" + - "\u001b[32m ;X. 'WN' \u001b[31m" + - @" _\/\\\////////\\\__\/////\\\///______/\\\////////__ " + "\n\u001b[0m" + - "\u001b[32m oMo cMM: \u001b[31m" + - @" _\/\\\______\//\\\_____\/\\\_______/\\\/___________ " + "\n\u001b[0m" + - "\u001b[32m ;MM. .MMM; \u001b[31m" + - @" _\/\\\_______\/\\\_____\/\\\______/\\\_____________ " + "\n\u001b[0m" + - "\u001b[32m NMM WMMW \u001b[31m" + - @" _\/\\\_______\/\\\_____\/\\\_____\/\\\_____________ " + "\n\u001b[0m" + - "\u001b[32m 'MMM MMMM; \u001b[31m" + - @" _\/\\\_______\/\\\_____\/\\\_____\//\\\____________ " + "\n\u001b[0m" + - "\u001b[32m ,MMM: dMMMM: \u001b[31m" + - @" _\/\\\_______/\\\______\/\\\______\///\\\__________ " + "\n\u001b[0m" + - "\u001b[32m .MMMW. :MMMMM. \u001b[31m" + - @" _\/\\\\\\\\\\\\/____/\\\\\\\\\\\____\////\\\\\\\\\_ " + "\n\u001b[0m" + - "\u001b[32m XMMMW: .:xKNMMMMMMN0d, lMMMMMd \u001b[31m" + - @" _\////////////_____\///////////________\/////////__" + "\n\u001b[0m" + - "\u001b[32m :MMMMMK; cWMNkl:;;;:lxKMXc .0MMMMMO\u001b[0m\n" + - "\u001b[32m ..KMMMMMMNo,. ,OMMMMMMW:,. \u001b[37;1m Aaru Website\u001b[0m\n" + - "\u001b[32m .;d0NMMMMMMMMMMMMMMW0d:' .;lOWMMMMMMMMMMMMMXkl. \u001b[37;1m Version \u001b[0m\u001b[33m{0}\u001b[37;1m-\u001b[0m\u001b[31m{1}\u001b[0m\n" + - "\u001b[32m :KMMMMMMMMMMMMMMMMMMMMMMMMc WMMMMMMMMMMMMMMMMMMMMMMWk'\u001b[0m\n" + - "\u001b[32m ;NMMMMWX0kkkkO0XMMMMMMMMMMM0' dNMMMMMMMMMMW0xl:;,;:oOWMMX; \u001b[37;1m Running under \u001b[35;1m{2}\u001b[37;1m, \u001b[35m{3}-bit\u001b[37;1m in \u001b[35m{4}-bit\u001b[37;1m mode.\u001b[0m\n" + - "\u001b[32m xMMWk:. .c0MMMMMW' OMMMMMM0c'.. .oNMO \u001b[37;1m Using \u001b[33;1m{5}\u001b[37;1m version \u001b[31;1m{6}\u001b[0m\n" + - "\u001b[32m OMNc .MNc oWMMk 'WMMNl. .MMK ;KX.\u001b[0m\n" + - "\u001b[32m xMO WMN ; ., , ': ,MMx lK\u001b[0m\n" + - "\u001b[32m ,Md cMMl .XMMMWWMMMO XMW. :\u001b[0m\n" + - "\u001b[32m Ok xMMl XMMMMMMMMc 0MW,\u001b[0m\n" + - "\u001b[32m 0 oMM0' lMMMMMMMM. :NMN'\u001b[0m\n" + - "\u001b[32m . .0MMKl ;MMMMMMMM oNMWd\u001b[0m\n" + - "\u001b[32m .dNW cMMMMMMMM, XKl\u001b[0m\n" + - "\u001b[32m 0MMMMMMMMK\u001b[0m\n" + - "\u001b[32m ;MMMMMMMMMMO \u001b[37;1m Proudly presented to you by:\u001b[0m\n" + - "\u001b[32m 'WMMMMKxMMMMM0 \u001b[34;1m Natalia Portillo\u001b[0m\n" + - "\u001b[32m oMMMMNc :WMMMMN:\u001b[0m\n" + - "\u001b[32m .dWMMM0; dWMMMMXl. \u001b[37;1m Thanks to all contributors, collaborators, translators, donators and friends.\u001b[0m\n" + - "\u001b[32m .......,cd0WMMNk: c0MMMMMWKkolc:clodc'\u001b[0m\n" + - "\u001b[32m .';loddol:'. ':oxkkOkkxoc,.\u001b[0m\n" + - "\u001b[0m\n", Version.GetVersion(), - #if DEBUG - "DEBUG" - #else + System.Console.Write( + "\u001b[32m . ,,\n" + + "\u001b[32m ;,. '0d.\n" + + "\u001b[32m oc oWd \u001b[31m" + + @"__/\\\\\\\\\\\\_____/\\\\\\\\\\\________/\\\\\\\\\_ " + "\n\u001b[0m" + + "\u001b[32m ;X. 'WN' \u001b[31m" + + @" _\/\\\////////\\\__\/////\\\///______/\\\////////__ " + "\n\u001b[0m" + + "\u001b[32m oMo cMM: \u001b[31m" + + @" _\/\\\______\//\\\_____\/\\\_______/\\\/___________ " + "\n\u001b[0m" + + "\u001b[32m ;MM. .MMM; \u001b[31m" + + @" _\/\\\_______\/\\\_____\/\\\______/\\\_____________ " + "\n\u001b[0m" + + "\u001b[32m NMM WMMW \u001b[31m" + + @" _\/\\\_______\/\\\_____\/\\\_____\/\\\_____________ " + "\n\u001b[0m" + + "\u001b[32m 'MMM MMMM; \u001b[31m" + + @" _\/\\\_______\/\\\_____\/\\\_____\//\\\____________ " + "\n\u001b[0m" + + "\u001b[32m ,MMM: dMMMM: \u001b[31m" + + @" _\/\\\_______/\\\______\/\\\______\///\\\__________ " + "\n\u001b[0m" + + "\u001b[32m .MMMW. :MMMMM. \u001b[31m" + + @" _\/\\\\\\\\\\\\/____/\\\\\\\\\\\____\////\\\\\\\\\_ " + "\n\u001b[0m" + + "\u001b[32m XMMMW: .:xKNMMMMMMN0d, lMMMMMd \u001b[31m" + + @" _\////////////_____\///////////________\/////////__" + "\n\u001b[0m" + + "\u001b[32m :MMMMMK; cWMNkl:;;;:lxKMXc .0MMMMMO\u001b[0m\n" + + "\u001b[32m ..KMMMMMMNo,. ,OMMMMMMW:,. \u001b[37;1m Aaru Website\u001b[0m\n" + + "\u001b[32m .;d0NMMMMMMMMMMMMMMW0d:' .;lOWMMMMMMMMMMMMMXkl. \u001b[37;1m Version \u001b[0m\u001b[33m{0}\u001b[37;1m-\u001b[0m\u001b[31m{1}\u001b[0m\n" + + "\u001b[32m :KMMMMMMMMMMMMMMMMMMMMMMMMc WMMMMMMMMMMMMMMMMMMMMMMWk'\u001b[0m\n" + + "\u001b[32m ;NMMMMWX0kkkkO0XMMMMMMMMMMM0' dNMMMMMMMMMMW0xl:;,;:oOWMMX; \u001b[37;1m Running under \u001b[35;1m{2}\u001b[37;1m, \u001b[35m{3}-bit\u001b[37;1m in \u001b[35m{4}-bit\u001b[37;1m mode.\u001b[0m\n" + + "\u001b[32m xMMWk:. .c0MMMMMW' OMMMMMM0c'.. .oNMO \u001b[37;1m Using \u001b[33;1m{5}\u001b[37;1m version \u001b[31;1m{6}\u001b[0m\n" + + "\u001b[32m OMNc .MNc oWMMk 'WMMNl. .MMK ;KX.\u001b[0m\n" + + "\u001b[32m xMO WMN ; ., , ': ,MMx lK\u001b[0m\n" + + "\u001b[32m ,Md cMMl .XMMMWWMMMO XMW. :\u001b[0m\n" + + "\u001b[32m Ok xMMl XMMMMMMMMc 0MW,\u001b[0m\n" + + "\u001b[32m 0 oMM0' lMMMMMMMM. :NMN'\u001b[0m\n" + + "\u001b[32m . .0MMKl ;MMMMMMMM oNMWd\u001b[0m\n" + + "\u001b[32m .dNW cMMMMMMMM, XKl\u001b[0m\n" + + "\u001b[32m 0MMMMMMMMK\u001b[0m\n" + + "\u001b[32m ;MMMMMMMMMMO \u001b[37;1m Proudly presented to you by:\u001b[0m\n" + + "\u001b[32m 'WMMMMKxMMMMM0 \u001b[34;1m Natalia Portillo\u001b[0m\n" + + "\u001b[32m oMMMMNc :WMMMMN:\u001b[0m\n" + + "\u001b[32m .dWMMM0; dWMMMMXl. \u001b[37;1m Thanks to all contributors, collaborators, translators, donators and friends.\u001b[0m\n" + + "\u001b[32m .......,cd0WMMNk: c0MMMMMWKkolc:clodc'\u001b[0m\n" + + "\u001b[32m .';loddol:'. ':oxkkOkkxoc,.\u001b[0m\n" + + "\u001b[0m\n", Version.GetVersion(), + #if DEBUG + "DEBUG" + #else "RELEASE" - #endif - , DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()), - Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32, - DetectOS.IsMono ? "Mono" : ".NET Core", - DetectOS.IsMono ? Version.GetMonoVersion() : Version.GetNetCoreVersion()); + #endif + , DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()), + Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32, + DetectOS.IsMono ? "Mono" : ".NET Core", + DetectOS.IsMono ? Version.GetMonoVersion() : Version.GetNetCoreVersion()); - System.Console.WriteLine("\u001b[31;1mBuilding web application...\u001b[0m"); + System.Console.WriteLine("\u001b[31;1mBuilding web application...\u001b[0m"); - WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); - builder.Services.AddDbContext(options => options. - UseMySql(builder.Configuration.GetConnectionString("DefaultConnection"), - new MariaDbServerVersion(new System. - Version(10, 4, 0))). - UseLazyLoadingProxies()); + builder.Services.AddDbContext(options => options. + UseMySql(builder.Configuration.GetConnectionString("DefaultConnection"), + new MariaDbServerVersion(new System. + Version(10, 4, 0))). + UseLazyLoadingProxies()); - builder.Services.AddDefaultIdentity(options => - { - options.SignIn.RequireConfirmedAccount = true; - options.User.RequireUniqueEmail = true; - }).AddEntityFrameworkStores(); + builder.Services.AddDefaultIdentity(options => + { + options.SignIn.RequireConfirmedAccount = true; + options.User.RequireUniqueEmail = true; + }).AddEntityFrameworkStores(); - builder.Services.AddApplicationInsightsTelemetry(); + builder.Services.AddApplicationInsightsTelemetry(); - builder.Services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); + builder.Services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); - WebApplication app = builder.Build(); + WebApplication app = builder.Build(); - app.UseForwardedHeaders(new ForwardedHeadersOptions - { - ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto - }); + app.UseForwardedHeaders(new ForwardedHeadersOptions + { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }); - app.UseHttpMetrics(); + app.UseHttpMetrics(); - if(builder.Environment.IsDevelopment()) - app.UseDeveloperExceptionPage(); - else - { - app.UseExceptionHandler("/Home/Error"); + if(builder.Environment.IsDevelopment()) + app.UseDeveloperExceptionPage(); + else + { + app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseDefaultFiles(); - app.UseStaticFiles(); - - // Add other security headers - app.UseMiddleware(); - - app.UseRouting(); - - app.UseAuthentication(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute("areas", "{area}/{controller=Home}/{action=Index}/{id?}"); - endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); - endpoints.MapRazorPages(); - }); - - app.Map("/metrics", metricsApp => - { - metricsApp.UseMiddleware("Aaru"); - - // We already specified URL prefix in .Map() above, no need to specify it again here. - metricsApp.UseMetricServer(""); - }); - - using(IServiceScope scope = app.Services.CreateScope()) - { - IServiceProvider services = scope.ServiceProvider; - - try - { - start = DateTime.Now; - System.Console.WriteLine("\u001b[31;1mUpdating database with Entity Framework...\u001b[0m"); - AaruServerContext context = services.GetRequiredService(); - context.Database.Migrate(); - end = DateTime.Now; - - System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m", - (end - start).TotalSeconds); - - start = DateTime.Now; - System.Console.WriteLine("\u001b[31;1mSeeding Identity...\u001b[0m"); - Seeder.Seed(context, services); - context.Database.Migrate(); - end = DateTime.Now; - - System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m", - (end - start).TotalSeconds); - } - catch(Exception ex) - { - System.Console.WriteLine("\u001b[31;1mCould not open database...\u001b[0m"); - #if DEBUG - System.Console.WriteLine("\u001b[31;1mException: {0}\u001b[0m", ex.Message); - #endif - return; - } - } - - System.Console.WriteLine("\u001b[31;1mStarting web server...\u001b[0m"); - - app.Run(); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + + app.UseDefaultFiles(); + app.UseStaticFiles(); + + // Add other security headers + app.UseMiddleware(); + + app.UseRouting(); + + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute("areas", "{area}/{controller=Home}/{action=Index}/{id?}"); + endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); + endpoints.MapRazorPages(); + }); + + app.Map("/metrics", metricsApp => + { + metricsApp.UseMiddleware("Aaru"); + + // We already specified URL prefix in .Map() above, no need to specify it again here. + metricsApp.UseMetricServer(""); + }); + + using(IServiceScope scope = app.Services.CreateScope()) + { + IServiceProvider services = scope.ServiceProvider; + + try + { + start = DateTime.Now; + System.Console.WriteLine("\u001b[31;1mUpdating database with Entity Framework...\u001b[0m"); + AaruServerContext context = services.GetRequiredService(); + context.Database.Migrate(); + end = DateTime.Now; + + System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m", + (end - start).TotalSeconds); + + start = DateTime.Now; + System.Console.WriteLine("\u001b[31;1mSeeding Identity...\u001b[0m"); + Seeder.Seed(context, services); + context.Database.Migrate(); + end = DateTime.Now; + + System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m", + (end - start).TotalSeconds); + } + catch(Exception ex) + { + System.Console.WriteLine("\u001b[31;1mCould not open database...\u001b[0m"); + #if DEBUG + System.Console.WriteLine("\u001b[31;1mException: {0}\u001b[0m", ex.Message); + #endif + return; + } + } + + System.Console.WriteLine("\u001b[31;1mStarting web server...\u001b[0m"); + + app.Run(); } } \ No newline at end of file diff --git a/Aaru.Server/SecurityHeadersMiddleware.cs b/Aaru.Server/SecurityHeadersMiddleware.cs index 4a4f1015..aeda934b 100644 --- a/Aaru.Server/SecurityHeadersMiddleware.cs +++ b/Aaru.Server/SecurityHeadersMiddleware.cs @@ -1,68 +1,67 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -namespace Aaru.Server +namespace Aaru.Server; + +public sealed class SecurityHeadersMiddleware { - public sealed class SecurityHeadersMiddleware + readonly RequestDelegate _next; + + public SecurityHeadersMiddleware(RequestDelegate next) => _next = next; + + public Task Invoke(HttpContext context) { - readonly RequestDelegate _next; + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy + // TODO Change the value depending of your needs + context.Response.Headers.Add("referrer-policy", new("strict-origin-when-cross-origin")); - public SecurityHeadersMiddleware(RequestDelegate next) => _next = next; + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options + context.Response.Headers.Add("x-content-type-options", new("nosniff")); - public Task Invoke(HttpContext context) - { - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy - // TODO Change the value depending of your needs - context.Response.Headers.Add("referrer-policy", new("strict-origin-when-cross-origin")); + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options + context.Response.Headers.Add("x-frame-options", new("DENY")); - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options - context.Response.Headers.Add("x-content-type-options", new("nosniff")); + // https://security.stackexchange.com/questions/166024/does-the-x-permitted-cross-domain-policies-header-have-any-benefit-for-my-websit + context.Response.Headers.Add("X-Permitted-Cross-Domain-Policies", new("none")); - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options - context.Response.Headers.Add("x-frame-options", new("DENY")); + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection + context.Response.Headers.Add("x-xss-protection", new("1; mode=block")); - // https://security.stackexchange.com/questions/166024/does-the-x-permitted-cross-domain-policies-header-have-any-benefit-for-my-websit - context.Response.Headers.Add("X-Permitted-Cross-Domain-Policies", new("none")); + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy + // https://github.com/w3c/webappsec-feature-policy/blob/master/features.md + // https://developers.google.com/web/updates/2018/06/feature-policy + // TODO change the value of each rule and check the documentation to see if new features are available + /*context.Response.Headers.Add("Feature-Policy", + new StringValues("accelerometer 'none';" + "ambient-light-sensor 'none';" + + "autoplay 'none';" + "battery 'none';" + "camera 'none';" + + "display-capture 'none';" + "document-domain 'none';" + + "encrypted-media 'none';" + + "execution-while-not-rendered 'none';" + + "execution-while-out-of-viewport 'none';" + + "gyroscope 'none';" + "magnetometer 'none';" + + "microphone 'none';" + "midi 'none';" + + "navigation-override 'none';" + "payment 'none';" + + "picture-in-picture 'none';" + + "publickey-credentials-get 'none';" + "sync-xhr 'none';" + + "usb 'none';" + "wake-lock 'none';" + + "xr-spatial-tracking 'none';"));*/ - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection - context.Response.Headers.Add("x-xss-protection", new("1; mode=block")); + // https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + // TODO change the value of each rule and check the documentation to see if new rules are available + /*context.Response.Headers.Add("Content-Security-Policy", + new StringValues("base-uri 'none';" + "block-all-mixed-content;" + + "child-src 'none';" + "connect-src 'none';" + + "default-src 'none';" + "font-src 'none';" + + "form-action 'none';" + "frame-ancestors 'none';" + + "frame-src 'none';" + "img-src 'none';" + + "manifest-src 'none';" + "media-src 'none';" + + "object-src 'none';" + "sandbox;" + "script-src 'none';" + + "script-src-attr 'none';" + "script-src-elem 'none';" + + "style-src 'none';" + "style-src-attr 'none';" + + "style-src-elem 'none';" + "upgrade-insecure-requests;" + + "worker-src 'none';"));*/ - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy - // https://github.com/w3c/webappsec-feature-policy/blob/master/features.md - // https://developers.google.com/web/updates/2018/06/feature-policy - // TODO change the value of each rule and check the documentation to see if new features are available - /*context.Response.Headers.Add("Feature-Policy", - new StringValues("accelerometer 'none';" + "ambient-light-sensor 'none';" + - "autoplay 'none';" + "battery 'none';" + "camera 'none';" + - "display-capture 'none';" + "document-domain 'none';" + - "encrypted-media 'none';" + - "execution-while-not-rendered 'none';" + - "execution-while-out-of-viewport 'none';" + - "gyroscope 'none';" + "magnetometer 'none';" + - "microphone 'none';" + "midi 'none';" + - "navigation-override 'none';" + "payment 'none';" + - "picture-in-picture 'none';" + - "publickey-credentials-get 'none';" + "sync-xhr 'none';" + - "usb 'none';" + "wake-lock 'none';" + - "xr-spatial-tracking 'none';"));*/ - - // https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy - // TODO change the value of each rule and check the documentation to see if new rules are available - /*context.Response.Headers.Add("Content-Security-Policy", - new StringValues("base-uri 'none';" + "block-all-mixed-content;" + - "child-src 'none';" + "connect-src 'none';" + - "default-src 'none';" + "font-src 'none';" + - "form-action 'none';" + "frame-ancestors 'none';" + - "frame-src 'none';" + "img-src 'none';" + - "manifest-src 'none';" + "media-src 'none';" + - "object-src 'none';" + "sandbox;" + "script-src 'none';" + - "script-src-attr 'none';" + "script-src-elem 'none';" + - "style-src 'none';" + "style-src-attr 'none';" + - "style-src-elem 'none';" + "upgrade-insecure-requests;" + - "worker-src 'none';"));*/ - - return _next(context); - } + return _next(context); } } \ No newline at end of file diff --git a/Aaru.Server/Seeder.cs b/Aaru.Server/Seeder.cs index 96f876eb..7e37f8f4 100644 --- a/Aaru.Server/Seeder.cs +++ b/Aaru.Server/Seeder.cs @@ -3,42 +3,41 @@ using Aaru.Server.Models; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; -namespace Aaru.Server +namespace Aaru.Server; + +public static class Seeder { - public static class Seeder + public static void Seed(AaruServerContext ctx, IServiceProvider serviceProvider) { - public static void Seed(AaruServerContext ctx, IServiceProvider serviceProvider) + string email = "claunia@claunia.com"; + char[] randChars = new char[16]; + UserManager userManager = serviceProvider.GetRequiredService>(); + var rnd = new Random(); + + for(int i = 0; i < randChars.Length; i++) { - string email = "claunia@claunia.com"; - char[] randChars = new char[16]; - UserManager userManager = serviceProvider.GetRequiredService>(); - var rnd = new Random(); + randChars[i] = (char)rnd.Next(32, 126); + } - for(int i = 0; i < randChars.Length; i++) - { - randChars[i] = (char)rnd.Next(32, 126); - } + string password = new(randChars); - string password = new(randChars); + if(userManager.FindByEmailAsync(email).Result != null) + return; - if(userManager.FindByEmailAsync(email).Result != null) - return; + var user = new IdentityUser + { + Email = email, + NormalizedEmail = email, + EmailConfirmed = true, + UserName = email, + NormalizedUserName = email + }; - var user = new IdentityUser - { - Email = email, - NormalizedEmail = email, - EmailConfirmed = true, - UserName = email, - NormalizedUserName = email - }; + IdentityResult result = userManager.CreateAsync(user, password).Result; - IdentityResult result = userManager.CreateAsync(user, password).Result; - - if(result.Succeeded) - { - System.Console.WriteLine("Password is {0}, save it!", password); - } + if(result.Succeeded) + { + System.Console.WriteLine("Password is {0}, save it!", password); } } } \ No newline at end of file diff --git a/Aaru.Server/appsettings.Development.json b/Aaru.Server/appsettings.Development.json index e20b6006..19c8f3a7 100644 --- a/Aaru.Server/appsettings.Development.json +++ b/Aaru.Server/appsettings.Development.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "server=localhost;port=3306;database=discimagechef;uid=dic;password=dicpass" + "DefaultConnection": "server=zeus.claunia.com;port=3306;database=discimagechef;uid=dic;password=dicpass" }, "Logging": { "LogLevel": { diff --git a/Aaru.Server/wwwroot b/Aaru.Server/wwwroot index 691449b3..a4703b65 160000 --- a/Aaru.Server/wwwroot +++ b/Aaru.Server/wwwroot @@ -1 +1 @@ -Subproject commit 691449b380652d4c47f96b35c0ac1f358e91b4e1 +Subproject commit a4703b6594b2195a8daed246f68081e1ae65b708