diff --git a/DiscImageChef.Checksums/CDChecksums.cs b/DiscImageChef.Checksums/CDChecksums.cs index 0a5c118c9..6f959a970 100644 --- a/DiscImageChef.Checksums/CDChecksums.cs +++ b/DiscImageChef.Checksums/CDChecksums.cs @@ -124,73 +124,73 @@ namespace DiscImageChef.Checksums { EccInit(); - if(channel[0x000] == 0x00 && // sync (12 bytes) - channel[0x001] == 0xFF && channel[0x002] == 0xFF && channel[0x003] == 0xFF && channel[0x004] == 0xFF && - channel[0x005] == 0xFF && channel[0x006] == 0xFF && channel[0x007] == 0xFF && channel[0x008] == 0xFF && - channel[0x009] == 0xFF && channel[0x00A] == 0xFF && channel[0x00B] == 0x00) + if(channel[0x000] != 0x00 || channel[0x001] != 0xFF || channel[0x002] != 0xFF || channel[0x003] != 0xFF || + channel[0x004] != 0xFF || channel[0x005] != 0xFF || channel[0x006] != 0xFF || channel[0x007] != 0xFF || + channel[0x008] != 0xFF || channel[0x009] != 0xFF || channel[0x00A] != 0xFF || + channel[0x00B] != 0x00) return null; + + DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], + channel[0x00D], channel[0x00E]); + + if(channel[0x00F] == 0x00) // mode (1 byte) { - DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], - channel[0x00D], channel[0x00E]); - - if(channel[0x00F] == 0x00) // mode (1 byte) - { - DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector at address {0:X2}:{1:X2}:{2:X2}", - channel[0x00C], channel[0x00D], channel[0x00E]); - for(int i = 0x010; i < 0x930; i++) - if(channel[i] != 0x00) - { - DicConsole.DebugWriteLine("CD checksums", - "Mode 0 sector with error at address: {0:X2}:{1:X2}:{2:X2}", - channel[0x00C], channel[0x00D], channel[0x00E]); - return false; - } - - return true; - } - - if(channel[0x00F] == 0x01) // mode (1 byte) - { - DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address {0:X2}:{1:X2}:{2:X2}", - channel[0x00C], channel[0x00D], channel[0x00E]); - - if(channel[0x814] != 0x00 || // reserved (8 bytes) - channel[0x815] != 0x00 || channel[0x816] != 0x00 || channel[0x817] != 0x00 || - channel[0x818] != 0x00 || channel[0x819] != 0x00 || channel[0x81A] != 0x00 || - channel[0x81B] != 0x00) + DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector at address {0:X2}:{1:X2}:{2:X2}", + channel[0x00C], channel[0x00D], channel[0x00E]); + for(int i = 0x010; i < 0x930; i++) + if(channel[i] != 0x00) { DicConsole.DebugWriteLine("CD checksums", - "Mode 1 sector with data in reserved bytes at address: {0:X2}:{1:X2}:{2:X2}", + "Mode 0 sector with error at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]); return false; } - byte[] address = new byte[4]; - byte[] data = new byte[2060]; - byte[] data2 = new byte[2232]; - byte[] eccP = new byte[172]; - byte[] eccQ = new byte[104]; + return true; + } - Array.Copy(channel, 0x0C, address, 0, 4); - Array.Copy(channel, 0x0C, data, 0, 2060); - Array.Copy(channel, 0x0C, data2, 0, 2232); - Array.Copy(channel, 0x81C, eccP, 0, 172); - Array.Copy(channel, 0x8C8, eccQ, 0, 104); + if(channel[0x00F] == 0x01) // mode (1 byte) + { + DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address {0:X2}:{1:X2}:{2:X2}", + channel[0x00C], channel[0x00D], channel[0x00E]); - bool failedEccP = CheckEcc(address, data, 86, 24, 2, 86, eccP); - bool failedEccQ = CheckEcc(address, data2, 52, 43, 86, 88, eccQ); + if(channel[0x814] != 0x00 || // reserved (8 bytes) + channel[0x815] != 0x00 || channel[0x816] != 0x00 || channel[0x817] != 0x00 || + channel[0x818] != 0x00 || channel[0x819] != 0x00 || channel[0x81A] != 0x00 || + channel[0x81B] != 0x00) + { + DicConsole.DebugWriteLine("CD checksums", + "Mode 1 sector with data in reserved bytes at address: {0:X2}:{1:X2}:{2:X2}", + channel[0x00C], channel[0x00D], channel[0x00E]); + return false; + } - if(failedEccP) - DicConsole.DebugWriteLine("CD checksums", - "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", - channel[0x00C], channel[0x00D], channel[0x00E]); - if(failedEccQ) - DicConsole.DebugWriteLine("CD checksums", - "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", - channel[0x00C], channel[0x00D], channel[0x00E]); + byte[] address = new byte[4]; + byte[] data = new byte[2060]; + byte[] data2 = new byte[2232]; + byte[] eccP = new byte[172]; + byte[] eccQ = new byte[104]; - if(failedEccP || failedEccQ) return false; + Array.Copy(channel, 0x0C, address, 0, 4); + Array.Copy(channel, 0x0C, data, 0, 2060); + Array.Copy(channel, 0x0C, data2, 0, 2232); + Array.Copy(channel, 0x81C, eccP, 0, 172); + Array.Copy(channel, 0x8C8, eccQ, 0, 104); - /* TODO: This is not working + bool failedEccP = CheckEcc(address, data, 86, 24, 2, 86, eccP); + bool failedEccQ = CheckEcc(address, data2, 52, 43, 86, 88, eccQ); + + if(failedEccP) + DicConsole.DebugWriteLine("CD checksums", + "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", + channel[0x00C], channel[0x00D], channel[0x00E]); + if(failedEccQ) + DicConsole.DebugWriteLine("CD checksums", + "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", + channel[0x00C], channel[0x00D], channel[0x00E]); + + if(failedEccP || failedEccQ) return false; + + /* TODO: This is not working byte[] SectorForCheck = new byte[0x810]; uint StoredEDC = BitConverter.ToUInt32(channel, 0x810); byte[] CalculatedEDCBytes; @@ -204,23 +204,23 @@ namespace DiscImageChef.Checksums return false; }*/ - return true; - } + return true; + } - if(channel[0x00F] == 0x02) // mode (1 byte) + if(channel[0x00F] == 0x02) // mode (1 byte) + { + DicConsole.DebugWriteLine("CD checksums", "Mode 2 sector at address {0:X2}:{1:X2}:{2:X2}", + channel[0x00C], channel[0x00D], channel[0x00E]); + + if((channel[0x012] & 0x20) == 0x20) // mode 2 form 2 { - DicConsole.DebugWriteLine("CD checksums", "Mode 2 sector at address {0:X2}:{1:X2}:{2:X2}", - channel[0x00C], channel[0x00D], channel[0x00E]); + if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || + channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017]) + DicConsole.DebugWriteLine("CD checksums", + "Subheader copies differ in mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}", + channel[0x00C], channel[0x00D], channel[0x00E]); - if((channel[0x012] & 0x20) == 0x20) // mode 2 form 2 - { - if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || - channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017]) - DicConsole.DebugWriteLine("CD checksums", - "Subheader copies differ in mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}", - channel[0x00C], channel[0x00D], channel[0x00E]); - - /* TODO: This is not working + /* TODO: This is not working byte[] SectorForCheck = new byte[0x91C]; uint StoredEDC = BitConverter.ToUInt32(channel, 0x92C); byte[] CalculatedEDCBytes; @@ -233,45 +233,45 @@ namespace DiscImageChef.Checksums DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}, got CRC 0x{3:X8} expected 0x{4:X8}", channel[0x00C], channel[0x00D], channel[0x00E], CalculatedEDC, StoredEDC); return false; }*/ - } - else - { - if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || - channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017]) - DicConsole.DebugWriteLine("CD checksums", - "Subheader copies differ in mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}", - channel[0x00C], channel[0x00D], channel[0x00E]); + } + else + { + if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || + channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017]) + DicConsole.DebugWriteLine("CD checksums", + "Subheader copies differ in mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}", + channel[0x00C], channel[0x00D], channel[0x00E]); - byte[] address = new byte[4]; - byte[] data = new byte[2060]; - byte[] data2 = new byte[2232]; - byte[] eccP = new byte[172]; - byte[] eccQ = new byte[104]; + byte[] address = new byte[4]; + byte[] data = new byte[2060]; + byte[] data2 = new byte[2232]; + byte[] eccP = new byte[172]; + byte[] eccQ = new byte[104]; - address[0] = 0; - address[1] = 0; - address[2] = 0; - address[3] = 0; - Array.Copy(channel, 0x0C, data, 0, 2060); - Array.Copy(channel, 0x0C, data2, 0, 2232); - Array.Copy(channel, 0x80C, eccP, 0, 172); - Array.Copy(channel, 0x8B8, eccQ, 0, 104); + address[0] = 0; + address[1] = 0; + address[2] = 0; + address[3] = 0; + Array.Copy(channel, 0x0C, data, 0, 2060); + Array.Copy(channel, 0x0C, data2, 0, 2232); + Array.Copy(channel, 0x80C, eccP, 0, 172); + Array.Copy(channel, 0x8B8, eccQ, 0, 104); - bool failedEccP = CheckEcc(address, data, 86, 24, 2, 86, eccP); - bool failedEccQ = CheckEcc(address, data2, 52, 43, 86, 88, eccQ); + bool failedEccP = CheckEcc(address, data, 86, 24, 2, 86, eccP); + bool failedEccQ = CheckEcc(address, data2, 52, 43, 86, 88, eccQ); - if(failedEccP) - DicConsole.DebugWriteLine("CD checksums", - "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", - channel[0x00C], channel[0x00D], channel[0x00E]); - if(failedEccQ) - DicConsole.DebugWriteLine("CD checksums", - "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", - channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]); + if(failedEccP) + DicConsole.DebugWriteLine("CD checksums", + "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", + channel[0x00C], channel[0x00D], channel[0x00E]); + if(failedEccQ) + DicConsole.DebugWriteLine("CD checksums", + "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", + channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]); - if(failedEccP || failedEccQ) return false; + if(failedEccP || failedEccQ) return false; - /* TODO: This is not working + /* TODO: This is not working byte[] SectorForCheck = new byte[0x808]; uint StoredEDC = BitConverter.ToUInt32(channel, 0x818); byte[] CalculatedEDCBytes; @@ -284,17 +284,14 @@ namespace DiscImageChef.Checksums DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, got CRC 0x{3:X8} expected 0x{4:X8}", channel[0x00C], channel[0x00D], channel[0x00E], CalculatedEDC, StoredEDC); return false; }*/ - } - - return true; } - DicConsole.DebugWriteLine("CD checksums", - "Unknown mode {0} sector at address: {1:X2}:{2:X2}:{3:X2}", - channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]); - return null; + return true; } + DicConsole.DebugWriteLine("CD checksums", + "Unknown mode {0} sector at address: {1:X2}:{2:X2}:{3:X2}", + channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]); return null; } @@ -478,22 +475,20 @@ namespace DiscImageChef.Checksums } } - if((cdTextPack4[0] & 0x80) == 0x80) - { - ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16); - byte[] cdTextPack4ForCrc = new byte[16]; - Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16); - ushort calculatedCdtp4Crc = CalculateCCITT_CRC16(cdTextPack4ForCrc); - DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", cdTextPack4Crc, - calculatedCdtp4Crc); + if((cdTextPack4[0] & 0x80) != 0x80) return status; - if(cdTextPack4Crc != calculatedCdtp4Crc && cdTextPack4Crc != 0) - { - DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}", - cdTextPack4Crc, calculatedCdtp4Crc); - status = false; - } - } + ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16); + byte[] cdTextPack4ForCrc = new byte[16]; + Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16); + ushort calculatedCdtp4Crc = CalculateCCITT_CRC16(cdTextPack4ForCrc); + DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", cdTextPack4Crc, + calculatedCdtp4Crc); + + if(cdTextPack4Crc == calculatedCdtp4Crc || cdTextPack4Crc == 0) return status; + + DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}", + cdTextPack4Crc, calculatedCdtp4Crc); + status = false; return status; } diff --git a/DiscImageChef.Checksums/ReedSolomon.cs b/DiscImageChef.Checksums/ReedSolomon.cs index 8eeda85c5..5dbdcd382 100644 --- a/DiscImageChef.Checksums/ReedSolomon.cs +++ b/DiscImageChef.Checksums/ReedSolomon.cs @@ -305,41 +305,38 @@ namespace DiscImageChef.Checksums /// Outs parity symbols. public int encode_rs(int[] data, out int[] bb) { - if(initialized) + if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); + + int i, j; + int feedback; + bb = new int[nn - kk]; + + Clear(ref bb, nn - kk); + for(i = kk - 1; i >= 0; i--) { - int i, j; - int feedback; - bb = new int[nn - kk]; + if(mm != 8) if(data[i] > nn) return -1; /* Illegal symbol */ - Clear(ref bb, nn - kk); - for(i = kk - 1; i >= 0; i--) + feedback = index_of[data[i] ^ bb[nn - kk - 1]]; + if(feedback != a0) { - if(mm != 8) if(data[i] > nn) return -1; /* Illegal symbol */ + /* feedback term is non-zero */ + for(j = nn - kk - 1; j > 0; j--) + if(gg[j] != a0) bb[j] = bb[j - 1] ^ alpha_to[Modnn(gg[j] + feedback)]; + else bb[j] = bb[j - 1]; - feedback = index_of[data[i] ^ bb[nn - kk - 1]]; - if(feedback != a0) - { - /* feedback term is non-zero */ - for(j = nn - kk - 1; j > 0; j--) - if(gg[j] != a0) bb[j] = bb[j - 1] ^ alpha_to[Modnn(gg[j] + feedback)]; - else bb[j] = bb[j - 1]; - - bb[0] = alpha_to[Modnn(gg[0] + feedback)]; - } - else - { - /* feedback term is zero. encoder becomes a - * single-byte shifter */ - for(j = nn - kk - 1; j > 0; j--) bb[j] = bb[j - 1]; - - bb[0] = 0; - } + bb[0] = alpha_to[Modnn(gg[0] + feedback)]; } + else + { + /* feedback term is zero. encoder becomes a + * single-byte shifter */ + for(j = nn - kk - 1; j > 0; j--) bb[j] = bb[j - 1]; - return 0; + bb[0] = 0; + } } - throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); + return 0; } /* @@ -364,243 +361,236 @@ namespace DiscImageChef.Checksums /// Number of erasures. public int eras_dec_rs(ref int[] data, out int[] erasPos, int noEras) { - if(initialized) + if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); + + erasPos = new int[nn - kk]; + int degLambda, el, degOmega; + int i, j, r; + int u, q, tmp, num1, num2, den, discrR; + int[] recd = new int[nn]; + int[] lambda = new int[nn - kk + 1]; /* Err+Eras Locator poly */ + int[] s = new int[nn - kk + 1]; /* syndrome poly */ + int[] b = new int[nn - kk + 1]; + int[] t = new int[nn - kk + 1]; + int[] omega = new int[nn - kk + 1]; + int[] root = new int[nn - kk]; + int[] reg = new int[nn - kk + 1]; + int[] loc = new int[nn - kk]; + int synError, count; + + /* data[] is in polynomial form, copy and convert to index form */ + for(i = nn - 1; i >= 0; i--) { - erasPos = new int[nn - kk]; - int degLambda, el, degOmega; - int i, j, r; - int u, q, tmp, num1, num2, den, discrR; - int[] recd = new int[nn]; - int[] lambda = new int[nn - kk + 1]; /* Err+Eras Locator poly */ - int[] s = new int[nn - kk + 1]; /* syndrome poly */ - int[] b = new int[nn - kk + 1]; - int[] t = new int[nn - kk + 1]; - int[] omega = new int[nn - kk + 1]; - int[] root = new int[nn - kk]; - int[] reg = new int[nn - kk + 1]; - int[] loc = new int[nn - kk]; - int synError, count; + if(mm != 8) if(data[i] > nn) return -1; /* Illegal symbol */ - /* data[] is in polynomial form, copy and convert to index form */ - for(i = nn - 1; i >= 0; i--) - { - if(mm != 8) if(data[i] > nn) return -1; /* Illegal symbol */ - - recd[i] = index_of[data[i]]; - } - /* first form the syndromes; i.e., evaluate recd(x) at roots of g(x) + recd[i] = index_of[data[i]]; + } + /* first form the syndromes; i.e., evaluate recd(x) at roots of g(x) * namely @**(B0+i), i = 0, ... ,(NN-KK-1) */ - synError = 0; - for(i = 1; i <= nn - kk; i++) - { - tmp = 0; - for(j = 0; j < nn; j++) - if(recd[j] != a0) /* recd[j] in index form */ - tmp ^= alpha_to[Modnn(recd[j] + (B0 + i - 1) * j)]; + synError = 0; + for(i = 1; i <= nn - kk; i++) + { + tmp = 0; + for(j = 0; j < nn; j++) + if(recd[j] != a0) /* recd[j] in index form */ + tmp ^= alpha_to[Modnn(recd[j] + (B0 + i - 1) * j)]; - synError |= tmp; /* set flag if non-zero syndrome => + synError |= tmp; /* set flag if non-zero syndrome => * error */ - /* store syndrome in index form */ - s[i] = index_of[tmp]; - } + /* store syndrome in index form */ + s[i] = index_of[tmp]; + } - if(synError == 0) return 0; + if(synError == 0) return 0; - Clear(ref lambda, nn - kk); - lambda[0] = 1; - if(noEras > 0) + Clear(ref lambda, nn - kk); + lambda[0] = 1; + if(noEras > 0) + { + /* Init lambda to be the erasure locator polynomial */ + lambda[1] = alpha_to[erasPos[0]]; + for(i = 1; i < noEras; i++) { - /* Init lambda to be the erasure locator polynomial */ - lambda[1] = alpha_to[erasPos[0]]; - for(i = 1; i < noEras; i++) + u = erasPos[i]; + for(j = i + 1; j > 0; j--) { - u = erasPos[i]; - for(j = i + 1; j > 0; j--) - { - tmp = index_of[lambda[j - 1]]; - if(tmp != a0) lambda[j] ^= alpha_to[Modnn(u + tmp)]; - } + tmp = index_of[lambda[j - 1]]; + if(tmp != a0) lambda[j] ^= alpha_to[Modnn(u + tmp)]; } + } #if DEBUG - /* find roots of the erasure location polynomial */ - for(i = 1; i <= noEras; i++) reg[i] = index_of[lambda[i]]; + /* find roots of the erasure location polynomial */ + for(i = 1; i <= noEras; i++) reg[i] = index_of[lambda[i]]; - count = 0; - for(i = 1; i <= nn; i++) - { - q = 1; - for(j = 1; j <= noEras; j++) - if(reg[j] != a0) - { - reg[j] = Modnn(reg[j] + j); - q ^= alpha_to[reg[j]]; - } - - if(q == 0) - { - /* store root and error location - * number indices - */ - root[count] = i; - loc[count] = nn - i; - count++; - } - } - - if(count != noEras) - { - DicConsole.DebugWriteLine("Reed Solomon", "\n lambda(x) is WRONG\n"); - return -1; - } - - DicConsole.DebugWriteLine("Reed Solomon", - "\n Erasure positions as determined by roots of Eras Loc Poly:\n"); - for(i = 0; i < count; i++) DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]); - - DicConsole.DebugWriteLine("Reed Solomon", "\n"); -#endif - } - - for(i = 0; i < nn - kk + 1; i++) b[i] = index_of[lambda[i]]; - - /* - * Begin Berlekamp-Massey algorithm to determine error+erasure - * locator polynomial - */ - r = noEras; - el = noEras; - while(++r <= nn - kk) - { - /* r is the step number */ - /* Compute discrepancy at the r-th step in poly-form */ - discrR = 0; - for(i = 0; i < r; i++) if(lambda[i] != 0 && s[r - i] != a0) discrR ^= alpha_to[Modnn(index_of[lambda[i]] + s[r - i])]; - - discrR = index_of[discrR]; /* Index form */ - if(discrR == a0) - { - /* 2 lines below: B(x) <-- x*B(x) */ - Copydown(ref b, ref b, nn - kk); - b[0] = a0; - } - else - { - /* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */ - t[0] = lambda[0]; - for(i = 0; i < nn - kk; i++) - if(b[i] != a0) t[i + 1] = lambda[i + 1] ^ alpha_to[Modnn(discrR + b[i])]; - else t[i + 1] = lambda[i + 1]; - - if(2 * el <= r + noEras - 1) - { - el = r + noEras - el; - /* - * 2 lines below: B(x) <-- inv(discr_r) * - * lambda(x) - */ - for(i = 0; i <= nn - kk; i++) - b[i] = lambda[i] == 0 ? a0 : Modnn(index_of[lambda[i]] - discrR + nn); - } - else - { - /* 2 lines below: B(x) <-- x*B(x) */ - Copydown(ref b, ref b, nn - kk); - b[0] = a0; - } - - Copy(ref lambda, ref t, nn - kk + 1); - } - } - - /* Convert lambda to index form and compute deg(lambda(x)) */ - degLambda = 0; - for(i = 0; i < nn - kk + 1; i++) - { - lambda[i] = index_of[lambda[i]]; - if(lambda[i] != a0) degLambda = i; - } - /* - * Find roots of the error+erasure locator polynomial. By Chien - * Search - */ - int temp = reg[0]; - Copy(ref reg, ref lambda, nn - kk); - reg[0] = temp; - count = 0; /* Number of roots of lambda(x) */ + count = 0; for(i = 1; i <= nn; i++) { q = 1; - for(j = degLambda; j > 0; j--) + for(j = 1; j <= noEras; j++) if(reg[j] != a0) { reg[j] = Modnn(reg[j] + j); q ^= alpha_to[reg[j]]; } - if(q == 0) - { - /* store root (index-form) and error location number */ - root[count] = i; - loc[count] = nn - i; - count++; - } + if(q != 0) continue; + /* store root and error location + * number indices + */ + root[count] = i; + loc[count] = nn - i; + count++; } -#if DEBUG - DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t"); + if(count != noEras) + { + DicConsole.DebugWriteLine("Reed Solomon", "\n lambda(x) is WRONG\n"); + return -1; + } + + DicConsole.DebugWriteLine("Reed Solomon", + "\n Erasure positions as determined by roots of Eras Loc Poly:\n"); for(i = 0; i < count; i++) DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]); DicConsole.DebugWriteLine("Reed Solomon", "\n"); #endif + } - if(degLambda != count) return -1; - /* + for(i = 0; i < nn - kk + 1; i++) b[i] = index_of[lambda[i]]; + + /* + * Begin Berlekamp-Massey algorithm to determine error+erasure + * locator polynomial + */ + r = noEras; + el = noEras; + while(++r <= nn - kk) + { + /* r is the step number */ + /* Compute discrepancy at the r-th step in poly-form */ + discrR = 0; + for(i = 0; i < r; i++) if(lambda[i] != 0 && s[r - i] != a0) discrR ^= alpha_to[Modnn(index_of[lambda[i]] + s[r - i])]; + + discrR = index_of[discrR]; /* Index form */ + if(discrR == a0) + { + /* 2 lines below: B(x) <-- x*B(x) */ + Copydown(ref b, ref b, nn - kk); + b[0] = a0; + } + else + { + /* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */ + t[0] = lambda[0]; + for(i = 0; i < nn - kk; i++) + if(b[i] != a0) t[i + 1] = lambda[i + 1] ^ alpha_to[Modnn(discrR + b[i])]; + else t[i + 1] = lambda[i + 1]; + + if(2 * el <= r + noEras - 1) + { + el = r + noEras - el; + /* + * 2 lines below: B(x) <-- inv(discr_r) * + * lambda(x) + */ + for(i = 0; i <= nn - kk; i++) + b[i] = lambda[i] == 0 ? a0 : Modnn(index_of[lambda[i]] - discrR + nn); + } + else + { + /* 2 lines below: B(x) <-- x*B(x) */ + Copydown(ref b, ref b, nn - kk); + b[0] = a0; + } + + Copy(ref lambda, ref t, nn - kk + 1); + } + } + + /* Convert lambda to index form and compute deg(lambda(x)) */ + degLambda = 0; + for(i = 0; i < nn - kk + 1; i++) + { + lambda[i] = index_of[lambda[i]]; + if(lambda[i] != a0) degLambda = i; + } + /* + * Find roots of the error+erasure locator polynomial. By Chien + * Search + */ + int temp = reg[0]; + Copy(ref reg, ref lambda, nn - kk); + reg[0] = temp; + count = 0; /* Number of roots of lambda(x) */ + for(i = 1; i <= nn; i++) + { + q = 1; + for(j = degLambda; j > 0; j--) + if(reg[j] != a0) + { + reg[j] = Modnn(reg[j] + j); + q ^= alpha_to[reg[j]]; + } + + if(q != 0) continue; + /* store root (index-form) and error location number */ + root[count] = i; + loc[count] = nn - i; + count++; + } + +#if DEBUG + DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t"); + for(i = 0; i < count; i++) DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]); + + DicConsole.DebugWriteLine("Reed Solomon", "\n"); +#endif + + if(degLambda != count) return -1; + /* * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo * x**(NN-KK)). in index form. Also find deg(omega). */ - degOmega = 0; - for(i = 0; i < nn - kk; i++) - { - tmp = 0; - j = degLambda < i ? degLambda : i; - for(; j >= 0; j--) if(s[i + 1 - j] != a0 && lambda[j] != a0) tmp ^= alpha_to[Modnn(s[i + 1 - j] + lambda[j])]; + degOmega = 0; + for(i = 0; i < nn - kk; i++) + { + tmp = 0; + j = degLambda < i ? degLambda : i; + for(; j >= 0; j--) if(s[i + 1 - j] != a0 && lambda[j] != a0) tmp ^= alpha_to[Modnn(s[i + 1 - j] + lambda[j])]; - if(tmp != 0) degOmega = i; - omega[i] = index_of[tmp]; - } + if(tmp != 0) degOmega = i; + omega[i] = index_of[tmp]; + } - omega[nn - kk] = a0; + omega[nn - kk] = a0; - /* + /* * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = * inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form */ - for(j = count - 1; j >= 0; j--) + for(j = count - 1; j >= 0; j--) + { + num1 = 0; + for(i = degOmega; i >= 0; i--) if(omega[i] != a0) num1 ^= alpha_to[Modnn(omega[i] + i * root[j])]; + + num2 = alpha_to[Modnn(root[j] * (B0 - 1) + nn)]; + den = 0; + + /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ + for(i = Min(degLambda, nn - kk - 1) & ~1; i >= 0; i -= 2) if(lambda[i + 1] != a0) den ^= alpha_to[Modnn(lambda[i + 1] + i * root[j])]; + + if(den == 0) { - num1 = 0; - for(i = degOmega; i >= 0; i--) if(omega[i] != a0) num1 ^= alpha_to[Modnn(omega[i] + i * root[j])]; - - num2 = alpha_to[Modnn(root[j] * (B0 - 1) + nn)]; - den = 0; - - /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ - for(i = Min(degLambda, nn - kk - 1) & ~1; i >= 0; i -= 2) if(lambda[i + 1] != a0) den ^= alpha_to[Modnn(lambda[i + 1] + i * root[j])]; - - if(den == 0) - { - DicConsole.DebugWriteLine("Reed Solomon", "\n ERROR: denominator = 0\n"); - return -1; - } - /* Apply error to data */ - if(num1 != 0) data[loc[j]] ^= alpha_to[Modnn(index_of[num1] + index_of[num2] + nn - index_of[den])]; + DicConsole.DebugWriteLine("Reed Solomon", "\n ERROR: denominator = 0\n"); + return -1; } - - return count; + /* Apply error to data */ + if(num1 != 0) data[loc[j]] ^= alpha_to[Modnn(index_of[num1] + index_of[num2] + nn - index_of[den])]; } - throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); + return count; } } } \ No newline at end of file diff --git a/DiscImageChef.Checksums/SpamSumContext.cs b/DiscImageChef.Checksums/SpamSumContext.cs index 8b18a6fa9..6e815e5b5 100644 --- a/DiscImageChef.Checksums/SpamSumContext.cs +++ b/DiscImageChef.Checksums/SpamSumContext.cs @@ -246,11 +246,10 @@ namespace DiscImageChef.Checksums * */ self.Bh[i].Digest[++self.Bh[i].Dlen] = 0; self.Bh[i].H = HASH_INIT; - if(self.Bh[i].Dlen < SPAMSUM_LENGTH / 2) - { - self.Bh[i].Halfh = HASH_INIT; - self.Bh[i].Halfdigest = 0; - } + if(self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2) continue; + + self.Bh[i].Halfh = HASH_INIT; + self.Bh[i].Halfdigest = 0; } else fuzzy_try_reduce_blockhash(); } diff --git a/DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs b/DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs index 27d3c3540..f17c40943 100644 --- a/DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs +++ b/DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs @@ -51,15 +51,14 @@ namespace DiscImageChef.CommonTypes { if(blocks == 173400 && blockSize == 256) return MediaType.SQ400; - if(blockSize == 512) - { - if(model.ToLowerInvariant().StartsWith("syjet")) return MediaType.SyJet; + if(blockSize != 512) return MediaType.Unknown; - switch(blocks) - { - case 262144: return MediaType.EZ135; - case 524288: return MediaType.SQ327; - } + if(model.ToLowerInvariant().StartsWith("syjet")) return MediaType.SyJet; + + switch(blocks) + { + case 262144: return MediaType.EZ135; + case 524288: return MediaType.SQ327; } return MediaType.Unknown; @@ -72,24 +71,20 @@ namespace DiscImageChef.CommonTypes if(model.ToLowerInvariant().StartsWith("zip")) { - if(blockSize == 512) - { - if(blocks == 196608) return MediaType.ZIP100; - if(blocks == 489532) return MediaType.ZIP250; + if(blockSize != 512) return MediaType.Unknown; - return MediaType.ZIP750; - } + if(blocks == 196608) return MediaType.ZIP100; + if(blocks == 489532) return MediaType.ZIP250; - return MediaType.Unknown; + return MediaType.ZIP750; } if(model.ToLowerInvariant().StartsWith("jaz")) { - if(blockSize == 512) - { - if(blocks == 2091050) return MediaType.Jaz; - if(blocks == 3915600) return MediaType.Jaz2; - } + if(blockSize != 512) return MediaType.Unknown; + + if(blocks == 2091050) return MediaType.Jaz; + if(blocks == 3915600) return MediaType.Jaz2; return MediaType.Unknown; } @@ -111,14 +106,11 @@ namespace DiscImageChef.CommonTypes if(model.ToLowerInvariant().StartsWith("rdx")) { - if(blockSize == 512) - { - if(blocks == 625134256) return MediaType.RDX320; + if(blockSize != 512) return MediaType.Unknown; - return MediaType.RDX; - } + if(blocks == 625134256) return MediaType.RDX320; - return MediaType.Unknown; + return MediaType.RDX; } switch(mediumType) @@ -1318,79 +1310,80 @@ namespace DiscImageChef.CommonTypes // Optical device case 0x07: { - if(mediumType == 0x01 || mediumType == 0x02 || mediumType == 0x03 || mediumType == 0x05 || - mediumType == 0x07) - switch(blockSize) + if(mediumType != 0x01 && mediumType != 0x02 && mediumType != 0x03 && mediumType != 0x05 && + mediumType != 0x07) return MediaType.UnknownMO; + + switch(blockSize) + { + case 512: { - case 512: + switch(blocks) { - switch(blocks) - { - case 249850: return MediaType.ECMA_154; - case 429975: return MediaType.ECMA_201_ROM; - case 446325: return MediaType.ECMA_201; - case 694929: return MediaType.ECMA_223_512; - case 904995: return MediaType.ECMA_183_512; - case 1128772: - case 1163337: return MediaType.ECMA_184_512; - case 1281856: return MediaType.PD650_WORM; - case 1298496: return MediaType.PD650; - case 1644581: - case 1647371: return MediaType.ECMA_195_512; - default: return MediaType.UnknownMO; - } + case 249850: return MediaType.ECMA_154; + case 429975: return MediaType.ECMA_201_ROM; + case 446325: return MediaType.ECMA_201; + case 694929: return MediaType.ECMA_223_512; + case 904995: return MediaType.ECMA_183_512; + case 1128772: + case 1163337: return MediaType.ECMA_184_512; + case 1281856: return MediaType.PD650_WORM; + case 1298496: return MediaType.PD650; + case 1644581: + case 1647371: return MediaType.ECMA_195_512; + default: return MediaType.UnknownMO; } - case 1024: - { - switch(blocks) - { - case 371371: return MediaType.ECMA_223; - case 498526: return MediaType.ECMA_183; - case 603466: - case 637041: return MediaType.ECMA_184; - case 936921: - case 948770: return MediaType.ECMA_195; - case 1244621: return MediaType.ECMA_238; - case 14476734: return MediaType.ECMA_260; - case 24445990: return MediaType.ECMA_260_Double; - default: return MediaType.UnknownMO; - } - } - case 2048: - { - switch(blocks) - { - case 318988: - case 320332: - case 321100: return MediaType.ECMA_239; - case 605846: return MediaType.GigaMo; - case 1063146: return MediaType.GigaMo2; - case 1128134: return MediaType.ECMA_280; - case 2043664: return MediaType.ECMA_322_2k; - case 7355716: return MediaType.ECMA_317; - default: return MediaType.UnknownMO; - } - } - case 4096: - { - switch(blocks) - { - case 1095840: return MediaType.ECMA_322; - default: return MediaType.UnknownMO; - } - } - case 8192: - { - switch(blocks) - { - case 1834348: return MediaType.UDO; - case 3668759: return MediaType.UDO2_WORM; - case 3669724: return MediaType.UDO2; - default: return MediaType.UnknownMO; - } - } - default: return MediaType.UnknownMO; } + case 1024: + { + switch(blocks) + { + case 371371: return MediaType.ECMA_223; + case 498526: return MediaType.ECMA_183; + case 603466: + case 637041: return MediaType.ECMA_184; + case 936921: + case 948770: return MediaType.ECMA_195; + case 1244621: return MediaType.ECMA_238; + case 14476734: return MediaType.ECMA_260; + case 24445990: return MediaType.ECMA_260_Double; + default: return MediaType.UnknownMO; + } + } + case 2048: + { + switch(blocks) + { + case 318988: + case 320332: + case 321100: return MediaType.ECMA_239; + case 605846: return MediaType.GigaMo; + case 1063146: return MediaType.GigaMo2; + case 1128134: return MediaType.ECMA_280; + case 2043664: return MediaType.ECMA_322_2k; + case 7355716: return MediaType.ECMA_317; + default: return MediaType.UnknownMO; + } + } + case 4096: + { + switch(blocks) + { + case 1095840: return MediaType.ECMA_322; + default: return MediaType.UnknownMO; + } + } + case 8192: + { + switch(blocks) + { + case 1834348: return MediaType.UDO; + case 3668759: return MediaType.UDO2_WORM; + case 3669724: return MediaType.UDO2; + default: return MediaType.UnknownMO; + } + } + default: return MediaType.UnknownMO; + } return MediaType.UnknownMO; } diff --git a/DiscImageChef.Core/Checksum.cs b/DiscImageChef.Core/Checksum.cs index ccf4595c9..bbb7e850b 100644 --- a/DiscImageChef.Core/Checksum.cs +++ b/DiscImageChef.Core/Checksum.cs @@ -370,13 +370,12 @@ namespace DiscImageChef.Core chks.Add(chk); } - if(enabled.HasFlag(EnableChecksum.SpamSum)) - { - chk = new ChecksumType(); - chk.type = ChecksumTypeType.spamsum; - chk.Value = ssctx.End(); - chks.Add(chk); - } + if(!enabled.HasFlag(EnableChecksum.SpamSum)) return chks; + + chk = new ChecksumType(); + chk.type = ChecksumTypeType.spamsum; + chk.Value = ssctx.End(); + chks.Add(chk); return chks; } @@ -617,13 +616,12 @@ namespace DiscImageChef.Core dataChecksums.Add(chk); } - if(enabled.HasFlag(EnableChecksum.SpamSum)) - { - chk = new ChecksumType(); - chk.type = ChecksumTypeType.spamsum; - chk.Value = ssctxData.End(); - dataChecksums.Add(chk); - } + if(!enabled.HasFlag(EnableChecksum.SpamSum)) return dataChecksums; + + chk = new ChecksumType(); + chk.type = ChecksumTypeType.spamsum; + chk.Value = ssctxData.End(); + dataChecksums.Add(chk); return dataChecksums; } diff --git a/DiscImageChef.Core/DataFile.cs b/DiscImageChef.Core/DataFile.cs index f1e45fd86..8a626eb1d 100644 --- a/DiscImageChef.Core/DataFile.cs +++ b/DiscImageChef.Core/DataFile.cs @@ -104,25 +104,24 @@ namespace DiscImageChef.Core public static void WriteTo(string who, string filename, byte[] data, string whatWriting = null, bool overwrite = false) { - if(!string.IsNullOrEmpty(filename)) - { - if(File.Exists(filename)) - if(overwrite) File.Delete(filename); - else - { - DicConsole.ErrorWriteLine("Not overwriting file {0}", filename); - return; - } + if(string.IsNullOrEmpty(filename)) return; - try + if(File.Exists(filename)) + if(overwrite) File.Delete(filename); + else { - DicConsole.DebugWriteLine(who, "Writing " + whatWriting + " to {0}", filename); - FileStream outputFs = new FileStream(filename, FileMode.CreateNew); - outputFs.Write(data, 0, data.Length); - outputFs.Close(); + DicConsole.ErrorWriteLine("Not overwriting file {0}", filename); + return; } - catch { DicConsole.ErrorWriteLine("Unable to write file {0}", filename); } + + try + { + DicConsole.DebugWriteLine(who, "Writing " + whatWriting + " to {0}", filename); + FileStream outputFs = new FileStream(filename, FileMode.CreateNew); + outputFs.Write(data, 0, data.Length); + outputFs.Close(); } + catch { DicConsole.ErrorWriteLine("Unable to write file {0}", filename); } } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Dumping/ATA.cs b/DiscImageChef.Core/Devices/Dumping/ATA.cs index a5e6c0ffb..b055bfb02 100644 --- a/DiscImageChef.Core/Devices/Dumping/ATA.cs +++ b/DiscImageChef.Core/Devices/Dumping/ATA.cs @@ -504,13 +504,12 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, partitions[i])) - { - plugin.GetInformation(imageFormat, partitions[i], out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - } + if(!plugin.Identify(imageFormat, partitions[i])) continue; + + plugin.GetInformation(imageFormat, partitions[i], out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch @@ -540,13 +539,12 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, wholePart)) - { - plugin.GetInformation(imageFormat, wholePart, out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - } + if(!plugin.Identify(imageFormat, wholePart)) continue; + + plugin.GetInformation(imageFormat, wholePart, out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch diff --git a/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs b/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs index 20acaf9a6..2d58d6a42 100644 --- a/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs +++ b/DiscImageChef.Core/Devices/Dumping/CompactDisc.cs @@ -715,22 +715,21 @@ namespace DiscImageChef.Core.Devices.Dumping totalDuration += cmdDuration; } - if(!sense && !dev.Error || runningPersistent) - { - if(!sense && !dev.Error) - { - resume.BadBlocks.Remove(badSector); - extents.Add(badSector); - dumpLog.WriteLine("Correctly retried sector {0} in pass {1}.", badSector, pass); - } + if((sense || dev.Error) && !runningPersistent) continue; - if(separateSubchannel) - { - dumpFile.WriteAt(readBuffer, badSector, (uint)sectorSize, 0, sectorSize); - subFile.WriteAt(readBuffer, badSector, subSize, sectorSize, (int)subSize); - } - else dumpFile.WriteAt(readBuffer, badSector, blockSize); + if(!sense && !dev.Error) + { + resume.BadBlocks.Remove(badSector); + extents.Add(badSector); + dumpLog.WriteLine("Correctly retried sector {0} in pass {1}.", badSector, pass); } + + if(separateSubchannel) + { + dumpFile.WriteAt(readBuffer, badSector, (uint)sectorSize, 0, sectorSize); + subFile.WriteAt(readBuffer, badSector, subSize, sectorSize, (int)subSize); + } + else dumpFile.WriteAt(readBuffer, badSector, blockSize); } if(pass < retryPasses && !aborted && resume.BadBlocks.Count > 0) diff --git a/DiscImageChef.Core/Devices/Dumping/ResumeSupport.cs b/DiscImageChef.Core/Devices/Dumping/ResumeSupport.cs index 70898ef44..39de09ff5 100644 --- a/DiscImageChef.Core/Devices/Dumping/ResumeSupport.cs +++ b/DiscImageChef.Core/Devices/Dumping/ResumeSupport.cs @@ -78,31 +78,29 @@ namespace DiscImageChef.Core.Devices.Dumping if(oldtry.Software == null) throw new Exception("Found corrupt resume file, cannot continue..."); - if(oldtry.Software.Name == "DiscImageChef" && - oldtry.Software.OperatingSystem == platform.ToString() && - oldtry.Software.Version == Version.GetVersion()) - { - if(removable && (oldtry.Manufacturer != manufacturer || oldtry.Model != model || - oldtry.Serial != serial)) continue; + if(oldtry.Software.Name != "DiscImageChef" || + oldtry.Software.OperatingSystem != platform.ToString() || + oldtry.Software.Version != Version.GetVersion()) continue; - currentTry = oldtry; - extents = ExtentsConverter.FromMetadata(currentTry.Extents); - break; - } + if(removable && (oldtry.Manufacturer != manufacturer || oldtry.Model != model || + oldtry.Serial != serial)) continue; + + currentTry = oldtry; + extents = ExtentsConverter.FromMetadata(currentTry.Extents); + break; } - if(currentTry == null) + if(currentTry != null) return; + + currentTry = new DumpHardwareType { - currentTry = new DumpHardwareType - { - Software = Version.GetSoftwareType(platform), - Manufacturer = manufacturer, - Model = model, - Serial = serial - }; - resume.Tries.Add(currentTry); - extents = new ExtentsULong(); - } + Software = Version.GetSoftwareType(platform), + Manufacturer = manufacturer, + Model = model, + Serial = serial + }; + resume.Tries.Add(currentTry); + extents = new ExtentsULong(); } else { diff --git a/DiscImageChef.Core/Devices/Dumping/SBC.cs b/DiscImageChef.Core/Devices/Dumping/SBC.cs index 7fef95faf..ac576fd00 100644 --- a/DiscImageChef.Core/Devices/Dumping/SBC.cs +++ b/DiscImageChef.Core/Devices/Dumping/SBC.cs @@ -211,18 +211,17 @@ namespace DiscImageChef.Core.Devices.Dumping { dumpLog.WriteLine("Requesting page {0:X2}h.", page); sense = dev.ScsiInquiry(out cmdBuf, out senseBuf, page); - if(!sense) + if(sense) continue; + + EVPDType evpd = new EVPDType { - EVPDType evpd = new EVPDType - { - Image = string.Format("{0}.evpd_{1:X2}h.bin", outputPrefix, page), - Checksums = Checksum.GetChecksums(cmdBuf).ToArray(), - Size = cmdBuf.Length - }; - evpd.Checksums = Checksum.GetChecksums(cmdBuf).ToArray(); - DataFile.WriteTo("SCSI Dump", evpd.Image, cmdBuf); - evpds.Add(evpd); - } + Image = string.Format("{0}.evpd_{1:X2}h.bin", outputPrefix, page), + Checksums = Checksum.GetChecksums(cmdBuf).ToArray(), + Size = cmdBuf.Length + }; + evpd.Checksums = Checksum.GetChecksums(cmdBuf).ToArray(); + DataFile.WriteTo("SCSI Dump", evpd.Image, cmdBuf); + evpds.Add(evpd); } if(evpds.Count > 0) sidecar.BlockMedia[0].SCSI.EVPD = evpds.ToArray(); @@ -651,23 +650,22 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, partitions[i])) - { - plugin.GetInformation(imageFormat, partitions[i], out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + if(!plugin.Identify(imageFormat, partitions[i])) continue; - switch(plugin.XmlFSType.Type) { - case "Opera": dskType = MediaType.ThreeDO; - break; - case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; - break; - case "Nintendo Wii filesystem": dskType = MediaType.WOD; - break; - case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; - break; - } + plugin.GetInformation(imageFormat, partitions[i], out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body @@ -693,23 +691,22 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, wholePart)) - { - plugin.GetInformation(imageFormat, wholePart, out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + if(!plugin.Identify(imageFormat, wholePart)) continue; - switch(plugin.XmlFSType.Type) { - case "Opera": dskType = MediaType.ThreeDO; - break; - case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; - break; - case "Nintendo Wii filesystem": dskType = MediaType.WOD; - break; - case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; - break; - } + plugin.GetInformation(imageFormat, wholePart, out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body diff --git a/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs b/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs index 9d2c1e274..0e7a9cad7 100644 --- a/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs +++ b/DiscImageChef.Core/Devices/Dumping/SecureDigital.cs @@ -495,13 +495,12 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, partitions[i])) - { - plugin.GetInformation(imageFormat, partitions[i], out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - } + if(!plugin.Identify(imageFormat, partitions[i])) continue; + + plugin.GetInformation(imageFormat, partitions[i], out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch @@ -527,13 +526,12 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, wholePart)) - { - plugin.GetInformation(imageFormat, wholePart, out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); - } + if(!plugin.Identify(imageFormat, wholePart)) continue; + + plugin.GetInformation(imageFormat, wholePart, out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch diff --git a/DiscImageChef.Core/Devices/Dumping/XGD.cs b/DiscImageChef.Core/Devices/Dumping/XGD.cs index caa37517f..4b18a778d 100644 --- a/DiscImageChef.Core/Devices/Dumping/XGD.cs +++ b/DiscImageChef.Core/Devices/Dumping/XGD.cs @@ -850,23 +850,22 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, partitions[i])) - { - plugin.GetInformation(imageFormat, partitions[i], out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + if(!plugin.Identify(imageFormat, partitions[i])) continue; - switch(plugin.XmlFSType.Type) { - case "Opera": dskType = MediaType.ThreeDO; - break; - case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; - break; - case "Nintendo Wii filesystem": dskType = MediaType.WOD; - break; - case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; - break; - } + plugin.GetInformation(imageFormat, partitions[i], out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body @@ -892,23 +891,22 @@ namespace DiscImageChef.Core.Devices.Dumping foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(imageFormat, wholePart)) - { - plugin.GetInformation(imageFormat, wholePart, out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + if(!plugin.Identify(imageFormat, wholePart)) continue; - switch(plugin.XmlFSType.Type) { - case "Opera": dskType = MediaType.ThreeDO; - break; - case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; - break; - case "Nintendo Wii filesystem": dskType = MediaType.WOD; - break; - case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; - break; - } + plugin.GetInformation(imageFormat, wholePart, out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + dumpLog.WriteLine("Filesystem {0} found.", plugin.XmlFSType.Type); + + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body diff --git a/DiscImageChef.Core/Devices/ReaderATA.cs b/DiscImageChef.Core/Devices/ReaderATA.cs index e6e95e429..ebc850657 100644 --- a/DiscImageChef.Core/Devices/ReaderATA.cs +++ b/DiscImageChef.Core/Devices/ReaderATA.cs @@ -86,13 +86,14 @@ namespace DiscImageChef.Core.Devices blocks = (ulong)(cylinders * heads * sectors); } - if((ataId.CurrentCylinders == 0 || ataId.CurrentHeads == 0 || ataId.CurrentSectorsPerTrack == 0) && ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0) - { - cylinders = ataId.Cylinders; - heads = (byte)ataId.Heads; - sectors = (byte)ataId.SectorsPerTrack; - blocks = (ulong)(cylinders * heads * sectors); - } + if((ataId.CurrentCylinders != 0 && ataId.CurrentHeads != 0 && ataId.CurrentSectorsPerTrack != 0) || + ataId.Cylinders <= 0 || ataId.Heads <= 0 || + ataId.SectorsPerTrack <= 0) return (cylinders, heads, sectors); + + cylinders = ataId.Cylinders; + heads = (byte)ataId.Heads; + sectors = (byte)ataId.SectorsPerTrack; + blocks = (ulong)(cylinders * heads * sectors); return (cylinders, heads, sectors); } @@ -107,11 +108,10 @@ namespace DiscImageChef.Core.Devices lbaMode = true; } - if(ataId.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48)) - { - blocks = ataId.LBA48Sectors; - lbaMode = true; - } + if(!ataId.CommandSet2.HasFlag(Identify.CommandSetBit2.LBA48)) return blocks; + + blocks = ataId.LBA48Sectors; + lbaMode = true; return blocks; } @@ -279,14 +279,11 @@ namespace DiscImageChef.Core.Devices if(!error || blocksToRead == 1) break; } - if(error && lbaMode) - { - blocksToRead = 1; - errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError); - return true; - } + if(!error || !lbaMode) return false; - return false; + blocksToRead = 1; + errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError); + return true; } bool AtaReadBlocks(out byte[] buffer, ulong block, uint count, out double duration) diff --git a/DiscImageChef.Core/Devices/ReaderSCSI.cs b/DiscImageChef.Core/Devices/ReaderSCSI.cs index f8e37e82b..c1a507cc4 100644 --- a/DiscImageChef.Core/Devices/ReaderSCSI.cs +++ b/DiscImageChef.Core/Devices/ReaderSCSI.cs @@ -174,13 +174,12 @@ namespace DiscImageChef.Core.Devices testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, testSize, timeout, out duration); - if(!testSense && !dev.Error) - { - readLong10 = true; - longBlockSize = testSize; - readRaw = true; - break; - } + if(testSense || dev.Error) continue; + + readLong10 = true; + longBlockSize = testSize; + readRaw = true; + break; } else if(blockSize == 1024) foreach(ushort testSize in new[] @@ -203,13 +202,12 @@ namespace DiscImageChef.Core.Devices testSense = dev.ReadLong10(out readBuffer, out senseBuf, false, false, 0, testSize, timeout, out duration); - if(!testSense && !dev.Error) - { - readLong10 = true; - longBlockSize = testSize; - readRaw = true; - break; - } + if(testSense || dev.Error) continue; + + readLong10 = true; + longBlockSize = testSize; + readRaw = true; + break; } else if(blockSize == 2048) { @@ -468,14 +466,11 @@ namespace DiscImageChef.Core.Devices if(!dev.Error || blocksToRead == 1) break; } - if(dev.Error) - { - blocksToRead = 1; - errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError); - return true; - } + if(!dev.Error) return false; - return false; + blocksToRead = 1; + errorMessage = string.Format("Device error {0} trying to guess ideal transfer length.", dev.LastError); + return true; } bool ScsiReadBlocks(out byte[] buffer, ulong block, uint count, out double duration) @@ -522,14 +517,11 @@ namespace DiscImageChef.Core.Devices else return true; } - if(sense || dev.Error) - { - DicConsole.DebugWriteLine("SCSI Reader", "READ error:\n{0}", - Decoders.SCSI.Sense.PrettifySense(senseBuf)); - return true; - } + if(!sense && !dev.Error) return false; - return false; + DicConsole.DebugWriteLine("SCSI Reader", "READ error:\n{0}", + Decoders.SCSI.Sense.PrettifySense(senseBuf)); + return true; } bool ScsiSeek(ulong block, out double duration) diff --git a/DiscImageChef.Core/Devices/Report/ATA.cs b/DiscImageChef.Core/Devices/Report/ATA.cs index 65832f288..3aad86474 100644 --- a/DiscImageChef.Core/Devices/Report/ATA.cs +++ b/DiscImageChef.Core/Devices/Report/ATA.cs @@ -60,1176 +60,1174 @@ namespace DiscImageChef.Core.Devices.Report dev.AtaIdentify(out buffer, out errorRegs, timeout, out duration); - if(Decoders.ATA.Identify.Decode(buffer).HasValue) - { - Decoders.ATA.Identify.IdentifyDevice ataId = Decoders.ATA.Identify.Decode(buffer).Value; + if(!Decoders.ATA.Identify.Decode(buffer).HasValue) return; - if((ushort)ataId.GeneralConfiguration == 0x848A) + Decoders.ATA.Identify.IdentifyDevice ataId = Decoders.ATA.Identify.Decode(buffer).Value; + + if((ushort)ataId.GeneralConfiguration == 0x848A) + { + report.CompactFlash = true; + report.CompactFlashSpecified = true; + removable = false; + } + else if(!removable && + ataId.GeneralConfiguration.HasFlag(Decoders.ATA.Identify.GeneralConfigurationBit.Removable)) + { + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) { - report.CompactFlash = true; - report.CompactFlashSpecified = true; - removable = false; + DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); } - else if(!removable && - ataId.GeneralConfiguration.HasFlag(Decoders.ATA.Identify.GeneralConfigurationBit.Removable)) + + removable = pressedKey.Key == ConsoleKey.Y; + } + + if(removable) + { + DicConsole.WriteLine("Please remove any media from the device and press any key when it is out."); + System.Console.ReadKey(true); + DicConsole.WriteLine("Querying ATA IDENTIFY..."); + dev.AtaIdentify(out buffer, out errorRegs, timeout, out duration); + ataId = Decoders.ATA.Identify.Decode(buffer).Value; + } + + report.ATA = new ataType(); + + if(!string.IsNullOrWhiteSpace(ataId.AdditionalPID)) + { + report.ATA.AdditionalPID = ataId.AdditionalPID; + report.ATA.AdditionalPIDSpecified = true; + } + if(ataId.APIOSupported != 0) + { + report.ATA.APIOSupported = ataId.APIOSupported; + report.ATA.APIOSupportedSpecified = true; + } + if(ataId.BufferType != 0) + { + report.ATA.BufferType = ataId.BufferType; + report.ATA.BufferTypeSpecified = true; + } + if(ataId.BufferSize != 0) + { + report.ATA.BufferSize = ataId.BufferSize; + report.ATA.BufferSizeSpecified = true; + } + if(ataId.Capabilities != 0) + { + report.ATA.Capabilities = ataId.Capabilities; + report.ATA.CapabilitiesSpecified = true; + } + if(ataId.Capabilities2 != 0) + { + report.ATA.Capabilities2 = ataId.Capabilities2; + report.ATA.Capabilities2Specified = true; + } + if(ataId.Capabilities3 != 0) + { + report.ATA.Capabilities3 = ataId.Capabilities3; + report.ATA.Capabilities3Specified = true; + } + if(ataId.CFAPowerMode != 0) + { + report.ATA.CFAPowerMode = ataId.CFAPowerMode; + report.ATA.CFAPowerModeSpecified = true; + } + if(ataId.CommandSet != 0) + { + report.ATA.CommandSet = ataId.CommandSet; + report.ATA.CommandSetSpecified = true; + } + if(ataId.CommandSet2 != 0) + { + report.ATA.CommandSet2 = ataId.CommandSet2; + report.ATA.CommandSet2Specified = true; + } + if(ataId.CommandSet3 != 0) + { + report.ATA.CommandSet3 = ataId.CommandSet3; + report.ATA.CommandSet3Specified = true; + } + if(ataId.CommandSet4 != 0) + { + report.ATA.CommandSet4 = ataId.CommandSet4; + report.ATA.CommandSet4Specified = true; + } + if(ataId.CommandSet5 != 0) + { + report.ATA.CommandSet5 = ataId.CommandSet5; + report.ATA.CommandSet5Specified = true; + } + if(ataId.CurrentAAM != 0) + { + report.ATA.CurrentAAM = ataId.CurrentAAM; + report.ATA.CurrentAAMSpecified = true; + } + if(ataId.CurrentAPM != 0) + { + report.ATA.CurrentAPM = ataId.CurrentAPM; + report.ATA.CurrentAPMSpecified = true; + } + if(ataId.DataSetMgmt != 0) + { + report.ATA.DataSetMgmt = ataId.DataSetMgmt; + report.ATA.DataSetMgmtSpecified = true; + } + if(ataId.DataSetMgmtSize != 0) + { + report.ATA.DataSetMgmtSize = ataId.DataSetMgmtSize; + report.ATA.DataSetMgmtSizeSpecified = true; + } + if(ataId.DeviceFormFactor != 0) + { + report.ATA.DeviceFormFactor = ataId.DeviceFormFactor; + report.ATA.DeviceFormFactorSpecified = true; + } + if(ataId.DMAActive != 0) + { + report.ATA.DMAActive = ataId.DMAActive; + report.ATA.DMAActiveSpecified = true; + } + if(ataId.DMASupported != 0) + { + report.ATA.DMASupported = ataId.DMASupported; + report.ATA.DMASupportedSpecified = true; + } + if(ataId.DMATransferTimingMode != 0) + { + report.ATA.DMATransferTimingMode = ataId.DMATransferTimingMode; + report.ATA.DMATransferTimingModeSpecified = true; + } + if(ataId.EnhancedSecurityEraseTime != 0) + { + report.ATA.EnhancedSecurityEraseTime = ataId.EnhancedSecurityEraseTime; + report.ATA.EnhancedSecurityEraseTimeSpecified = true; + } + if(ataId.EnabledCommandSet != 0) + { + report.ATA.EnabledCommandSet = ataId.EnabledCommandSet; + report.ATA.EnabledCommandSetSpecified = true; + } + if(ataId.EnabledCommandSet2 != 0) + { + report.ATA.EnabledCommandSet2 = ataId.EnabledCommandSet2; + report.ATA.EnabledCommandSet2Specified = true; + } + if(ataId.EnabledCommandSet3 != 0) + { + report.ATA.EnabledCommandSet3 = ataId.EnabledCommandSet3; + report.ATA.EnabledCommandSet3Specified = true; + } + if(ataId.EnabledCommandSet4 != 0) + { + report.ATA.EnabledCommandSet4 = ataId.EnabledCommandSet4; + report.ATA.EnabledCommandSet4Specified = true; + } + if(ataId.EnabledSATAFeatures != 0) + { + report.ATA.EnabledSATAFeatures = ataId.EnabledSATAFeatures; + report.ATA.EnabledSATAFeaturesSpecified = true; + } + if(ataId.ExtendedUserSectors != 0) + { + report.ATA.ExtendedUserSectors = ataId.ExtendedUserSectors; + report.ATA.ExtendedUserSectorsSpecified = true; + } + if(ataId.FreeFallSensitivity != 0) + { + report.ATA.FreeFallSensitivity = ataId.FreeFallSensitivity; + report.ATA.FreeFallSensitivitySpecified = true; + } + if(!string.IsNullOrWhiteSpace(ataId.FirmwareRevision)) + { + report.ATA.FirmwareRevision = ataId.FirmwareRevision; + report.ATA.FirmwareRevisionSpecified = true; + } + if(ataId.GeneralConfiguration != 0) + { + report.ATA.GeneralConfiguration = ataId.GeneralConfiguration; + report.ATA.GeneralConfigurationSpecified = true; + } + if(ataId.HardwareResetResult != 0) + { + report.ATA.HardwareResetResult = ataId.HardwareResetResult; + report.ATA.HardwareResetResultSpecified = true; + } + if(ataId.InterseekDelay != 0) + { + report.ATA.InterseekDelay = ataId.InterseekDelay; + report.ATA.InterseekDelaySpecified = true; + } + if(ataId.MajorVersion != 0) + { + report.ATA.MajorVersion = ataId.MajorVersion; + report.ATA.MajorVersionSpecified = true; + } + if(ataId.MasterPasswordRevisionCode != 0) + { + report.ATA.MasterPasswordRevisionCode = ataId.MasterPasswordRevisionCode; + report.ATA.MasterPasswordRevisionCodeSpecified = true; + } + if(ataId.MaxDownloadMicroMode3 != 0) + { + report.ATA.MaxDownloadMicroMode3 = ataId.MaxDownloadMicroMode3; + report.ATA.MaxDownloadMicroMode3Specified = true; + } + if(ataId.MaxQueueDepth != 0) + { + report.ATA.MaxQueueDepth = ataId.MaxQueueDepth; + report.ATA.MaxQueueDepthSpecified = true; + } + if(ataId.MDMAActive != 0) + { + report.ATA.MDMAActive = ataId.MDMAActive; + report.ATA.MDMAActiveSpecified = true; + } + if(ataId.MDMASupported != 0) + { + report.ATA.MDMASupported = ataId.MDMASupported; + report.ATA.MDMASupportedSpecified = true; + } + if(ataId.MinDownloadMicroMode3 != 0) + { + report.ATA.MinDownloadMicroMode3 = ataId.MinDownloadMicroMode3; + report.ATA.MinDownloadMicroMode3Specified = true; + } + if(ataId.MinMDMACycleTime != 0) + { + report.ATA.MinMDMACycleTime = ataId.MinMDMACycleTime; + report.ATA.MinMDMACycleTimeSpecified = true; + } + if(ataId.MinorVersion != 0) + { + report.ATA.MinorVersion = ataId.MinorVersion; + report.ATA.MinorVersionSpecified = true; + } + if(ataId.MinPIOCycleTimeNoFlow != 0) + { + report.ATA.MinPIOCycleTimeNoFlow = ataId.MinPIOCycleTimeNoFlow; + report.ATA.MinPIOCycleTimeNoFlowSpecified = true; + } + if(ataId.MinPIOCycleTimeFlow != 0) + { + report.ATA.MinPIOCycleTimeFlow = ataId.MinPIOCycleTimeFlow; + report.ATA.MinPIOCycleTimeFlowSpecified = true; + } + if(!string.IsNullOrWhiteSpace(ataId.Model)) + { + report.ATA.Model = ataId.Model; + report.ATA.ModelSpecified = true; + } + if(ataId.MultipleMaxSectors != 0) + { + report.ATA.MultipleMaxSectors = ataId.MultipleMaxSectors; + report.ATA.MultipleMaxSectorsSpecified = true; + } + if(ataId.MultipleSectorNumber != 0) + { + report.ATA.MultipleSectorNumber = ataId.MultipleSectorNumber; + report.ATA.MultipleSectorNumberSpecified = true; + } + if(ataId.NVCacheCaps != 0) + { + report.ATA.NVCacheCaps = ataId.NVCacheCaps; + report.ATA.NVCacheCapsSpecified = true; + } + if(ataId.NVCacheSize != 0) + { + report.ATA.NVCacheSize = ataId.NVCacheSize; + report.ATA.NVCacheSizeSpecified = true; + } + if(ataId.NVCacheWriteSpeed != 0) + { + report.ATA.NVCacheWriteSpeed = ataId.NVCacheWriteSpeed; + report.ATA.NVCacheWriteSpeedSpecified = true; + } + if(ataId.NVEstimatedSpinUp != 0) + { + report.ATA.NVEstimatedSpinUp = ataId.NVEstimatedSpinUp; + report.ATA.NVEstimatedSpinUpSpecified = true; + } + if(ataId.PacketBusRelease != 0) + { + report.ATA.PacketBusRelease = ataId.PacketBusRelease; + report.ATA.PacketBusReleaseSpecified = true; + } + if(ataId.PIOTransferTimingMode != 0) + { + report.ATA.PIOTransferTimingMode = ataId.PIOTransferTimingMode; + report.ATA.PIOTransferTimingModeSpecified = true; + } + if(ataId.RecommendedAAM != 0) + { + report.ATA.RecommendedAAM = ataId.RecommendedAAM; + report.ATA.RecommendedAAMSpecified = true; + } + if(ataId.RecMDMACycleTime != 0) + { + report.ATA.RecommendedMDMACycleTime = ataId.RecMDMACycleTime; + report.ATA.RecommendedMDMACycleTimeSpecified = true; + } + if(ataId.RemovableStatusSet != 0) + { + report.ATA.RemovableStatusSet = ataId.RemovableStatusSet; + report.ATA.RemovableStatusSetSpecified = true; + } + if(ataId.SATACapabilities != 0) + { + report.ATA.SATACapabilities = ataId.SATACapabilities; + report.ATA.SATACapabilitiesSpecified = true; + } + if(ataId.SATACapabilities2 != 0) + { + report.ATA.SATACapabilities2 = ataId.SATACapabilities2; + report.ATA.SATACapabilities2Specified = true; + } + if(ataId.SATAFeatures != 0) + { + report.ATA.SATAFeatures = ataId.SATAFeatures; + report.ATA.SATAFeaturesSpecified = true; + } + if(ataId.SCTCommandTransport != 0) + { + report.ATA.SCTCommandTransport = ataId.SCTCommandTransport; + report.ATA.SCTCommandTransportSpecified = true; + } + if(ataId.SectorsPerCard != 0) + { + report.ATA.SectorsPerCard = ataId.SectorsPerCard; + report.ATA.SectorsPerCardSpecified = true; + } + if(ataId.SecurityEraseTime != 0) + { + report.ATA.SecurityEraseTime = ataId.SecurityEraseTime; + report.ATA.SecurityEraseTimeSpecified = true; + } + if(ataId.SecurityStatus != 0) + { + report.ATA.SecurityStatus = ataId.SecurityStatus; + report.ATA.SecurityStatusSpecified = true; + } + if(ataId.ServiceBusyClear != 0) + { + report.ATA.ServiceBusyClear = ataId.ServiceBusyClear; + report.ATA.ServiceBusyClearSpecified = true; + } + if(ataId.SpecificConfiguration != 0) + { + report.ATA.SpecificConfiguration = ataId.SpecificConfiguration; + report.ATA.SpecificConfigurationSpecified = true; + } + if(ataId.StreamAccessLatency != 0) + { + report.ATA.StreamAccessLatency = ataId.StreamAccessLatency; + report.ATA.StreamAccessLatencySpecified = true; + } + if(ataId.StreamMinReqSize != 0) + { + report.ATA.StreamMinReqSize = ataId.StreamMinReqSize; + report.ATA.StreamMinReqSizeSpecified = true; + } + if(ataId.StreamPerformanceGranularity != 0) + { + report.ATA.StreamPerformanceGranularity = ataId.StreamPerformanceGranularity; + report.ATA.StreamPerformanceGranularitySpecified = true; + } + if(ataId.StreamTransferTimeDMA != 0) + { + report.ATA.StreamTransferTimeDMA = ataId.StreamTransferTimeDMA; + report.ATA.StreamTransferTimeDMASpecified = true; + } + if(ataId.StreamTransferTimePIO != 0) + { + report.ATA.StreamTransferTimePIO = ataId.StreamTransferTimePIO; + report.ATA.StreamTransferTimePIOSpecified = true; + } + if(ataId.TransportMajorVersion != 0) + { + report.ATA.TransportMajorVersion = ataId.TransportMajorVersion; + report.ATA.TransportMajorVersionSpecified = true; + } + if(ataId.TransportMinorVersion != 0) + { + report.ATA.TransportMinorVersion = ataId.TransportMinorVersion; + report.ATA.TransportMinorVersionSpecified = true; + } + if(ataId.TrustedComputing != 0) + { + report.ATA.TrustedComputing = ataId.TrustedComputing; + report.ATA.TrustedComputingSpecified = true; + } + if(ataId.UDMAActive != 0) + { + report.ATA.UDMAActive = ataId.UDMAActive; + report.ATA.UDMAActiveSpecified = true; + } + if(ataId.UDMASupported != 0) + { + report.ATA.UDMASupported = ataId.UDMASupported; + report.ATA.UDMASupportedSpecified = true; + } + if(ataId.WRVMode != 0) + { + report.ATA.WRVMode = ataId.WRVMode; + report.ATA.WRVModeSpecified = true; + } + if(ataId.WRVSectorCountMode3 != 0) + { + report.ATA.WRVSectorCountMode3 = ataId.WRVSectorCountMode3; + report.ATA.WRVSectorCountMode3Specified = true; + } + if(ataId.WRVSectorCountMode2 != 0) + { + report.ATA.WRVSectorCountMode2 = ataId.WRVSectorCountMode2; + report.ATA.WRVSectorCountMode2Specified = true; + } + if(debug) report.ATA.Identify = buffer; + + if(removable) + { + List mediaTests = new List(); + + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.N) { pressedKey = new ConsoleKeyInfo(); while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) { - DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): "); + DicConsole.Write("Do you have media that you can insert in the drive? (Y/N): "); pressedKey = System.Console.ReadKey(); DicConsole.WriteLine(); } - removable = pressedKey.Key == ConsoleKey.Y; - } + if(pressedKey.Key != ConsoleKey.Y) continue; - if(removable) - { - DicConsole.WriteLine("Please remove any media from the device and press any key when it is out."); + DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); System.Console.ReadKey(true); + + testedMediaType mediaTest = new testedMediaType(); + DicConsole.Write("Please write a description of the media type and press enter: "); + mediaTest.MediumTypeName = System.Console.ReadLine(); + DicConsole.Write("Please write the media model and press enter: "); + mediaTest.Model = System.Console.ReadLine(); + + mediaTest.ManufacturerSpecified = true; + mediaTest.ModelSpecified = true; + mediaTest.MediaIsRecognized = true; + DicConsole.WriteLine("Querying ATA IDENTIFY..."); dev.AtaIdentify(out buffer, out errorRegs, timeout, out duration); - ataId = Decoders.ATA.Identify.Decode(buffer).Value; - } - report.ATA = new ataType(); - - if(!string.IsNullOrWhiteSpace(ataId.AdditionalPID)) - { - report.ATA.AdditionalPID = ataId.AdditionalPID; - report.ATA.AdditionalPIDSpecified = true; - } - if(ataId.APIOSupported != 0) - { - report.ATA.APIOSupported = ataId.APIOSupported; - report.ATA.APIOSupportedSpecified = true; - } - if(ataId.BufferType != 0) - { - report.ATA.BufferType = ataId.BufferType; - report.ATA.BufferTypeSpecified = true; - } - if(ataId.BufferSize != 0) - { - report.ATA.BufferSize = ataId.BufferSize; - report.ATA.BufferSizeSpecified = true; - } - if(ataId.Capabilities != 0) - { - report.ATA.Capabilities = ataId.Capabilities; - report.ATA.CapabilitiesSpecified = true; - } - if(ataId.Capabilities2 != 0) - { - report.ATA.Capabilities2 = ataId.Capabilities2; - report.ATA.Capabilities2Specified = true; - } - if(ataId.Capabilities3 != 0) - { - report.ATA.Capabilities3 = ataId.Capabilities3; - report.ATA.Capabilities3Specified = true; - } - if(ataId.CFAPowerMode != 0) - { - report.ATA.CFAPowerMode = ataId.CFAPowerMode; - report.ATA.CFAPowerModeSpecified = true; - } - if(ataId.CommandSet != 0) - { - report.ATA.CommandSet = ataId.CommandSet; - report.ATA.CommandSetSpecified = true; - } - if(ataId.CommandSet2 != 0) - { - report.ATA.CommandSet2 = ataId.CommandSet2; - report.ATA.CommandSet2Specified = true; - } - if(ataId.CommandSet3 != 0) - { - report.ATA.CommandSet3 = ataId.CommandSet3; - report.ATA.CommandSet3Specified = true; - } - if(ataId.CommandSet4 != 0) - { - report.ATA.CommandSet4 = ataId.CommandSet4; - report.ATA.CommandSet4Specified = true; - } - if(ataId.CommandSet5 != 0) - { - report.ATA.CommandSet5 = ataId.CommandSet5; - report.ATA.CommandSet5Specified = true; - } - if(ataId.CurrentAAM != 0) - { - report.ATA.CurrentAAM = ataId.CurrentAAM; - report.ATA.CurrentAAMSpecified = true; - } - if(ataId.CurrentAPM != 0) - { - report.ATA.CurrentAPM = ataId.CurrentAPM; - report.ATA.CurrentAPMSpecified = true; - } - if(ataId.DataSetMgmt != 0) - { - report.ATA.DataSetMgmt = ataId.DataSetMgmt; - report.ATA.DataSetMgmtSpecified = true; - } - if(ataId.DataSetMgmtSize != 0) - { - report.ATA.DataSetMgmtSize = ataId.DataSetMgmtSize; - report.ATA.DataSetMgmtSizeSpecified = true; - } - if(ataId.DeviceFormFactor != 0) - { - report.ATA.DeviceFormFactor = ataId.DeviceFormFactor; - report.ATA.DeviceFormFactorSpecified = true; - } - if(ataId.DMAActive != 0) - { - report.ATA.DMAActive = ataId.DMAActive; - report.ATA.DMAActiveSpecified = true; - } - if(ataId.DMASupported != 0) - { - report.ATA.DMASupported = ataId.DMASupported; - report.ATA.DMASupportedSpecified = true; - } - if(ataId.DMATransferTimingMode != 0) - { - report.ATA.DMATransferTimingMode = ataId.DMATransferTimingMode; - report.ATA.DMATransferTimingModeSpecified = true; - } - if(ataId.EnhancedSecurityEraseTime != 0) - { - report.ATA.EnhancedSecurityEraseTime = ataId.EnhancedSecurityEraseTime; - report.ATA.EnhancedSecurityEraseTimeSpecified = true; - } - if(ataId.EnabledCommandSet != 0) - { - report.ATA.EnabledCommandSet = ataId.EnabledCommandSet; - report.ATA.EnabledCommandSetSpecified = true; - } - if(ataId.EnabledCommandSet2 != 0) - { - report.ATA.EnabledCommandSet2 = ataId.EnabledCommandSet2; - report.ATA.EnabledCommandSet2Specified = true; - } - if(ataId.EnabledCommandSet3 != 0) - { - report.ATA.EnabledCommandSet3 = ataId.EnabledCommandSet3; - report.ATA.EnabledCommandSet3Specified = true; - } - if(ataId.EnabledCommandSet4 != 0) - { - report.ATA.EnabledCommandSet4 = ataId.EnabledCommandSet4; - report.ATA.EnabledCommandSet4Specified = true; - } - if(ataId.EnabledSATAFeatures != 0) - { - report.ATA.EnabledSATAFeatures = ataId.EnabledSATAFeatures; - report.ATA.EnabledSATAFeaturesSpecified = true; - } - if(ataId.ExtendedUserSectors != 0) - { - report.ATA.ExtendedUserSectors = ataId.ExtendedUserSectors; - report.ATA.ExtendedUserSectorsSpecified = true; - } - if(ataId.FreeFallSensitivity != 0) - { - report.ATA.FreeFallSensitivity = ataId.FreeFallSensitivity; - report.ATA.FreeFallSensitivitySpecified = true; - } - if(!string.IsNullOrWhiteSpace(ataId.FirmwareRevision)) - { - report.ATA.FirmwareRevision = ataId.FirmwareRevision; - report.ATA.FirmwareRevisionSpecified = true; - } - if(ataId.GeneralConfiguration != 0) - { - report.ATA.GeneralConfiguration = ataId.GeneralConfiguration; - report.ATA.GeneralConfigurationSpecified = true; - } - if(ataId.HardwareResetResult != 0) - { - report.ATA.HardwareResetResult = ataId.HardwareResetResult; - report.ATA.HardwareResetResultSpecified = true; - } - if(ataId.InterseekDelay != 0) - { - report.ATA.InterseekDelay = ataId.InterseekDelay; - report.ATA.InterseekDelaySpecified = true; - } - if(ataId.MajorVersion != 0) - { - report.ATA.MajorVersion = ataId.MajorVersion; - report.ATA.MajorVersionSpecified = true; - } - if(ataId.MasterPasswordRevisionCode != 0) - { - report.ATA.MasterPasswordRevisionCode = ataId.MasterPasswordRevisionCode; - report.ATA.MasterPasswordRevisionCodeSpecified = true; - } - if(ataId.MaxDownloadMicroMode3 != 0) - { - report.ATA.MaxDownloadMicroMode3 = ataId.MaxDownloadMicroMode3; - report.ATA.MaxDownloadMicroMode3Specified = true; - } - if(ataId.MaxQueueDepth != 0) - { - report.ATA.MaxQueueDepth = ataId.MaxQueueDepth; - report.ATA.MaxQueueDepthSpecified = true; - } - if(ataId.MDMAActive != 0) - { - report.ATA.MDMAActive = ataId.MDMAActive; - report.ATA.MDMAActiveSpecified = true; - } - if(ataId.MDMASupported != 0) - { - report.ATA.MDMASupported = ataId.MDMASupported; - report.ATA.MDMASupportedSpecified = true; - } - if(ataId.MinDownloadMicroMode3 != 0) - { - report.ATA.MinDownloadMicroMode3 = ataId.MinDownloadMicroMode3; - report.ATA.MinDownloadMicroMode3Specified = true; - } - if(ataId.MinMDMACycleTime != 0) - { - report.ATA.MinMDMACycleTime = ataId.MinMDMACycleTime; - report.ATA.MinMDMACycleTimeSpecified = true; - } - if(ataId.MinorVersion != 0) - { - report.ATA.MinorVersion = ataId.MinorVersion; - report.ATA.MinorVersionSpecified = true; - } - if(ataId.MinPIOCycleTimeNoFlow != 0) - { - report.ATA.MinPIOCycleTimeNoFlow = ataId.MinPIOCycleTimeNoFlow; - report.ATA.MinPIOCycleTimeNoFlowSpecified = true; - } - if(ataId.MinPIOCycleTimeFlow != 0) - { - report.ATA.MinPIOCycleTimeFlow = ataId.MinPIOCycleTimeFlow; - report.ATA.MinPIOCycleTimeFlowSpecified = true; - } - if(!string.IsNullOrWhiteSpace(ataId.Model)) - { - report.ATA.Model = ataId.Model; - report.ATA.ModelSpecified = true; - } - if(ataId.MultipleMaxSectors != 0) - { - report.ATA.MultipleMaxSectors = ataId.MultipleMaxSectors; - report.ATA.MultipleMaxSectorsSpecified = true; - } - if(ataId.MultipleSectorNumber != 0) - { - report.ATA.MultipleSectorNumber = ataId.MultipleSectorNumber; - report.ATA.MultipleSectorNumberSpecified = true; - } - if(ataId.NVCacheCaps != 0) - { - report.ATA.NVCacheCaps = ataId.NVCacheCaps; - report.ATA.NVCacheCapsSpecified = true; - } - if(ataId.NVCacheSize != 0) - { - report.ATA.NVCacheSize = ataId.NVCacheSize; - report.ATA.NVCacheSizeSpecified = true; - } - if(ataId.NVCacheWriteSpeed != 0) - { - report.ATA.NVCacheWriteSpeed = ataId.NVCacheWriteSpeed; - report.ATA.NVCacheWriteSpeedSpecified = true; - } - if(ataId.NVEstimatedSpinUp != 0) - { - report.ATA.NVEstimatedSpinUp = ataId.NVEstimatedSpinUp; - report.ATA.NVEstimatedSpinUpSpecified = true; - } - if(ataId.PacketBusRelease != 0) - { - report.ATA.PacketBusRelease = ataId.PacketBusRelease; - report.ATA.PacketBusReleaseSpecified = true; - } - if(ataId.PIOTransferTimingMode != 0) - { - report.ATA.PIOTransferTimingMode = ataId.PIOTransferTimingMode; - report.ATA.PIOTransferTimingModeSpecified = true; - } - if(ataId.RecommendedAAM != 0) - { - report.ATA.RecommendedAAM = ataId.RecommendedAAM; - report.ATA.RecommendedAAMSpecified = true; - } - if(ataId.RecMDMACycleTime != 0) - { - report.ATA.RecommendedMDMACycleTime = ataId.RecMDMACycleTime; - report.ATA.RecommendedMDMACycleTimeSpecified = true; - } - if(ataId.RemovableStatusSet != 0) - { - report.ATA.RemovableStatusSet = ataId.RemovableStatusSet; - report.ATA.RemovableStatusSetSpecified = true; - } - if(ataId.SATACapabilities != 0) - { - report.ATA.SATACapabilities = ataId.SATACapabilities; - report.ATA.SATACapabilitiesSpecified = true; - } - if(ataId.SATACapabilities2 != 0) - { - report.ATA.SATACapabilities2 = ataId.SATACapabilities2; - report.ATA.SATACapabilities2Specified = true; - } - if(ataId.SATAFeatures != 0) - { - report.ATA.SATAFeatures = ataId.SATAFeatures; - report.ATA.SATAFeaturesSpecified = true; - } - if(ataId.SCTCommandTransport != 0) - { - report.ATA.SCTCommandTransport = ataId.SCTCommandTransport; - report.ATA.SCTCommandTransportSpecified = true; - } - if(ataId.SectorsPerCard != 0) - { - report.ATA.SectorsPerCard = ataId.SectorsPerCard; - report.ATA.SectorsPerCardSpecified = true; - } - if(ataId.SecurityEraseTime != 0) - { - report.ATA.SecurityEraseTime = ataId.SecurityEraseTime; - report.ATA.SecurityEraseTimeSpecified = true; - } - if(ataId.SecurityStatus != 0) - { - report.ATA.SecurityStatus = ataId.SecurityStatus; - report.ATA.SecurityStatusSpecified = true; - } - if(ataId.ServiceBusyClear != 0) - { - report.ATA.ServiceBusyClear = ataId.ServiceBusyClear; - report.ATA.ServiceBusyClearSpecified = true; - } - if(ataId.SpecificConfiguration != 0) - { - report.ATA.SpecificConfiguration = ataId.SpecificConfiguration; - report.ATA.SpecificConfigurationSpecified = true; - } - if(ataId.StreamAccessLatency != 0) - { - report.ATA.StreamAccessLatency = ataId.StreamAccessLatency; - report.ATA.StreamAccessLatencySpecified = true; - } - if(ataId.StreamMinReqSize != 0) - { - report.ATA.StreamMinReqSize = ataId.StreamMinReqSize; - report.ATA.StreamMinReqSizeSpecified = true; - } - if(ataId.StreamPerformanceGranularity != 0) - { - report.ATA.StreamPerformanceGranularity = ataId.StreamPerformanceGranularity; - report.ATA.StreamPerformanceGranularitySpecified = true; - } - if(ataId.StreamTransferTimeDMA != 0) - { - report.ATA.StreamTransferTimeDMA = ataId.StreamTransferTimeDMA; - report.ATA.StreamTransferTimeDMASpecified = true; - } - if(ataId.StreamTransferTimePIO != 0) - { - report.ATA.StreamTransferTimePIO = ataId.StreamTransferTimePIO; - report.ATA.StreamTransferTimePIOSpecified = true; - } - if(ataId.TransportMajorVersion != 0) - { - report.ATA.TransportMajorVersion = ataId.TransportMajorVersion; - report.ATA.TransportMajorVersionSpecified = true; - } - if(ataId.TransportMinorVersion != 0) - { - report.ATA.TransportMinorVersion = ataId.TransportMinorVersion; - report.ATA.TransportMinorVersionSpecified = true; - } - if(ataId.TrustedComputing != 0) - { - report.ATA.TrustedComputing = ataId.TrustedComputing; - report.ATA.TrustedComputingSpecified = true; - } - if(ataId.UDMAActive != 0) - { - report.ATA.UDMAActive = ataId.UDMAActive; - report.ATA.UDMAActiveSpecified = true; - } - if(ataId.UDMASupported != 0) - { - report.ATA.UDMASupported = ataId.UDMASupported; - report.ATA.UDMASupportedSpecified = true; - } - if(ataId.WRVMode != 0) - { - report.ATA.WRVMode = ataId.WRVMode; - report.ATA.WRVModeSpecified = true; - } - if(ataId.WRVSectorCountMode3 != 0) - { - report.ATA.WRVSectorCountMode3 = ataId.WRVSectorCountMode3; - report.ATA.WRVSectorCountMode3Specified = true; - } - if(ataId.WRVSectorCountMode2 != 0) - { - report.ATA.WRVSectorCountMode2 = ataId.WRVSectorCountMode2; - report.ATA.WRVSectorCountMode2Specified = true; - } - if(debug) report.ATA.Identify = buffer; - - if(removable) - { - List mediaTests = new List(); - - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.N) + if(Decoders.ATA.Identify.Decode(buffer).HasValue) { - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) + ataId = Decoders.ATA.Identify.Decode(buffer).Value; + + if(ataId.UnformattedBPT != 0) { - DicConsole.Write("Do you have media that you can insert in the drive? (Y/N): "); - pressedKey = System.Console.ReadKey(); - DicConsole.WriteLine(); + mediaTest.UnformattedBPT = ataId.UnformattedBPT; + mediaTest.UnformattedBPTSpecified = true; + } + if(ataId.UnformattedBPS != 0) + { + mediaTest.UnformattedBPS = ataId.UnformattedBPS; + mediaTest.UnformattedBPSSpecified = true; } - if(pressedKey.Key == ConsoleKey.Y) + if(ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0) { - DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); - System.Console.ReadKey(true); + mediaTest.CHS = new chsType(); + mediaTest.CHS.Cylinders = ataId.Cylinders; + mediaTest.CHS.Heads = ataId.Heads; + mediaTest.CHS.Sectors = ataId.SectorsPerTrack; + mediaTest.Blocks = (ulong)(ataId.Cylinders * ataId.Heads * ataId.SectorsPerTrack); + mediaTest.BlocksSpecified = true; + } - testedMediaType mediaTest = new testedMediaType(); - DicConsole.Write("Please write a description of the media type and press enter: "); - mediaTest.MediumTypeName = System.Console.ReadLine(); - DicConsole.Write("Please write the media model and press enter: "); - mediaTest.Model = System.Console.ReadLine(); + if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && + ataId.CurrentSectorsPerTrack > 0) + { + mediaTest.CurrentCHS = new chsType(); + mediaTest.CurrentCHS.Cylinders = ataId.CurrentCylinders; + mediaTest.CurrentCHS.Heads = ataId.CurrentHeads; + mediaTest.CurrentCHS.Sectors = ataId.CurrentSectorsPerTrack; + if(mediaTest.Blocks == 0) + mediaTest.Blocks = + (ulong)(ataId.CurrentCylinders * ataId.CurrentHeads * + ataId.CurrentSectorsPerTrack); + mediaTest.BlocksSpecified = true; + } - mediaTest.ManufacturerSpecified = true; - mediaTest.ModelSpecified = true; - mediaTest.MediaIsRecognized = true; + if(ataId.Capabilities.HasFlag(Decoders.ATA.Identify.CapabilitiesBit.LBASupport)) + { + mediaTest.LBASectors = ataId.LBASectors; + mediaTest.LBASectorsSpecified = true; + mediaTest.Blocks = ataId.LBASectors; + mediaTest.BlocksSpecified = true; + } - DicConsole.WriteLine("Querying ATA IDENTIFY..."); - dev.AtaIdentify(out buffer, out errorRegs, timeout, out duration); + if(ataId.CommandSet2.HasFlag(Decoders.ATA.Identify.CommandSetBit2.LBA48)) + { + mediaTest.LBA48Sectors = ataId.LBA48Sectors; + mediaTest.LBA48SectorsSpecified = true; + mediaTest.Blocks = ataId.LBA48Sectors; + mediaTest.BlocksSpecified = true; + } - if(Decoders.ATA.Identify.Decode(buffer).HasValue) + if(ataId.NominalRotationRate != 0x0000 && ataId.NominalRotationRate != 0xFFFF) + if(ataId.NominalRotationRate == 0x0001) { - ataId = Decoders.ATA.Identify.Decode(buffer).Value; - - if(ataId.UnformattedBPT != 0) - { - mediaTest.UnformattedBPT = ataId.UnformattedBPT; - mediaTest.UnformattedBPTSpecified = true; - } - if(ataId.UnformattedBPS != 0) - { - mediaTest.UnformattedBPS = ataId.UnformattedBPS; - mediaTest.UnformattedBPSSpecified = true; - } - - if(ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0) - { - mediaTest.CHS = new chsType(); - mediaTest.CHS.Cylinders = ataId.Cylinders; - mediaTest.CHS.Heads = ataId.Heads; - mediaTest.CHS.Sectors = ataId.SectorsPerTrack; - mediaTest.Blocks = (ulong)(ataId.Cylinders * ataId.Heads * ataId.SectorsPerTrack); - mediaTest.BlocksSpecified = true; - } - - if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && - ataId.CurrentSectorsPerTrack > 0) - { - mediaTest.CurrentCHS = new chsType(); - mediaTest.CurrentCHS.Cylinders = ataId.CurrentCylinders; - mediaTest.CurrentCHS.Heads = ataId.CurrentHeads; - mediaTest.CurrentCHS.Sectors = ataId.CurrentSectorsPerTrack; - if(mediaTest.Blocks == 0) - mediaTest.Blocks = - (ulong)(ataId.CurrentCylinders * ataId.CurrentHeads * - ataId.CurrentSectorsPerTrack); - mediaTest.BlocksSpecified = true; - } - - if(ataId.Capabilities.HasFlag(Decoders.ATA.Identify.CapabilitiesBit.LBASupport)) - { - mediaTest.LBASectors = ataId.LBASectors; - mediaTest.LBASectorsSpecified = true; - mediaTest.Blocks = ataId.LBASectors; - mediaTest.BlocksSpecified = true; - } - - if(ataId.CommandSet2.HasFlag(Decoders.ATA.Identify.CommandSetBit2.LBA48)) - { - mediaTest.LBA48Sectors = ataId.LBA48Sectors; - mediaTest.LBA48SectorsSpecified = true; - mediaTest.Blocks = ataId.LBA48Sectors; - mediaTest.BlocksSpecified = true; - } - - if(ataId.NominalRotationRate != 0x0000 && ataId.NominalRotationRate != 0xFFFF) - if(ataId.NominalRotationRate == 0x0001) - { - mediaTest.SolidStateDevice = true; - mediaTest.SolidStateDeviceSpecified = true; - } - else - { - mediaTest.SolidStateDevice = false; - mediaTest.SolidStateDeviceSpecified = true; - mediaTest.NominalRotationRate = ataId.NominalRotationRate; - mediaTest.NominalRotationRateSpecified = true; - } - - uint logicalsectorsize = 0; - uint physicalsectorsize; - if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && - (ataId.PhysLogSectorSize & 0x4000) == 0x4000) - { - if((ataId.PhysLogSectorSize & 0x1000) == 0x1000) - if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF) - logicalsectorsize = 512; - else logicalsectorsize = ataId.LogicalSectorWords * 2; - else logicalsectorsize = 512; - - if((ataId.PhysLogSectorSize & 0x2000) == 0x2000) - { -#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created - physicalsectorsize = - (uint)(logicalsectorsize * ((1 << ataId.PhysLogSectorSize) & 0xF)); -#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created - } - else physicalsectorsize = logicalsectorsize; - } - else - { - logicalsectorsize = 512; - physicalsectorsize = 512; - } - - mediaTest.BlockSize = logicalsectorsize; - mediaTest.BlockSizeSpecified = true; - if(physicalsectorsize != logicalsectorsize) - { - mediaTest.PhysicalBlockSize = physicalsectorsize; - mediaTest.PhysicalBlockSizeSpecified = true; - - if((ataId.LogicalAlignment & 0x8000) == 0x0000 && - (ataId.LogicalAlignment & 0x4000) == 0x4000) - { - mediaTest.LogicalAlignment = (ushort)(ataId.LogicalAlignment & 0x3FFF); - mediaTest.LogicalAlignmentSpecified = true; - } - } - - if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) - { - mediaTest.LongBlockSize = logicalsectorsize + ataId.EccBytes; - mediaTest.LongBlockSizeSpecified = true; - } - - if(ataId.UnformattedBPS > logicalsectorsize && - (!mediaTest.LongBlockSizeSpecified || mediaTest.LongBlockSize == 516)) - { - mediaTest.LongBlockSize = ataId.UnformattedBPS; - mediaTest.LongBlockSizeSpecified = true; - } - - if(ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeSet) && - !ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeClear) && - ataId.EnabledCommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MediaSerial)) - { - mediaTest.CanReadMediaSerial = true; - mediaTest.CanReadMediaSerialSpecified = true; - if(!string.IsNullOrWhiteSpace(ataId.MediaManufacturer)) - { - mediaTest.Manufacturer = ataId.MediaManufacturer; - mediaTest.ManufacturerSpecified = true; - } - } - - mediaTest.SupportsReadLbaSpecified = true; - mediaTest.SupportsReadRetryLbaSpecified = true; - mediaTest.SupportsReadDmaLbaSpecified = true; - mediaTest.SupportsReadDmaRetryLbaSpecified = true; - mediaTest.SupportsReadLongLbaSpecified = true; - mediaTest.SupportsReadLongRetryLbaSpecified = true; - mediaTest.SupportsSeekLbaSpecified = true; - - mediaTest.SupportsReadLba48Specified = true; - mediaTest.SupportsReadDmaLba48Specified = true; - - mediaTest.SupportsReadSpecified = true; - mediaTest.SupportsReadRetrySpecified = true; - mediaTest.SupportsReadDmaSpecified = true; - mediaTest.SupportsReadDmaRetrySpecified = true; - mediaTest.SupportsReadLongSpecified = true; - mediaTest.SupportsReadLongRetrySpecified = true; - mediaTest.SupportsSeekSpecified = true; - - Decoders.ATA.AtaErrorRegistersCHS errorChs; - Decoders.ATA.AtaErrorRegistersLBA28 errorLba; - Decoders.ATA.AtaErrorRegistersLBA48 errorLba48; - - byte[] readBuf; - ulong checkCorrectRead = BitConverter.ToUInt64(buffer, 0); - bool sense = true; - - DicConsole.WriteLine("Trying READ SECTOR(S) in CHS mode..."); - sense = dev.Read(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, out duration); - mediaTest.SupportsRead = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectorschs", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in CHS mode..."); - sense = dev.Read(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); - mediaTest.SupportsReadRetry = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectorsretrychs", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ DMA in CHS mode..."); - sense = dev.ReadDma(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, - out duration); - mediaTest.SupportsReadDma = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdmachs", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ DMA RETRY in CHS mode..."); - sense = dev.ReadDma(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); - mediaTest.SupportsReadDmaRetry = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdmaretrychs", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying SEEK in CHS mode..."); - sense = dev.Seek(out errorChs, 0, 0, 1, timeout, out duration); - mediaTest.SupportsSeek = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, - errorChs.status, errorChs.error); - - DicConsole.WriteLine("Trying READ SECTOR(S) in LBA mode..."); - sense = dev.Read(out readBuf, out errorLba, false, 0, 1, timeout, out duration); - mediaTest.SupportsReadLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectors", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in LBA mode..."); - sense = dev.Read(out readBuf, out errorLba, true, 0, 1, timeout, out duration); - mediaTest.SupportsReadRetryLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectorsretry", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ DMA in LBA mode..."); - sense = dev.ReadDma(out readBuf, out errorLba, false, 0, 1, timeout, out duration); - mediaTest.SupportsReadDmaLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdma", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ DMA RETRY in LBA mode..."); - sense = dev.ReadDma(out readBuf, out errorLba, true, 0, 1, timeout, out duration); - mediaTest.SupportsReadDmaRetryLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdmaretry", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying SEEK in LBA mode..."); - sense = dev.Seek(out errorLba, 0, timeout, out duration); - mediaTest.SupportsSeekLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, - errorChs.status, errorChs.error); - - DicConsole.WriteLine("Trying READ SECTOR(S) in LBA48 mode..."); - sense = dev.Read(out readBuf, out errorLba48, 0, 1, timeout, out duration); - mediaTest.SupportsReadLba48 = - !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectors48", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ DMA in LBA48 mode..."); - sense = dev.ReadDma(out readBuf, out errorLba48, 0, 1, timeout, out duration); - mediaTest.SupportsReadDmaLba48 = - !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && - readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdma48", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ LONG in CHS mode..."); - sense = dev.ReadLong(out readBuf, out errorChs, false, 0, 0, 1, mediaTest.LongBlockSize, - timeout, out duration); - mediaTest.SupportsReadLong = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && - readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlongchs", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ LONG RETRY in CHS mode..."); - sense = dev.ReadLong(out readBuf, out errorChs, true, 0, 0, 1, mediaTest.LongBlockSize, - timeout, out duration); - mediaTest.SupportsReadLongRetry = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && - readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlongretrychs", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ LONG in LBA mode..."); - sense = dev.ReadLong(out readBuf, out errorLba, false, 0, mediaTest.LongBlockSize, - timeout, out duration); - mediaTest.SupportsReadLongLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && - readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlong", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ LONG RETRY in LBA mode..."); - sense = dev.ReadLong(out readBuf, out errorLba, true, 0, mediaTest.LongBlockSize, - timeout, out duration); - mediaTest.SupportsReadLongRetryLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && - readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", - sense, errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlongretry", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - readBuf); + mediaTest.SolidStateDevice = true; + mediaTest.SolidStateDeviceSpecified = true; + } + else + { + mediaTest.SolidStateDevice = false; + mediaTest.SolidStateDeviceSpecified = true; + mediaTest.NominalRotationRate = ataId.NominalRotationRate; + mediaTest.NominalRotationRateSpecified = true; } - else mediaTest.MediaIsRecognized = false; - mediaTests.Add(mediaTest); - } - } - - report.ATA.RemovableMedias = mediaTests.ToArray(); - } - else - { - report.ATA.ReadCapabilities = new testedMediaType(); - - if(ataId.UnformattedBPT != 0) - { - report.ATA.ReadCapabilities.UnformattedBPT = ataId.UnformattedBPT; - report.ATA.ReadCapabilities.UnformattedBPTSpecified = true; - } - if(ataId.UnformattedBPS != 0) - { - report.ATA.ReadCapabilities.UnformattedBPS = ataId.UnformattedBPS; - report.ATA.ReadCapabilities.UnformattedBPSSpecified = true; - } - - if(ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0) - { - report.ATA.ReadCapabilities.CHS = new chsType(); - report.ATA.ReadCapabilities.CHS.Cylinders = ataId.Cylinders; - report.ATA.ReadCapabilities.CHS.Heads = ataId.Heads; - report.ATA.ReadCapabilities.CHS.Sectors = ataId.SectorsPerTrack; - report.ATA.ReadCapabilities.Blocks = - (ulong)(ataId.Cylinders * ataId.Heads * ataId.SectorsPerTrack); - report.ATA.ReadCapabilities.BlocksSpecified = true; - } - - if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && ataId.CurrentSectorsPerTrack > 0) - { - report.ATA.ReadCapabilities.CurrentCHS = new chsType(); - report.ATA.ReadCapabilities.CurrentCHS.Cylinders = ataId.CurrentCylinders; - report.ATA.ReadCapabilities.CurrentCHS.Heads = ataId.CurrentHeads; - report.ATA.ReadCapabilities.CurrentCHS.Sectors = ataId.CurrentSectorsPerTrack; - report.ATA.ReadCapabilities.Blocks = - (ulong)(ataId.CurrentCylinders * ataId.CurrentHeads * ataId.CurrentSectorsPerTrack); - report.ATA.ReadCapabilities.BlocksSpecified = true; - } - - if(ataId.Capabilities.HasFlag(Decoders.ATA.Identify.CapabilitiesBit.LBASupport)) - { - report.ATA.ReadCapabilities.LBASectors = ataId.LBASectors; - report.ATA.ReadCapabilities.LBASectorsSpecified = true; - report.ATA.ReadCapabilities.Blocks = ataId.LBASectors; - report.ATA.ReadCapabilities.BlocksSpecified = true; - } - - if(ataId.CommandSet2.HasFlag(Decoders.ATA.Identify.CommandSetBit2.LBA48)) - { - report.ATA.ReadCapabilities.LBA48Sectors = ataId.LBA48Sectors; - report.ATA.ReadCapabilities.LBA48SectorsSpecified = true; - report.ATA.ReadCapabilities.Blocks = ataId.LBA48Sectors; - report.ATA.ReadCapabilities.BlocksSpecified = true; - } - - if(ataId.NominalRotationRate != 0x0000 && ataId.NominalRotationRate != 0xFFFF) - if(ataId.NominalRotationRate == 0x0001) + uint logicalsectorsize = 0; + uint physicalsectorsize; + if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && + (ataId.PhysLogSectorSize & 0x4000) == 0x4000) { - report.ATA.ReadCapabilities.SolidStateDevice = true; - report.ATA.ReadCapabilities.SolidStateDeviceSpecified = true; + if((ataId.PhysLogSectorSize & 0x1000) == 0x1000) + if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF) + logicalsectorsize = 512; + else logicalsectorsize = ataId.LogicalSectorWords * 2; + else logicalsectorsize = 512; + + if((ataId.PhysLogSectorSize & 0x2000) == 0x2000) + { +#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created + physicalsectorsize = + (uint)(logicalsectorsize * ((1 << ataId.PhysLogSectorSize) & 0xF)); +#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created + } + else physicalsectorsize = logicalsectorsize; } else { - report.ATA.ReadCapabilities.SolidStateDevice = false; - report.ATA.ReadCapabilities.SolidStateDeviceSpecified = true; - report.ATA.ReadCapabilities.NominalRotationRate = ataId.NominalRotationRate; - report.ATA.ReadCapabilities.NominalRotationRateSpecified = true; + logicalsectorsize = 512; + physicalsectorsize = 512; } - uint logicalsectorsize = 0; - uint physicalsectorsize; - if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && (ataId.PhysLogSectorSize & 0x4000) == 0x4000) - { - if((ataId.PhysLogSectorSize & 0x1000) == 0x1000) - if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF) - logicalsectorsize = 512; - else logicalsectorsize = ataId.LogicalSectorWords * 2; - else logicalsectorsize = 512; - - if((ataId.PhysLogSectorSize & 0x2000) == 0x2000) + mediaTest.BlockSize = logicalsectorsize; + mediaTest.BlockSizeSpecified = true; + if(physicalsectorsize != logicalsectorsize) { -#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created - physicalsectorsize = logicalsectorsize * - (uint)Math.Pow(2, (double)(ataId.PhysLogSectorSize & 0xF)); -#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created + mediaTest.PhysicalBlockSize = physicalsectorsize; + mediaTest.PhysicalBlockSizeSpecified = true; + + if((ataId.LogicalAlignment & 0x8000) == 0x0000 && + (ataId.LogicalAlignment & 0x4000) == 0x4000) + { + mediaTest.LogicalAlignment = (ushort)(ataId.LogicalAlignment & 0x3FFF); + mediaTest.LogicalAlignmentSpecified = true; + } } - else physicalsectorsize = logicalsectorsize; + + if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) + { + mediaTest.LongBlockSize = logicalsectorsize + ataId.EccBytes; + mediaTest.LongBlockSizeSpecified = true; + } + + if(ataId.UnformattedBPS > logicalsectorsize && + (!mediaTest.LongBlockSizeSpecified || mediaTest.LongBlockSize == 516)) + { + mediaTest.LongBlockSize = ataId.UnformattedBPS; + mediaTest.LongBlockSizeSpecified = true; + } + + if(ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeSet) && + !ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeClear) && + ataId.EnabledCommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MediaSerial)) + { + mediaTest.CanReadMediaSerial = true; + mediaTest.CanReadMediaSerialSpecified = true; + if(!string.IsNullOrWhiteSpace(ataId.MediaManufacturer)) + { + mediaTest.Manufacturer = ataId.MediaManufacturer; + mediaTest.ManufacturerSpecified = true; + } + } + + mediaTest.SupportsReadLbaSpecified = true; + mediaTest.SupportsReadRetryLbaSpecified = true; + mediaTest.SupportsReadDmaLbaSpecified = true; + mediaTest.SupportsReadDmaRetryLbaSpecified = true; + mediaTest.SupportsReadLongLbaSpecified = true; + mediaTest.SupportsReadLongRetryLbaSpecified = true; + mediaTest.SupportsSeekLbaSpecified = true; + + mediaTest.SupportsReadLba48Specified = true; + mediaTest.SupportsReadDmaLba48Specified = true; + + mediaTest.SupportsReadSpecified = true; + mediaTest.SupportsReadRetrySpecified = true; + mediaTest.SupportsReadDmaSpecified = true; + mediaTest.SupportsReadDmaRetrySpecified = true; + mediaTest.SupportsReadLongSpecified = true; + mediaTest.SupportsReadLongRetrySpecified = true; + mediaTest.SupportsSeekSpecified = true; + + Decoders.ATA.AtaErrorRegistersCHS errorChs; + Decoders.ATA.AtaErrorRegistersLBA28 errorLba; + Decoders.ATA.AtaErrorRegistersLBA48 errorLba48; + + byte[] readBuf; + ulong checkCorrectRead = BitConverter.ToUInt64(buffer, 0); + bool sense = true; + + DicConsole.WriteLine("Trying READ SECTOR(S) in CHS mode..."); + sense = dev.Read(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, out duration); + mediaTest.SupportsRead = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectorschs", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in CHS mode..."); + sense = dev.Read(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); + mediaTest.SupportsReadRetry = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectorsretrychs", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ DMA in CHS mode..."); + sense = dev.ReadDma(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, + out duration); + mediaTest.SupportsReadDma = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdmachs", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ DMA RETRY in CHS mode..."); + sense = dev.ReadDma(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); + mediaTest.SupportsReadDmaRetry = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdmaretrychs", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying SEEK in CHS mode..."); + sense = dev.Seek(out errorChs, 0, 0, 1, timeout, out duration); + mediaTest.SupportsSeek = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, + errorChs.status, errorChs.error); + + DicConsole.WriteLine("Trying READ SECTOR(S) in LBA mode..."); + sense = dev.Read(out readBuf, out errorLba, false, 0, 1, timeout, out duration); + mediaTest.SupportsReadLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectors", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in LBA mode..."); + sense = dev.Read(out readBuf, out errorLba, true, 0, 1, timeout, out duration); + mediaTest.SupportsReadRetryLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectorsretry", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ DMA in LBA mode..."); + sense = dev.ReadDma(out readBuf, out errorLba, false, 0, 1, timeout, out duration); + mediaTest.SupportsReadDmaLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdma", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ DMA RETRY in LBA mode..."); + sense = dev.ReadDma(out readBuf, out errorLba, true, 0, 1, timeout, out duration); + mediaTest.SupportsReadDmaRetryLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdmaretry", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying SEEK in LBA mode..."); + sense = dev.Seek(out errorLba, 0, timeout, out duration); + mediaTest.SupportsSeekLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, + errorChs.status, errorChs.error); + + DicConsole.WriteLine("Trying READ SECTOR(S) in LBA48 mode..."); + sense = dev.Read(out readBuf, out errorLba48, 0, 1, timeout, out duration); + mediaTest.SupportsReadLba48 = + !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectors48", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ DMA in LBA48 mode..."); + sense = dev.ReadDma(out readBuf, out errorLba48, 0, 1, timeout, out duration); + mediaTest.SupportsReadDmaLba48 = + !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && + readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdma48", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ LONG in CHS mode..."); + sense = dev.ReadLong(out readBuf, out errorChs, false, 0, 0, 1, mediaTest.LongBlockSize, + timeout, out duration); + mediaTest.SupportsReadLong = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && + readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlongchs", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ LONG RETRY in CHS mode..."); + sense = dev.ReadLong(out readBuf, out errorChs, true, 0, 0, 1, mediaTest.LongBlockSize, + timeout, out duration); + mediaTest.SupportsReadLongRetry = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && + readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlongretrychs", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ LONG in LBA mode..."); + sense = dev.ReadLong(out readBuf, out errorLba, false, 0, mediaTest.LongBlockSize, + timeout, out duration); + mediaTest.SupportsReadLongLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && + readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlong", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ LONG RETRY in LBA mode..."); + sense = dev.ReadLong(out readBuf, out errorLba, true, 0, mediaTest.LongBlockSize, + timeout, out duration); + mediaTest.SupportsReadLongRetryLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && + readBuf.Length > 0 && BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", + sense, errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlongretry", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + readBuf); + } + else mediaTest.MediaIsRecognized = false; + + mediaTests.Add(mediaTest); + } + + report.ATA.RemovableMedias = mediaTests.ToArray(); + } + else + { + report.ATA.ReadCapabilities = new testedMediaType(); + + if(ataId.UnformattedBPT != 0) + { + report.ATA.ReadCapabilities.UnformattedBPT = ataId.UnformattedBPT; + report.ATA.ReadCapabilities.UnformattedBPTSpecified = true; + } + if(ataId.UnformattedBPS != 0) + { + report.ATA.ReadCapabilities.UnformattedBPS = ataId.UnformattedBPS; + report.ATA.ReadCapabilities.UnformattedBPSSpecified = true; + } + + if(ataId.Cylinders > 0 && ataId.Heads > 0 && ataId.SectorsPerTrack > 0) + { + report.ATA.ReadCapabilities.CHS = new chsType(); + report.ATA.ReadCapabilities.CHS.Cylinders = ataId.Cylinders; + report.ATA.ReadCapabilities.CHS.Heads = ataId.Heads; + report.ATA.ReadCapabilities.CHS.Sectors = ataId.SectorsPerTrack; + report.ATA.ReadCapabilities.Blocks = + (ulong)(ataId.Cylinders * ataId.Heads * ataId.SectorsPerTrack); + report.ATA.ReadCapabilities.BlocksSpecified = true; + } + + if(ataId.CurrentCylinders > 0 && ataId.CurrentHeads > 0 && ataId.CurrentSectorsPerTrack > 0) + { + report.ATA.ReadCapabilities.CurrentCHS = new chsType(); + report.ATA.ReadCapabilities.CurrentCHS.Cylinders = ataId.CurrentCylinders; + report.ATA.ReadCapabilities.CurrentCHS.Heads = ataId.CurrentHeads; + report.ATA.ReadCapabilities.CurrentCHS.Sectors = ataId.CurrentSectorsPerTrack; + report.ATA.ReadCapabilities.Blocks = + (ulong)(ataId.CurrentCylinders * ataId.CurrentHeads * ataId.CurrentSectorsPerTrack); + report.ATA.ReadCapabilities.BlocksSpecified = true; + } + + if(ataId.Capabilities.HasFlag(Decoders.ATA.Identify.CapabilitiesBit.LBASupport)) + { + report.ATA.ReadCapabilities.LBASectors = ataId.LBASectors; + report.ATA.ReadCapabilities.LBASectorsSpecified = true; + report.ATA.ReadCapabilities.Blocks = ataId.LBASectors; + report.ATA.ReadCapabilities.BlocksSpecified = true; + } + + if(ataId.CommandSet2.HasFlag(Decoders.ATA.Identify.CommandSetBit2.LBA48)) + { + report.ATA.ReadCapabilities.LBA48Sectors = ataId.LBA48Sectors; + report.ATA.ReadCapabilities.LBA48SectorsSpecified = true; + report.ATA.ReadCapabilities.Blocks = ataId.LBA48Sectors; + report.ATA.ReadCapabilities.BlocksSpecified = true; + } + + if(ataId.NominalRotationRate != 0x0000 && ataId.NominalRotationRate != 0xFFFF) + if(ataId.NominalRotationRate == 0x0001) + { + report.ATA.ReadCapabilities.SolidStateDevice = true; + report.ATA.ReadCapabilities.SolidStateDeviceSpecified = true; } else { - logicalsectorsize = 512; - physicalsectorsize = 512; + report.ATA.ReadCapabilities.SolidStateDevice = false; + report.ATA.ReadCapabilities.SolidStateDeviceSpecified = true; + report.ATA.ReadCapabilities.NominalRotationRate = ataId.NominalRotationRate; + report.ATA.ReadCapabilities.NominalRotationRateSpecified = true; } - report.ATA.ReadCapabilities.BlockSize = logicalsectorsize; - report.ATA.ReadCapabilities.BlockSizeSpecified = true; - if(physicalsectorsize != logicalsectorsize) + uint logicalsectorsize = 0; + uint physicalsectorsize; + if((ataId.PhysLogSectorSize & 0x8000) == 0x0000 && (ataId.PhysLogSectorSize & 0x4000) == 0x4000) + { + if((ataId.PhysLogSectorSize & 0x1000) == 0x1000) + if(ataId.LogicalSectorWords <= 255 || ataId.LogicalAlignment == 0xFFFF) + logicalsectorsize = 512; + else logicalsectorsize = ataId.LogicalSectorWords * 2; + else logicalsectorsize = 512; + + if((ataId.PhysLogSectorSize & 0x2000) == 0x2000) { - report.ATA.ReadCapabilities.PhysicalBlockSize = physicalsectorsize; - report.ATA.ReadCapabilities.PhysicalBlockSizeSpecified = true; - - if((ataId.LogicalAlignment & 0x8000) == 0x0000 && (ataId.LogicalAlignment & 0x4000) == 0x4000) - { - report.ATA.ReadCapabilities.LogicalAlignment = (ushort)(ataId.LogicalAlignment & 0x3FFF); - report.ATA.ReadCapabilities.LogicalAlignmentSpecified = true; - } +#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created + physicalsectorsize = logicalsectorsize * + (uint)Math.Pow(2, (double)(ataId.PhysLogSectorSize & 0xF)); +#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created } - - if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) - { - report.ATA.ReadCapabilities.LongBlockSize = logicalsectorsize + ataId.EccBytes; - report.ATA.ReadCapabilities.LongBlockSizeSpecified = true; - } - - if(ataId.UnformattedBPS > logicalsectorsize && - (!report.ATA.ReadCapabilities.LongBlockSizeSpecified || - report.ATA.ReadCapabilities.LongBlockSize == 516)) - { - report.ATA.ReadCapabilities.LongBlockSize = ataId.UnformattedBPS; - report.ATA.ReadCapabilities.LongBlockSizeSpecified = true; - } - - if(ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeSet) && - !ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeClear) && - ataId.EnabledCommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MediaSerial)) - { - report.ATA.ReadCapabilities.CanReadMediaSerial = true; - report.ATA.ReadCapabilities.CanReadMediaSerialSpecified = true; - if(!string.IsNullOrWhiteSpace(ataId.MediaManufacturer)) - { - report.ATA.ReadCapabilities.Manufacturer = ataId.MediaManufacturer; - report.ATA.ReadCapabilities.ManufacturerSpecified = true; - } - } - - report.ATA.ReadCapabilities.SupportsReadLbaSpecified = true; - report.ATA.ReadCapabilities.SupportsReadRetryLbaSpecified = true; - report.ATA.ReadCapabilities.SupportsReadDmaLbaSpecified = true; - report.ATA.ReadCapabilities.SupportsReadDmaRetryLbaSpecified = true; - report.ATA.ReadCapabilities.SupportsReadLongLbaSpecified = true; - report.ATA.ReadCapabilities.SupportsReadLongRetryLbaSpecified = true; - report.ATA.ReadCapabilities.SupportsSeekLbaSpecified = true; - - report.ATA.ReadCapabilities.SupportsReadLba48Specified = true; - report.ATA.ReadCapabilities.SupportsReadDmaLba48Specified = true; - - report.ATA.ReadCapabilities.SupportsReadSpecified = true; - report.ATA.ReadCapabilities.SupportsReadRetrySpecified = true; - report.ATA.ReadCapabilities.SupportsReadDmaSpecified = true; - report.ATA.ReadCapabilities.SupportsReadDmaRetrySpecified = true; - report.ATA.ReadCapabilities.SupportsReadLongSpecified = true; - report.ATA.ReadCapabilities.SupportsReadLongRetrySpecified = true; - report.ATA.ReadCapabilities.SupportsSeekSpecified = true; - - Decoders.ATA.AtaErrorRegistersCHS errorChs; - Decoders.ATA.AtaErrorRegistersLBA28 errorLba; - Decoders.ATA.AtaErrorRegistersLBA48 errorLba48; - - byte[] readBuf; - ulong checkCorrectRead = BitConverter.ToUInt64(buffer, 0); - bool sense = true; - - DicConsole.WriteLine("Trying READ SECTOR(S) in CHS mode..."); - sense = dev.Read(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsRead = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectorschs", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in CHS mode..."); - sense = dev.Read(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadRetry = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectorsretrychs", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ DMA in CHS mode..."); - sense = dev.ReadDma(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadDma = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdmachs", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ DMA RETRY in CHS mode..."); - sense = dev.ReadDma(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadDmaRetry = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdmaretrychs", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying SEEK in CHS mode..."); - sense = dev.Seek(out errorChs, 0, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsSeek = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0; - DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, - errorChs.status, errorChs.error); - - DicConsole.WriteLine("Trying READ SECTOR(S) in LBA mode..."); - sense = dev.Read(out readBuf, out errorLba, false, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba.status, errorLba.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectors", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in LBA mode..."); - sense = dev.Read(out readBuf, out errorLba, true, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadRetryLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba.status, errorLba.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectorsretry", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ DMA in LBA mode..."); - sense = dev.ReadDma(out readBuf, out errorLba, false, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadDmaLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba.status, errorLba.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdma", "_debug_" + report.ATA.Model + ".bin", "read results", - readBuf); - - DicConsole.WriteLine("Trying READ DMA RETRY in LBA mode..."); - sense = dev.ReadDma(out readBuf, out errorLba, true, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadDmaRetryLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba.status, errorLba.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdmaretry", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying SEEK in LBA mode..."); - sense = dev.Seek(out errorLba, 0, timeout, out duration); - report.ATA.ReadCapabilities.SupportsSeekLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0; - DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, - errorLba.status, errorLba.error); - - DicConsole.WriteLine("Trying READ SECTOR(S) in LBA48 mode..."); - sense = dev.Read(out readBuf, out errorLba48, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadLba48 = - !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba48.status, errorLba48.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readsectors48", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ DMA in LBA48 mode..."); - sense = dev.ReadDma(out readBuf, out errorLba48, 0, 1, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadDmaLba48 = - !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && readBuf.Length > 0; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba48.status, errorLba48.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readdma48", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ LONG in CHS mode..."); - sense = dev.ReadLong(out readBuf, out errorChs, false, 0, 0, 1, - report.ATA.ReadCapabilities.LongBlockSize, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadLong = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0 && - BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlongchs", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ LONG RETRY in CHS mode..."); - sense = dev.ReadLong(out readBuf, out errorChs, true, 0, 0, 1, - report.ATA.ReadCapabilities.LongBlockSize, timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadLongRetry = - !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0 && - BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorChs.status, errorChs.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlongretrychs", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ LONG in LBA mode..."); - sense = dev.ReadLong(out readBuf, out errorLba, false, 0, report.ATA.ReadCapabilities.LongBlockSize, - timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadLongLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0 && - BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba.status, errorLba.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlong", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); - - DicConsole.WriteLine("Trying READ LONG RETRY in LBA mode..."); - sense = dev.ReadLong(out readBuf, out errorLba, true, 0, report.ATA.ReadCapabilities.LongBlockSize, - timeout, out duration); - report.ATA.ReadCapabilities.SupportsReadLongRetryLba = - !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0 && - BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; - DicConsole.DebugWriteLine("ATA Report", - "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, - errorLba.status, errorLba.error, readBuf.Length); - if(debug) - DataFile.WriteTo("ATA Report", "readlongretry", "_debug_" + report.ATA.Model + ".bin", - "read results", readBuf); + else physicalsectorsize = logicalsectorsize; } + else + { + logicalsectorsize = 512; + physicalsectorsize = 512; + } + + report.ATA.ReadCapabilities.BlockSize = logicalsectorsize; + report.ATA.ReadCapabilities.BlockSizeSpecified = true; + if(physicalsectorsize != logicalsectorsize) + { + report.ATA.ReadCapabilities.PhysicalBlockSize = physicalsectorsize; + report.ATA.ReadCapabilities.PhysicalBlockSizeSpecified = true; + + if((ataId.LogicalAlignment & 0x8000) == 0x0000 && (ataId.LogicalAlignment & 0x4000) == 0x4000) + { + report.ATA.ReadCapabilities.LogicalAlignment = (ushort)(ataId.LogicalAlignment & 0x3FFF); + report.ATA.ReadCapabilities.LogicalAlignmentSpecified = true; + } + } + + if(ataId.EccBytes != 0x0000 && ataId.EccBytes != 0xFFFF) + { + report.ATA.ReadCapabilities.LongBlockSize = logicalsectorsize + ataId.EccBytes; + report.ATA.ReadCapabilities.LongBlockSizeSpecified = true; + } + + if(ataId.UnformattedBPS > logicalsectorsize && + (!report.ATA.ReadCapabilities.LongBlockSizeSpecified || + report.ATA.ReadCapabilities.LongBlockSize == 516)) + { + report.ATA.ReadCapabilities.LongBlockSize = ataId.UnformattedBPS; + report.ATA.ReadCapabilities.LongBlockSizeSpecified = true; + } + + if(ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeSet) && + !ataId.CommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MustBeClear) && + ataId.EnabledCommandSet3.HasFlag(Decoders.ATA.Identify.CommandSetBit3.MediaSerial)) + { + report.ATA.ReadCapabilities.CanReadMediaSerial = true; + report.ATA.ReadCapabilities.CanReadMediaSerialSpecified = true; + if(!string.IsNullOrWhiteSpace(ataId.MediaManufacturer)) + { + report.ATA.ReadCapabilities.Manufacturer = ataId.MediaManufacturer; + report.ATA.ReadCapabilities.ManufacturerSpecified = true; + } + } + + report.ATA.ReadCapabilities.SupportsReadLbaSpecified = true; + report.ATA.ReadCapabilities.SupportsReadRetryLbaSpecified = true; + report.ATA.ReadCapabilities.SupportsReadDmaLbaSpecified = true; + report.ATA.ReadCapabilities.SupportsReadDmaRetryLbaSpecified = true; + report.ATA.ReadCapabilities.SupportsReadLongLbaSpecified = true; + report.ATA.ReadCapabilities.SupportsReadLongRetryLbaSpecified = true; + report.ATA.ReadCapabilities.SupportsSeekLbaSpecified = true; + + report.ATA.ReadCapabilities.SupportsReadLba48Specified = true; + report.ATA.ReadCapabilities.SupportsReadDmaLba48Specified = true; + + report.ATA.ReadCapabilities.SupportsReadSpecified = true; + report.ATA.ReadCapabilities.SupportsReadRetrySpecified = true; + report.ATA.ReadCapabilities.SupportsReadDmaSpecified = true; + report.ATA.ReadCapabilities.SupportsReadDmaRetrySpecified = true; + report.ATA.ReadCapabilities.SupportsReadLongSpecified = true; + report.ATA.ReadCapabilities.SupportsReadLongRetrySpecified = true; + report.ATA.ReadCapabilities.SupportsSeekSpecified = true; + + Decoders.ATA.AtaErrorRegistersCHS errorChs; + Decoders.ATA.AtaErrorRegistersLBA28 errorLba; + Decoders.ATA.AtaErrorRegistersLBA48 errorLba48; + + byte[] readBuf; + ulong checkCorrectRead = BitConverter.ToUInt64(buffer, 0); + bool sense = true; + + DicConsole.WriteLine("Trying READ SECTOR(S) in CHS mode..."); + sense = dev.Read(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsRead = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectorschs", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in CHS mode..."); + sense = dev.Read(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadRetry = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectorsretrychs", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ DMA in CHS mode..."); + sense = dev.ReadDma(out readBuf, out errorChs, false, 0, 0, 1, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadDma = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdmachs", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ DMA RETRY in CHS mode..."); + sense = dev.ReadDma(out readBuf, out errorChs, true, 0, 0, 1, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadDmaRetry = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdmaretrychs", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying SEEK in CHS mode..."); + sense = dev.Seek(out errorChs, 0, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsSeek = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0; + DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, + errorChs.status, errorChs.error); + + DicConsole.WriteLine("Trying READ SECTOR(S) in LBA mode..."); + sense = dev.Read(out readBuf, out errorLba, false, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba.status, errorLba.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectors", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ SECTOR(S) RETRY in LBA mode..."); + sense = dev.Read(out readBuf, out errorLba, true, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadRetryLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba.status, errorLba.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectorsretry", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ DMA in LBA mode..."); + sense = dev.ReadDma(out readBuf, out errorLba, false, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadDmaLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba.status, errorLba.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdma", "_debug_" + report.ATA.Model + ".bin", "read results", + readBuf); + + DicConsole.WriteLine("Trying READ DMA RETRY in LBA mode..."); + sense = dev.ReadDma(out readBuf, out errorLba, true, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadDmaRetryLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba.status, errorLba.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdmaretry", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying SEEK in LBA mode..."); + sense = dev.Seek(out errorLba, 0, timeout, out duration); + report.ATA.ReadCapabilities.SupportsSeekLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0; + DicConsole.DebugWriteLine("ATA Report", "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}", sense, + errorLba.status, errorLba.error); + + DicConsole.WriteLine("Trying READ SECTOR(S) in LBA48 mode..."); + sense = dev.Read(out readBuf, out errorLba48, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadLba48 = + !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba48.status, errorLba48.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readsectors48", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ DMA in LBA48 mode..."); + sense = dev.ReadDma(out readBuf, out errorLba48, 0, 1, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadDmaLba48 = + !sense && (errorLba48.status & 0x01) != 0x01 && errorLba48.error == 0 && readBuf.Length > 0; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba48.status, errorLba48.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readdma48", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ LONG in CHS mode..."); + sense = dev.ReadLong(out readBuf, out errorChs, false, 0, 0, 1, + report.ATA.ReadCapabilities.LongBlockSize, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadLong = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0 && + BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlongchs", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ LONG RETRY in CHS mode..."); + sense = dev.ReadLong(out readBuf, out errorChs, true, 0, 0, 1, + report.ATA.ReadCapabilities.LongBlockSize, timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadLongRetry = + !sense && (errorChs.status & 0x01) != 0x01 && errorChs.error == 0 && readBuf.Length > 0 && + BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorChs.status, errorChs.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlongretrychs", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ LONG in LBA mode..."); + sense = dev.ReadLong(out readBuf, out errorLba, false, 0, report.ATA.ReadCapabilities.LongBlockSize, + timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadLongLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0 && + BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba.status, errorLba.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlong", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); + + DicConsole.WriteLine("Trying READ LONG RETRY in LBA mode..."); + sense = dev.ReadLong(out readBuf, out errorLba, true, 0, report.ATA.ReadCapabilities.LongBlockSize, + timeout, out duration); + report.ATA.ReadCapabilities.SupportsReadLongRetryLba = + !sense && (errorLba.status & 0x01) != 0x01 && errorLba.error == 0 && readBuf.Length > 0 && + BitConverter.ToUInt64(readBuf, 0) != checkCorrectRead; + DicConsole.DebugWriteLine("ATA Report", + "Sense = {0}, Status = 0x{1:X2}, Error = 0x{2:X2}, Length = {3}", sense, + errorLba.status, errorLba.error, readBuf.Length); + if(debug) + DataFile.WriteTo("ATA Report", "readlongretry", "_debug_" + report.ATA.Model + ".bin", + "read results", readBuf); } } } diff --git a/DiscImageChef.Core/Devices/Report/ATAPI.cs b/DiscImageChef.Core/Devices/Report/ATAPI.cs index bacad152f..8f1df5828 100644 --- a/DiscImageChef.Core/Devices/Report/ATAPI.cs +++ b/DiscImageChef.Core/Devices/Report/ATAPI.cs @@ -51,409 +51,408 @@ namespace DiscImageChef.Core.Devices.Report Decoders.ATA.AtaErrorRegistersCHS errorRegs; dev.AtapiIdentify(out buffer, out errorRegs, timeout, out duration); - if(Decoders.ATA.Identify.Decode(buffer).HasValue) + if(!Decoders.ATA.Identify.Decode(buffer).HasValue) return; + + Decoders.ATA.Identify.IdentifyDevice atapiId = Decoders.ATA.Identify.Decode(buffer).Value; + + report.ATAPI = new ataType(); + + if(!string.IsNullOrWhiteSpace(atapiId.AdditionalPID)) { - Decoders.ATA.Identify.IdentifyDevice atapiId = Decoders.ATA.Identify.Decode(buffer).Value; - - report.ATAPI = new ataType(); - - if(!string.IsNullOrWhiteSpace(atapiId.AdditionalPID)) - { - report.ATAPI.AdditionalPID = atapiId.AdditionalPID; - report.ATAPI.AdditionalPIDSpecified = true; - } - if(atapiId.APIOSupported != 0) - { - report.ATAPI.APIOSupported = atapiId.APIOSupported; - report.ATAPI.APIOSupportedSpecified = true; - } - if(atapiId.ATAPIByteCount != 0) - { - report.ATAPI.ATAPIByteCount = atapiId.ATAPIByteCount; - report.ATAPI.ATAPIByteCountSpecified = true; - } - if(atapiId.BufferType != 0) - { - report.ATAPI.BufferType = atapiId.BufferType; - report.ATAPI.BufferTypeSpecified = true; - } - if(atapiId.BufferSize != 0) - { - report.ATAPI.BufferSize = atapiId.BufferSize; - report.ATAPI.BufferSizeSpecified = true; - } - if(atapiId.Capabilities != 0) - { - report.ATAPI.Capabilities = atapiId.Capabilities; - report.ATAPI.CapabilitiesSpecified = true; - } - if(atapiId.Capabilities2 != 0) - { - report.ATAPI.Capabilities2 = atapiId.Capabilities2; - report.ATAPI.Capabilities2Specified = true; - } - if(atapiId.Capabilities3 != 0) - { - report.ATAPI.Capabilities3 = atapiId.Capabilities3; - report.ATAPI.Capabilities3Specified = true; - } - if(atapiId.CFAPowerMode != 0) - { - report.ATAPI.CFAPowerMode = atapiId.CFAPowerMode; - report.ATAPI.CFAPowerModeSpecified = true; - } - if(atapiId.CommandSet != 0) - { - report.ATAPI.CommandSet = atapiId.CommandSet; - report.ATAPI.CommandSetSpecified = true; - } - if(atapiId.CommandSet2 != 0) - { - report.ATAPI.CommandSet2 = atapiId.CommandSet2; - report.ATAPI.CommandSet2Specified = true; - } - if(atapiId.CommandSet3 != 0) - { - report.ATAPI.CommandSet3 = atapiId.CommandSet3; - report.ATAPI.CommandSet3Specified = true; - } - if(atapiId.CommandSet4 != 0) - { - report.ATAPI.CommandSet4 = atapiId.CommandSet4; - report.ATAPI.CommandSet4Specified = true; - } - if(atapiId.CommandSet5 != 0) - { - report.ATAPI.CommandSet5 = atapiId.CommandSet5; - report.ATAPI.CommandSet5Specified = true; - } - if(atapiId.CurrentAAM != 0) - { - report.ATAPI.CurrentAAM = atapiId.CurrentAAM; - report.ATAPI.CurrentAAMSpecified = true; - } - if(atapiId.CurrentAPM != 0) - { - report.ATAPI.CurrentAPM = atapiId.CurrentAPM; - report.ATAPI.CurrentAPMSpecified = true; - } - if(atapiId.DataSetMgmt != 0) - { - report.ATAPI.DataSetMgmt = atapiId.DataSetMgmt; - report.ATAPI.DataSetMgmtSpecified = true; - } - if(atapiId.DataSetMgmtSize != 0) - { - report.ATAPI.DataSetMgmtSize = atapiId.DataSetMgmtSize; - report.ATAPI.DataSetMgmtSizeSpecified = true; - } - if(atapiId.DeviceFormFactor != 0) - { - report.ATAPI.DeviceFormFactor = atapiId.DeviceFormFactor; - report.ATAPI.DeviceFormFactorSpecified = true; - } - if(atapiId.DMAActive != 0) - { - report.ATAPI.DMAActive = atapiId.DMAActive; - report.ATAPI.DMAActiveSpecified = true; - } - if(atapiId.DMASupported != 0) - { - report.ATAPI.DMASupported = atapiId.DMASupported; - report.ATAPI.DMASupportedSpecified = true; - } - if(atapiId.DMATransferTimingMode != 0) - { - report.ATAPI.DMATransferTimingMode = atapiId.DMATransferTimingMode; - report.ATAPI.DMATransferTimingModeSpecified = true; - } - if(atapiId.EnhancedSecurityEraseTime != 0) - { - report.ATAPI.EnhancedSecurityEraseTime = atapiId.EnhancedSecurityEraseTime; - report.ATAPI.EnhancedSecurityEraseTimeSpecified = true; - } - if(atapiId.EnabledCommandSet != 0) - { - report.ATAPI.EnabledCommandSet = atapiId.EnabledCommandSet; - report.ATAPI.EnabledCommandSetSpecified = true; - } - if(atapiId.EnabledCommandSet2 != 0) - { - report.ATAPI.EnabledCommandSet2 = atapiId.EnabledCommandSet2; - report.ATAPI.EnabledCommandSet2Specified = true; - } - if(atapiId.EnabledCommandSet3 != 0) - { - report.ATAPI.EnabledCommandSet3 = atapiId.EnabledCommandSet3; - report.ATAPI.EnabledCommandSet3Specified = true; - } - if(atapiId.EnabledCommandSet4 != 0) - { - report.ATAPI.EnabledCommandSet4 = atapiId.EnabledCommandSet4; - report.ATAPI.EnabledCommandSet4Specified = true; - } - if(atapiId.EnabledSATAFeatures != 0) - { - report.ATAPI.EnabledSATAFeatures = atapiId.EnabledSATAFeatures; - report.ATAPI.EnabledSATAFeaturesSpecified = true; - } - if(atapiId.ExtendedUserSectors != 0) - { - report.ATAPI.ExtendedUserSectors = atapiId.ExtendedUserSectors; - report.ATAPI.ExtendedUserSectorsSpecified = true; - } - if(atapiId.FreeFallSensitivity != 0) - { - report.ATAPI.FreeFallSensitivity = atapiId.FreeFallSensitivity; - report.ATAPI.FreeFallSensitivitySpecified = true; - } - if(!string.IsNullOrWhiteSpace(atapiId.FirmwareRevision)) - { - report.ATAPI.FirmwareRevision = atapiId.FirmwareRevision; - report.ATAPI.FirmwareRevisionSpecified = true; - } - if(atapiId.GeneralConfiguration != 0) - { - report.ATAPI.GeneralConfiguration = atapiId.GeneralConfiguration; - report.ATAPI.GeneralConfigurationSpecified = true; - } - if(atapiId.HardwareResetResult != 0) - { - report.ATAPI.HardwareResetResult = atapiId.HardwareResetResult; - report.ATAPI.HardwareResetResultSpecified = true; - } - if(atapiId.InterseekDelay != 0) - { - report.ATAPI.InterseekDelay = atapiId.InterseekDelay; - report.ATAPI.InterseekDelaySpecified = true; - } - if(atapiId.MajorVersion != 0) - { - report.ATAPI.MajorVersion = atapiId.MajorVersion; - report.ATAPI.MajorVersionSpecified = true; - } - if(atapiId.MasterPasswordRevisionCode != 0) - { - report.ATAPI.MasterPasswordRevisionCode = atapiId.MasterPasswordRevisionCode; - report.ATAPI.MasterPasswordRevisionCodeSpecified = true; - } - if(atapiId.MaxDownloadMicroMode3 != 0) - { - report.ATAPI.MaxDownloadMicroMode3 = atapiId.MaxDownloadMicroMode3; - report.ATAPI.MaxDownloadMicroMode3Specified = true; - } - if(atapiId.MaxQueueDepth != 0) - { - report.ATAPI.MaxQueueDepth = atapiId.MaxQueueDepth; - report.ATAPI.MaxQueueDepthSpecified = true; - } - if(atapiId.MDMAActive != 0) - { - report.ATAPI.MDMAActive = atapiId.MDMAActive; - report.ATAPI.MDMAActiveSpecified = true; - } - if(atapiId.MDMASupported != 0) - { - report.ATAPI.MDMASupported = atapiId.MDMASupported; - report.ATAPI.MDMASupportedSpecified = true; - } - if(atapiId.MinDownloadMicroMode3 != 0) - { - report.ATAPI.MinDownloadMicroMode3 = atapiId.MinDownloadMicroMode3; - report.ATAPI.MinDownloadMicroMode3Specified = true; - } - if(atapiId.MinMDMACycleTime != 0) - { - report.ATAPI.MinMDMACycleTime = atapiId.MinMDMACycleTime; - report.ATAPI.MinMDMACycleTimeSpecified = true; - } - if(atapiId.MinorVersion != 0) - { - report.ATAPI.MinorVersion = atapiId.MinorVersion; - report.ATAPI.MinorVersionSpecified = true; - } - if(atapiId.MinPIOCycleTimeNoFlow != 0) - { - report.ATAPI.MinPIOCycleTimeNoFlow = atapiId.MinPIOCycleTimeNoFlow; - report.ATAPI.MinPIOCycleTimeNoFlowSpecified = true; - } - if(atapiId.MinPIOCycleTimeFlow != 0) - { - report.ATAPI.MinPIOCycleTimeFlow = atapiId.MinPIOCycleTimeFlow; - report.ATAPI.MinPIOCycleTimeFlowSpecified = true; - } - if(!string.IsNullOrWhiteSpace(atapiId.Model)) - { - report.ATAPI.Model = atapiId.Model; - report.ATAPI.ModelSpecified = true; - } - if(atapiId.MultipleMaxSectors != 0) - { - report.ATAPI.MultipleMaxSectors = atapiId.MultipleMaxSectors; - report.ATAPI.MultipleMaxSectorsSpecified = true; - } - if(atapiId.MultipleSectorNumber != 0) - { - report.ATAPI.MultipleSectorNumber = atapiId.MultipleSectorNumber; - report.ATAPI.MultipleSectorNumberSpecified = true; - } - if(atapiId.NVCacheCaps != 0) - { - report.ATAPI.NVCacheCaps = atapiId.NVCacheCaps; - report.ATAPI.NVCacheCapsSpecified = true; - } - if(atapiId.NVCacheSize != 0) - { - report.ATAPI.NVCacheSize = atapiId.NVCacheSize; - report.ATAPI.NVCacheSizeSpecified = true; - } - if(atapiId.NVCacheWriteSpeed != 0) - { - report.ATAPI.NVCacheWriteSpeed = atapiId.NVCacheWriteSpeed; - report.ATAPI.NVCacheWriteSpeedSpecified = true; - } - if(atapiId.NVEstimatedSpinUp != 0) - { - report.ATAPI.NVEstimatedSpinUp = atapiId.NVEstimatedSpinUp; - report.ATAPI.NVEstimatedSpinUpSpecified = true; - } - if(atapiId.PacketBusRelease != 0) - { - report.ATAPI.PacketBusRelease = atapiId.PacketBusRelease; - report.ATAPI.PacketBusReleaseSpecified = true; - } - if(atapiId.PIOTransferTimingMode != 0) - { - report.ATAPI.PIOTransferTimingMode = atapiId.PIOTransferTimingMode; - report.ATAPI.PIOTransferTimingModeSpecified = true; - } - if(atapiId.RecommendedAAM != 0) - { - report.ATAPI.RecommendedAAM = atapiId.RecommendedAAM; - report.ATAPI.RecommendedAAMSpecified = true; - } - if(atapiId.RecMDMACycleTime != 0) - { - report.ATAPI.RecommendedMDMACycleTime = atapiId.RecMDMACycleTime; - report.ATAPI.RecommendedMDMACycleTimeSpecified = true; - } - if(atapiId.RemovableStatusSet != 0) - { - report.ATAPI.RemovableStatusSet = atapiId.RemovableStatusSet; - report.ATAPI.RemovableStatusSetSpecified = true; - } - if(atapiId.SATACapabilities != 0) - { - report.ATAPI.SATACapabilities = atapiId.SATACapabilities; - report.ATAPI.SATACapabilitiesSpecified = true; - } - if(atapiId.SATACapabilities2 != 0) - { - report.ATAPI.SATACapabilities2 = atapiId.SATACapabilities2; - report.ATAPI.SATACapabilities2Specified = true; - } - if(atapiId.SATAFeatures != 0) - { - report.ATAPI.SATAFeatures = atapiId.SATAFeatures; - report.ATAPI.SATAFeaturesSpecified = true; - } - if(atapiId.SCTCommandTransport != 0) - { - report.ATAPI.SCTCommandTransport = atapiId.SCTCommandTransport; - report.ATAPI.SCTCommandTransportSpecified = true; - } - if(atapiId.SectorsPerCard != 0) - { - report.ATAPI.SectorsPerCard = atapiId.SectorsPerCard; - report.ATAPI.SectorsPerCardSpecified = true; - } - if(atapiId.SecurityEraseTime != 0) - { - report.ATAPI.SecurityEraseTime = atapiId.SecurityEraseTime; - report.ATAPI.SecurityEraseTimeSpecified = true; - } - if(atapiId.SecurityStatus != 0) - { - report.ATAPI.SecurityStatus = atapiId.SecurityStatus; - report.ATAPI.SecurityStatusSpecified = true; - } - if(atapiId.ServiceBusyClear != 0) - { - report.ATAPI.ServiceBusyClear = atapiId.ServiceBusyClear; - report.ATAPI.ServiceBusyClearSpecified = true; - } - if(atapiId.SpecificConfiguration != 0) - { - report.ATAPI.SpecificConfiguration = atapiId.SpecificConfiguration; - report.ATAPI.SpecificConfigurationSpecified = true; - } - if(atapiId.StreamAccessLatency != 0) - { - report.ATAPI.StreamAccessLatency = atapiId.StreamAccessLatency; - report.ATAPI.StreamAccessLatencySpecified = true; - } - if(atapiId.StreamMinReqSize != 0) - { - report.ATAPI.StreamMinReqSize = atapiId.StreamMinReqSize; - report.ATAPI.StreamMinReqSizeSpecified = true; - } - if(atapiId.StreamPerformanceGranularity != 0) - { - report.ATAPI.StreamPerformanceGranularity = atapiId.StreamPerformanceGranularity; - report.ATAPI.StreamPerformanceGranularitySpecified = true; - } - if(atapiId.StreamTransferTimeDMA != 0) - { - report.ATAPI.StreamTransferTimeDMA = atapiId.StreamTransferTimeDMA; - report.ATAPI.StreamTransferTimeDMASpecified = true; - } - if(atapiId.StreamTransferTimePIO != 0) - { - report.ATAPI.StreamTransferTimePIO = atapiId.StreamTransferTimePIO; - report.ATAPI.StreamTransferTimePIOSpecified = true; - } - if(atapiId.TransportMajorVersion != 0) - { - report.ATAPI.TransportMajorVersion = atapiId.TransportMajorVersion; - report.ATAPI.TransportMajorVersionSpecified = true; - } - if(atapiId.TransportMinorVersion != 0) - { - report.ATAPI.TransportMinorVersion = atapiId.TransportMinorVersion; - report.ATAPI.TransportMinorVersionSpecified = true; - } - if(atapiId.TrustedComputing != 0) - { - report.ATAPI.TrustedComputing = atapiId.TrustedComputing; - report.ATAPI.TrustedComputingSpecified = true; - } - if(atapiId.UDMAActive != 0) - { - report.ATAPI.UDMAActive = atapiId.UDMAActive; - report.ATAPI.UDMAActiveSpecified = true; - } - if(atapiId.UDMASupported != 0) - { - report.ATAPI.UDMASupported = atapiId.UDMASupported; - report.ATAPI.UDMASupportedSpecified = true; - } - if(atapiId.WRVMode != 0) - { - report.ATAPI.WRVMode = atapiId.WRVMode; - report.ATAPI.WRVModeSpecified = true; - } - if(atapiId.WRVSectorCountMode3 != 0) - { - report.ATAPI.WRVSectorCountMode3 = atapiId.WRVSectorCountMode3; - report.ATAPI.WRVSectorCountMode3Specified = true; - } - if(atapiId.WRVSectorCountMode2 != 0) - { - report.ATAPI.WRVSectorCountMode2 = atapiId.WRVSectorCountMode2; - report.ATAPI.WRVSectorCountMode2Specified = true; - } - if(debug) report.ATAPI.Identify = buffer; + report.ATAPI.AdditionalPID = atapiId.AdditionalPID; + report.ATAPI.AdditionalPIDSpecified = true; } + if(atapiId.APIOSupported != 0) + { + report.ATAPI.APIOSupported = atapiId.APIOSupported; + report.ATAPI.APIOSupportedSpecified = true; + } + if(atapiId.ATAPIByteCount != 0) + { + report.ATAPI.ATAPIByteCount = atapiId.ATAPIByteCount; + report.ATAPI.ATAPIByteCountSpecified = true; + } + if(atapiId.BufferType != 0) + { + report.ATAPI.BufferType = atapiId.BufferType; + report.ATAPI.BufferTypeSpecified = true; + } + if(atapiId.BufferSize != 0) + { + report.ATAPI.BufferSize = atapiId.BufferSize; + report.ATAPI.BufferSizeSpecified = true; + } + if(atapiId.Capabilities != 0) + { + report.ATAPI.Capabilities = atapiId.Capabilities; + report.ATAPI.CapabilitiesSpecified = true; + } + if(atapiId.Capabilities2 != 0) + { + report.ATAPI.Capabilities2 = atapiId.Capabilities2; + report.ATAPI.Capabilities2Specified = true; + } + if(atapiId.Capabilities3 != 0) + { + report.ATAPI.Capabilities3 = atapiId.Capabilities3; + report.ATAPI.Capabilities3Specified = true; + } + if(atapiId.CFAPowerMode != 0) + { + report.ATAPI.CFAPowerMode = atapiId.CFAPowerMode; + report.ATAPI.CFAPowerModeSpecified = true; + } + if(atapiId.CommandSet != 0) + { + report.ATAPI.CommandSet = atapiId.CommandSet; + report.ATAPI.CommandSetSpecified = true; + } + if(atapiId.CommandSet2 != 0) + { + report.ATAPI.CommandSet2 = atapiId.CommandSet2; + report.ATAPI.CommandSet2Specified = true; + } + if(atapiId.CommandSet3 != 0) + { + report.ATAPI.CommandSet3 = atapiId.CommandSet3; + report.ATAPI.CommandSet3Specified = true; + } + if(atapiId.CommandSet4 != 0) + { + report.ATAPI.CommandSet4 = atapiId.CommandSet4; + report.ATAPI.CommandSet4Specified = true; + } + if(atapiId.CommandSet5 != 0) + { + report.ATAPI.CommandSet5 = atapiId.CommandSet5; + report.ATAPI.CommandSet5Specified = true; + } + if(atapiId.CurrentAAM != 0) + { + report.ATAPI.CurrentAAM = atapiId.CurrentAAM; + report.ATAPI.CurrentAAMSpecified = true; + } + if(atapiId.CurrentAPM != 0) + { + report.ATAPI.CurrentAPM = atapiId.CurrentAPM; + report.ATAPI.CurrentAPMSpecified = true; + } + if(atapiId.DataSetMgmt != 0) + { + report.ATAPI.DataSetMgmt = atapiId.DataSetMgmt; + report.ATAPI.DataSetMgmtSpecified = true; + } + if(atapiId.DataSetMgmtSize != 0) + { + report.ATAPI.DataSetMgmtSize = atapiId.DataSetMgmtSize; + report.ATAPI.DataSetMgmtSizeSpecified = true; + } + if(atapiId.DeviceFormFactor != 0) + { + report.ATAPI.DeviceFormFactor = atapiId.DeviceFormFactor; + report.ATAPI.DeviceFormFactorSpecified = true; + } + if(atapiId.DMAActive != 0) + { + report.ATAPI.DMAActive = atapiId.DMAActive; + report.ATAPI.DMAActiveSpecified = true; + } + if(atapiId.DMASupported != 0) + { + report.ATAPI.DMASupported = atapiId.DMASupported; + report.ATAPI.DMASupportedSpecified = true; + } + if(atapiId.DMATransferTimingMode != 0) + { + report.ATAPI.DMATransferTimingMode = atapiId.DMATransferTimingMode; + report.ATAPI.DMATransferTimingModeSpecified = true; + } + if(atapiId.EnhancedSecurityEraseTime != 0) + { + report.ATAPI.EnhancedSecurityEraseTime = atapiId.EnhancedSecurityEraseTime; + report.ATAPI.EnhancedSecurityEraseTimeSpecified = true; + } + if(atapiId.EnabledCommandSet != 0) + { + report.ATAPI.EnabledCommandSet = atapiId.EnabledCommandSet; + report.ATAPI.EnabledCommandSetSpecified = true; + } + if(atapiId.EnabledCommandSet2 != 0) + { + report.ATAPI.EnabledCommandSet2 = atapiId.EnabledCommandSet2; + report.ATAPI.EnabledCommandSet2Specified = true; + } + if(atapiId.EnabledCommandSet3 != 0) + { + report.ATAPI.EnabledCommandSet3 = atapiId.EnabledCommandSet3; + report.ATAPI.EnabledCommandSet3Specified = true; + } + if(atapiId.EnabledCommandSet4 != 0) + { + report.ATAPI.EnabledCommandSet4 = atapiId.EnabledCommandSet4; + report.ATAPI.EnabledCommandSet4Specified = true; + } + if(atapiId.EnabledSATAFeatures != 0) + { + report.ATAPI.EnabledSATAFeatures = atapiId.EnabledSATAFeatures; + report.ATAPI.EnabledSATAFeaturesSpecified = true; + } + if(atapiId.ExtendedUserSectors != 0) + { + report.ATAPI.ExtendedUserSectors = atapiId.ExtendedUserSectors; + report.ATAPI.ExtendedUserSectorsSpecified = true; + } + if(atapiId.FreeFallSensitivity != 0) + { + report.ATAPI.FreeFallSensitivity = atapiId.FreeFallSensitivity; + report.ATAPI.FreeFallSensitivitySpecified = true; + } + if(!string.IsNullOrWhiteSpace(atapiId.FirmwareRevision)) + { + report.ATAPI.FirmwareRevision = atapiId.FirmwareRevision; + report.ATAPI.FirmwareRevisionSpecified = true; + } + if(atapiId.GeneralConfiguration != 0) + { + report.ATAPI.GeneralConfiguration = atapiId.GeneralConfiguration; + report.ATAPI.GeneralConfigurationSpecified = true; + } + if(atapiId.HardwareResetResult != 0) + { + report.ATAPI.HardwareResetResult = atapiId.HardwareResetResult; + report.ATAPI.HardwareResetResultSpecified = true; + } + if(atapiId.InterseekDelay != 0) + { + report.ATAPI.InterseekDelay = atapiId.InterseekDelay; + report.ATAPI.InterseekDelaySpecified = true; + } + if(atapiId.MajorVersion != 0) + { + report.ATAPI.MajorVersion = atapiId.MajorVersion; + report.ATAPI.MajorVersionSpecified = true; + } + if(atapiId.MasterPasswordRevisionCode != 0) + { + report.ATAPI.MasterPasswordRevisionCode = atapiId.MasterPasswordRevisionCode; + report.ATAPI.MasterPasswordRevisionCodeSpecified = true; + } + if(atapiId.MaxDownloadMicroMode3 != 0) + { + report.ATAPI.MaxDownloadMicroMode3 = atapiId.MaxDownloadMicroMode3; + report.ATAPI.MaxDownloadMicroMode3Specified = true; + } + if(atapiId.MaxQueueDepth != 0) + { + report.ATAPI.MaxQueueDepth = atapiId.MaxQueueDepth; + report.ATAPI.MaxQueueDepthSpecified = true; + } + if(atapiId.MDMAActive != 0) + { + report.ATAPI.MDMAActive = atapiId.MDMAActive; + report.ATAPI.MDMAActiveSpecified = true; + } + if(atapiId.MDMASupported != 0) + { + report.ATAPI.MDMASupported = atapiId.MDMASupported; + report.ATAPI.MDMASupportedSpecified = true; + } + if(atapiId.MinDownloadMicroMode3 != 0) + { + report.ATAPI.MinDownloadMicroMode3 = atapiId.MinDownloadMicroMode3; + report.ATAPI.MinDownloadMicroMode3Specified = true; + } + if(atapiId.MinMDMACycleTime != 0) + { + report.ATAPI.MinMDMACycleTime = atapiId.MinMDMACycleTime; + report.ATAPI.MinMDMACycleTimeSpecified = true; + } + if(atapiId.MinorVersion != 0) + { + report.ATAPI.MinorVersion = atapiId.MinorVersion; + report.ATAPI.MinorVersionSpecified = true; + } + if(atapiId.MinPIOCycleTimeNoFlow != 0) + { + report.ATAPI.MinPIOCycleTimeNoFlow = atapiId.MinPIOCycleTimeNoFlow; + report.ATAPI.MinPIOCycleTimeNoFlowSpecified = true; + } + if(atapiId.MinPIOCycleTimeFlow != 0) + { + report.ATAPI.MinPIOCycleTimeFlow = atapiId.MinPIOCycleTimeFlow; + report.ATAPI.MinPIOCycleTimeFlowSpecified = true; + } + if(!string.IsNullOrWhiteSpace(atapiId.Model)) + { + report.ATAPI.Model = atapiId.Model; + report.ATAPI.ModelSpecified = true; + } + if(atapiId.MultipleMaxSectors != 0) + { + report.ATAPI.MultipleMaxSectors = atapiId.MultipleMaxSectors; + report.ATAPI.MultipleMaxSectorsSpecified = true; + } + if(atapiId.MultipleSectorNumber != 0) + { + report.ATAPI.MultipleSectorNumber = atapiId.MultipleSectorNumber; + report.ATAPI.MultipleSectorNumberSpecified = true; + } + if(atapiId.NVCacheCaps != 0) + { + report.ATAPI.NVCacheCaps = atapiId.NVCacheCaps; + report.ATAPI.NVCacheCapsSpecified = true; + } + if(atapiId.NVCacheSize != 0) + { + report.ATAPI.NVCacheSize = atapiId.NVCacheSize; + report.ATAPI.NVCacheSizeSpecified = true; + } + if(atapiId.NVCacheWriteSpeed != 0) + { + report.ATAPI.NVCacheWriteSpeed = atapiId.NVCacheWriteSpeed; + report.ATAPI.NVCacheWriteSpeedSpecified = true; + } + if(atapiId.NVEstimatedSpinUp != 0) + { + report.ATAPI.NVEstimatedSpinUp = atapiId.NVEstimatedSpinUp; + report.ATAPI.NVEstimatedSpinUpSpecified = true; + } + if(atapiId.PacketBusRelease != 0) + { + report.ATAPI.PacketBusRelease = atapiId.PacketBusRelease; + report.ATAPI.PacketBusReleaseSpecified = true; + } + if(atapiId.PIOTransferTimingMode != 0) + { + report.ATAPI.PIOTransferTimingMode = atapiId.PIOTransferTimingMode; + report.ATAPI.PIOTransferTimingModeSpecified = true; + } + if(atapiId.RecommendedAAM != 0) + { + report.ATAPI.RecommendedAAM = atapiId.RecommendedAAM; + report.ATAPI.RecommendedAAMSpecified = true; + } + if(atapiId.RecMDMACycleTime != 0) + { + report.ATAPI.RecommendedMDMACycleTime = atapiId.RecMDMACycleTime; + report.ATAPI.RecommendedMDMACycleTimeSpecified = true; + } + if(atapiId.RemovableStatusSet != 0) + { + report.ATAPI.RemovableStatusSet = atapiId.RemovableStatusSet; + report.ATAPI.RemovableStatusSetSpecified = true; + } + if(atapiId.SATACapabilities != 0) + { + report.ATAPI.SATACapabilities = atapiId.SATACapabilities; + report.ATAPI.SATACapabilitiesSpecified = true; + } + if(atapiId.SATACapabilities2 != 0) + { + report.ATAPI.SATACapabilities2 = atapiId.SATACapabilities2; + report.ATAPI.SATACapabilities2Specified = true; + } + if(atapiId.SATAFeatures != 0) + { + report.ATAPI.SATAFeatures = atapiId.SATAFeatures; + report.ATAPI.SATAFeaturesSpecified = true; + } + if(atapiId.SCTCommandTransport != 0) + { + report.ATAPI.SCTCommandTransport = atapiId.SCTCommandTransport; + report.ATAPI.SCTCommandTransportSpecified = true; + } + if(atapiId.SectorsPerCard != 0) + { + report.ATAPI.SectorsPerCard = atapiId.SectorsPerCard; + report.ATAPI.SectorsPerCardSpecified = true; + } + if(atapiId.SecurityEraseTime != 0) + { + report.ATAPI.SecurityEraseTime = atapiId.SecurityEraseTime; + report.ATAPI.SecurityEraseTimeSpecified = true; + } + if(atapiId.SecurityStatus != 0) + { + report.ATAPI.SecurityStatus = atapiId.SecurityStatus; + report.ATAPI.SecurityStatusSpecified = true; + } + if(atapiId.ServiceBusyClear != 0) + { + report.ATAPI.ServiceBusyClear = atapiId.ServiceBusyClear; + report.ATAPI.ServiceBusyClearSpecified = true; + } + if(atapiId.SpecificConfiguration != 0) + { + report.ATAPI.SpecificConfiguration = atapiId.SpecificConfiguration; + report.ATAPI.SpecificConfigurationSpecified = true; + } + if(atapiId.StreamAccessLatency != 0) + { + report.ATAPI.StreamAccessLatency = atapiId.StreamAccessLatency; + report.ATAPI.StreamAccessLatencySpecified = true; + } + if(atapiId.StreamMinReqSize != 0) + { + report.ATAPI.StreamMinReqSize = atapiId.StreamMinReqSize; + report.ATAPI.StreamMinReqSizeSpecified = true; + } + if(atapiId.StreamPerformanceGranularity != 0) + { + report.ATAPI.StreamPerformanceGranularity = atapiId.StreamPerformanceGranularity; + report.ATAPI.StreamPerformanceGranularitySpecified = true; + } + if(atapiId.StreamTransferTimeDMA != 0) + { + report.ATAPI.StreamTransferTimeDMA = atapiId.StreamTransferTimeDMA; + report.ATAPI.StreamTransferTimeDMASpecified = true; + } + if(atapiId.StreamTransferTimePIO != 0) + { + report.ATAPI.StreamTransferTimePIO = atapiId.StreamTransferTimePIO; + report.ATAPI.StreamTransferTimePIOSpecified = true; + } + if(atapiId.TransportMajorVersion != 0) + { + report.ATAPI.TransportMajorVersion = atapiId.TransportMajorVersion; + report.ATAPI.TransportMajorVersionSpecified = true; + } + if(atapiId.TransportMinorVersion != 0) + { + report.ATAPI.TransportMinorVersion = atapiId.TransportMinorVersion; + report.ATAPI.TransportMinorVersionSpecified = true; + } + if(atapiId.TrustedComputing != 0) + { + report.ATAPI.TrustedComputing = atapiId.TrustedComputing; + report.ATAPI.TrustedComputingSpecified = true; + } + if(atapiId.UDMAActive != 0) + { + report.ATAPI.UDMAActive = atapiId.UDMAActive; + report.ATAPI.UDMAActiveSpecified = true; + } + if(atapiId.UDMASupported != 0) + { + report.ATAPI.UDMASupported = atapiId.UDMASupported; + report.ATAPI.UDMASupportedSpecified = true; + } + if(atapiId.WRVMode != 0) + { + report.ATAPI.WRVMode = atapiId.WRVMode; + report.ATAPI.WRVModeSpecified = true; + } + if(atapiId.WRVSectorCountMode3 != 0) + { + report.ATAPI.WRVSectorCountMode3 = atapiId.WRVSectorCountMode3; + report.ATAPI.WRVSectorCountMode3Specified = true; + } + if(atapiId.WRVSectorCountMode2 != 0) + { + report.ATAPI.WRVSectorCountMode2 = atapiId.WRVSectorCountMode2; + report.ATAPI.WRVSectorCountMode2Specified = true; + } + if(debug) report.ATAPI.Identify = buffer; } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Report/FireWire.cs b/DiscImageChef.Core/Devices/Report/FireWire.cs index 468c048fe..3c5347b09 100644 --- a/DiscImageChef.Core/Devices/Report/FireWire.cs +++ b/DiscImageChef.Core/Devices/Report/FireWire.cs @@ -51,25 +51,24 @@ namespace DiscImageChef.Core.Devices.Report DicConsole.WriteLine(); } - if(pressedKey.Key == ConsoleKey.Y) + if(pressedKey.Key != ConsoleKey.Y) return; + + report.FireWire = new firewireType(); + report.FireWire.Manufacturer = dev.FireWireVendorName; + report.FireWire.Product = dev.FireWireModelName; + report.FireWire.ProductID = dev.FireWireModel; + report.FireWire.VendorID = dev.FireWireVendor; + + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) { - report.FireWire = new firewireType(); - report.FireWire.Manufacturer = dev.FireWireVendorName; - report.FireWire.Product = dev.FireWireModelName; - report.FireWire.ProductID = dev.FireWireModel; - report.FireWire.VendorID = dev.FireWireVendor; - - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) - { - DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): "); - pressedKey = System.Console.ReadKey(); - DicConsole.WriteLine(); - } - - report.FireWire.RemovableMedia = pressedKey.Key == ConsoleKey.Y; - removable = report.FireWire.RemovableMedia; + DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); } + + report.FireWire.RemovableMedia = pressedKey.Key == ConsoleKey.Y; + removable = report.FireWire.RemovableMedia; } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Report/PCMCIA.cs b/DiscImageChef.Core/Devices/Report/PCMCIA.cs index 12c2455dd..cf1b7e0ed 100644 --- a/DiscImageChef.Core/Devices/Report/PCMCIA.cs +++ b/DiscImageChef.Core/Devices/Report/PCMCIA.cs @@ -43,32 +43,33 @@ namespace DiscImageChef.Core.Devices.Report report.PCMCIA = new pcmciaType(); report.PCMCIA.CIS = dev.Cis; Tuple[] tuples = CIS.GetTuples(dev.Cis); - if(tuples != null) - foreach(Tuple tuple in tuples) - switch(tuple.Code) { - case TupleCodes.CISTPL_MANFID: - ManufacturerIdentificationTuple manfid = CIS.DecodeManufacturerIdentificationTuple(tuple); + if(tuples == null) return; - if(manfid != null) - { - report.PCMCIA.ManufacturerCode = manfid.ManufacturerID; - report.PCMCIA.CardCode = manfid.CardID; - report.PCMCIA.ManufacturerCodeSpecified = true; - report.PCMCIA.CardCodeSpecified = true; - } - break; - case TupleCodes.CISTPL_VERS_1: - Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); + foreach(Tuple tuple in tuples) + switch(tuple.Code) { + case TupleCodes.CISTPL_MANFID: + ManufacturerIdentificationTuple manfid = CIS.DecodeManufacturerIdentificationTuple(tuple); - if(vers != null) - { - report.PCMCIA.Manufacturer = vers.Manufacturer; - report.PCMCIA.ProductName = vers.Product; - report.PCMCIA.Compliance = string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); - report.PCMCIA.AdditionalInformation = vers.AdditionalInformation; - } - break; - } + if(manfid != null) + { + report.PCMCIA.ManufacturerCode = manfid.ManufacturerID; + report.PCMCIA.CardCode = manfid.CardID; + report.PCMCIA.ManufacturerCodeSpecified = true; + report.PCMCIA.CardCodeSpecified = true; + } + break; + case TupleCodes.CISTPL_VERS_1: + Level1VersionTuple vers = CIS.DecodeLevel1VersionTuple(tuple); + + if(vers != null) + { + report.PCMCIA.Manufacturer = vers.Manufacturer; + report.PCMCIA.ProductName = vers.Product; + report.PCMCIA.Compliance = string.Format("{0}.{1}", vers.MajorVersion, vers.MinorVersion); + report.PCMCIA.AdditionalInformation = vers.AdditionalInformation; + } + break; + } } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Report/SCSI/General.cs b/DiscImageChef.Core/Devices/Report/SCSI/General.cs index 0a8c9fcd6..db3eeec89 100644 --- a/DiscImageChef.Core/Devices/Report/SCSI/General.cs +++ b/DiscImageChef.Core/Devices/Report/SCSI/General.cs @@ -189,13 +189,12 @@ namespace DiscImageChef.Core.Devices.Report.SCSI { DicConsole.WriteLine("Querying SCSI EVPD {0:X2}h...", page); sense = dev.ScsiInquiry(out buffer, out senseBuffer, page); - if(!sense) - { - pageType evpd = new pageType(); - evpd.page = page; - evpd.value = buffer; - evpds.Add(evpd); - } + if(sense) continue; + + pageType evpd = new pageType(); + evpd.page = page; + evpd.value = buffer; + evpds.Add(evpd); } if(evpds.Count > 0) report.SCSI.EVPDPages = evpds.ToArray(); @@ -330,324 +329,321 @@ namespace DiscImageChef.Core.Devices.Report.SCSI DicConsole.WriteLine(); } - if(pressedKey.Key == ConsoleKey.Y) + if(pressedKey.Key != ConsoleKey.Y) continue; + + DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); + System.Console.ReadKey(true); + + testedMediaType mediaTest = new testedMediaType(); + DicConsole.Write("Please write a description of the media type and press enter: "); + mediaTest.MediumTypeName = System.Console.ReadLine(); + DicConsole.Write("Please write the media manufacturer and press enter: "); + mediaTest.Manufacturer = System.Console.ReadLine(); + DicConsole.Write("Please write the media model and press enter: "); + mediaTest.Model = System.Console.ReadLine(); + + mediaTest.ManufacturerSpecified = true; + mediaTest.ModelSpecified = true; + mediaTest.MediaIsRecognized = true; + + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(sense) { - DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); - System.Console.ReadKey(true); + Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); + if(decSense.HasValue) + if(decSense.Value.ASC == 0x3A) + { + int leftRetries = 20; + while(leftRetries > 0) + { + DicConsole.Write("\rWaiting for drive to become ready"); + System.Threading.Thread.Sleep(2000); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(!sense) break; - testedMediaType mediaTest = new testedMediaType(); - DicConsole.Write("Please write a description of the media type and press enter: "); - mediaTest.MediumTypeName = System.Console.ReadLine(); - DicConsole.Write("Please write the media manufacturer and press enter: "); - mediaTest.Manufacturer = System.Console.ReadLine(); - DicConsole.Write("Please write the media model and press enter: "); - mediaTest.Model = System.Console.ReadLine(); + leftRetries--; + } - mediaTest.ManufacturerSpecified = true; - mediaTest.ModelSpecified = true; - mediaTest.MediaIsRecognized = true; + mediaTest.MediaIsRecognized &= !sense; + } + else if(decSense.Value.ASC == 0x04 && decSense.Value.ASCQ == 0x01) + { + int leftRetries = 20; + while(leftRetries > 0) + { + DicConsole.Write("\rWaiting for drive to become ready"); + System.Threading.Thread.Sleep(2000); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(!sense) break; - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(sense) + leftRetries--; + } + + mediaTest.MediaIsRecognized &= !sense; + } + else mediaTest.MediaIsRecognized = false; + else mediaTest.MediaIsRecognized = false; + } + + if(mediaTest.MediaIsRecognized) + { + mediaTest.SupportsReadCapacitySpecified = true; + mediaTest.SupportsReadCapacity16Specified = true; + + DicConsole.WriteLine("Querying SCSI READ CAPACITY..."); + sense = dev.ReadCapacity(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadCapacity = true; + mediaTest.Blocks = + (ulong)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + + buffer[3]) + 1; + mediaTest.BlockSize = + (uint)((buffer[4] << 24) + (buffer[5] << 16) + (buffer[6] << 8) + buffer[7]); + mediaTest.BlocksSpecified = true; + mediaTest.BlockSizeSpecified = true; + } + + DicConsole.WriteLine("Querying SCSI READ CAPACITY (16)..."); + sense = dev.ReadCapacity16(out buffer, out buffer, timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadCapacity16 = true; + byte[] temp = new byte[8]; + Array.Copy(buffer, 0, temp, 0, 8); + Array.Reverse(temp); + mediaTest.Blocks = BitConverter.ToUInt64(temp, 0) + 1; + mediaTest.BlockSize = + (uint)((buffer[8] << 24) + (buffer[9] << 16) + (buffer[10] << 8) + + buffer[11]); + mediaTest.BlocksSpecified = true; + mediaTest.BlockSizeSpecified = true; + } + + decMode = null; + + DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); + sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, + ScsiModeSensePageControl.Current, 0x3F, 0x00, timeout, + out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense10 = true; + decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); + if(debug) mediaTest.ModeSense10Data = buffer; + } + + DicConsole.WriteLine("Querying SCSI MODE SENSE..."); + sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense6 = true; + if(!decMode.HasValue) + decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); + if(debug) mediaTest.ModeSense6Data = buffer; + } + + if(decMode.HasValue) + { + mediaTest.MediumType = (byte)decMode.Value.Header.MediumType; + mediaTest.MediumTypeSpecified = true; + if(decMode.Value.Header.BlockDescriptors != null && + decMode.Value.Header.BlockDescriptors.Length > 0) + { + mediaTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density; + mediaTest.DensitySpecified = true; + } + } + + mediaTest.SupportsReadSpecified = true; + mediaTest.SupportsRead10Specified = true; + mediaTest.SupportsRead12Specified = true; + mediaTest.SupportsRead16Specified = true; + mediaTest.SupportsReadLongSpecified = true; + + DicConsole.WriteLine("Trying SCSI READ (6)..."); + mediaTest.SupportsRead = !dev.Read6(out buffer, out senseBuffer, 0, mediaTest.BlockSize, + timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead); + if(debug) + DataFile.WriteTo("SCSI Report", "read6", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (10)..."); + mediaTest.SupportsRead10 = + !dev.Read10(out buffer, out senseBuffer, 0, false, true, false, false, 0, + mediaTest.BlockSize, 0, 1, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead10); + if(debug) + DataFile.WriteTo("SCSI Report", "read10", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (12)..."); + mediaTest.SupportsRead12 = + !dev.Read12(out buffer, out senseBuffer, 0, false, true, false, false, 0, + mediaTest.BlockSize, 0, 1, false, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead12); + if(debug) + DataFile.WriteTo("SCSI Report", "read12", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + DicConsole.WriteLine("Trying SCSI READ (16)..."); + mediaTest.SupportsRead16 = + !dev.Read16(out buffer, out senseBuffer, 0, false, true, false, 0, + mediaTest.BlockSize, 0, 1, false, timeout, out duration); + DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead16); + if(debug) + DataFile.WriteTo("SCSI Report", "read16", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + + mediaTest.LongBlockSize = mediaTest.BlockSize; + DicConsole.WriteLine("Trying SCSI READ LONG (10)..."); + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 0xFFFF, timeout, + out duration); + if(sense && !dev.Error) { Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); if(decSense.HasValue) - if(decSense.Value.ASC == 0x3A) + if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest && + decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00) { - int leftRetries = 20; - while(leftRetries > 0) + mediaTest.SupportsReadLong = true; + if(decSense.Value.InformationValid && decSense.Value.ILI) { - DicConsole.Write("\rWaiting for drive to become ready"); - System.Threading.Thread.Sleep(2000); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(!sense) break; - - leftRetries--; + mediaTest.LongBlockSize = + 0xFFFF - (decSense.Value.Information & 0xFFFF); + mediaTest.LongBlockSizeSpecified = true; } - - mediaTest.MediaIsRecognized &= !sense; } - else if(decSense.Value.ASC == 0x04 && decSense.Value.ASCQ == 0x01) - { - int leftRetries = 20; - while(leftRetries > 0) - { - DicConsole.Write("\rWaiting for drive to become ready"); - System.Threading.Thread.Sleep(2000); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(!sense) break; - - leftRetries--; - } - - mediaTest.MediaIsRecognized &= !sense; - } - else mediaTest.MediaIsRecognized = false; - else mediaTest.MediaIsRecognized = false; } - if(mediaTest.MediaIsRecognized) + if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) + if(mediaTest.BlockSize == 512) + foreach(ushort testSize in new[] + { + // Long sector sizes for floppies + 514, + // Long sector sizes for SuperDisk + 536, 558, + // Long sector sizes for 512-byte magneto-opticals + 600, 610, 630 + }) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + testSize, timeout, out duration); + if(sense || dev.Error) continue; + + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = testSize; + mediaTest.LongBlockSizeSpecified = true; + break; + } + else if(mediaTest.BlockSize == 1024) + foreach(ushort testSize in new[] + { + // Long sector sizes for floppies + 1026, + // Long sector sizes for 1024-byte magneto-opticals + 1200 + }) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + testSize, timeout, out duration); + if(sense || dev.Error) continue; + + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = testSize; + mediaTest.LongBlockSizeSpecified = true; + break; + } + else if(mediaTest.BlockSize == 2048) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 2380, + timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = 2380; + mediaTest.LongBlockSizeSpecified = true; + } + } + else if(mediaTest.BlockSize == 4096) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 4760, + timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = 4760; + mediaTest.LongBlockSizeSpecified = true; + } + } + else if(mediaTest.BlockSize == 8192) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 9424, + timeout, out duration); + if(!sense && !dev.Error) + { + mediaTest.SupportsReadLong = true; + mediaTest.LongBlockSize = 9424; + mediaTest.LongBlockSizeSpecified = true; + } + } + + if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) { - mediaTest.SupportsReadCapacitySpecified = true; - mediaTest.SupportsReadCapacity16Specified = true; - - DicConsole.WriteLine("Querying SCSI READ CAPACITY..."); - sense = dev.ReadCapacity(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) { - mediaTest.SupportsReadCapacity = true; - mediaTest.Blocks = - (ulong)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + - buffer[3]) + 1; - mediaTest.BlockSize = - (uint)((buffer[4] << 24) + (buffer[5] << 16) + (buffer[6] << 8) + buffer[7]); - mediaTest.BlocksSpecified = true; - mediaTest.BlockSizeSpecified = true; + DicConsole + .Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); } - DicConsole.WriteLine("Querying SCSI READ CAPACITY (16)..."); - sense = dev.ReadCapacity16(out buffer, out buffer, timeout, out duration); - if(!sense && !dev.Error) + if(pressedKey.Key == ConsoleKey.Y) { - mediaTest.SupportsReadCapacity16 = true; - byte[] temp = new byte[8]; - Array.Copy(buffer, 0, temp, 0, 8); - Array.Reverse(temp); - mediaTest.Blocks = BitConverter.ToUInt64(temp, 0) + 1; - mediaTest.BlockSize = - (uint)((buffer[8] << 24) + (buffer[9] << 16) + (buffer[10] << 8) + - buffer[11]); - mediaTest.BlocksSpecified = true; - mediaTest.BlockSizeSpecified = true; - } - - decMode = null; - - DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); - sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, - ScsiModeSensePageControl.Current, 0x3F, 0x00, timeout, - out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense10 = true; - decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); - if(debug) mediaTest.ModeSense10Data = buffer; - } - - DicConsole.WriteLine("Querying SCSI MODE SENSE..."); - sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense6 = true; - if(!decMode.HasValue) - decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); - if(debug) mediaTest.ModeSense6Data = buffer; - } - - if(decMode.HasValue) - { - mediaTest.MediumType = (byte)decMode.Value.Header.MediumType; - mediaTest.MediumTypeSpecified = true; - if(decMode.Value.Header.BlockDescriptors != null && - decMode.Value.Header.BlockDescriptors.Length > 0) + for(ushort i = (ushort)mediaTest.BlockSize; i <= ushort.MaxValue; i++) { - mediaTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density; - mediaTest.DensitySpecified = true; - } - } - - mediaTest.SupportsReadSpecified = true; - mediaTest.SupportsRead10Specified = true; - mediaTest.SupportsRead12Specified = true; - mediaTest.SupportsRead16Specified = true; - mediaTest.SupportsReadLongSpecified = true; - - DicConsole.WriteLine("Trying SCSI READ (6)..."); - mediaTest.SupportsRead = !dev.Read6(out buffer, out senseBuffer, 0, mediaTest.BlockSize, - timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead); - if(debug) - DataFile.WriteTo("SCSI Report", "read6", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (10)..."); - mediaTest.SupportsRead10 = - !dev.Read10(out buffer, out senseBuffer, 0, false, true, false, false, 0, - mediaTest.BlockSize, 0, 1, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead10); - if(debug) - DataFile.WriteTo("SCSI Report", "read10", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (12)..."); - mediaTest.SupportsRead12 = - !dev.Read12(out buffer, out senseBuffer, 0, false, true, false, false, 0, - mediaTest.BlockSize, 0, 1, false, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead12); - if(debug) - DataFile.WriteTo("SCSI Report", "read12", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - DicConsole.WriteLine("Trying SCSI READ (16)..."); - mediaTest.SupportsRead16 = - !dev.Read16(out buffer, out senseBuffer, 0, false, true, false, 0, - mediaTest.BlockSize, 0, 1, false, timeout, out duration); - DicConsole.DebugWriteLine("SCSI Report", "Sense = {0}", !mediaTest.SupportsRead16); - if(debug) - DataFile.WriteTo("SCSI Report", "read16", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - - mediaTest.LongBlockSize = mediaTest.BlockSize; - DicConsole.WriteLine("Trying SCSI READ LONG (10)..."); - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 0xFFFF, timeout, - out duration); - if(sense && !dev.Error) - { - Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); - if(decSense.HasValue) - if(decSense.Value.SenseKey == Decoders.SCSI.SenseKeys.IllegalRequest && - decSense.Value.ASC == 0x24 && decSense.Value.ASCQ == 0x00) - { - mediaTest.SupportsReadLong = true; - if(decSense.Value.InformationValid && decSense.Value.ILI) - { - mediaTest.LongBlockSize = - 0xFFFF - (decSense.Value.Information & 0xFFFF); - mediaTest.LongBlockSizeSpecified = true; - } - } - } - - if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) - if(mediaTest.BlockSize == 512) - foreach(ushort testSize in new[] - { - // Long sector sizes for floppies - 514, - // Long sector sizes for SuperDisk - 536, 558, - // Long sector sizes for 512-byte magneto-opticals - 600, 610, 630 - }) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - testSize, timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = testSize; - mediaTest.LongBlockSizeSpecified = true; - break; - } - } - else if(mediaTest.BlockSize == 1024) - foreach(ushort testSize in new[] - { - // Long sector sizes for floppies - 1026, - // Long sector sizes for 1024-byte magneto-opticals - 1200 - }) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - testSize, timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = testSize; - mediaTest.LongBlockSizeSpecified = true; - break; - } - } - else if(mediaTest.BlockSize == 2048) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 2380, + DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i); + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, i, timeout, out duration); - if(!sense && !dev.Error) + if(!sense) { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = 2380; + mediaTest.LongBlockSize = i; mediaTest.LongBlockSizeSpecified = true; - } - } - else if(mediaTest.BlockSize == 4096) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 4760, - timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = 4760; - mediaTest.LongBlockSizeSpecified = true; - } - } - else if(mediaTest.BlockSize == 8192) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, 9424, - timeout, out duration); - if(!sense && !dev.Error) - { - mediaTest.SupportsReadLong = true; - mediaTest.LongBlockSize = 9424; - mediaTest.LongBlockSizeSpecified = true; - } - } - - if(mediaTest.SupportsReadLong && mediaTest.LongBlockSize == mediaTest.BlockSize) - { - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) - { - DicConsole - .Write("Drive supports SCSI READ LONG but I cannot find the correct size. Do you want me to try? (This can take hours) (Y/N): "); - pressedKey = System.Console.ReadKey(); - DicConsole.WriteLine(); - } - - if(pressedKey.Key == ConsoleKey.Y) - { - for(ushort i = (ushort)mediaTest.BlockSize; i <= ushort.MaxValue; i++) - { - DicConsole.Write("\rTrying to READ LONG with a size of {0} bytes...", i); - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, i, - timeout, out duration); - if(!sense) - { - mediaTest.LongBlockSize = i; - mediaTest.LongBlockSizeSpecified = true; - break; - } - - if(i == ushort.MaxValue) break; + break; } - DicConsole.WriteLine(); + if(i == ushort.MaxValue) break; } + + DicConsole.WriteLine(); } - - if(debug && mediaTest.SupportsReadLong && mediaTest.LongBlockSizeSpecified && - mediaTest.LongBlockSize != mediaTest.BlockSize) - { - sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, - (ushort)mediaTest.LongBlockSize, timeout, out duration); - if(!sense) - DataFile.WriteTo("SCSI Report", "readlong10", - "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", - buffer); - } - - mediaTest.CanReadMediaSerialSpecified = true; - DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER..."); - mediaTest.CanReadMediaSerial = - !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, timeout, out duration); } - mediaTests.Add(mediaTest); + if(debug && mediaTest.SupportsReadLong && mediaTest.LongBlockSizeSpecified && + mediaTest.LongBlockSize != mediaTest.BlockSize) + { + sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, + (ushort)mediaTest.LongBlockSize, timeout, out duration); + if(!sense) + DataFile.WriteTo("SCSI Report", "readlong10", + "_debug_" + mediaTest.MediumTypeName + ".bin", "read results", + buffer); + } + + mediaTest.CanReadMediaSerialSpecified = true; + DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER..."); + mediaTest.CanReadMediaSerial = + !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, timeout, out duration); } + + mediaTests.Add(mediaTest); } report.SCSI.RemovableMedias = mediaTests.ToArray(); @@ -807,13 +803,12 @@ namespace DiscImageChef.Core.Devices.Report.SCSI { sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, testSize, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = testSize; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - break; - } + if(sense || dev.Error) continue; + + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = testSize; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + break; } else if(report.SCSI.ReadCapabilities.BlockSize == 1024) foreach(ushort testSize in new[] @@ -826,13 +821,12 @@ namespace DiscImageChef.Core.Devices.Report.SCSI { sense = dev.ReadLong10(out buffer, out senseBuffer, false, false, 0, testSize, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.ReadCapabilities.SupportsReadLong = true; - report.SCSI.ReadCapabilities.LongBlockSize = testSize; - report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; - break; - } + if(sense || dev.Error) continue; + + report.SCSI.ReadCapabilities.SupportsReadLong = true; + report.SCSI.ReadCapabilities.LongBlockSize = testSize; + report.SCSI.ReadCapabilities.LongBlockSizeSpecified = true; + break; } else if(report.SCSI.ReadCapabilities.BlockSize == 2048) { diff --git a/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs b/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs index df146b629..31e5f4cf2 100644 --- a/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs +++ b/DiscImageChef.Core/Devices/Report/SCSI/MMC.cs @@ -1333,11 +1333,10 @@ namespace DiscImageChef.Core.Devices.Report.SCSI DataFile.WriteTo("SCSI Report", "leadin", "_debug_" + report.SCSI.Inquiry.ProductIdentification + "_" + mediaType + ".bin", "read results", buffer); - if(!sense) - { - mediaTest.CanReadLeadIn = true; - break; - } + if(sense) continue; + + mediaTest.CanReadLeadIn = true; + break; } DicConsole.WriteLine("Trying to read CD Lead-Out..."); diff --git a/DiscImageChef.Core/Devices/Report/SCSI/SSC.cs b/DiscImageChef.Core/Devices/Report/SCSI/SSC.cs index 77e9b6511..87ddb2d2c 100644 --- a/DiscImageChef.Core/Devices/Report/SCSI/SSC.cs +++ b/DiscImageChef.Core/Devices/Report/SCSI/SSC.cs @@ -133,14 +133,13 @@ namespace DiscImageChef.Core.Devices.Report.SCSI report.SCSI.SequentialDevice.SupportedMediaTypes[i].Organization = mtsh.Value.descriptors[i].organization; report.SCSI.SequentialDevice.SupportedMediaTypes[i].Width = mtsh.Value.descriptors[i].width; - if(mtsh.Value.descriptors[i].densityCodes != null) - { - report.SCSI.SequentialDevice.SupportedMediaTypes[i].DensityCodes = - new int[mtsh.Value.descriptors[i].densityCodes.Length]; - for(int j = 0; j < mtsh.Value.descriptors.Length; j++) - report.SCSI.SequentialDevice.SupportedMediaTypes[i].DensityCodes[j] = - mtsh.Value.descriptors[i].densityCodes[j]; - } + if(mtsh.Value.descriptors[i].densityCodes == null) continue; + + report.SCSI.SequentialDevice.SupportedMediaTypes[i].DensityCodes = + new int[mtsh.Value.descriptors[i].densityCodes.Length]; + for(int j = 0; j < mtsh.Value.descriptors.Length; j++) + report.SCSI.SequentialDevice.SupportedMediaTypes[i].DensityCodes[j] = + mtsh.Value.descriptors[i].densityCodes[j]; } } } @@ -158,159 +157,157 @@ namespace DiscImageChef.Core.Devices.Report.SCSI DicConsole.WriteLine(); } - if(pressedKey.Key == ConsoleKey.Y) + if(pressedKey.Key != ConsoleKey.Y) continue; + + DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); + System.Console.ReadKey(true); + + SequentialMedia seqTest = new SequentialMedia(); + DicConsole.Write("Please write a description of the media type and press enter: "); + seqTest.MediumTypeName = System.Console.ReadLine(); + DicConsole.Write("Please write the media manufacturer and press enter: "); + seqTest.Manufacturer = System.Console.ReadLine(); + DicConsole.Write("Please write the media model and press enter: "); + seqTest.Model = System.Console.ReadLine(); + + seqTest.MediaIsRecognized = true; + + sense = dev.Load(out senseBuffer, timeout, out duration); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(sense) { - DicConsole.WriteLine("Please insert it in the drive and press any key when it is ready."); - System.Console.ReadKey(true); - - SequentialMedia seqTest = new SequentialMedia(); - DicConsole.Write("Please write a description of the media type and press enter: "); - seqTest.MediumTypeName = System.Console.ReadLine(); - DicConsole.Write("Please write the media manufacturer and press enter: "); - seqTest.Manufacturer = System.Console.ReadLine(); - DicConsole.Write("Please write the media model and press enter: "); - seqTest.Model = System.Console.ReadLine(); - - seqTest.MediaIsRecognized = true; - - sense = dev.Load(out senseBuffer, timeout, out duration); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(sense) - { - Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); - if(decSense.HasValue) - if(decSense.Value.ASC == 0x3A) + Decoders.SCSI.FixedSense? decSense = Decoders.SCSI.Sense.DecodeFixed(senseBuffer); + if(decSense.HasValue) + if(decSense.Value.ASC == 0x3A) + { + int leftRetries = 20; + while(leftRetries > 0) { - int leftRetries = 20; - while(leftRetries > 0) - { - DicConsole.Write("\rWaiting for drive to become ready"); - System.Threading.Thread.Sleep(2000); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(!sense) break; + DicConsole.Write("\rWaiting for drive to become ready"); + System.Threading.Thread.Sleep(2000); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(!sense) break; - leftRetries--; - } - - seqTest.MediaIsRecognized &= !sense; + leftRetries--; } - else if(decSense.Value.ASC == 0x04 && decSense.Value.ASCQ == 0x01) + + seqTest.MediaIsRecognized &= !sense; + } + else if(decSense.Value.ASC == 0x04 && decSense.Value.ASCQ == 0x01) + { + int leftRetries = 20; + while(leftRetries > 0) { - int leftRetries = 20; - while(leftRetries > 0) - { - DicConsole.Write("\rWaiting for drive to become ready"); - System.Threading.Thread.Sleep(2000); - sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); - if(!sense) break; + DicConsole.Write("\rWaiting for drive to become ready"); + System.Threading.Thread.Sleep(2000); + sense = dev.ScsiTestUnitReady(out senseBuffer, timeout, out duration); + if(!sense) break; - leftRetries--; - } - - seqTest.MediaIsRecognized &= !sense; + leftRetries--; } - else seqTest.MediaIsRecognized = false; + + seqTest.MediaIsRecognized &= !sense; + } else seqTest.MediaIsRecognized = false; - } - - if(seqTest.MediaIsRecognized) - { - decMode = null; - - DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); - sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, - ScsiModeSensePageControl.Current, 0x3F, 0x00, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense10 = true; - decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); - if(debug) seqTest.ModeSense10Data = buffer; - } - - DicConsole.WriteLine("Querying SCSI MODE SENSE..."); - sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); - if(!sense && !dev.Error) - { - report.SCSI.SupportsModeSense6 = true; - if(!decMode.HasValue) decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); - if(debug) seqTest.ModeSense6Data = buffer; - } - - if(decMode.HasValue) - { - seqTest.MediumType = (byte)decMode.Value.Header.MediumType; - seqTest.MediumTypeSpecified = true; - if(decMode.Value.Header.BlockDescriptors != null && - decMode.Value.Header.BlockDescriptors.Length > 0) - { - seqTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density; - seqTest.DensitySpecified = true; - } - } - } - - DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for current media..."); - sense = dev.ReportDensitySupport(out buffer, out senseBuffer, false, true, timeout, out duration); - if(!sense) - { - Decoders.SCSI.SSC.DensitySupport.DensitySupportHeader? dsh = - Decoders.SCSI.SSC.DensitySupport.DecodeDensity(buffer); - if(dsh.HasValue) - { - seqTest.SupportedDensities = new SupportedDensity[dsh.Value.descriptors.Length]; - for(int i = 0; i < dsh.Value.descriptors.Length; i++) - { - seqTest.SupportedDensities[i].BitsPerMm = dsh.Value.descriptors[i].bpmm; - seqTest.SupportedDensities[i].Capacity = dsh.Value.descriptors[i].capacity; - seqTest.SupportedDensities[i].DefaultDensity = dsh.Value.descriptors[i].defaultDensity; - seqTest.SupportedDensities[i].Description = dsh.Value.descriptors[i].description; - seqTest.SupportedDensities[i].Duplicate = dsh.Value.descriptors[i].duplicate; - seqTest.SupportedDensities[i].Name = dsh.Value.descriptors[i].name; - seqTest.SupportedDensities[i].Organization = dsh.Value.descriptors[i].organization; - seqTest.SupportedDensities[i].PrimaryCode = dsh.Value.descriptors[i].primaryCode; - seqTest.SupportedDensities[i].SecondaryCode = dsh.Value.descriptors[i].secondaryCode; - seqTest.SupportedDensities[i].Tracks = dsh.Value.descriptors[i].tracks; - seqTest.SupportedDensities[i].Width = dsh.Value.descriptors[i].width; - seqTest.SupportedDensities[i].Writable = dsh.Value.descriptors[i].writable; - } - } - } - - DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types for current media..."); - sense = dev.ReportDensitySupport(out buffer, out senseBuffer, true, true, timeout, out duration); - if(!sense) - { - Decoders.SCSI.SSC.DensitySupport.MediaTypeSupportHeader? mtsh = - Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(buffer); - if(mtsh.HasValue) - { - seqTest.SupportedMediaTypes = new SupportedMedia[mtsh.Value.descriptors.Length]; - for(int i = 0; i < mtsh.Value.descriptors.Length; i++) - { - seqTest.SupportedMediaTypes[i].Description = mtsh.Value.descriptors[i].description; - seqTest.SupportedMediaTypes[i].Length = mtsh.Value.descriptors[i].length; - seqTest.SupportedMediaTypes[i].MediumType = mtsh.Value.descriptors[i].mediumType; - seqTest.SupportedMediaTypes[i].Name = mtsh.Value.descriptors[i].name; - seqTest.SupportedMediaTypes[i].Organization = mtsh.Value.descriptors[i].organization; - seqTest.SupportedMediaTypes[i].Width = mtsh.Value.descriptors[i].width; - if(mtsh.Value.descriptors[i].densityCodes != null) - { - seqTest.SupportedMediaTypes[i].DensityCodes = - new int[mtsh.Value.descriptors[i].densityCodes.Length]; - for(int j = 0; j < mtsh.Value.descriptors.Length; j++) - seqTest.SupportedMediaTypes[i].DensityCodes[j] = - mtsh.Value.descriptors[i].densityCodes[j]; - } - } - } - } - - seqTest.CanReadMediaSerialSpecified = true; - DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER..."); - seqTest.CanReadMediaSerial = - !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, timeout, out duration); - seqTests.Add(seqTest); + else seqTest.MediaIsRecognized = false; } + + if(seqTest.MediaIsRecognized) + { + decMode = null; + + DicConsole.WriteLine("Querying SCSI MODE SENSE (10)..."); + sense = dev.ModeSense10(out buffer, out senseBuffer, false, true, + ScsiModeSensePageControl.Current, 0x3F, 0x00, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense10 = true; + decMode = Decoders.SCSI.Modes.DecodeMode10(buffer, dev.ScsiType); + if(debug) seqTest.ModeSense10Data = buffer; + } + + DicConsole.WriteLine("Querying SCSI MODE SENSE..."); + sense = dev.ModeSense(out buffer, out senseBuffer, timeout, out duration); + if(!sense && !dev.Error) + { + report.SCSI.SupportsModeSense6 = true; + if(!decMode.HasValue) decMode = Decoders.SCSI.Modes.DecodeMode6(buffer, dev.ScsiType); + if(debug) seqTest.ModeSense6Data = buffer; + } + + if(decMode.HasValue) + { + seqTest.MediumType = (byte)decMode.Value.Header.MediumType; + seqTest.MediumTypeSpecified = true; + if(decMode.Value.Header.BlockDescriptors != null && + decMode.Value.Header.BlockDescriptors.Length > 0) + { + seqTest.Density = (byte)decMode.Value.Header.BlockDescriptors[0].Density; + seqTest.DensitySpecified = true; + } + } + } + + DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for current media..."); + sense = dev.ReportDensitySupport(out buffer, out senseBuffer, false, true, timeout, out duration); + if(!sense) + { + Decoders.SCSI.SSC.DensitySupport.DensitySupportHeader? dsh = + Decoders.SCSI.SSC.DensitySupport.DecodeDensity(buffer); + if(dsh.HasValue) + { + seqTest.SupportedDensities = new SupportedDensity[dsh.Value.descriptors.Length]; + for(int i = 0; i < dsh.Value.descriptors.Length; i++) + { + seqTest.SupportedDensities[i].BitsPerMm = dsh.Value.descriptors[i].bpmm; + seqTest.SupportedDensities[i].Capacity = dsh.Value.descriptors[i].capacity; + seqTest.SupportedDensities[i].DefaultDensity = dsh.Value.descriptors[i].defaultDensity; + seqTest.SupportedDensities[i].Description = dsh.Value.descriptors[i].description; + seqTest.SupportedDensities[i].Duplicate = dsh.Value.descriptors[i].duplicate; + seqTest.SupportedDensities[i].Name = dsh.Value.descriptors[i].name; + seqTest.SupportedDensities[i].Organization = dsh.Value.descriptors[i].organization; + seqTest.SupportedDensities[i].PrimaryCode = dsh.Value.descriptors[i].primaryCode; + seqTest.SupportedDensities[i].SecondaryCode = dsh.Value.descriptors[i].secondaryCode; + seqTest.SupportedDensities[i].Tracks = dsh.Value.descriptors[i].tracks; + seqTest.SupportedDensities[i].Width = dsh.Value.descriptors[i].width; + seqTest.SupportedDensities[i].Writable = dsh.Value.descriptors[i].writable; + } + } + } + + DicConsole.WriteLine("Querying SCSI REPORT DENSITY SUPPORT for medium types for current media..."); + sense = dev.ReportDensitySupport(out buffer, out senseBuffer, true, true, timeout, out duration); + if(!sense) + { + Decoders.SCSI.SSC.DensitySupport.MediaTypeSupportHeader? mtsh = + Decoders.SCSI.SSC.DensitySupport.DecodeMediumType(buffer); + if(mtsh.HasValue) + { + seqTest.SupportedMediaTypes = new SupportedMedia[mtsh.Value.descriptors.Length]; + for(int i = 0; i < mtsh.Value.descriptors.Length; i++) + { + seqTest.SupportedMediaTypes[i].Description = mtsh.Value.descriptors[i].description; + seqTest.SupportedMediaTypes[i].Length = mtsh.Value.descriptors[i].length; + seqTest.SupportedMediaTypes[i].MediumType = mtsh.Value.descriptors[i].mediumType; + seqTest.SupportedMediaTypes[i].Name = mtsh.Value.descriptors[i].name; + seqTest.SupportedMediaTypes[i].Organization = mtsh.Value.descriptors[i].organization; + seqTest.SupportedMediaTypes[i].Width = mtsh.Value.descriptors[i].width; + if(mtsh.Value.descriptors[i].densityCodes == null) continue; + + seqTest.SupportedMediaTypes[i].DensityCodes = + new int[mtsh.Value.descriptors[i].densityCodes.Length]; + for(int j = 0; j < mtsh.Value.descriptors.Length; j++) + seqTest.SupportedMediaTypes[i].DensityCodes[j] = + mtsh.Value.descriptors[i].densityCodes[j]; + } + } + } + + seqTest.CanReadMediaSerialSpecified = true; + DicConsole.WriteLine("Trying SCSI READ MEDIA SERIAL NUMBER..."); + seqTest.CanReadMediaSerial = + !dev.ReadMediaSerialNumber(out buffer, out senseBuffer, timeout, out duration); + seqTests.Add(seqTest); } report.SCSI.SequentialDevice.TestedMedia = seqTests.ToArray(); diff --git a/DiscImageChef.Core/Devices/Report/USB.cs b/DiscImageChef.Core/Devices/Report/USB.cs index f8ea73109..5487ea12b 100644 --- a/DiscImageChef.Core/Devices/Report/USB.cs +++ b/DiscImageChef.Core/Devices/Report/USB.cs @@ -51,26 +51,25 @@ namespace DiscImageChef.Core.Devices.Report DicConsole.WriteLine(); } - if(pressedKey.Key == ConsoleKey.Y) + if(pressedKey.Key != ConsoleKey.Y) return; + + report.USB = new usbType(); + report.USB.Manufacturer = dev.UsbManufacturerString; + report.USB.Product = dev.UsbProductString; + report.USB.ProductID = dev.UsbProductId; + report.USB.VendorID = dev.UsbVendorId; + + pressedKey = new ConsoleKeyInfo(); + while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) { - report.USB = new usbType(); - report.USB.Manufacturer = dev.UsbManufacturerString; - report.USB.Product = dev.UsbProductString; - report.USB.ProductID = dev.UsbProductId; - report.USB.VendorID = dev.UsbVendorId; - - pressedKey = new ConsoleKeyInfo(); - while(pressedKey.Key != ConsoleKey.Y && pressedKey.Key != ConsoleKey.N) - { - DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): "); - pressedKey = System.Console.ReadKey(); - DicConsole.WriteLine(); - } - - report.USB.RemovableMedia = pressedKey.Key == ConsoleKey.Y; - removable = report.USB.RemovableMedia; - if(debug) report.USB.Descriptors = dev.UsbDescriptors; + DicConsole.Write("Is the media removable from the reading/writing elements? (Y/N): "); + pressedKey = System.Console.ReadKey(); + DicConsole.WriteLine(); } + + report.USB.RemovableMedia = pressedKey.Key == ConsoleKey.Y; + removable = report.USB.RemovableMedia; + if(debug) report.USB.Descriptors = dev.UsbDescriptors; } } } \ No newline at end of file diff --git a/DiscImageChef.Core/ImageFormat.cs b/DiscImageChef.Core/ImageFormat.cs index 5fccc6af2..03ec0e99e 100644 --- a/DiscImageChef.Core/ImageFormat.cs +++ b/DiscImageChef.Core/ImageFormat.cs @@ -56,11 +56,10 @@ namespace DiscImageChef.Core try { DicConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imageplugin.Name); - if(imageplugin.IdentifyImage(imageFilter)) - { - imageFormat = imageplugin; - break; - } + if(!imageplugin.IdentifyImage(imageFilter)) continue; + + imageFormat = imageplugin; + break; } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch { } @@ -75,11 +74,10 @@ namespace DiscImageChef.Core try { DicConsole.DebugWriteLine("Format detection", "Trying plugin {0}", imageplugin.Name); - if(imageplugin.IdentifyImage(imageFilter)) - { - imageFormat = imageplugin; - break; - } + if(!imageplugin.IdentifyImage(imageFilter)) continue; + + imageFormat = imageplugin; + break; } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch { } diff --git a/DiscImageChef.Core/Logging/DumpLog.cs b/DiscImageChef.Core/Logging/DumpLog.cs index eac4b52e8..78b378056 100644 --- a/DiscImageChef.Core/Logging/DumpLog.cs +++ b/DiscImageChef.Core/Logging/DumpLog.cs @@ -43,93 +43,90 @@ namespace DiscImageChef.Core.Logging public DumpLog(string outputFile, Device dev) { - if(!string.IsNullOrEmpty(outputFile)) + if(string.IsNullOrEmpty(outputFile)) return; + + logSw = new StreamWriter(outputFile, true); + + logSw.WriteLine("Start logging at {0}", DateTime.Now); + + Interop.PlatformID platId = Interop.DetectOS.GetRealPlatformID(); + string platVer = Interop.DetectOS.GetVersion(); + Type monoRunType = Type.GetType("Mono.Runtime"); + + logSw.WriteLine("################# System information #################"); + logSw.WriteLine("{0} {1} ({2}-bit)", Interop.DetectOS.GetPlatformName(platId, platVer), platVer, + Environment.Is64BitOperatingSystem ? 64 : 32); + if(monoRunType != null) { - logSw = new StreamWriter(outputFile, true); - - logSw.WriteLine("Start logging at {0}", DateTime.Now); - - Interop.PlatformID platId = Interop.DetectOS.GetRealPlatformID(); - string platVer = Interop.DetectOS.GetVersion(); - Type monoRunType = Type.GetType("Mono.Runtime"); - - logSw.WriteLine("################# System information #################"); - logSw.WriteLine("{0} {1} ({2}-bit)", Interop.DetectOS.GetPlatformName(platId, platVer), platVer, - Environment.Is64BitOperatingSystem ? 64 : 32); - if(monoRunType != null) - { - string monoVer = "unknown version"; - MethodInfo monoDisplayName = - monoRunType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); - if(monoDisplayName != null) monoVer = (string)monoDisplayName.Invoke(null, null); - logSw.WriteLine("Mono {0}", monoVer); - } - else logSw.WriteLine(".NET Framework {0}", Environment.Version); - logSw.WriteLine(); - - logSw.WriteLine("################# Program information ################"); - logSw.WriteLine("DiscImageChef {0} running in {1}-bit", Version.GetVersion(), - Environment.Is64BitProcess ? 64 : 32); -#if DEBUG - logSw.WriteLine("DEBUG version"); -#endif - logSw.WriteLine("Command line: {0}", Environment.CommandLine); - logSw.WriteLine(); - - logSw.WriteLine("################# Device information #################"); - logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer); - logSw.WriteLine("Model: {0}", dev.Model); - logSw.WriteLine("Firmware revision: {0}", dev.Revision); - logSw.WriteLine("Serial number: {0}", dev.Serial); - logSw.WriteLine("Removable device: {0}", dev.IsRemovable); - logSw.WriteLine("Device type: {0}", dev.Type); - logSw.WriteLine("CompactFlash device: {0}", dev.IsCompactFlash); - logSw.WriteLine("PCMCIA device: {0}", dev.IsPcmcia); - logSw.WriteLine("USB device: {0}", dev.IsUsb); - if(dev.IsUsb) - { - logSw.WriteLine("USB manufacturer: {0}", dev.UsbManufacturerString); - logSw.WriteLine("USB product: {0}", dev.UsbProductString); - logSw.WriteLine("USB serial: {0}", dev.UsbSerialString); - logSw.WriteLine("USB vendor ID: {0:X4}h", dev.UsbVendorId); - logSw.WriteLine("USB product ID: {0:X4}h", dev.UsbProductId); - } - logSw.WriteLine("FireWire device: {0}", dev.IsFireWire); - if(dev.IsFireWire) - { - logSw.WriteLine("FireWire vendor: {0}", dev.FireWireVendorName); - logSw.WriteLine("FireWire model: {0}", dev.FireWireModelName); - logSw.WriteLine("FireWire GUID: 0x{0:X16}", dev.FireWireGuid); - logSw.WriteLine("FireWire vendor ID: 0x{0:X8}", dev.FireWireVendor); - logSw.WriteLine("FireWire product ID: 0x{0:X8}", dev.FireWireModel); - } - logSw.WriteLine(); - logSw.WriteLine("######################################################"); - - logSw.WriteLine(); - logSw.WriteLine("################ Dumping progress log ################"); - logSw.Flush(); + string monoVer = "unknown version"; + MethodInfo monoDisplayName = + monoRunType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static); + if(monoDisplayName != null) monoVer = (string)monoDisplayName.Invoke(null, null); + logSw.WriteLine("Mono {0}", monoVer); } + else logSw.WriteLine(".NET Framework {0}", Environment.Version); + logSw.WriteLine(); + + logSw.WriteLine("################# Program information ################"); + logSw.WriteLine("DiscImageChef {0} running in {1}-bit", Version.GetVersion(), + Environment.Is64BitProcess ? 64 : 32); +#if DEBUG + logSw.WriteLine("DEBUG version"); +#endif + logSw.WriteLine("Command line: {0}", Environment.CommandLine); + logSw.WriteLine(); + + logSw.WriteLine("################# Device information #################"); + logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer); + logSw.WriteLine("Model: {0}", dev.Model); + logSw.WriteLine("Firmware revision: {0}", dev.Revision); + logSw.WriteLine("Serial number: {0}", dev.Serial); + logSw.WriteLine("Removable device: {0}", dev.IsRemovable); + logSw.WriteLine("Device type: {0}", dev.Type); + logSw.WriteLine("CompactFlash device: {0}", dev.IsCompactFlash); + logSw.WriteLine("PCMCIA device: {0}", dev.IsPcmcia); + logSw.WriteLine("USB device: {0}", dev.IsUsb); + if(dev.IsUsb) + { + logSw.WriteLine("USB manufacturer: {0}", dev.UsbManufacturerString); + logSw.WriteLine("USB product: {0}", dev.UsbProductString); + logSw.WriteLine("USB serial: {0}", dev.UsbSerialString); + logSw.WriteLine("USB vendor ID: {0:X4}h", dev.UsbVendorId); + logSw.WriteLine("USB product ID: {0:X4}h", dev.UsbProductId); + } + logSw.WriteLine("FireWire device: {0}", dev.IsFireWire); + if(dev.IsFireWire) + { + logSw.WriteLine("FireWire vendor: {0}", dev.FireWireVendorName); + logSw.WriteLine("FireWire model: {0}", dev.FireWireModelName); + logSw.WriteLine("FireWire GUID: 0x{0:X16}", dev.FireWireGuid); + logSw.WriteLine("FireWire vendor ID: 0x{0:X8}", dev.FireWireVendor); + logSw.WriteLine("FireWire product ID: 0x{0:X8}", dev.FireWireModel); + } + logSw.WriteLine(); + logSw.WriteLine("######################################################"); + + logSw.WriteLine(); + logSw.WriteLine("################ Dumping progress log ################"); + logSw.Flush(); } public void WriteLine(string format, params object[] args) { - if(logSw != null) - { - string text = string.Format(format, args); - logSw.WriteLine("{0:s} {1}", DateTime.Now, text); - logSw.Flush(); - } + if(logSw == null) return; + + string text = string.Format(format, args); + logSw.WriteLine("{0:s} {1}", DateTime.Now, text); + logSw.Flush(); } public void Close() { - if(logSw != null) - { - logSw.WriteLine("######################################################"); - logSw.WriteLine("End logging at {0}", DateTime.Now); - logSw.Close(); - } + if(logSw == null) return; + + logSw.WriteLine("######################################################"); + logSw.WriteLine("End logging at {0}", DateTime.Now); + logSw.Close(); } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Logging/IBGLog.cs b/DiscImageChef.Core/Logging/IBGLog.cs index fb4c0b5f8..52fe2bb71 100644 --- a/DiscImageChef.Core/Logging/IBGLog.cs +++ b/DiscImageChef.Core/Logging/IBGLog.cs @@ -56,237 +56,233 @@ namespace DiscImageChef.Core.Logging internal IbgLog(string outputFile, ushort currentProfile) { - if(!string.IsNullOrEmpty(outputFile)) - { - ibgFs = new FileStream(outputFile, FileMode.Create); - ibgSb = new StringBuilder(); - ibgDatePoint = DateTime.Now; - ibgCulture = new CultureInfo("en-US"); - ibgStartSet = false; - ibgMaxSpeed = 0; - ibgIntSpeed = 0; - ibgSnaps = 0; - ibgIntSector = 0; + if(string.IsNullOrEmpty(outputFile)) return; - switch(currentProfile) - { - case 0x0001: - ibgMediaType = "HDD"; - ibgDivider = 1353; - break; - case 0x0005: - ibgMediaType = "CD-MO"; - ibgDivider = 150; - break; - case 0x0008: - ibgMediaType = "CD-ROM"; - ibgDivider = 150; - break; - case 0x0009: - ibgMediaType = "CD-R"; - ibgDivider = 150; - break; - case 0x000A: - ibgMediaType = "CD-RW"; - ibgDivider = 150; - break; - case 0x0010: - ibgMediaType = "DVD-ROM"; - ibgDivider = 1353; - break; - case 0x0011: - ibgMediaType = "DVD-R"; - ibgDivider = 1353; - break; - case 0x0012: - ibgMediaType = "DVD-RAM"; - ibgDivider = 1353; - break; - case 0x0013: - case 0x0014: - ibgMediaType = "DVD-RW"; - ibgDivider = 1353; - break; - case 0x0015: - case 0x0016: - ibgMediaType = "DVD-R DL"; - ibgDivider = 1353; - break; - case 0x0017: - ibgMediaType = "DVD-RW DL"; - ibgDivider = 1353; - break; - case 0x0018: - ibgMediaType = "DVD-Download"; - ibgDivider = 1353; - break; - case 0x001A: - ibgMediaType = "DVD+RW"; - ibgDivider = 1353; - break; - case 0x001B: - ibgMediaType = "DVD+R"; - ibgDivider = 1353; - break; - case 0x0020: - ibgMediaType = "DDCD-ROM"; - ibgDivider = 150; - break; - case 0x0021: - ibgMediaType = "DDCD-R"; - ibgDivider = 150; - break; - case 0x0022: - ibgMediaType = "DDCD-RW"; - ibgDivider = 150; - break; - case 0x002A: - ibgMediaType = "DVD+RW DL"; - ibgDivider = 1353; - break; - case 0x002B: - ibgMediaType = "DVD+R DL"; - ibgDivider = 1353; - break; - case 0x0040: - ibgMediaType = "BD-ROM"; - ibgDivider = 4500; - break; - case 0x0041: - case 0x0042: - ibgMediaType = "BD-R"; - ibgDivider = 4500; - break; - case 0x0043: - ibgMediaType = "BD-RE"; - ibgDivider = 4500; - break; - case 0x0050: - ibgMediaType = "HD DVD-ROM"; - ibgDivider = 4500; - break; - case 0x0051: - ibgMediaType = "HD DVD-R"; - ibgDivider = 4500; - break; - case 0x0052: - ibgMediaType = "HD DVD-RAM"; - ibgDivider = 4500; - break; - case 0x0053: - ibgMediaType = "HD DVD-RW"; - ibgDivider = 4500; - break; - case 0x0058: - ibgMediaType = "HD DVD-R DL"; - ibgDivider = 4500; - break; - case 0x005A: - ibgMediaType = "HD DVD-RW DL"; - ibgDivider = 4500; - break; - default: - ibgMediaType = "Unknown"; - ibgDivider = 1353; - break; - } + ibgFs = new FileStream(outputFile, FileMode.Create); + ibgSb = new StringBuilder(); + ibgDatePoint = DateTime.Now; + ibgCulture = new CultureInfo("en-US"); + ibgStartSet = false; + ibgMaxSpeed = 0; + ibgIntSpeed = 0; + ibgSnaps = 0; + ibgIntSector = 0; + + switch(currentProfile) + { + case 0x0001: + ibgMediaType = "HDD"; + ibgDivider = 1353; + break; + case 0x0005: + ibgMediaType = "CD-MO"; + ibgDivider = 150; + break; + case 0x0008: + ibgMediaType = "CD-ROM"; + ibgDivider = 150; + break; + case 0x0009: + ibgMediaType = "CD-R"; + ibgDivider = 150; + break; + case 0x000A: + ibgMediaType = "CD-RW"; + ibgDivider = 150; + break; + case 0x0010: + ibgMediaType = "DVD-ROM"; + ibgDivider = 1353; + break; + case 0x0011: + ibgMediaType = "DVD-R"; + ibgDivider = 1353; + break; + case 0x0012: + ibgMediaType = "DVD-RAM"; + ibgDivider = 1353; + break; + case 0x0013: + case 0x0014: + ibgMediaType = "DVD-RW"; + ibgDivider = 1353; + break; + case 0x0015: + case 0x0016: + ibgMediaType = "DVD-R DL"; + ibgDivider = 1353; + break; + case 0x0017: + ibgMediaType = "DVD-RW DL"; + ibgDivider = 1353; + break; + case 0x0018: + ibgMediaType = "DVD-Download"; + ibgDivider = 1353; + break; + case 0x001A: + ibgMediaType = "DVD+RW"; + ibgDivider = 1353; + break; + case 0x001B: + ibgMediaType = "DVD+R"; + ibgDivider = 1353; + break; + case 0x0020: + ibgMediaType = "DDCD-ROM"; + ibgDivider = 150; + break; + case 0x0021: + ibgMediaType = "DDCD-R"; + ibgDivider = 150; + break; + case 0x0022: + ibgMediaType = "DDCD-RW"; + ibgDivider = 150; + break; + case 0x002A: + ibgMediaType = "DVD+RW DL"; + ibgDivider = 1353; + break; + case 0x002B: + ibgMediaType = "DVD+R DL"; + ibgDivider = 1353; + break; + case 0x0040: + ibgMediaType = "BD-ROM"; + ibgDivider = 4500; + break; + case 0x0041: + case 0x0042: + ibgMediaType = "BD-R"; + ibgDivider = 4500; + break; + case 0x0043: + ibgMediaType = "BD-RE"; + ibgDivider = 4500; + break; + case 0x0050: + ibgMediaType = "HD DVD-ROM"; + ibgDivider = 4500; + break; + case 0x0051: + ibgMediaType = "HD DVD-R"; + ibgDivider = 4500; + break; + case 0x0052: + ibgMediaType = "HD DVD-RAM"; + ibgDivider = 4500; + break; + case 0x0053: + ibgMediaType = "HD DVD-RW"; + ibgDivider = 4500; + break; + case 0x0058: + ibgMediaType = "HD DVD-R DL"; + ibgDivider = 4500; + break; + case 0x005A: + ibgMediaType = "HD DVD-RW DL"; + ibgDivider = 4500; + break; + default: + ibgMediaType = "Unknown"; + ibgDivider = 1353; + break; } } internal void Write(ulong sector, double currentSpeed) { - if(ibgFs != null) + if(ibgFs == null) return; + + ibgIntSpeed += currentSpeed; + ibgSampleRate += (int)Math.Floor((DateTime.Now - ibgDatePoint).TotalMilliseconds); + ibgSnaps++; + + if(ibgSampleRate < 100) return; + + if(ibgIntSpeed > 0 && !ibgStartSet) { - ibgIntSpeed += currentSpeed; - ibgSampleRate += (int)Math.Floor((DateTime.Now - ibgDatePoint).TotalMilliseconds); - ibgSnaps++; - - if(ibgSampleRate >= 100) - { - if(ibgIntSpeed > 0 && !ibgStartSet) - { - ibgStartSpeed = ibgIntSpeed / ibgSnaps / ibgDivider; - ibgStartSet = true; - } - - ibgSb.AppendFormat("{0:0.00},{1},{2:0},0", ibgIntSpeed / ibgSnaps / ibgDivider, ibgIntSector, - ibgSampleRate).AppendLine(); - if(ibgIntSpeed / ibgSnaps / ibgDivider > ibgMaxSpeed) ibgMaxSpeed = ibgIntSpeed / ibgDivider; - - ibgDatePoint = DateTime.Now; - ibgIntSpeed = 0; - ibgSampleRate = 0; - ibgSnaps = 0; - ibgIntSector = sector; - } + ibgStartSpeed = ibgIntSpeed / ibgSnaps / ibgDivider; + ibgStartSet = true; } + + ibgSb.AppendFormat("{0:0.00},{1},{2:0},0", ibgIntSpeed / ibgSnaps / ibgDivider, ibgIntSector, + ibgSampleRate).AppendLine(); + if(ibgIntSpeed / ibgSnaps / ibgDivider > ibgMaxSpeed) ibgMaxSpeed = ibgIntSpeed / ibgDivider; + + ibgDatePoint = DateTime.Now; + ibgIntSpeed = 0; + ibgSampleRate = 0; + ibgSnaps = 0; + ibgIntSector = sector; } internal void Close(Device dev, ulong blocks, ulong blockSize, double totalSeconds, double currentSpeed, double averageSpeed, string devicePath) { - if(ibgFs != null) - { - StringBuilder ibgHeader = new StringBuilder(); - string ibgBusType; + if(ibgFs == null) return; - if(dev.IsUsb) ibgBusType = "USB"; - else if(dev.IsFireWire) ibgBusType = "FireWire"; - else ibgBusType = dev.Type.ToString(); + StringBuilder ibgHeader = new StringBuilder(); + string ibgBusType; - ibgHeader.AppendLine("IBGD"); - ibgHeader.AppendLine(); - ibgHeader.AppendLine("[START_CONFIGURATION]"); - ibgHeader.AppendLine("IBGD_VERSION=2"); - ibgHeader.AppendLine(); - ibgHeader.AppendFormat("DATE={0}", DateTime.Now).AppendLine(); - ibgHeader.AppendLine(); - ibgHeader.AppendFormat("SAMPLE_RATE={0}", 100).AppendLine(); + if(dev.IsUsb) ibgBusType = "USB"; + else if(dev.IsFireWire) ibgBusType = "FireWire"; + else ibgBusType = dev.Type.ToString(); - ibgHeader.AppendLine(); - ibgHeader.AppendFormat("DEVICE=[0:0:0] {0} {1} ({2}) ({3})", dev.Manufacturer, dev.Model, devicePath, - ibgBusType).AppendLine(); - ibgHeader.AppendLine("DEVICE_ADDRESS=0:0:0"); - ibgHeader.AppendFormat("DEVICE_MAKEMODEL={0} {1}", dev.Manufacturer, dev.Model).AppendLine(); - ibgHeader.AppendFormat("DEVICE_FIRMWAREVERSION={0}", dev.Revision).AppendLine(); - ibgHeader.AppendFormat("DEVICE_DRIVELETTER={0}", devicePath).AppendLine(); - ibgHeader.AppendFormat("DEVICE_BUSTYPE={0}", ibgBusType).AppendLine(); - ibgHeader.AppendLine(); + ibgHeader.AppendLine("IBGD"); + ibgHeader.AppendLine(); + ibgHeader.AppendLine("[START_CONFIGURATION]"); + ibgHeader.AppendLine("IBGD_VERSION=2"); + ibgHeader.AppendLine(); + ibgHeader.AppendFormat("DATE={0}", DateTime.Now).AppendLine(); + ibgHeader.AppendLine(); + ibgHeader.AppendFormat("SAMPLE_RATE={0}", 100).AppendLine(); - ibgHeader.AppendFormat("MEDIA_TYPE={0}", ibgMediaType).AppendLine(); - ibgHeader.AppendLine("MEDIA_BOOKTYPE=Unknown"); - ibgHeader.AppendLine("MEDIA_ID=N/A"); - ibgHeader.AppendLine("MEDIA_TRACKPATH=PTP"); - ibgHeader.AppendLine("MEDIA_SPEEDS=N/A"); - ibgHeader.AppendFormat("MEDIA_CAPACITY={0}", blocks).AppendLine(); - ibgHeader.AppendLine("MEDIA_LAYER_BREAK=0"); - ibgHeader.AppendLine(); - ibgHeader.AppendLine("DATA_IMAGEFILE=/dev/null"); - ibgHeader.AppendFormat("DATA_SECTORS={0}", blocks).AppendLine(); - ibgHeader.AppendFormat("DATA_TYPE=MODE1/{0}", blockSize).AppendLine(); - ibgHeader.AppendLine("DATA_VOLUMEIDENTIFIER="); - ibgHeader.AppendLine(); - ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_START={0:0.00}", ibgStartSpeed).AppendLine(); - ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_END={0:0.00}", currentSpeed / ibgDivider).AppendLine(); - ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_AVERAGE={0:0.00}", averageSpeed / ibgDivider) - .AppendLine(); - ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_MAX={0:0.00}", ibgMaxSpeed).AppendLine(); - ibgHeader.AppendFormat(ibgCulture, "VERIFY_TIME_TAKEN={0:0}", Math.Floor(totalSeconds)).AppendLine(); - ibgHeader.AppendLine("[END_CONFIGURATION]"); - ibgHeader.AppendLine(); - ibgHeader.AppendLine("HRPC=True"); - ibgHeader.AppendLine(); - ibgHeader.AppendLine("[START_VERIFY_GRAPH_VALUES]"); - ibgHeader.Append(ibgSb.ToString()); - ibgHeader.AppendLine("[END_VERIFY_GRAPH_VALUES]"); - ibgHeader.AppendLine(); - ibgHeader.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); + ibgHeader.AppendLine(); + ibgHeader.AppendFormat("DEVICE=[0:0:0] {0} {1} ({2}) ({3})", dev.Manufacturer, dev.Model, devicePath, + ibgBusType).AppendLine(); + ibgHeader.AppendLine("DEVICE_ADDRESS=0:0:0"); + ibgHeader.AppendFormat("DEVICE_MAKEMODEL={0} {1}", dev.Manufacturer, dev.Model).AppendLine(); + ibgHeader.AppendFormat("DEVICE_FIRMWAREVERSION={0}", dev.Revision).AppendLine(); + ibgHeader.AppendFormat("DEVICE_DRIVELETTER={0}", devicePath).AppendLine(); + ibgHeader.AppendFormat("DEVICE_BUSTYPE={0}", ibgBusType).AppendLine(); + ibgHeader.AppendLine(); - StreamWriter sr = new StreamWriter(ibgFs); - sr.Write(ibgHeader); - sr.Close(); - ibgFs.Close(); - } + ibgHeader.AppendFormat("MEDIA_TYPE={0}", ibgMediaType).AppendLine(); + ibgHeader.AppendLine("MEDIA_BOOKTYPE=Unknown"); + ibgHeader.AppendLine("MEDIA_ID=N/A"); + ibgHeader.AppendLine("MEDIA_TRACKPATH=PTP"); + ibgHeader.AppendLine("MEDIA_SPEEDS=N/A"); + ibgHeader.AppendFormat("MEDIA_CAPACITY={0}", blocks).AppendLine(); + ibgHeader.AppendLine("MEDIA_LAYER_BREAK=0"); + ibgHeader.AppendLine(); + ibgHeader.AppendLine("DATA_IMAGEFILE=/dev/null"); + ibgHeader.AppendFormat("DATA_SECTORS={0}", blocks).AppendLine(); + ibgHeader.AppendFormat("DATA_TYPE=MODE1/{0}", blockSize).AppendLine(); + ibgHeader.AppendLine("DATA_VOLUMEIDENTIFIER="); + ibgHeader.AppendLine(); + ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_START={0:0.00}", ibgStartSpeed).AppendLine(); + ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_END={0:0.00}", currentSpeed / ibgDivider).AppendLine(); + ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_AVERAGE={0:0.00}", averageSpeed / ibgDivider) + .AppendLine(); + ibgHeader.AppendFormat(ibgCulture, "VERIFY_SPEED_MAX={0:0.00}", ibgMaxSpeed).AppendLine(); + ibgHeader.AppendFormat(ibgCulture, "VERIFY_TIME_TAKEN={0:0}", Math.Floor(totalSeconds)).AppendLine(); + ibgHeader.AppendLine("[END_CONFIGURATION]"); + ibgHeader.AppendLine(); + ibgHeader.AppendLine("HRPC=True"); + ibgHeader.AppendLine(); + ibgHeader.AppendLine("[START_VERIFY_GRAPH_VALUES]"); + ibgHeader.Append(ibgSb.ToString()); + ibgHeader.AppendLine("[END_VERIFY_GRAPH_VALUES]"); + ibgHeader.AppendLine(); + ibgHeader.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); + + StreamWriter sr = new StreamWriter(ibgFs); + sr.Write(ibgHeader); + sr.Close(); + ibgFs.Close(); } } } \ No newline at end of file diff --git a/DiscImageChef.Core/Logging/MHDDLog.cs b/DiscImageChef.Core/Logging/MHDDLog.cs index 6078b1fff..c7a8cfe53 100644 --- a/DiscImageChef.Core/Logging/MHDDLog.cs +++ b/DiscImageChef.Core/Logging/MHDDLog.cs @@ -43,101 +43,99 @@ namespace DiscImageChef.Core.Logging internal MhddLog(string outputFile, Device dev, ulong blocks, ulong blockSize, ulong blocksToRead) { - if(dev != null && !string.IsNullOrEmpty(outputFile)) + if(dev == null || string.IsNullOrEmpty(outputFile)) return; + + mhddFs = new FileStream(outputFile, FileMode.Create); + + string device; + string mode; + string fw; + string sn; + string sectors; + string sectorsize; + string scanblocksize; + string ver; + + switch(dev.Type) { - mhddFs = new FileStream(outputFile, FileMode.Create); - - string device; - string mode; - string fw; - string sn; - string sectors; - string sectorsize; - string scanblocksize; - string ver; - - switch(dev.Type) - { - case DeviceType.ATA: - case DeviceType.ATAPI: - mode = "MODE: IDE"; - break; - case DeviceType.SCSI: - mode = "MODE: SCSI"; - break; - case DeviceType.MMC: - mode = "MODE: MMC"; - break; - case DeviceType.NVMe: - mode = "MODE: NVMe"; - break; - case DeviceType.SecureDigital: - mode = "MODE: SD"; - break; - default: - mode = "MODE: IDE"; - break; - } - - device = string.Format("DEVICE: {0} {1}", dev.Manufacturer, dev.Model); - fw = string.Format("F/W: {0}", dev.Revision); - sn = string.Format("S/N: {0}", dev.Serial); - sectors = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTORS: {0:n0}", blocks); - sectorsize = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTOR SIZE: {0:n0} bytes", - blockSize); - scanblocksize = string.Format(new System.Globalization.CultureInfo("en-US"), - "SCAN BLOCK SIZE: {0:n0} sectors", blocksToRead); - ver = "VER:2 "; - - byte[] deviceBytes = Encoding.ASCII.GetBytes(device); - byte[] modeBytes = Encoding.ASCII.GetBytes(mode); - byte[] fwBytes = Encoding.ASCII.GetBytes(fw); - byte[] snBytes = Encoding.ASCII.GetBytes(sn); - byte[] sectorsBytes = Encoding.ASCII.GetBytes(sectors); - byte[] sectorsizeBytes = Encoding.ASCII.GetBytes(sectorsize); - byte[] scanblocksizeBytes = Encoding.ASCII.GetBytes(scanblocksize); - byte[] verBytes = Encoding.ASCII.GetBytes(ver); - - uint pointer = (uint)(deviceBytes.Length + modeBytes.Length + fwBytes.Length + snBytes.Length + - sectorsBytes.Length + sectorsizeBytes.Length + scanblocksizeBytes.Length + - verBytes.Length + 2 * 9 + // New lines - 4); // Pointer - - byte[] newLine = new byte[2]; - newLine[0] = 0x0D; - newLine[1] = 0x0A; - - mhddFs.Write(BitConverter.GetBytes(pointer), 0, 4); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(verBytes, 0, verBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(modeBytes, 0, modeBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(deviceBytes, 0, deviceBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(fwBytes, 0, fwBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(snBytes, 0, snBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(sectorsBytes, 0, sectorsBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(sectorsizeBytes, 0, sectorsizeBytes.Length); - mhddFs.Write(newLine, 0, 2); - mhddFs.Write(scanblocksizeBytes, 0, scanblocksizeBytes.Length); - mhddFs.Write(newLine, 0, 2); + case DeviceType.ATA: + case DeviceType.ATAPI: + mode = "MODE: IDE"; + break; + case DeviceType.SCSI: + mode = "MODE: SCSI"; + break; + case DeviceType.MMC: + mode = "MODE: MMC"; + break; + case DeviceType.NVMe: + mode = "MODE: NVMe"; + break; + case DeviceType.SecureDigital: + mode = "MODE: SD"; + break; + default: + mode = "MODE: IDE"; + break; } + + device = string.Format("DEVICE: {0} {1}", dev.Manufacturer, dev.Model); + fw = string.Format("F/W: {0}", dev.Revision); + sn = string.Format("S/N: {0}", dev.Serial); + sectors = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTORS: {0:n0}", blocks); + sectorsize = string.Format(new System.Globalization.CultureInfo("en-US"), "SECTOR SIZE: {0:n0} bytes", + blockSize); + scanblocksize = string.Format(new System.Globalization.CultureInfo("en-US"), + "SCAN BLOCK SIZE: {0:n0} sectors", blocksToRead); + ver = "VER:2 "; + + byte[] deviceBytes = Encoding.ASCII.GetBytes(device); + byte[] modeBytes = Encoding.ASCII.GetBytes(mode); + byte[] fwBytes = Encoding.ASCII.GetBytes(fw); + byte[] snBytes = Encoding.ASCII.GetBytes(sn); + byte[] sectorsBytes = Encoding.ASCII.GetBytes(sectors); + byte[] sectorsizeBytes = Encoding.ASCII.GetBytes(sectorsize); + byte[] scanblocksizeBytes = Encoding.ASCII.GetBytes(scanblocksize); + byte[] verBytes = Encoding.ASCII.GetBytes(ver); + + uint pointer = (uint)(deviceBytes.Length + modeBytes.Length + fwBytes.Length + snBytes.Length + + sectorsBytes.Length + sectorsizeBytes.Length + scanblocksizeBytes.Length + + verBytes.Length + 2 * 9 + // New lines + 4); // Pointer + + byte[] newLine = new byte[2]; + newLine[0] = 0x0D; + newLine[1] = 0x0A; + + mhddFs.Write(BitConverter.GetBytes(pointer), 0, 4); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(verBytes, 0, verBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(modeBytes, 0, modeBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(deviceBytes, 0, deviceBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(fwBytes, 0, fwBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(snBytes, 0, snBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(sectorsBytes, 0, sectorsBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(sectorsizeBytes, 0, sectorsizeBytes.Length); + mhddFs.Write(newLine, 0, 2); + mhddFs.Write(scanblocksizeBytes, 0, scanblocksizeBytes.Length); + mhddFs.Write(newLine, 0, 2); } internal void Write(ulong sector, double duration) { - if(mhddFs != null) - { - byte[] sectorBytes = BitConverter.GetBytes(sector); - byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000)); + if(mhddFs == null) return; - mhddFs.Write(sectorBytes, 0, 8); - mhddFs.Write(durationBytes, 0, 8); - } + byte[] sectorBytes = BitConverter.GetBytes(sector); + byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000)); + + mhddFs.Write(sectorBytes, 0, 8); + mhddFs.Write(durationBytes, 0, 8); } internal void Close() diff --git a/DiscImageChef.Core/Partitions.cs b/DiscImageChef.Core/Partitions.cs index d198a7262..ed42061e8 100644 --- a/DiscImageChef.Core/Partitions.cs +++ b/DiscImageChef.Core/Partitions.cs @@ -90,12 +90,12 @@ namespace DiscImageChef.Core foreach(PartitionPlugin _partplugin in plugins.PartPluginsList.Values) { DicConsole.DebugWriteLine("Partitions", "Trying {0} @ {1}", _partplugin.Name, partitions[0].Start); - if(_partplugin.GetInformation(image, out List _partitions, partitions[0].Start)) - { - DicConsole.DebugWriteLine("Partitions", "Found {0} @ {1}", _partplugin.Name, - partitions[0].Start); - childs.AddRange(_partitions); - } + if(!_partplugin.GetInformation(image, out List _partitions, partitions[0].Start)) + continue; + + DicConsole.DebugWriteLine("Partitions", "Found {0} @ {1}", _partplugin.Name, + partitions[0].Start); + childs.AddRange(_partitions); } checkedLocations.Add(partitions[0].Start); diff --git a/DiscImageChef.Core/PluginBase.cs b/DiscImageChef.Core/PluginBase.cs index 731463a1d..3228c1582 100644 --- a/DiscImageChef.Core/PluginBase.cs +++ b/DiscImageChef.Core/PluginBase.cs @@ -63,11 +63,10 @@ namespace DiscImageChef.Core foreach(Type type in assembly.GetTypes()) try { - if(type.IsSubclassOf(typeof(ImagePlugin))) - { - ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); - RegisterImagePlugin(plugin); - } + if(!type.IsSubclassOf(typeof(ImagePlugin))) continue; + + ImagePlugin plugin = (ImagePlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); + RegisterImagePlugin(plugin); } catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } @@ -76,11 +75,10 @@ namespace DiscImageChef.Core foreach(Type type in assembly.GetTypes()) try { - if(type.IsSubclassOf(typeof(PartitionPlugin))) - { - PartitionPlugin plugin = (PartitionPlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); - RegisterPartPlugin(plugin); - } + if(!type.IsSubclassOf(typeof(PartitionPlugin))) continue; + + PartitionPlugin plugin = (PartitionPlugin)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); + RegisterPartPlugin(plugin); } catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } @@ -89,15 +87,14 @@ namespace DiscImageChef.Core foreach(Type type in assembly.GetTypes()) try { - if(type.IsSubclassOf(typeof(Filesystem))) - { - Filesystem plugin; - if(encoding != null) - plugin = (Filesystem)type.GetConstructor(new Type[] {encoding.GetType()}) - .Invoke(new object[] {encoding}); - else plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); - RegisterPlugin(plugin); - } + if(!type.IsSubclassOf(typeof(Filesystem))) continue; + + Filesystem plugin; + if(encoding != null) + plugin = (Filesystem)type.GetConstructor(new Type[] {encoding.GetType()}) + .Invoke(new object[] {encoding}); + else plugin = (Filesystem)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); + RegisterPlugin(plugin); } catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } } diff --git a/DiscImageChef.Core/Sidecar/BlockMedia.cs b/DiscImageChef.Core/Sidecar/BlockMedia.cs index f1a26dbc9..5c6c36749 100644 --- a/DiscImageChef.Core/Sidecar/BlockMedia.cs +++ b/DiscImageChef.Core/Sidecar/BlockMedia.cs @@ -308,12 +308,11 @@ namespace DiscImageChef.Core foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(image, partitions[i])) - { - plugin.GetInformation(image, partitions[i], out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - } + if(!plugin.Identify(image, partitions[i])) continue; + + plugin.GetInformation(image, partitions[i], out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch @@ -342,12 +341,11 @@ namespace DiscImageChef.Core foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(image, wholePart)) - { - plugin.GetInformation(image, wholePart, out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); - } + if(!plugin.Identify(image, wholePart)) continue; + + plugin.GetInformation(image, wholePart, out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch @@ -676,70 +674,68 @@ namespace DiscImageChef.Core string dfiFilePath = Path.Combine(Path.GetDirectoryName(imagePath), Path.GetFileNameWithoutExtension(imagePath) + ".dfi"); - if(File.Exists(dfiFilePath)) - { - DiscImages.DiscFerret dfiImage = new DiscFerret(); - Filters.ZZZNoFilter dfiFilter = new ZZZNoFilter(); - dfiFilter.Open(dfiFilePath); + if(!File.Exists(dfiFilePath)) return; - if(dfiImage.IdentifyImage(dfiFilter)) + DiscImages.DiscFerret dfiImage = new DiscFerret(); + Filters.ZZZNoFilter dfiFilter = new ZZZNoFilter(); + dfiFilter.Open(dfiFilePath); + + if(!dfiImage.IdentifyImage(dfiFilter)) return; + + try { dfiImage.OpenImage(dfiFilter); } + catch(NotImplementedException) { } + + if(image.ImageInfo.Heads == dfiImage.ImageInfo.Heads) + if(dfiImage.ImageInfo.Cylinders >= image.ImageInfo.Cylinders) { - try { dfiImage.OpenImage(dfiFilter); } - catch(NotImplementedException) { } + List dfiBlockTrackTypes = new List(); + long currentSector = 0; + Stream dfiStream = dfiFilter.GetDataForkStream(); - if(image.ImageInfo.Heads == dfiImage.ImageInfo.Heads) - if(dfiImage.ImageInfo.Cylinders >= image.ImageInfo.Cylinders) + foreach(int t in dfiImage.TrackOffsets.Keys) + { + BlockTrackType dfiBlockTrackType = new BlockTrackType(); + dfiBlockTrackType.Cylinder = t / image.ImageInfo.Heads; + dfiBlockTrackType.Head = t % image.ImageInfo.Heads; + dfiBlockTrackType.Image = new ImageType(); + dfiBlockTrackType.Image.format = dfiImage.GetImageFormat(); + dfiBlockTrackType.Image.Value = Path.GetFileName(dfiFilePath); + + if(dfiBlockTrackType.Cylinder < image.ImageInfo.Cylinders) { - List dfiBlockTrackTypes = new List(); - long currentSector = 0; - Stream dfiStream = dfiFilter.GetDataForkStream(); - - foreach(int t in dfiImage.TrackOffsets.Keys) - { - BlockTrackType dfiBlockTrackType = new BlockTrackType(); - dfiBlockTrackType.Cylinder = t / image.ImageInfo.Heads; - dfiBlockTrackType.Head = t % image.ImageInfo.Heads; - dfiBlockTrackType.Image = new ImageType(); - dfiBlockTrackType.Image.format = dfiImage.GetImageFormat(); - dfiBlockTrackType.Image.Value = Path.GetFileName(dfiFilePath); - - if(dfiBlockTrackType.Cylinder < image.ImageInfo.Cylinders) - { - dfiBlockTrackType.StartSector = currentSector; - currentSector += image.ImageInfo.SectorsPerTrack; - dfiBlockTrackType.EndSector = currentSector - 1; - dfiBlockTrackType.Sectors = image.ImageInfo.SectorsPerTrack; - dfiBlockTrackType.BytesPerSector = (int)image.ImageInfo.SectorSize; - dfiBlockTrackType.Format = trkFormat; - } - - if(dfiImage.TrackOffsets.TryGetValue(t, out long offset) && - dfiImage.TrackLengths.TryGetValue(t, out long length)) - { - dfiBlockTrackType.Image.offset = offset; - byte[] trackContents = new byte[length]; - dfiStream.Position = offset; - dfiStream.Read(trackContents, 0, trackContents.Length); - dfiBlockTrackType.Size = trackContents.Length; - dfiBlockTrackType.Checksums = Checksum.GetChecksums(trackContents).ToArray(); - } - - dfiBlockTrackTypes.Add(dfiBlockTrackType); - } - - sidecar.BlockMedia[0].Track = - dfiBlockTrackTypes.OrderBy(t => t.Cylinder).ThenBy(t => t.Head).ToArray(); + dfiBlockTrackType.StartSector = currentSector; + currentSector += image.ImageInfo.SectorsPerTrack; + dfiBlockTrackType.EndSector = currentSector - 1; + dfiBlockTrackType.Sectors = image.ImageInfo.SectorsPerTrack; + dfiBlockTrackType.BytesPerSector = (int)image.ImageInfo.SectorSize; + dfiBlockTrackType.Format = trkFormat; } - else - DicConsole - .ErrorWriteLine("DiscFerret image do not contain same number of tracks ({0}) than disk image ({1}), ignoring...", - dfiImage.ImageInfo.Cylinders, image.ImageInfo.Cylinders); - else - DicConsole - .ErrorWriteLine("DiscFerret image do not contain same number of heads ({0}) than disk image ({1}), ignoring...", - dfiImage.ImageInfo.Heads, image.ImageInfo.Heads); + + if(dfiImage.TrackOffsets.TryGetValue(t, out long offset) && + dfiImage.TrackLengths.TryGetValue(t, out long length)) + { + dfiBlockTrackType.Image.offset = offset; + byte[] trackContents = new byte[length]; + dfiStream.Position = offset; + dfiStream.Read(trackContents, 0, trackContents.Length); + dfiBlockTrackType.Size = trackContents.Length; + dfiBlockTrackType.Checksums = Checksum.GetChecksums(trackContents).ToArray(); + } + + dfiBlockTrackTypes.Add(dfiBlockTrackType); + } + + sidecar.BlockMedia[0].Track = + dfiBlockTrackTypes.OrderBy(t => t.Cylinder).ThenBy(t => t.Head).ToArray(); } - } + else + DicConsole + .ErrorWriteLine("DiscFerret image do not contain same number of tracks ({0}) than disk image ({1}), ignoring...", + dfiImage.ImageInfo.Cylinders, image.ImageInfo.Cylinders); + else + DicConsole + .ErrorWriteLine("DiscFerret image do not contain same number of heads ({0}) than disk image ({1}), ignoring...", + dfiImage.ImageInfo.Heads, image.ImageInfo.Heads); #endregion // TODO: Implement support for getting CHS from SCSI mode pages diff --git a/DiscImageChef.Core/Sidecar/OpticalDisc.cs b/DiscImageChef.Core/Sidecar/OpticalDisc.cs index 8940cb2ba..d53340f04 100644 --- a/DiscImageChef.Core/Sidecar/OpticalDisc.cs +++ b/DiscImageChef.Core/Sidecar/OpticalDisc.cs @@ -465,22 +465,21 @@ namespace DiscImageChef.Core foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(image, partitions[i])) - { - plugin.GetInformation(image, partitions[i], out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); + if(!plugin.Identify(image, partitions[i])) continue; - switch(plugin.XmlFSType.Type) { - case "Opera": dskType = MediaType.ThreeDO; - break; - case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; - break; - case "Nintendo Wii filesystem": dskType = MediaType.WOD; - break; - case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; - break; - } + plugin.GetInformation(image, partitions[i], out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body @@ -513,22 +512,21 @@ namespace DiscImageChef.Core foreach(Filesystem plugin in plugins.PluginsList.Values) try { - if(plugin.Identify(image, xmlPart)) - { - plugin.GetInformation(image, xmlPart, out string foo); - lstFs.Add(plugin.XmlFSType); - Statistics.AddFilesystem(plugin.XmlFSType.Type); + if(!plugin.Identify(image, xmlPart)) continue; - switch(plugin.XmlFSType.Type) { - case "Opera": dskType = MediaType.ThreeDO; - break; - case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; - break; - case "Nintendo Wii filesystem": dskType = MediaType.WOD; - break; - case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; - break; - } + plugin.GetInformation(image, xmlPart, out string foo); + lstFs.Add(plugin.XmlFSType); + Statistics.AddFilesystem(plugin.XmlFSType.Type); + + switch(plugin.XmlFSType.Type) { + case "Opera": dskType = MediaType.ThreeDO; + break; + case "PC Engine filesystem": dskType = MediaType.SuperCDROM2; + break; + case "Nintendo Wii filesystem": dskType = MediaType.WOD; + break; + case "Nintendo Gamecube filesystem": dskType = MediaType.GOD; + break; } } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body diff --git a/DiscImageChef.Core/Statistics.cs b/DiscImageChef.Core/Statistics.cs index 405d26872..992b256fe 100644 --- a/DiscImageChef.Core/Statistics.cs +++ b/DiscImageChef.Core/Statistics.cs @@ -98,72 +98,71 @@ namespace DiscImageChef.Core public static void SaveStats() { - if(AllStats != null) + if(AllStats == null) return; + + if(AllStats.OperatingSystems != null) { - if(AllStats.OperatingSystems != null) - { - long count = 0; + long count = 0; - OsStats old = null; - foreach(OsStats nvs in AllStats.OperatingSystems) - if(nvs.name == Interop.DetectOS.GetRealPlatformID().ToString() && - nvs.version == Interop.DetectOS.GetVersion()) - { - count = nvs.Value + 1; - old = nvs; - break; - } - - if(old != null) AllStats.OperatingSystems.Remove(old); - - count++; - AllStats.OperatingSystems.Add(new OsStats + OsStats old = null; + foreach(OsStats nvs in AllStats.OperatingSystems) + if(nvs.name == Interop.DetectOS.GetRealPlatformID().ToString() && + nvs.version == Interop.DetectOS.GetVersion()) { - name = Interop.DetectOS.GetRealPlatformID().ToString(), - Value = count, - version = Interop.DetectOS.GetVersion() - }); - } - else if(CurrentStats != null) AllStats.OperatingSystems = CurrentStats.OperatingSystems; + count = nvs.Value + 1; + old = nvs; + break; + } - if(AllStats.Versions != null) + if(old != null) AllStats.OperatingSystems.Remove(old); + + count++; + AllStats.OperatingSystems.Add(new OsStats { - long count = 0; - - NameValueStats old = null; - foreach(NameValueStats nvs in AllStats.Versions) - if(nvs.name == Version.GetVersion()) - { - count = nvs.Value + 1; - old = nvs; - break; - } - - if(old != null) AllStats.Versions.Remove(old); - - count++; - AllStats.Versions.Add(new NameValueStats {name = Version.GetVersion(), Value = count}); - } - else if(CurrentStats != null) AllStats.Versions = CurrentStats.Versions; - - FileStream fs = new FileStream(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml"), - FileMode.Create); - XmlSerializer xs = new XmlSerializer(AllStats.GetType()); - xs.Serialize(fs, AllStats); - fs.Close(); - - if(CurrentStats != null) - { - string partial = string.Format("PartialStats_{0:yyyyMMddHHmmssfff}.xml", DateTime.UtcNow); - - fs = new FileStream(Path.Combine(Settings.Settings.StatsPath, partial), FileMode.Create); - xs = new XmlSerializer(CurrentStats.GetType()); - xs.Serialize(fs, CurrentStats); - fs.Close(); - } - - if(Settings.Settings.Current.Stats.ShareStats) SubmitStats(); + name = Interop.DetectOS.GetRealPlatformID().ToString(), + Value = count, + version = Interop.DetectOS.GetVersion() + }); } + else if(CurrentStats != null) AllStats.OperatingSystems = CurrentStats.OperatingSystems; + + if(AllStats.Versions != null) + { + long count = 0; + + NameValueStats old = null; + foreach(NameValueStats nvs in AllStats.Versions) + if(nvs.name == Version.GetVersion()) + { + count = nvs.Value + 1; + old = nvs; + break; + } + + if(old != null) AllStats.Versions.Remove(old); + + count++; + AllStats.Versions.Add(new NameValueStats {name = Version.GetVersion(), Value = count}); + } + else if(CurrentStats != null) AllStats.Versions = CurrentStats.Versions; + + FileStream fs = new FileStream(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml"), + FileMode.Create); + XmlSerializer xs = new XmlSerializer(AllStats.GetType()); + xs.Serialize(fs, AllStats); + fs.Close(); + + if(CurrentStats != null) + { + string partial = string.Format("PartialStats_{0:yyyyMMddHHmmssfff}.xml", DateTime.UtcNow); + + fs = new FileStream(Path.Combine(Settings.Settings.StatsPath, partial), FileMode.Create); + xs = new XmlSerializer(CurrentStats.GetType()); + xs.Serialize(fs, CurrentStats); + fs.Close(); + } + + if(Settings.Settings.Current.Stats.ShareStats) SubmitStats(); } public static void SubmitStats() @@ -240,529 +239,519 @@ namespace DiscImageChef.Core public static void AddCommand(string command) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.DeviceStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.DeviceStats) return; + + if(AllStats.Commands == null) AllStats.Commands = new CommandsStats(); + + if(CurrentStats.Commands == null) CurrentStats.Commands = new CommandsStats(); + + switch(command) { - if(AllStats.Commands == null) AllStats.Commands = new CommandsStats(); - - if(CurrentStats.Commands == null) CurrentStats.Commands = new CommandsStats(); - - switch(command) - { - case "analyze": - AllStats.Commands.Analyze++; - CurrentStats.Commands.Analyze++; - break; - case "benchmark": - AllStats.Commands.Benchmark++; - CurrentStats.Commands.Benchmark++; - break; - case "checksum": - AllStats.Commands.Checksum++; - CurrentStats.Commands.Checksum++; - break; - case "compare": - AllStats.Commands.Compare++; - CurrentStats.Commands.Compare++; - break; - case "create-sidecar": - AllStats.Commands.CreateSidecar++; - CurrentStats.Commands.CreateSidecar++; - break; - case "decode": - AllStats.Commands.Decode++; - CurrentStats.Commands.Decode++; - break; - case "device-info": - AllStats.Commands.DeviceInfo++; - CurrentStats.Commands.DeviceInfo++; - break; - case "device-report": - AllStats.Commands.DeviceReport++; - CurrentStats.Commands.DeviceReport++; - break; - case "dump-media": - AllStats.Commands.DumpMedia++; - CurrentStats.Commands.DumpMedia++; - break; - case "entropy": - AllStats.Commands.Entropy++; - CurrentStats.Commands.Entropy++; - break; - case "extract-files": - AllStats.Commands.ExtractFiles++; - CurrentStats.Commands.ExtractFiles++; - break; - case "formats": - AllStats.Commands.Formats++; - CurrentStats.Commands.Formats++; - break; - case "ls": - AllStats.Commands.Ls++; - CurrentStats.Commands.Ls++; - break; - case "media-info": - AllStats.Commands.MediaInfo++; - CurrentStats.Commands.MediaInfo++; - break; - case "media-scan": - AllStats.Commands.MediaScan++; - CurrentStats.Commands.MediaScan++; - break; - case "print-hex": - AllStats.Commands.PrintHex++; - CurrentStats.Commands.PrintHex++; - break; - case "verify": - AllStats.Commands.Verify++; - CurrentStats.Commands.Verify++; - break; - case "list-devices": - AllStats.Commands.ListDevices++; - CurrentStats.Commands.ListDevices++; - break; - case "list-encodings": - AllStats.Commands.ListEncodings++; - CurrentStats.Commands.ListEncodings++; - break; - } + case "analyze": + AllStats.Commands.Analyze++; + CurrentStats.Commands.Analyze++; + break; + case "benchmark": + AllStats.Commands.Benchmark++; + CurrentStats.Commands.Benchmark++; + break; + case "checksum": + AllStats.Commands.Checksum++; + CurrentStats.Commands.Checksum++; + break; + case "compare": + AllStats.Commands.Compare++; + CurrentStats.Commands.Compare++; + break; + case "create-sidecar": + AllStats.Commands.CreateSidecar++; + CurrentStats.Commands.CreateSidecar++; + break; + case "decode": + AllStats.Commands.Decode++; + CurrentStats.Commands.Decode++; + break; + case "device-info": + AllStats.Commands.DeviceInfo++; + CurrentStats.Commands.DeviceInfo++; + break; + case "device-report": + AllStats.Commands.DeviceReport++; + CurrentStats.Commands.DeviceReport++; + break; + case "dump-media": + AllStats.Commands.DumpMedia++; + CurrentStats.Commands.DumpMedia++; + break; + case "entropy": + AllStats.Commands.Entropy++; + CurrentStats.Commands.Entropy++; + break; + case "extract-files": + AllStats.Commands.ExtractFiles++; + CurrentStats.Commands.ExtractFiles++; + break; + case "formats": + AllStats.Commands.Formats++; + CurrentStats.Commands.Formats++; + break; + case "ls": + AllStats.Commands.Ls++; + CurrentStats.Commands.Ls++; + break; + case "media-info": + AllStats.Commands.MediaInfo++; + CurrentStats.Commands.MediaInfo++; + break; + case "media-scan": + AllStats.Commands.MediaScan++; + CurrentStats.Commands.MediaScan++; + break; + case "print-hex": + AllStats.Commands.PrintHex++; + CurrentStats.Commands.PrintHex++; + break; + case "verify": + AllStats.Commands.Verify++; + CurrentStats.Commands.Verify++; + break; + case "list-devices": + AllStats.Commands.ListDevices++; + CurrentStats.Commands.ListDevices++; + break; + case "list-encodings": + AllStats.Commands.ListEncodings++; + CurrentStats.Commands.ListEncodings++; + break; } } public static void AddFilesystem(string filesystem) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.FilesystemStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilesystemStats) return; + + if(AllStats.Filesystems == null) AllStats.Filesystems = new List(); + if(CurrentStats.Filesystems == null) CurrentStats.Filesystems = new List(); + + NameValueStats old = null; + foreach(NameValueStats nvs in AllStats.Filesystems) + if(nvs.name == filesystem) + { + old = nvs; + break; + } + + NameValueStats nw = new NameValueStats(); + if(old != null) { - if(AllStats.Filesystems == null) AllStats.Filesystems = new List(); - if(CurrentStats.Filesystems == null) CurrentStats.Filesystems = new List(); - - NameValueStats old = null; - foreach(NameValueStats nvs in AllStats.Filesystems) - if(nvs.name == filesystem) - { - old = nvs; - break; - } - - NameValueStats nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - AllStats.Filesystems.Remove(old); - } - else - { - nw.name = filesystem; - nw.Value = 1; - } - AllStats.Filesystems.Add(nw); - - old = null; - foreach(NameValueStats nvs in CurrentStats.Filesystems) - if(nvs.name == filesystem) - { - old = nvs; - break; - } - - nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - CurrentStats.Filesystems.Remove(old); - } - else - { - nw.name = filesystem; - nw.Value = 1; - } - CurrentStats.Filesystems.Add(nw); + nw.name = old.name; + nw.Value = old.Value + 1; + AllStats.Filesystems.Remove(old); } + else + { + nw.name = filesystem; + nw.Value = 1; + } + AllStats.Filesystems.Add(nw); + + old = null; + foreach(NameValueStats nvs in CurrentStats.Filesystems) + if(nvs.name == filesystem) + { + old = nvs; + break; + } + + nw = new NameValueStats(); + if(old != null) + { + nw.name = old.name; + nw.Value = old.Value + 1; + CurrentStats.Filesystems.Remove(old); + } + else + { + nw.name = filesystem; + nw.Value = 1; + } + CurrentStats.Filesystems.Add(nw); } public static void AddPartition(string partition) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.PartitionStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.PartitionStats) return; + + if(AllStats.Partitions == null) AllStats.Partitions = new List(); + if(CurrentStats.Partitions == null) CurrentStats.Partitions = new List(); + + NameValueStats old = null; + foreach(NameValueStats nvs in AllStats.Partitions) + if(nvs.name == partition) + { + old = nvs; + break; + } + + NameValueStats nw = new NameValueStats(); + if(old != null) { - if(AllStats.Partitions == null) AllStats.Partitions = new List(); - if(CurrentStats.Partitions == null) CurrentStats.Partitions = new List(); - - NameValueStats old = null; - foreach(NameValueStats nvs in AllStats.Partitions) - if(nvs.name == partition) - { - old = nvs; - break; - } - - NameValueStats nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - AllStats.Partitions.Remove(old); - } - else - { - nw.name = partition; - nw.Value = 1; - } - AllStats.Partitions.Add(nw); - - old = null; - foreach(NameValueStats nvs in CurrentStats.Partitions) - if(nvs.name == partition) - { - old = nvs; - break; - } - - nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - CurrentStats.Partitions.Remove(old); - } - else - { - nw.name = partition; - nw.Value = 1; - } - CurrentStats.Partitions.Add(nw); + nw.name = old.name; + nw.Value = old.Value + 1; + AllStats.Partitions.Remove(old); } + else + { + nw.name = partition; + nw.Value = 1; + } + AllStats.Partitions.Add(nw); + + old = null; + foreach(NameValueStats nvs in CurrentStats.Partitions) + if(nvs.name == partition) + { + old = nvs; + break; + } + + nw = new NameValueStats(); + if(old != null) + { + nw.name = old.name; + nw.Value = old.Value + 1; + CurrentStats.Partitions.Remove(old); + } + else + { + nw.name = partition; + nw.Value = 1; + } + CurrentStats.Partitions.Add(nw); } public static void AddFilter(string format) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.FilterStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilterStats) return; + + if(AllStats.Filters == null) AllStats.Filters = new List(); + if(CurrentStats.Filters == null) CurrentStats.Filters = new List(); + + NameValueStats old = null; + foreach(NameValueStats nvs in AllStats.Filters) + if(nvs.name == format) + { + old = nvs; + break; + } + + NameValueStats nw = new NameValueStats(); + if(old != null) { - if(AllStats.Filters == null) AllStats.Filters = new List(); - if(CurrentStats.Filters == null) CurrentStats.Filters = new List(); - - NameValueStats old = null; - foreach(NameValueStats nvs in AllStats.Filters) - if(nvs.name == format) - { - old = nvs; - break; - } - - NameValueStats nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - AllStats.Filters.Remove(old); - } - else - { - nw.name = format; - nw.Value = 1; - } - AllStats.Filters.Add(nw); - - old = null; - foreach(NameValueStats nvs in CurrentStats.Filters) - if(nvs.name == format) - { - old = nvs; - break; - } - - nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - CurrentStats.Filters.Remove(old); - } - else - { - nw.name = format; - nw.Value = 1; - } - CurrentStats.Filters.Add(nw); + nw.name = old.name; + nw.Value = old.Value + 1; + AllStats.Filters.Remove(old); } + else + { + nw.name = format; + nw.Value = 1; + } + AllStats.Filters.Add(nw); + + old = null; + foreach(NameValueStats nvs in CurrentStats.Filters) + if(nvs.name == format) + { + old = nvs; + break; + } + + nw = new NameValueStats(); + if(old != null) + { + nw.name = old.name; + nw.Value = old.Value + 1; + CurrentStats.Filters.Remove(old); + } + else + { + nw.name = format; + nw.Value = 1; + } + CurrentStats.Filters.Add(nw); } public static void AddMediaFormat(string format) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.MediaImageStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaImageStats) return; + + if(AllStats.MediaImages == null) AllStats.MediaImages = new List(); + if(CurrentStats.MediaImages == null) CurrentStats.MediaImages = new List(); + + NameValueStats old = null; + foreach(NameValueStats nvs in AllStats.MediaImages) + if(nvs.name == format) + { + old = nvs; + break; + } + + NameValueStats nw = new NameValueStats(); + if(old != null) { - if(AllStats.MediaImages == null) AllStats.MediaImages = new List(); - if(CurrentStats.MediaImages == null) CurrentStats.MediaImages = new List(); - - NameValueStats old = null; - foreach(NameValueStats nvs in AllStats.MediaImages) - if(nvs.name == format) - { - old = nvs; - break; - } - - NameValueStats nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - AllStats.MediaImages.Remove(old); - } - else - { - nw.name = format; - nw.Value = 1; - } - AllStats.MediaImages.Add(nw); - - old = null; - foreach(NameValueStats nvs in CurrentStats.MediaImages) - if(nvs.name == format) - { - old = nvs; - break; - } - - nw = new NameValueStats(); - if(old != null) - { - nw.name = old.name; - nw.Value = old.Value + 1; - CurrentStats.MediaImages.Remove(old); - } - else - { - nw.name = format; - nw.Value = 1; - } - CurrentStats.MediaImages.Add(nw); + nw.name = old.name; + nw.Value = old.Value + 1; + AllStats.MediaImages.Remove(old); } + else + { + nw.name = format; + nw.Value = 1; + } + AllStats.MediaImages.Add(nw); + + old = null; + foreach(NameValueStats nvs in CurrentStats.MediaImages) + if(nvs.name == format) + { + old = nvs; + break; + } + + nw = new NameValueStats(); + if(old != null) + { + nw.name = old.name; + nw.Value = old.Value + 1; + CurrentStats.MediaImages.Remove(old); + } + else + { + nw.name = format; + nw.Value = 1; + } + CurrentStats.MediaImages.Add(nw); } public static void AddDevice(DiscImageChef.Devices.Device dev) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.DeviceStats) - { - if(AllStats.Devices == null) AllStats.Devices = new List(); - if(CurrentStats.Devices == null) CurrentStats.Devices = new List(); + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.DeviceStats) return; - string deviceBus; - if(dev.IsUsb) deviceBus = "USB"; - else if(dev.IsFireWire) deviceBus = "FireWire"; - else deviceBus = dev.Type.ToString(); + if(AllStats.Devices == null) AllStats.Devices = new List(); + if(CurrentStats.Devices == null) CurrentStats.Devices = new List(); - DeviceStats old = null; - foreach(DeviceStats ds in AllStats.Devices) - if(ds.Manufacturer == dev.Manufacturer && ds.Model == dev.Model && ds.Revision == dev.Revision && - ds.Bus == deviceBus) - { - old = ds; - break; - } + string deviceBus; + if(dev.IsUsb) deviceBus = "USB"; + else if(dev.IsFireWire) deviceBus = "FireWire"; + else deviceBus = dev.Type.ToString(); - if(old != null) AllStats.Devices.Remove(old); + DeviceStats old = null; + foreach(DeviceStats ds in AllStats.Devices) + if(ds.Manufacturer == dev.Manufacturer && ds.Model == dev.Model && ds.Revision == dev.Revision && + ds.Bus == deviceBus) + { + old = ds; + break; + } - DeviceStats nw = new DeviceStats(); - nw.Model = dev.Model; - nw.Manufacturer = dev.Manufacturer; - nw.Revision = dev.Revision; - nw.Bus = deviceBus; - nw.ManufacturerSpecified = true; - AllStats.Devices.Add(nw); + if(old != null) AllStats.Devices.Remove(old); - old = null; - foreach(DeviceStats ds in CurrentStats.Devices) - if(ds.Manufacturer == dev.Manufacturer && ds.Model == dev.Model && ds.Revision == dev.Revision && - ds.Bus == deviceBus) - { - old = ds; - break; - } + DeviceStats nw = new DeviceStats(); + nw.Model = dev.Model; + nw.Manufacturer = dev.Manufacturer; + nw.Revision = dev.Revision; + nw.Bus = deviceBus; + nw.ManufacturerSpecified = true; + AllStats.Devices.Add(nw); - if(old != null) CurrentStats.Devices.Remove(old); + old = null; + foreach(DeviceStats ds in CurrentStats.Devices) + if(ds.Manufacturer == dev.Manufacturer && ds.Model == dev.Model && ds.Revision == dev.Revision && + ds.Bus == deviceBus) + { + old = ds; + break; + } - nw = new DeviceStats(); - nw.Model = dev.Model; - nw.Manufacturer = dev.Manufacturer; - nw.Revision = dev.Revision; - nw.Bus = deviceBus; - nw.ManufacturerSpecified = true; - CurrentStats.Devices.Add(nw); - } + if(old != null) CurrentStats.Devices.Remove(old); + + nw = new DeviceStats(); + nw.Model = dev.Model; + nw.Manufacturer = dev.Manufacturer; + nw.Revision = dev.Revision; + nw.Bus = deviceBus; + nw.ManufacturerSpecified = true; + CurrentStats.Devices.Add(nw); } public static void AddMedia(CommonTypes.MediaType type, bool real) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.MediaStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaStats) return; + + if(AllStats.Medias == null) AllStats.Medias = new List(); + if(CurrentStats.Medias == null) CurrentStats.Medias = new List(); + + MediaStats old = null; + foreach(MediaStats ms in AllStats.Medias) + if(ms.real == real && ms.type == type.ToString()) + { + old = ms; + break; + } + + MediaStats nw = new MediaStats(); + if(old != null) { - if(AllStats.Medias == null) AllStats.Medias = new List(); - if(CurrentStats.Medias == null) CurrentStats.Medias = new List(); - - MediaStats old = null; - foreach(MediaStats ms in AllStats.Medias) - if(ms.real == real && ms.type == type.ToString()) - { - old = ms; - break; - } - - MediaStats nw = new MediaStats(); - if(old != null) - { - nw.type = old.type; - nw.real = old.real; - nw.Value = old.Value + 1; - AllStats.Medias.Remove(old); - } - else - { - nw.type = type.ToString(); - nw.real = real; - nw.Value = 1; - } - AllStats.Medias.Add(nw); - - old = null; - foreach(MediaStats ms in CurrentStats.Medias) - if(ms.real == real && ms.type == type.ToString()) - { - old = ms; - break; - } - - nw = new MediaStats(); - if(old != null) - { - nw.type = old.type; - nw.real = old.real; - nw.Value = old.Value + 1; - CurrentStats.Medias.Remove(old); - } - else - { - nw.type = type.ToString(); - nw.real = real; - nw.Value = 1; - } - CurrentStats.Medias.Add(nw); + nw.type = old.type; + nw.real = old.real; + nw.Value = old.Value + 1; + AllStats.Medias.Remove(old); } + else + { + nw.type = type.ToString(); + nw.real = real; + nw.Value = 1; + } + AllStats.Medias.Add(nw); + + old = null; + foreach(MediaStats ms in CurrentStats.Medias) + if(ms.real == real && ms.type == type.ToString()) + { + old = ms; + break; + } + + nw = new MediaStats(); + if(old != null) + { + nw.type = old.type; + nw.real = old.real; + nw.Value = old.Value + 1; + CurrentStats.Medias.Remove(old); + } + else + { + nw.type = type.ToString(); + nw.real = real; + nw.Value = 1; + } + CurrentStats.Medias.Add(nw); } public static void AddBenchmark(Dictionary checksums, double entropy, double all, double sequential, long maxMemory, long minMemory) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.BenchmarkStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.BenchmarkStats) return; + + CurrentStats.Benchmark = new BenchmarkStats(); + CurrentStats.Benchmark.Checksum = new List(); + AllStats.Benchmark = new BenchmarkStats(); + AllStats.Benchmark.Checksum = new List(); + + foreach(KeyValuePair kvp in checksums) { - CurrentStats.Benchmark = new BenchmarkStats(); - CurrentStats.Benchmark.Checksum = new List(); - AllStats.Benchmark = new BenchmarkStats(); - AllStats.Benchmark.Checksum = new List(); - - foreach(KeyValuePair kvp in checksums) - { - ChecksumStats st = new ChecksumStats(); - st.algorithm = kvp.Key; - st.Value = kvp.Value; - CurrentStats.Benchmark.Checksum.Add(st); - AllStats.Benchmark.Checksum.Add(st); - } - - CurrentStats.Benchmark.All = all; - CurrentStats.Benchmark.Entropy = entropy; - CurrentStats.Benchmark.MaxMemory = maxMemory; - CurrentStats.Benchmark.MinMemory = minMemory; - CurrentStats.Benchmark.Sequential = sequential; - - AllStats.Benchmark.All = all; - AllStats.Benchmark.Entropy = entropy; - AllStats.Benchmark.MaxMemory = maxMemory; - AllStats.Benchmark.MinMemory = minMemory; - AllStats.Benchmark.Sequential = sequential; + ChecksumStats st = new ChecksumStats(); + st.algorithm = kvp.Key; + st.Value = kvp.Value; + CurrentStats.Benchmark.Checksum.Add(st); + AllStats.Benchmark.Checksum.Add(st); } + + CurrentStats.Benchmark.All = all; + CurrentStats.Benchmark.Entropy = entropy; + CurrentStats.Benchmark.MaxMemory = maxMemory; + CurrentStats.Benchmark.MinMemory = minMemory; + CurrentStats.Benchmark.Sequential = sequential; + + AllStats.Benchmark.All = all; + AllStats.Benchmark.Entropy = entropy; + AllStats.Benchmark.MaxMemory = maxMemory; + AllStats.Benchmark.MinMemory = minMemory; + AllStats.Benchmark.Sequential = sequential; } public static void AddVerify(bool? mediaVerified, long correct, long failed, long unknown, long total) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.VerifyStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.VerifyStats) return; + + if(CurrentStats.Verify == null) { - if(CurrentStats.Verify == null) - { - CurrentStats.Verify = new VerifyStats(); - CurrentStats.Verify.MediaImages = new VerifiedItems(); - CurrentStats.Verify.Sectors = new ScannedSectors(); - } - - if(AllStats.Verify == null) - { - AllStats.Verify = new VerifyStats(); - AllStats.Verify.MediaImages = new VerifiedItems(); - AllStats.Verify.Sectors = new ScannedSectors(); - } - - if(mediaVerified.HasValue) - if(mediaVerified.Value) - { - CurrentStats.Verify.MediaImages.Correct++; - AllStats.Verify.MediaImages.Correct++; - } - else - { - CurrentStats.Verify.MediaImages.Failed++; - AllStats.Verify.MediaImages.Failed++; - } - - CurrentStats.Verify.Sectors.Correct += correct; - CurrentStats.Verify.Sectors.Error += failed; - CurrentStats.Verify.Sectors.Unverifiable += unknown; - CurrentStats.Verify.Sectors.Total += total; - - AllStats.Verify.Sectors.Correct += correct; - AllStats.Verify.Sectors.Error += failed; - AllStats.Verify.Sectors.Unverifiable += unknown; - AllStats.Verify.Sectors.Total += total; + CurrentStats.Verify = new VerifyStats(); + CurrentStats.Verify.MediaImages = new VerifiedItems(); + CurrentStats.Verify.Sectors = new ScannedSectors(); } + + if(AllStats.Verify == null) + { + AllStats.Verify = new VerifyStats(); + AllStats.Verify.MediaImages = new VerifiedItems(); + AllStats.Verify.Sectors = new ScannedSectors(); + } + + if(mediaVerified.HasValue) + if(mediaVerified.Value) + { + CurrentStats.Verify.MediaImages.Correct++; + AllStats.Verify.MediaImages.Correct++; + } + else + { + CurrentStats.Verify.MediaImages.Failed++; + AllStats.Verify.MediaImages.Failed++; + } + + CurrentStats.Verify.Sectors.Correct += correct; + CurrentStats.Verify.Sectors.Error += failed; + CurrentStats.Verify.Sectors.Unverifiable += unknown; + CurrentStats.Verify.Sectors.Total += total; + + AllStats.Verify.Sectors.Correct += correct; + AllStats.Verify.Sectors.Error += failed; + AllStats.Verify.Sectors.Unverifiable += unknown; + AllStats.Verify.Sectors.Total += total; } public static void AddMediaScan(long lessThan3ms, long lessThan10ms, long lessThan50ms, long lessThan150ms, long lessThan500ms, long moreThan500ms, long total, long error, long correct) { - if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.MediaScanStats) + if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaScanStats) return; + + if(CurrentStats.MediaScan == null) { - if(CurrentStats.MediaScan == null) - { - CurrentStats.MediaScan = new MediaScanStats(); - CurrentStats.MediaScan.Sectors = new ScannedSectors(); - CurrentStats.MediaScan.Times = new TimeStats(); - } - - if(AllStats.MediaScan == null) - { - AllStats.MediaScan = new MediaScanStats(); - AllStats.MediaScan.Sectors = new ScannedSectors(); - AllStats.MediaScan.Times = new TimeStats(); - } - - CurrentStats.MediaScan.Sectors.Correct += correct; - CurrentStats.MediaScan.Sectors.Error += error; - CurrentStats.MediaScan.Sectors.Total += total; - CurrentStats.MediaScan.Times.LessThan3ms += lessThan3ms; - CurrentStats.MediaScan.Times.LessThan10ms += lessThan10ms; - CurrentStats.MediaScan.Times.LessThan50ms += lessThan50ms; - CurrentStats.MediaScan.Times.LessThan150ms += lessThan150ms; - CurrentStats.MediaScan.Times.LessThan500ms += lessThan500ms; - CurrentStats.MediaScan.Times.MoreThan500ms += moreThan500ms; - - AllStats.MediaScan.Sectors.Correct += correct; - AllStats.MediaScan.Sectors.Error += error; - AllStats.MediaScan.Sectors.Total += total; - AllStats.MediaScan.Times.LessThan3ms += lessThan3ms; - AllStats.MediaScan.Times.LessThan10ms += lessThan10ms; - AllStats.MediaScan.Times.LessThan50ms += lessThan50ms; - AllStats.MediaScan.Times.LessThan150ms += lessThan150ms; - AllStats.MediaScan.Times.LessThan500ms += lessThan500ms; - AllStats.MediaScan.Times.MoreThan500ms += moreThan500ms; + CurrentStats.MediaScan = new MediaScanStats(); + CurrentStats.MediaScan.Sectors = new ScannedSectors(); + CurrentStats.MediaScan.Times = new TimeStats(); } + + if(AllStats.MediaScan == null) + { + AllStats.MediaScan = new MediaScanStats(); + AllStats.MediaScan.Sectors = new ScannedSectors(); + AllStats.MediaScan.Times = new TimeStats(); + } + + CurrentStats.MediaScan.Sectors.Correct += correct; + CurrentStats.MediaScan.Sectors.Error += error; + CurrentStats.MediaScan.Sectors.Total += total; + CurrentStats.MediaScan.Times.LessThan3ms += lessThan3ms; + CurrentStats.MediaScan.Times.LessThan10ms += lessThan10ms; + CurrentStats.MediaScan.Times.LessThan50ms += lessThan50ms; + CurrentStats.MediaScan.Times.LessThan150ms += lessThan150ms; + CurrentStats.MediaScan.Times.LessThan500ms += lessThan500ms; + CurrentStats.MediaScan.Times.MoreThan500ms += moreThan500ms; + + AllStats.MediaScan.Sectors.Correct += correct; + AllStats.MediaScan.Sectors.Error += error; + AllStats.MediaScan.Sectors.Total += total; + AllStats.MediaScan.Times.LessThan3ms += lessThan3ms; + AllStats.MediaScan.Times.LessThan10ms += lessThan10ms; + AllStats.MediaScan.Times.LessThan50ms += lessThan50ms; + AllStats.MediaScan.Times.LessThan150ms += lessThan150ms; + AllStats.MediaScan.Times.LessThan500ms += lessThan500ms; + AllStats.MediaScan.Times.MoreThan500ms += moreThan500ms; } } } \ No newline at end of file diff --git a/DiscImageChef.Decoders/Blu-ray/DI.cs b/DiscImageChef.Decoders/Blu-ray/DI.cs index e7546df0d..24d5938c9 100644 --- a/DiscImageChef.Decoders/Blu-ray/DI.cs +++ b/DiscImageChef.Decoders/Blu-ray/DI.cs @@ -142,11 +142,10 @@ namespace DiscImageChef.Decoders.Bluray offset += unit.Length; } - if(units.Count > 0) - { - decoded.Units = new DiscInformationUnits[units.Count]; - for(int i = 0; i < units.Count; i++) decoded.Units[i] = units[i]; - } + if(units.Count <= 0) return decoded; + + decoded.Units = new DiscInformationUnits[units.Count]; + for(int i = 0; i < units.Count; i++) decoded.Units[i] = units[i]; return decoded; } diff --git a/DiscImageChef.Decoders/CD/ATIP.cs b/DiscImageChef.Decoders/CD/ATIP.cs index 816856b05..2867657ea 100644 --- a/DiscImageChef.Decoders/CD/ATIP.cs +++ b/DiscImageChef.Decoders/CD/ATIP.cs @@ -272,12 +272,11 @@ namespace DiscImageChef.Decoders.CD decoded.Reserved8 = CDATIPResponse[23]; decoded.Reserved9 = CDATIPResponse[27]; - if(CDATIPResponse.Length >= 32) - { - decoded.S4Values = new byte[3]; - Array.Copy(CDATIPResponse, 28, decoded.S4Values, 0, 3); - decoded.Reserved10 = CDATIPResponse[31]; - } + if(CDATIPResponse.Length < 32) return decoded; + + decoded.S4Values = new byte[3]; + Array.Copy(CDATIPResponse, 28, decoded.S4Values, 0, 3); + decoded.Reserved10 = CDATIPResponse[31]; return decoded; } @@ -425,24 +424,23 @@ namespace DiscImageChef.Decoders.CD .AppendLine(); } - if(response.LeadInStartMin == 97) + if(response.LeadInStartMin != 97) return sb.ToString(); + + int type = response.LeadInStartFrame % 10; + int frm = response.LeadInStartFrame - type; + string manufacturer = ""; + + if(response.DiscType) sb.AppendLine("Disc uses phase change"); + else { - int type = response.LeadInStartFrame % 10; - int frm = response.LeadInStartFrame - type; - string manufacturer = ""; - - if(response.DiscType) sb.AppendLine("Disc uses phase change"); - else - { - if(type < 5) sb.AppendLine("Disc uses long strategy type dye (Cyanine, AZO, etc...)"); - else sb.AppendLine("Disc uses short strategy type dye (Phthalocyanine, etc...)"); - } - - manufacturer = ManufacturerFromATIP(response.LeadInStartSec, frm); - - if(manufacturer != "") sb.AppendFormat("Disc manufactured by: {0}", manufacturer).AppendLine(); + if(type < 5) sb.AppendLine("Disc uses long strategy type dye (Cyanine, AZO, etc...)"); + else sb.AppendLine("Disc uses short strategy type dye (Phthalocyanine, etc...)"); } + manufacturer = ManufacturerFromATIP(response.LeadInStartSec, frm); + + if(manufacturer != "") sb.AppendFormat("Disc manufactured by: {0}", manufacturer).AppendLine(); + return sb.ToString(); } diff --git a/DiscImageChef.Decoders/CD/Sector.cs b/DiscImageChef.Decoders/CD/Sector.cs index d3637f2f2..c16b4b05a 100644 --- a/DiscImageChef.Decoders/CD/Sector.cs +++ b/DiscImageChef.Decoders/CD/Sector.cs @@ -187,7 +187,9 @@ namespace DiscImageChef.Decoders.CD byte[] scrambled = new byte[sector.Length]; for(int i = 0; i < 2352; i++) scrambled[i] = (byte)(sector[i] ^ ScrambleTable[i]); - if(sector.Length > 2352) for(int i = 2352; i < sector.Length; i++) scrambled[i] = sector[i]; + if(sector.Length <= 2352) return scrambled; + + for(int i = 2352; i < sector.Length; i++) scrambled[i] = sector[i]; return scrambled; } diff --git a/DiscImageChef.Decoders/DVD/Cartridge.cs b/DiscImageChef.Decoders/DVD/Cartridge.cs index 64c09a390..e061ab9d9 100644 --- a/DiscImageChef.Decoders/DVD/Cartridge.cs +++ b/DiscImageChef.Decoders/DVD/Cartridge.cs @@ -174,21 +174,22 @@ namespace DiscImageChef.Decoders.DVD break; } - if(decoded.MSWI) - switch(decoded.RAMSWI) - { - case 0: break; - case 1: - sb.AppendLine("Disc is write inhibited because it has been extracted from the cartridge"); - break; - case 0xFF: - sb.AppendLine("Disc is write inhibited for an unspecified reason"); - break; - default: - sb.AppendFormat("Disc has unknown reason {0} for write inhibition", decoded.RAMSWI) - .AppendLine(); - break; - } + if(!decoded.MSWI) return sb.ToString(); + + switch(decoded.RAMSWI) + { + case 0: break; + case 1: + sb.AppendLine("Disc is write inhibited because it has been extracted from the cartridge"); + break; + case 0xFF: + sb.AppendLine("Disc is write inhibited for an unspecified reason"); + break; + default: + sb.AppendFormat("Disc has unknown reason {0} for write inhibition", decoded.RAMSWI) + .AppendLine(); + break; + } return sb.ToString(); } diff --git a/DiscImageChef.Decoders/DVD/DDS.cs b/DiscImageChef.Decoders/DVD/DDS.cs index 7b3fd4d9f..cf37e0c16 100644 --- a/DiscImageChef.Decoders/DVD/DDS.cs +++ b/DiscImageChef.Decoders/DVD/DDS.cs @@ -237,7 +237,8 @@ namespace DiscImageChef.Decoders.DVD } // ECMA-330 - if(dds.Groups == 1) + if(dds.Groups != 1) return dds; + { dds.Reserved4 = (byte)((response[7] & 0x7C) >> 2); dds.Reserved = new byte[68]; @@ -291,7 +292,8 @@ namespace DiscImageChef.Decoders.DVD sb.AppendFormat("Group {0} has been certified by an user", i).AppendLine(); } - if(decoded.Groups == 1) + if(decoded.Groups != 1) return sb.ToString(); + { sb.AppendFormat("Disc has {0} zones", decoded.Zones).AppendLine(); sb.AppendFormat("Primary Spare Area stats at PSN {0:X}h and ends at PSN {1:X}h, inclusively", diff --git a/DiscImageChef.Decoders/Floppy/Apple2.cs b/DiscImageChef.Decoders/Floppy/Apple2.cs index 554f78cce..6acf68108 100644 --- a/DiscImageChef.Decoders/Floppy/Apple2.cs +++ b/DiscImageChef.Decoders/Floppy/Apple2.cs @@ -290,18 +290,15 @@ namespace DiscImageChef.Decoders.Floppy public static byte[] DecodeSector(RawSector sector) { - if(sector.addressField.prologue[0] == 0xD5 && sector.addressField.prologue[1] == 0xAA) - { - // Pre DOS 3.3 - if(sector.addressField.prologue[2] == 0xB5) return Decode5and3(sector.dataField.data); - // DOS 3.3 - if(sector.addressField.prologue[2] == 0x96) return Decode6and2(sector.dataField.data); - // Unknown - return null; - } + if(sector.addressField.prologue[0] != 0xD5 || sector.addressField.prologue[1] != 0xAA) return null; + // Pre DOS 3.3 + if(sector.addressField.prologue[2] == 0xB5) return Decode5and3(sector.dataField.data); + // DOS 3.3 + if(sector.addressField.prologue[2] == 0x96) return Decode6and2(sector.dataField.data); + // Unknown + return null; // Not Apple ][ GCR? - return null; } public static RawSector MarshalSector(byte[] data, int offset = 0) diff --git a/DiscImageChef.Decoders/Floppy/AppleSony.cs b/DiscImageChef.Decoders/Floppy/AppleSony.cs index ae3c59cf7..cb9d495be 100644 --- a/DiscImageChef.Decoders/Floppy/AppleSony.cs +++ b/DiscImageChef.Decoders/Floppy/AppleSony.cs @@ -144,78 +144,76 @@ namespace DiscImageChef.Decoders.Floppy public static byte[] DecodeSector(RawSector sector) { - if(sector.addressField.prologue[0] == 0xD5 && sector.addressField.prologue[1] == 0xAA && - sector.addressField.prologue[2] == 0x96) + if(sector.addressField.prologue[0] != 0xD5 || sector.addressField.prologue[1] != 0xAA || + sector.addressField.prologue[2] != 0x96) return null; + + uint ck1, ck2, ck3; + byte carry; + byte w1, w2, w3, w4; + byte[] bf1 = new byte[175]; + byte[] bf2 = new byte[175]; + byte[] bf3 = new byte[175]; + byte[] nib_data = sector.dataField.data; + MemoryStream ms = new MemoryStream(); + + int j = 0; + w3 = 0; + for(int i = 0; i <= 174; i++) { - uint ck1, ck2, ck3; - byte carry; - byte w1, w2, w3, w4; - byte[] bf1 = new byte[175]; - byte[] bf2 = new byte[175]; - byte[] bf3 = new byte[175]; - byte[] nib_data = sector.dataField.data; - MemoryStream ms = new MemoryStream(); + w4 = nib_data[j++]; + w1 = nib_data[j++]; + w2 = nib_data[j++]; - int j = 0; - w3 = 0; - for(int i = 0; i <= 174; i++) - { - w4 = nib_data[j++]; - w1 = nib_data[j++]; - w2 = nib_data[j++]; + if(i != 174) w3 = nib_data[j++]; - if(i != 174) w3 = nib_data[j++]; - - bf1[i] = (byte)(((w1 & 0x3F) | ((w4 << 2) & 0xC0)) & 0x0F); - bf2[i] = (byte)(((w2 & 0x3F) | ((w4 << 4) & 0xC0)) & 0x0F); - bf3[i] = (byte)(((w3 & 0x3F) | ((w4 << 6) & 0xC0)) & 0x0F); - } - - j = 0; - ck1 = 0; - ck2 = 0; - ck3 = 0; - while(true) - { - ck1 = (ck1 & 0xFF) << 1; - if((ck1 & 0x0100) > 0) ck1++; - - carry = (byte)((bf1[j] ^ ck1) & 0xFF); - ck3 += carry; - if((ck1 & 0x0100) > 0) - { - ck3++; - ck1 &= 0xFF; - } - ms.WriteByte(carry); - - carry = (byte)((bf2[j] ^ ck3) & 0xFF); - ck2 += carry; - if(ck3 > 0xFF) - { - ck2++; - ck3 &= 0xFF; - } - ms.WriteByte(carry); - - if(ms.Length == 524) break; - - carry = (byte)((bf3[j] ^ ck2) & 0xFF); - ck1 += carry; - if(ck2 > 0xFF) - { - ck1++; - ck2 &= 0xFF; - } - ms.WriteByte(carry); - j++; - } - - return ms.ToArray(); + bf1[i] = (byte)(((w1 & 0x3F) | ((w4 << 2) & 0xC0)) & 0x0F); + bf2[i] = (byte)(((w2 & 0x3F) | ((w4 << 4) & 0xC0)) & 0x0F); + bf3[i] = (byte)(((w3 & 0x3F) | ((w4 << 6) & 0xC0)) & 0x0F); } + j = 0; + ck1 = 0; + ck2 = 0; + ck3 = 0; + while(true) + { + ck1 = (ck1 & 0xFF) << 1; + if((ck1 & 0x0100) > 0) ck1++; + + carry = (byte)((bf1[j] ^ ck1) & 0xFF); + ck3 += carry; + if((ck1 & 0x0100) > 0) + { + ck3++; + ck1 &= 0xFF; + } + ms.WriteByte(carry); + + carry = (byte)((bf2[j] ^ ck3) & 0xFF); + ck2 += carry; + if(ck3 > 0xFF) + { + ck2++; + ck3 &= 0xFF; + } + ms.WriteByte(carry); + + if(ms.Length == 524) break; + + carry = (byte)((bf3[j] ^ ck2) & 0xFF); + ck1 += carry; + if(ck2 > 0xFF) + { + ck1++; + ck2 &= 0xFF; + } + ms.WriteByte(carry); + j++; + } + + return ms.ToArray(); + // Not Apple Sony GCR? - return null; } public static RawSector MarshalSector(byte[] data, int offset = 0) diff --git a/DiscImageChef.Decoders/PCMCIA/CIS.cs b/DiscImageChef.Decoders/PCMCIA/CIS.cs index b69d8e961..db96994ca 100644 --- a/DiscImageChef.Decoders/PCMCIA/CIS.cs +++ b/DiscImageChef.Decoders/PCMCIA/CIS.cs @@ -226,29 +226,28 @@ namespace DiscImageChef.Decoders.PCMCIA buffer.Add(data[position]); - if(data[position] == 0x00) + if(data[position] != 0x00) continue; + + if(!firstString) { - if(!firstString) - { - tuple.Manufacturer = StringHandlers.CToString(buffer.ToArray()); - buffer = new List(); - firstString = true; - continue; - } - - if(!secondString) - { - tuple.Product = StringHandlers.CToString(buffer.ToArray()); - buffer = new List(); - firstString = true; - continue; - } - - if(strings == null) strings = new List(); - - strings.Add(StringHandlers.CToString(buffer.ToArray())); + tuple.Manufacturer = StringHandlers.CToString(buffer.ToArray()); buffer = new List(); + firstString = true; + continue; } + + if(!secondString) + { + tuple.Product = StringHandlers.CToString(buffer.ToArray()); + buffer = new List(); + firstString = true; + continue; + } + + if(strings == null) strings = new List(); + + strings.Add(StringHandlers.CToString(buffer.ToArray())); + buffer = new List(); } if(strings != null) tuple.AdditionalInformation = strings.ToArray(); diff --git a/DiscImageChef.Decoders/SCSI/EVPD.cs b/DiscImageChef.Decoders/SCSI/EVPD.cs index 9af225589..7ba2bf047 100644 --- a/DiscImageChef.Decoders/SCSI/EVPD.cs +++ b/DiscImageChef.Decoders/SCSI/EVPD.cs @@ -2301,52 +2301,49 @@ namespace DiscImageChef.Decoders.SCSI return decoded; } - if(pageResponse[4] == pageResponse[3] - 1) - { - List array = new List(); - string fwRegExStr = - "Firmware Rev\\s+=\\s+(?\\d+\\.\\d+)\\s+Build date\\s+=\\s+(?(\\w|\\d|\\s*.)*)\\s*$"; - string fwcRegExStr = "FW_CONF\\s+=\\s+(?0x[0-9A-Fa-f]{8})\\s*$"; - string servoRegExStr = "Servo\\s+Rev\\s+=\\s+(?\\d+\\.\\d+)\\s*$"; - Regex fwRegEx = new Regex(fwRegExStr); - Regex fwcRegEx = new Regex(fwcRegExStr); - Regex servoRegEx = new Regex(servoRegExStr); - Match fwMatch; - Match fwcMatch; - Match servoMatch; + if(pageResponse[4] != pageResponse[3] - 1) return null; - for(int pos = 5; pos < pageResponse.Length; pos++) - if(pageResponse[pos] == 0x00) + List array = new List(); + string fwRegExStr = + "Firmware Rev\\s+=\\s+(?\\d+\\.\\d+)\\s+Build date\\s+=\\s+(?(\\w|\\d|\\s*.)*)\\s*$"; + string fwcRegExStr = "FW_CONF\\s+=\\s+(?0x[0-9A-Fa-f]{8})\\s*$"; + string servoRegExStr = "Servo\\s+Rev\\s+=\\s+(?\\d+\\.\\d+)\\s*$"; + Regex fwRegEx = new Regex(fwRegExStr); + Regex fwcRegEx = new Regex(fwcRegExStr); + Regex servoRegEx = new Regex(servoRegExStr); + Match fwMatch; + Match fwcMatch; + Match servoMatch; + + for(int pos = 5; pos < pageResponse.Length; pos++) + if(pageResponse[pos] == 0x00) + { + string str = StringHandlers.CToString(array.ToArray()); + fwMatch = fwRegEx.Match(str); + fwcMatch = fwcRegEx.Match(str); + servoMatch = servoRegEx.Match(str); + + if(str.ToLowerInvariant().StartsWith("copyright", StringComparison.Ordinal)) + decoded.Copyright = Encoding.ASCII.GetBytes(str); + else if(fwMatch.Success) { - string str = StringHandlers.CToString(array.ToArray()); - fwMatch = fwRegEx.Match(str); - fwcMatch = fwcRegEx.Match(str); - servoMatch = servoRegEx.Match(str); - - if(str.ToLowerInvariant().StartsWith("copyright", StringComparison.Ordinal)) - decoded.Copyright = Encoding.ASCII.GetBytes(str); - else if(fwMatch.Success) - { - decoded.Component = Encoding.ASCII.GetBytes("Firmware"); - decoded.Version = Encoding.ASCII.GetBytes(fwMatch.Groups["fw"].Value); - decoded.Date = Encoding.ASCII.GetBytes(fwMatch.Groups["date"].Value); - } - else if(fwcMatch.Success) - decoded.Variant = Encoding.ASCII.GetBytes(fwMatch.Groups["value"].Value); - else if(servoMatch.Success) - { - decoded.Component = Encoding.ASCII.GetBytes("Servo"); - decoded.Version = Encoding.ASCII.GetBytes(servoMatch.Groups["version"].Value); - } - - array = new List(); + decoded.Component = Encoding.ASCII.GetBytes("Firmware"); + decoded.Version = Encoding.ASCII.GetBytes(fwMatch.Groups["fw"].Value); + decoded.Date = Encoding.ASCII.GetBytes(fwMatch.Groups["date"].Value); + } + else if(fwcMatch.Success) + decoded.Variant = Encoding.ASCII.GetBytes(fwMatch.Groups["value"].Value); + else if(servoMatch.Success) + { + decoded.Component = Encoding.ASCII.GetBytes("Servo"); + decoded.Version = Encoding.ASCII.GetBytes(servoMatch.Groups["version"].Value); } - else array.Add(pageResponse[pos]); - return decoded; - } + array = new List(); + } + else array.Add(pageResponse[pos]); - return null; + return decoded; } public static string PrettifyPage_C0_to_C5_HP(byte[] pageResponse) diff --git a/DiscImageChef.Decoders/SCSI/Inquiry.cs b/DiscImageChef.Decoders/SCSI/Inquiry.cs index f828a51db..805a2a85a 100644 --- a/DiscImageChef.Decoders/SCSI/Inquiry.cs +++ b/DiscImageChef.Decoders/SCSI/Inquiry.cs @@ -248,13 +248,11 @@ namespace DiscImageChef.Decoders.SCSI decoded.Seagate_Copyright = new byte[48]; Array.Copy(SCSIInquiryResponse, 96, decoded.Seagate_Copyright, 0, 48); } - if(SCSIInquiryResponse.Length >= 148) - { - // Seagate 2 - decoded.Seagate3Present = true; - decoded.Seagate_ServoPROMPartNo = new byte[4]; - Array.Copy(SCSIInquiryResponse, 144, decoded.Seagate_ServoPROMPartNo, 0, 4); - } + if(SCSIInquiryResponse.Length < 148) return decoded; + // Seagate 2 + decoded.Seagate3Present = true; + decoded.Seagate_ServoPROMPartNo = new byte[4]; + Array.Copy(SCSIInquiryResponse, 144, decoded.Seagate_ServoPROMPartNo, 0, 4); return decoded; } @@ -2059,13 +2057,12 @@ namespace DiscImageChef.Decoders.SCSI sb.AppendLine("============================================================"); } - if(response.VendorSpecific2 != null) - { - sb.AppendFormat("Vendor-specific bytes 96 to {0}", response.AdditionalLength + 4).AppendLine(); - sb.AppendLine("============================================================"); - sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.VendorSpecific2, 60)); - sb.AppendLine("============================================================"); - } + if(response.VendorSpecific2 == null) return sb.ToString(); + + sb.AppendFormat("Vendor-specific bytes 96 to {0}", response.AdditionalLength + 4).AppendLine(); + sb.AppendLine("============================================================"); + sb.AppendLine(PrintHex.ByteArrayToHexArrayString(response.VendorSpecific2, 60)); + sb.AppendLine("============================================================"); #endif return sb.ToString(); diff --git a/DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs b/DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs index 0a92f4003..2bcd1ec18 100644 --- a/DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs +++ b/DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs @@ -316,15 +316,14 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.DiscApplicationCode = response[32]; decoded.OPCTablesNumber = response[33]; - if(decoded.OPCTablesNumber > 0 && response.Length == decoded.OPCTablesNumber * 8 + 34) + if(decoded.OPCTablesNumber <= 0 || response.Length != decoded.OPCTablesNumber * 8 + 34) return decoded; + + decoded.OPCTables = new OPCTable[decoded.OPCTablesNumber]; + for(int i = 0; i < decoded.OPCTablesNumber; i++) { - decoded.OPCTables = new OPCTable[decoded.OPCTablesNumber]; - for(int i = 0; i < decoded.OPCTablesNumber; i++) - { - decoded.OPCTables[i].Speed = (ushort)((response[34 + i * 8 + 0] << 16) + response[34 + i * 8 + 1]); - decoded.OPCTables[i].OPCValues = new byte[6]; - Array.Copy(response, 34 + i * 8 + 2, decoded.OPCTables[i].OPCValues, 0, 6); - } + decoded.OPCTables[i].Speed = (ushort)((response[34 + i * 8 + 0] << 16) + response[34 + i * 8 + 1]); + decoded.OPCTables[i].OPCValues = new byte[6]; + Array.Copy(response, 34 + i * 8 + 2, decoded.OPCTables[i].OPCValues, 0, 6); } return decoded; @@ -425,11 +424,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC if(decoded.DBC_V) sb.AppendFormat("Disc barcode: {0:X16}", decoded.DiscBarcode).AppendLine(); if(decoded.DAC_V) sb.AppendFormat("Disc application code: {0}", decoded.DiscApplicationCode).AppendLine(); - if(decoded.OPCTables != null) - foreach(OPCTable table in decoded.OPCTables) - sb.AppendFormat("OPC values for {0}Kbit/sec.: {1}, {2}, {3}, {4}, {5}, {6}", table.Speed, - table.OPCValues[0], table.OPCValues[1], table.OPCValues[2], table.OPCValues[3], - table.OPCValues[4], table.OPCValues[5]).AppendLine(); + if(decoded.OPCTables == null) return sb.ToString(); + + foreach(OPCTable table in decoded.OPCTables) + sb.AppendFormat("OPC values for {0}Kbit/sec.: {1}, {2}, {3}, {4}, {5}, {6}", table.Speed, + table.OPCValues[0], table.OPCValues[1], table.OPCValues[2], table.OPCValues[3], + table.OPCValues[4], table.OPCValues[5]).AppendLine(); return sb.ToString(); } diff --git a/DiscImageChef.Decoders/SCSI/MMC/Features.cs b/DiscImageChef.Decoders/SCSI/MMC/Features.cs index 46fc99f08..f4bebdd76 100644 --- a/DiscImageChef.Decoders/SCSI/MMC/Features.cs +++ b/DiscImageChef.Decoders/SCSI/MMC/Features.cs @@ -2274,11 +2274,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Lock |= (feature[4] & 0x01) == 0x01; } - if(decoded.Version >= 2) - { - decoded.Load |= (feature[4] & 0x10) == 0x10; - decoded.DBML |= (feature[4] & 0x02) == 0x02; - } + if(decoded.Version < 2) return decoded; + + decoded.Load |= (feature[4] & 0x10) == 0x10; + decoded.DBML |= (feature[4] & 0x02) == 0x02; return decoded; } @@ -2332,13 +2331,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.LogicalBlockSize = - (uint)((feature[4] << 24) + (feature[5] << 16) + (feature[6] << 8) + feature[7]); - decoded.Blocking = (ushort)((feature[8] << 8) + feature[9]); - decoded.PP |= (feature[10] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.LogicalBlockSize = + (uint)((feature[4] << 24) + (feature[5] << 16) + (feature[6] << 8) + feature[7]); + decoded.Blocking = (ushort)((feature[8] << 8) + feature[9]); + decoded.PP |= (feature[10] & 0x01) == 0x01; return decoded; } @@ -2441,14 +2439,13 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 1) - { - decoded.LastLBA = (uint)((feature[4] << 24) + (feature[5] << 16) + (feature[6] << 8) + feature[7]); - decoded.LogicalBlockSize = - (uint)((feature[8] << 24) + (feature[9] << 16) + (feature[10] << 8) + feature[11]); - decoded.Blocking = (ushort)((feature[12] << 8) + feature[13]); - decoded.PP |= (feature[14] & 0x01) == 0x01; - } + if(decoded.Version < 1) return decoded; + + decoded.LastLBA = (uint)((feature[4] << 24) + (feature[5] << 16) + (feature[6] << 8) + feature[7]); + decoded.LogicalBlockSize = + (uint)((feature[8] << 24) + (feature[9] << 16) + (feature[10] << 8) + feature[11]); + decoded.Blocking = (ushort)((feature[12] << 8) + feature[13]); + decoded.PP |= (feature[14] & 0x01) == 0x01; return decoded; } @@ -2479,11 +2476,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC if(feature.Length > feature[7] + 8) Array.Copy(feature, 8, decoded.LinkSizes, 0, feature[7]); } - if(decoded.Version >= 3) - { - decoded.TRIO |= (feature[6] & 0x04) == 0x04; - decoded.ARSV |= (feature[6] & 0x02) == 0x02; - } + if(decoded.Version < 3) return decoded; + + decoded.TRIO |= (feature[6] & 0x04) == 0x04; + decoded.ARSV |= (feature[6] & 0x02) == 0x02; return decoded; } @@ -2582,13 +2578,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.LogicalBlockSize = - (uint)((feature[4] << 24) + (feature[5] << 16) + (feature[6] << 8) + feature[7]); - decoded.Blocking = (ushort)((feature[8] << 8) + feature[9]); - decoded.PP |= (feature[10] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.LogicalBlockSize = + (uint)((feature[4] << 24) + (feature[5] << 16) + (feature[6] << 8) + feature[7]); + decoded.Blocking = (ushort)((feature[8] << 8) + feature[9]); + decoded.PP |= (feature[10] & 0x01) == 0x01; return decoded; } @@ -2655,11 +2650,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC if(decoded.Version >= 0) decoded.Write |= (feature[4] & 0x01) == 0x01; - if(decoded.Version >= 1) - { - decoded.DVDPWrite |= (feature[4] & 0x04) == 0x04; - decoded.DVDPRead |= (feature[4] & 0x02) == 0x02; - } + if(decoded.Version < 1) return decoded; + + decoded.DVDPWrite |= (feature[4] & 0x04) == 0x04; + decoded.DVDPRead |= (feature[4] & 0x02) == 0x02; return decoded; } @@ -2682,12 +2676,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.DRTDM |= (feature[4] & 0x01) == 0x01; - decoded.DBICacheZones = feature[5]; - decoded.Entries = (ushort)((feature[6] << 8) + feature[7]); - } + if(decoded.Version < 0) return decoded; + + decoded.DRTDM |= (feature[4] & 0x01) == 0x01; + decoded.DBICacheZones = feature[5]; + decoded.Entries = (ushort)((feature[6] << 8) + feature[7]); return decoded; } @@ -2762,13 +2755,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.DSDG |= (feature[4] & 0x08) == 0x08; - decoded.DSDR |= (feature[4] & 0x04) == 0x04; - decoded.Intermediate |= (feature[4] & 0x02) == 0x02; - decoded.Blank |= (feature[4] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.DSDG |= (feature[4] & 0x08) == 0x08; + decoded.DSDR |= (feature[4] & 0x04) == 0x04; + decoded.Intermediate |= (feature[4] & 0x02) == 0x02; + decoded.Blank |= (feature[4] & 0x01) == 0x01; return decoded; } @@ -2799,12 +2791,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.DataTypeSupported = (ushort)((feature[6] << 8) + feature[7]); } - if(decoded.Version >= 2) - { - decoded.BUF |= (feature[4] & 0x40) == 0x40; - decoded.RWRaw |= (feature[4] & 0x10) == 0x10; - decoded.RWPack |= (feature[4] & 0x08) == 0x08; - } + if(decoded.Version < 2) return decoded; + + decoded.BUF |= (feature[4] & 0x40) == 0x40; + decoded.RWRaw |= (feature[4] & 0x10) == 0x10; + decoded.RWPack |= (feature[4] & 0x08) == 0x08; return decoded; } @@ -2936,11 +2927,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.Intermediate |= (feature[4] & 0x02) == 0x02; - decoded.Blank |= (feature[4] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.Intermediate |= (feature[4] & 0x02) == 0x02; + decoded.Blank |= (feature[4] & 0x01) == 0x01; return decoded; } @@ -2963,11 +2953,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(feature[7] > 0 && feature.Length > feature[7] + 8) - { - decoded.LinkSizes = new byte[feature[7]]; - Array.Copy(feature, 8, decoded.LinkSizes, 0, feature[7]); - } + if(feature[7] <= 0 || feature.Length <= feature[7] + 8) return decoded; + + decoded.LinkSizes = new byte[feature[7]]; + Array.Copy(feature, 8, decoded.LinkSizes, 0, feature[7]); return decoded; } @@ -3055,12 +3044,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.Write |= (feature[4] & 0x01) == 0x01; - decoded.QuickStart |= (feature[5] & 0x02) == 0x02; - decoded.CloseOnly |= (feature[5] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.Write |= (feature[4] & 0x01) == 0x01; + decoded.QuickStart |= (feature[5] & 0x02) == 0x02; + decoded.CloseOnly |= (feature[5] & 0x01) == 0x01; return decoded; } @@ -3113,14 +3101,13 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.OldROM |= (feature[25] & 0x01) == 0x01; } - if(decoded.Version >= 1) - { - decoded.BCA |= (feature[4] & 0x01) == 0x01; - decoded.RE2 |= (feature[9] & 0x04) == 0x04; - decoded.RE1 |= (feature[9] & 0x02) == 0x02; - decoded.R |= (feature[17] & 0x02) == 0x02; - decoded.ROM |= (feature[25] & 0x02) == 0x02; - } + if(decoded.Version < 1) return decoded; + + decoded.BCA |= (feature[4] & 0x01) == 0x01; + decoded.RE2 |= (feature[9] & 0x04) == 0x04; + decoded.RE1 |= (feature[9] & 0x02) == 0x02; + decoded.R |= (feature[17] & 0x02) == 0x02; + decoded.ROM |= (feature[25] & 0x02) == 0x02; return decoded; } @@ -3150,12 +3137,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.OldR |= (feature[17] & 0x01) == 0x01; } - if(decoded.Version >= 1) - { - decoded.RE2 |= (feature[9] & 0x04) == 0x04; - decoded.RE1 |= (feature[9] & 0x02) == 0x02; - decoded.R |= (feature[17] & 0x02) == 0x02; - } + if(decoded.Version < 1) return decoded; + + decoded.RE2 |= (feature[9] & 0x04) == 0x04; + decoded.RE1 |= (feature[9] & 0x02) == 0x02; + decoded.R |= (feature[17] & 0x02) == 0x02; return decoded; } @@ -3199,11 +3185,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.HDDVDR |= (feature[4] & 0x01) == 0x01; - decoded.HDDVDRAM |= (feature[6] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.HDDVDR |= (feature[4] & 0x01) == 0x01; + decoded.HDDVDRAM |= (feature[6] & 0x01) == 0x01; return decoded; } @@ -3226,11 +3211,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.HDDVDR |= (feature[4] & 0x01) == 0x01; - decoded.HDDVDRAM |= (feature[6] & 0x01) == 0x01; - } + if(decoded.Version < 0) return decoded; + + decoded.HDDVDR |= (feature[4] & 0x01) == 0x01; + decoded.HDDVDRAM |= (feature[6] & 0x01) == 0x01; return decoded; } @@ -3320,12 +3304,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.SCC |= (feature[4] & 0x10) == 0x10; - decoded.SDP |= (feature[4] & 0x04) == 0x04; - decoded.HighestSlotNumber = (byte)(feature[7] & 0x1F); - } + if(decoded.Version < 0) return decoded; + + decoded.SCC |= (feature[4] & 0x10) == 0x10; + decoded.SDP |= (feature[4] & 0x04) == 0x04; + decoded.HighestSlotNumber = (byte)(feature[7] & 0x1F); return decoded; } @@ -3348,13 +3331,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.Scan |= (feature[4] & 0x04) == 0x04; - decoded.SCM |= (feature[4] & 0x02) == 0x02; - decoded.SV |= (feature[4] & 0x01) == 0x01; - decoded.VolumeLevels = (ushort)((feature[6] << 8) + feature[7]); - } + if(decoded.Version < 0) return decoded; + + decoded.Scan |= (feature[4] & 0x04) == 0x04; + decoded.SCM |= (feature[4] & 0x02) == 0x02; + decoded.SV |= (feature[4] & 0x01) == 0x01; + decoded.VolumeLevels = (ushort)((feature[6] << 8) + feature[7]); return decoded; } @@ -3400,11 +3382,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 1 && feature.Length >= 8) - { - decoded.Group3 |= (feature[4] & 0x01) == 0x01; - decoded.UnitLength = (ushort)((feature[6] << 8) + feature[7]); - } + if(decoded.Version < 1 || feature.Length < 8) return decoded; + + decoded.Group3 |= (feature[4] & 0x01) == 0x01; + decoded.UnitLength = (ushort)((feature[6] << 8) + feature[7]); return decoded; } @@ -3459,11 +3440,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.SW |= (feature[4] & 0x01) == 0x01; } - if(decoded.Version >= 5 && feature.Length >= 8) - { - decoded.SMP |= (feature[4] & 0x20) == 0x20; - decoded.RBCB |= (feature[4] & 0x10) == 0x10; - } + if(decoded.Version < 5 || feature.Length < 8) return decoded; + + decoded.SMP |= (feature[4] & 0x20) == 0x20; + decoded.RBCB |= (feature[4] & 0x10) == 0x10; return decoded; } @@ -3486,12 +3466,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - byte[] serial = new byte[feature.Length]; - Array.Copy(feature, 4, serial, 0, feature.Length - 4); - decoded.Serial = StringHandlers.CToString(serial).Trim(); - } + if(decoded.Version < 0) return decoded; + + byte[] serial = new byte[feature.Length]; + Array.Copy(feature, 4, serial, 0, feature.Length - 4); + decoded.Serial = StringHandlers.CToString(serial).Trim(); return decoded; } @@ -3535,13 +3514,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.DCBs = new uint[feature[3] / 4]; - for(int i = 0; i < decoded.DCBs.Length; i++) - decoded.DCBs[i] = (uint)((feature[0 + 4 + i * 4] << 24) + (feature[1 + 4 + i * 4] << 16) + - (feature[2 + 4 + i * 4] << 8) + feature[3 + 4 + i * 4]); - } + if(decoded.Version < 0) return decoded; + + decoded.DCBs = new uint[feature[3] / 4]; + for(int i = 0; i < decoded.DCBs.Length; i++) + decoded.DCBs[i] = (uint)((feature[0 + 4 + i * 4] << 24) + (feature[1 + 4 + i * 4] << 16) + + (feature[2 + 4 + i * 4] << 8) + feature[3 + 4 + i * 4]); return decoded; } @@ -3587,16 +3565,15 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.Century = (ushort)((feature[4] << 8) + feature[5]); - decoded.Year = (ushort)((feature[6] << 8) + feature[7]); - decoded.Month = (ushort)((feature[8] << 8) + feature[9]); - decoded.Day = (ushort)((feature[10] << 8) + feature[11]); - decoded.Hour = (ushort)((feature[12] << 8) + feature[13]); - decoded.Minute = (ushort)((feature[14] << 8) + feature[15]); - decoded.Second = (ushort)((feature[16] << 8) + feature[17]); - } + if(decoded.Version < 0) return decoded; + + decoded.Century = (ushort)((feature[4] << 8) + feature[5]); + decoded.Year = (ushort)((feature[6] << 8) + feature[7]); + decoded.Month = (ushort)((feature[8] << 8) + feature[9]); + decoded.Day = (ushort)((feature[10] << 8) + feature[11]); + decoded.Hour = (ushort)((feature[12] << 8) + feature[13]); + decoded.Minute = (ushort)((feature[14] << 8) + feature[15]); + decoded.Second = (ushort)((feature[16] << 8) + feature[17]); return decoded; } @@ -3627,13 +3604,12 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.AACSVersion = feature[7]; } - if(decoded.Version >= 2) - { - decoded.RDC |= (feature[4] & 0x10) == 0x10; - decoded.RMC |= (feature[4] & 0x08) == 0x08; - decoded.WBE |= (feature[4] & 0x04) == 0x04; - decoded.BEC |= (feature[4] & 0x02) == 0x02; - } + if(decoded.Version < 2) return decoded; + + decoded.RDC |= (feature[4] & 0x10) == 0x10; + decoded.RMC |= (feature[4] & 0x08) == 0x08; + decoded.WBE |= (feature[4] & 0x04) == 0x04; + decoded.BEC |= (feature[4] & 0x02) == 0x02; return decoded; } @@ -3721,16 +3697,16 @@ namespace DiscImageChef.Decoders.SCSI.MMC decoded.Persistent |= (feature[2] & 0x02) == 0x02; decoded.Version = (byte)((feature[2] & 0x3C) >> 2); - if(decoded.Version >= 0) - { - decoded.PSAU |= (feature[4] & 0x80) == 0x80; - decoded.LOSPB |= (feature[4] & 0x40) == 0x40; - decoded.ME |= (feature[4] & 0x01) == 0x01; - decoded.Profiles = new ushort[feature[5]]; - if(feature[5] * 2 + 6 == feature.Length) - for(int i = 0; i < feature[5]; i++) - decoded.Profiles[i] = (ushort)((feature[0 + 6 + 2 * i] << 8) + feature[1 + 6 + 2 * i]); - } + if(decoded.Version < 0) return decoded; + + decoded.PSAU |= (feature[4] & 0x80) == 0x80; + decoded.LOSPB |= (feature[4] & 0x40) == 0x40; + decoded.ME |= (feature[4] & 0x01) == 0x01; + decoded.Profiles = new ushort[feature[5]]; + if(feature[5] * 2 + 6 != feature.Length) return decoded; + + for(int i = 0; i < feature[5]; i++) + decoded.Profiles[i] = (ushort)((feature[0 + 6 + 2 * i] << 8) + feature[1 + 6 + 2 * i]); return decoded; } @@ -3743,137 +3719,138 @@ namespace DiscImageChef.Decoders.SCSI.MMC StringBuilder sb = new StringBuilder(); sb.AppendLine("MMC Supported Profiles:"); - if(ftr.Profiles != null) - foreach(Profile prof in ftr.Profiles) - { - switch(prof.Number) - { - case ProfileNumber.Reserved: - sb.Append("\tDrive reported a reserved profile number"); - break; - case ProfileNumber.NonRemovable: - sb.Append("\tDrive supports non-removable changeable media"); - break; - case ProfileNumber.Removable: - sb.Append("\tDrive supports rewritable and removable media"); - break; - case ProfileNumber.MOErasable: - sb.Append("\tDrive supports Magnet-Optical media"); - break; - case ProfileNumber.OpticalWORM: - sb.Append("\tDrive supports optical write-once media"); - break; - case ProfileNumber.ASMO: - sb.Append("\tDrive supports Advanced Storage - Magneto-Optical"); - break; - case ProfileNumber.CDROM: - sb.Append("\tDrive supports CD-ROM"); - break; - case ProfileNumber.CDR: - sb.Append("\tDrive supports CD-R"); - break; - case ProfileNumber.CDRW: - sb.Append("\tDrive supports CD-RW"); - break; - case ProfileNumber.DVDROM: - sb.Append("\tDrive supports DVD-ROM"); - break; - case ProfileNumber.DVDRSeq: - sb.Append("\tDrive supports DVD-R"); - break; - case ProfileNumber.DVDRAM: - sb.Append("\tDrive supports DVD-RAM"); - break; - case ProfileNumber.DVDRWRes: - sb.Append("\tDrive supports restricted overwrite DVD-RW"); - break; - case ProfileNumber.DVDRWSeq: - sb.Append("\tDrive supports sequentially recorded DVD-RW"); - break; - case ProfileNumber.DVDRDLSeq: - sb.Append("\tDrive supports sequentially recorded DVD-R DL"); - break; - case ProfileNumber.DVDRDLJump: - sb.Append("\tDrive supports layer jump recorded DVD-R DL"); - break; - case ProfileNumber.DVDRWDL: - sb.Append("\tDrive supports DVD-RW DL"); - break; - case ProfileNumber.DVDDownload: - sb.Append("\tDrive supports DVD-Download"); - break; - case ProfileNumber.DVDRWPlus: - sb.Append("\tDrive supports DVD+RW"); - break; - case ProfileNumber.DVDRPlus: - sb.Append("\tDrive supports DVD+R"); - break; - case ProfileNumber.DDCDROM: - sb.Append("\tDrive supports DDCD-ROM"); - break; - case ProfileNumber.DDCDR: - sb.Append("\tDrive supports DDCD-R"); - break; - case ProfileNumber.DDCDRW: - sb.Append("\tDrive supports DDCD-RW"); - break; - case ProfileNumber.DVDRWDLPlus: - sb.Append("\tDrive supports DVD+RW DL"); - break; - case ProfileNumber.DVDRDLPlus: - sb.Append("\tDrive supports DVD+R DL"); - break; - case ProfileNumber.BDROM: - sb.Append("\tDrive supports BD-ROM"); - break; - case ProfileNumber.BDRSeq: - sb.Append("\tDrive supports BD-R SRM"); - break; - case ProfileNumber.BDRRdm: - sb.Append("\tDrive supports BD-R RRM"); - break; - case ProfileNumber.BDRE: - sb.Append("\tDrive supports BD-RE"); - break; - case ProfileNumber.HDDVDROM: - sb.Append("\tDrive supports HD DVD-ROM"); - break; - case ProfileNumber.HDDVDR: - sb.Append("\tDrive supports HD DVD-R"); - break; - case ProfileNumber.HDDVDRAM: - sb.Append("\tDrive supports HD DVD-RAM"); - break; - case ProfileNumber.HDDVDRW: - sb.Append("\tDrive supports HD DVD-RW"); - break; - case ProfileNumber.HDDVDRDL: - sb.Append("\tDrive supports HD DVD-R DL"); - break; - case ProfileNumber.HDDVDRWDL: - sb.Append("\tDrive supports HD DVD-RW DL"); - break; - case ProfileNumber.HDBURNROM: - sb.Append("\tDrive supports HDBurn CD-ROM"); - break; - case ProfileNumber.HDBURNR: - sb.Append("\tDrive supports HDBurn CD-R"); - break; - case ProfileNumber.HDBURNRW: - sb.Append("\tDrive supports HDBurn CD-RW"); - break; - case ProfileNumber.Unconforming: - sb.Append("\tDrive is not conforming to any profile"); - break; - default: - sb.AppendFormat("\tDrive informs of unknown profile 0x{0:X4}", (ushort)prof.Number); - break; - } + if(ftr.Profiles == null) return sb.ToString(); - if(prof.Current) sb.AppendLine(" (current)"); - else sb.AppendLine(); + foreach(Profile prof in ftr.Profiles) + { + switch(prof.Number) + { + case ProfileNumber.Reserved: + sb.Append("\tDrive reported a reserved profile number"); + break; + case ProfileNumber.NonRemovable: + sb.Append("\tDrive supports non-removable changeable media"); + break; + case ProfileNumber.Removable: + sb.Append("\tDrive supports rewritable and removable media"); + break; + case ProfileNumber.MOErasable: + sb.Append("\tDrive supports Magnet-Optical media"); + break; + case ProfileNumber.OpticalWORM: + sb.Append("\tDrive supports optical write-once media"); + break; + case ProfileNumber.ASMO: + sb.Append("\tDrive supports Advanced Storage - Magneto-Optical"); + break; + case ProfileNumber.CDROM: + sb.Append("\tDrive supports CD-ROM"); + break; + case ProfileNumber.CDR: + sb.Append("\tDrive supports CD-R"); + break; + case ProfileNumber.CDRW: + sb.Append("\tDrive supports CD-RW"); + break; + case ProfileNumber.DVDROM: + sb.Append("\tDrive supports DVD-ROM"); + break; + case ProfileNumber.DVDRSeq: + sb.Append("\tDrive supports DVD-R"); + break; + case ProfileNumber.DVDRAM: + sb.Append("\tDrive supports DVD-RAM"); + break; + case ProfileNumber.DVDRWRes: + sb.Append("\tDrive supports restricted overwrite DVD-RW"); + break; + case ProfileNumber.DVDRWSeq: + sb.Append("\tDrive supports sequentially recorded DVD-RW"); + break; + case ProfileNumber.DVDRDLSeq: + sb.Append("\tDrive supports sequentially recorded DVD-R DL"); + break; + case ProfileNumber.DVDRDLJump: + sb.Append("\tDrive supports layer jump recorded DVD-R DL"); + break; + case ProfileNumber.DVDRWDL: + sb.Append("\tDrive supports DVD-RW DL"); + break; + case ProfileNumber.DVDDownload: + sb.Append("\tDrive supports DVD-Download"); + break; + case ProfileNumber.DVDRWPlus: + sb.Append("\tDrive supports DVD+RW"); + break; + case ProfileNumber.DVDRPlus: + sb.Append("\tDrive supports DVD+R"); + break; + case ProfileNumber.DDCDROM: + sb.Append("\tDrive supports DDCD-ROM"); + break; + case ProfileNumber.DDCDR: + sb.Append("\tDrive supports DDCD-R"); + break; + case ProfileNumber.DDCDRW: + sb.Append("\tDrive supports DDCD-RW"); + break; + case ProfileNumber.DVDRWDLPlus: + sb.Append("\tDrive supports DVD+RW DL"); + break; + case ProfileNumber.DVDRDLPlus: + sb.Append("\tDrive supports DVD+R DL"); + break; + case ProfileNumber.BDROM: + sb.Append("\tDrive supports BD-ROM"); + break; + case ProfileNumber.BDRSeq: + sb.Append("\tDrive supports BD-R SRM"); + break; + case ProfileNumber.BDRRdm: + sb.Append("\tDrive supports BD-R RRM"); + break; + case ProfileNumber.BDRE: + sb.Append("\tDrive supports BD-RE"); + break; + case ProfileNumber.HDDVDROM: + sb.Append("\tDrive supports HD DVD-ROM"); + break; + case ProfileNumber.HDDVDR: + sb.Append("\tDrive supports HD DVD-R"); + break; + case ProfileNumber.HDDVDRAM: + sb.Append("\tDrive supports HD DVD-RAM"); + break; + case ProfileNumber.HDDVDRW: + sb.Append("\tDrive supports HD DVD-RW"); + break; + case ProfileNumber.HDDVDRDL: + sb.Append("\tDrive supports HD DVD-R DL"); + break; + case ProfileNumber.HDDVDRWDL: + sb.Append("\tDrive supports HD DVD-RW DL"); + break; + case ProfileNumber.HDBURNROM: + sb.Append("\tDrive supports HDBurn CD-ROM"); + break; + case ProfileNumber.HDBURNR: + sb.Append("\tDrive supports HDBurn CD-R"); + break; + case ProfileNumber.HDBURNRW: + sb.Append("\tDrive supports HDBurn CD-RW"); + break; + case ProfileNumber.Unconforming: + sb.Append("\tDrive is not conforming to any profile"); + break; + default: + sb.AppendFormat("\tDrive informs of unknown profile 0x{0:X4}", (ushort)prof.Number); + break; } + if(prof.Current) sb.AppendLine(" (current)"); + else sb.AppendLine(); + } + return sb.ToString(); } @@ -4337,27 +4314,26 @@ namespace DiscImageChef.Decoders.SCSI.MMC if(ftr.TestWrite) sb.AppendLine("\tDrive can do a test writing"); if(ftr.BUF) sb.AppendLine("\tDrive supports zero loss linking"); - if(ftr.DataTypeSupported > 0) - { - sb.Append("\tDrive supports data block types:"); - if((ftr.DataTypeSupported & 0x0001) == 0x0001) sb.Append(" 0"); - if((ftr.DataTypeSupported & 0x0002) == 0x0002) sb.Append(" 1"); - if((ftr.DataTypeSupported & 0x0004) == 0x0004) sb.Append(" 2"); - if((ftr.DataTypeSupported & 0x0008) == 0x0008) sb.Append(" 3"); - if((ftr.DataTypeSupported & 0x0010) == 0x0010) sb.Append(" 4"); - if((ftr.DataTypeSupported & 0x0020) == 0x0020) sb.Append(" 5"); - if((ftr.DataTypeSupported & 0x0040) == 0x0040) sb.Append(" 6"); - if((ftr.DataTypeSupported & 0x0080) == 0x0080) sb.Append(" 7"); - if((ftr.DataTypeSupported & 0x0100) == 0x0100) sb.Append(" 8"); - if((ftr.DataTypeSupported & 0x0200) == 0x0200) sb.Append(" 9"); - if((ftr.DataTypeSupported & 0x0400) == 0x0400) sb.Append(" 10"); - if((ftr.DataTypeSupported & 0x0800) == 0x0800) sb.Append(" 11"); - if((ftr.DataTypeSupported & 0x1000) == 0x1000) sb.Append(" 12"); - if((ftr.DataTypeSupported & 0x2000) == 0x2000) sb.Append(" 13"); - if((ftr.DataTypeSupported & 0x4000) == 0x4000) sb.Append(" 14"); - if((ftr.DataTypeSupported & 0x8000) == 0x8000) sb.Append(" 15"); - sb.AppendLine(); - } + if(ftr.DataTypeSupported <= 0) return sb.ToString(); + + sb.Append("\tDrive supports data block types:"); + if((ftr.DataTypeSupported & 0x0001) == 0x0001) sb.Append(" 0"); + if((ftr.DataTypeSupported & 0x0002) == 0x0002) sb.Append(" 1"); + if((ftr.DataTypeSupported & 0x0004) == 0x0004) sb.Append(" 2"); + if((ftr.DataTypeSupported & 0x0008) == 0x0008) sb.Append(" 3"); + if((ftr.DataTypeSupported & 0x0010) == 0x0010) sb.Append(" 4"); + if((ftr.DataTypeSupported & 0x0020) == 0x0020) sb.Append(" 5"); + if((ftr.DataTypeSupported & 0x0040) == 0x0040) sb.Append(" 6"); + if((ftr.DataTypeSupported & 0x0080) == 0x0080) sb.Append(" 7"); + if((ftr.DataTypeSupported & 0x0100) == 0x0100) sb.Append(" 8"); + if((ftr.DataTypeSupported & 0x0200) == 0x0200) sb.Append(" 9"); + if((ftr.DataTypeSupported & 0x0400) == 0x0400) sb.Append(" 10"); + if((ftr.DataTypeSupported & 0x0800) == 0x0800) sb.Append(" 11"); + if((ftr.DataTypeSupported & 0x1000) == 0x1000) sb.Append(" 12"); + if((ftr.DataTypeSupported & 0x2000) == 0x2000) sb.Append(" 13"); + if((ftr.DataTypeSupported & 0x4000) == 0x4000) sb.Append(" 14"); + if((ftr.DataTypeSupported & 0x8000) == 0x8000) sb.Append(" 15"); + sb.AppendLine(); return sb.ToString(); } @@ -4449,9 +4425,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC sb.AppendLine("MMC Layer Jump Recording:"); - if(ftr.LinkSizes != null) - foreach(byte link in ftr.LinkSizes) - sb.AppendFormat("\tCurrent media has a {0} bytes link available", link).AppendLine(); + if(ftr.LinkSizes == null) return sb.ToString(); + + foreach(byte link in ftr.LinkSizes) + sb.AppendFormat("\tCurrent media has a {0} bytes link available", link).AppendLine(); return sb.ToString(); } @@ -4469,19 +4446,18 @@ namespace DiscImageChef.Decoders.SCSI.MMC StringBuilder sb = new StringBuilder(); sb.AppendLine("Drive can write CD-RW"); - if(ftr.SubtypeSupport > 0) - { - sb.Append("\tDrive supports CD-RW subtypes"); - if((ftr.SubtypeSupport & 0x01) == 0x01) sb.Append(" 0"); - if((ftr.SubtypeSupport & 0x02) == 0x02) sb.Append(" 1"); - if((ftr.SubtypeSupport & 0x04) == 0x04) sb.Append(" 2"); - if((ftr.SubtypeSupport & 0x08) == 0x08) sb.Append(" 3"); - if((ftr.SubtypeSupport & 0x10) == 0x10) sb.Append(" 4"); - if((ftr.SubtypeSupport & 0x20) == 0x20) sb.Append(" 5"); - if((ftr.SubtypeSupport & 0x40) == 0x40) sb.Append(" 6"); - if((ftr.SubtypeSupport & 0x80) == 0x80) sb.Append(" 7"); - sb.AppendLine(); - } + if(ftr.SubtypeSupport <= 0) return sb.ToString(); + + sb.Append("\tDrive supports CD-RW subtypes"); + if((ftr.SubtypeSupport & 0x01) == 0x01) sb.Append(" 0"); + if((ftr.SubtypeSupport & 0x02) == 0x02) sb.Append(" 1"); + if((ftr.SubtypeSupport & 0x04) == 0x04) sb.Append(" 2"); + if((ftr.SubtypeSupport & 0x08) == 0x08) sb.Append(" 3"); + if((ftr.SubtypeSupport & 0x10) == 0x10) sb.Append(" 4"); + if((ftr.SubtypeSupport & 0x20) == 0x20) sb.Append(" 5"); + if((ftr.SubtypeSupport & 0x40) == 0x40) sb.Append(" 6"); + if((ftr.SubtypeSupport & 0x80) == 0x80) sb.Append(" 7"); + sb.AppendLine(); return sb.ToString(); } @@ -4722,12 +4698,11 @@ namespace DiscImageChef.Decoders.SCSI.MMC sb.AppendLine("Drive supports Timeout & Protect mode page 1Dh"); - if(ftr.Group3) - { - sb.AppendLine("\tDrive supports the Group3 in Timeout & Protect mode page 1Dh"); - if(ftr.UnitLength > 0) - sb.AppendFormat("\tDrive has {0} increase of Group 3 time unit", ftr.UnitLength).AppendLine(); - } + if(!ftr.Group3) return sb.ToString(); + + sb.AppendLine("\tDrive supports the Group3 in Timeout & Protect mode page 1Dh"); + if(ftr.UnitLength > 0) + sb.AppendFormat("\tDrive has {0} increase of Group 3 time unit", ftr.UnitLength).AppendLine(); return sb.ToString(); } @@ -4791,7 +4766,9 @@ namespace DiscImageChef.Decoders.SCSI.MMC Feature_010A ftr = feature.Value; StringBuilder sb = new StringBuilder(); - if(ftr.DCBs != null) foreach(uint DCB in ftr.DCBs) sb.AppendFormat("Drive supports DCB {0:X8}h", DCB).AppendLine(); + if(ftr.DCBs == null) return sb.ToString(); + + foreach(uint DCB in ftr.DCBs) sb.AppendFormat("Drive supports DCB {0:X8}h", DCB).AppendLine(); return sb.ToString(); } @@ -4946,9 +4923,10 @@ namespace DiscImageChef.Decoders.SCSI.MMC if(ftr.LOSPB) sb.AppendLine("\tDrive supports linked OSPBs"); if(ftr.ME) sb.AppendLine("\tDrive will only record on the OSSC Disc Format"); - if(ftr.Profiles != null) - for(int i = 0; i < ftr.Profiles.Length; i++) - sb.AppendFormat("\tProfile {0}: {1}", i, ftr.Profiles[i]).AppendLine(); + if(ftr.Profiles == null) return sb.ToString(); + + for(int i = 0; i < ftr.Profiles.Length; i++) + sb.AppendFormat("\tProfile {0}: {1}", i, ftr.Profiles[i]).AppendLine(); return sb.ToString(); } diff --git a/DiscImageChef.Decoders/SCSI/Modes/00_SFF.cs b/DiscImageChef.Decoders/SCSI/Modes/00_SFF.cs index 586708e52..70fa358c5 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/00_SFF.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/00_SFF.cs @@ -110,12 +110,11 @@ namespace DiscImageChef.Decoders.SCSI if(page.DVW) sb.AppendLine("\tVerifying after writing is disabled"); if(page.DDE) sb.AppendLine("\tDrive will abort when a writing error is detected"); - if(page.SLM) - { - sb.Append("\tDrive has two LUNs with rewritable being "); - if(page.SLM) sb.AppendLine("LUN 1"); - else sb.AppendLine("LUN 0"); - } + if(!page.SLM) return sb.ToString(); + + sb.Append("\tDrive has two LUNs with rewritable being "); + if(page.SLM) sb.AppendLine("LUN 1"); + else sb.AppendLine("LUN 0"); return sb.ToString(); } diff --git a/DiscImageChef.Decoders/SCSI/Modes/0E.cs b/DiscImageChef.Decoders/SCSI/Modes/0E.cs index 4533bfdab..1a217234d 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/0E.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/0E.cs @@ -228,26 +228,25 @@ namespace DiscImageChef.Decoders.SCSI } } - if(page.OutputPort3ChannelSelection > 0) - { - sb.Append("\tOutput port 3 has channels "); - if((page.OutputPort3ChannelSelection & 0x01) == 0x01) sb.Append("0 "); - if((page.OutputPort3ChannelSelection & 0x02) == 0x02) sb.Append("1 "); - if((page.OutputPort3ChannelSelection & 0x04) == 0x04) sb.Append("2 "); - if((page.OutputPort3ChannelSelection & 0x08) == 0x08) sb.Append("3 "); + if(page.OutputPort3ChannelSelection <= 0) return sb.ToString(); - switch(page.OutputPort3Volume) - { - case 0: - sb.AppendLine("muted"); - break; - case 0xFF: - sb.AppendLine("at maximum volume"); - break; - default: - sb.AppendFormat("at volume {0}", page.OutputPort3Volume).AppendLine(); - break; - } + sb.Append("\tOutput port 3 has channels "); + if((page.OutputPort3ChannelSelection & 0x01) == 0x01) sb.Append("0 "); + if((page.OutputPort3ChannelSelection & 0x02) == 0x02) sb.Append("1 "); + if((page.OutputPort3ChannelSelection & 0x04) == 0x04) sb.Append("2 "); + if((page.OutputPort3ChannelSelection & 0x08) == 0x08) sb.Append("3 "); + + switch(page.OutputPort3Volume) + { + case 0: + sb.AppendLine("muted"); + break; + case 0xFF: + sb.AppendLine("at maximum volume"); + break; + default: + sb.AppendFormat("at volume {0}", page.OutputPort3Volume).AppendLine(); + break; } return sb.ToString(); diff --git a/DiscImageChef.Decoders/SCSI/Modes/24_IBM.cs b/DiscImageChef.Decoders/SCSI/Modes/24_IBM.cs index d87d66297..3a11d61df 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/24_IBM.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/24_IBM.cs @@ -91,11 +91,10 @@ namespace DiscImageChef.Decoders.SCSI sb.AppendFormat("\tVendor-specific mode control: {0}", page.ModeControl); sb.AppendFormat("\tVendor-specific velocity setting: {0}", page.VelocitySetting); - if(page.EncryptionCapable) - { - sb.AppendLine("\tDrive supports encryption"); - if(page.EncryptionEnabled) sb.AppendLine("\tDrive has encryption enabled"); - } + if(!page.EncryptionCapable) return sb.ToString(); + + sb.AppendLine("\tDrive supports encryption"); + if(page.EncryptionEnabled) sb.AppendLine("\tDrive has encryption enabled"); return sb.ToString(); } diff --git a/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs b/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs index 194b6f056..7202acd49 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/Mode10.cs @@ -236,37 +236,38 @@ namespace DiscImageChef.Decoders.SCSI if(longLBA) hdr[4] += 0x01; - if(header.BlockDescriptors != null) - if(longLBA) - for(int i = 0; i < header.BlockDescriptors.Length; i++) - { - byte[] temp = BitConverter.GetBytes(header.BlockDescriptors[i].Blocks); - hdr[7 + i * 16 + 8] = temp[0]; - hdr[6 + i * 16 + 8] = temp[1]; - hdr[5 + i * 16 + 8] = temp[2]; - hdr[4 + i * 16 + 8] = temp[3]; - hdr[3 + i * 16 + 8] = temp[4]; - hdr[2 + i * 16 + 8] = temp[5]; - hdr[1 + i * 16 + 8] = temp[6]; - hdr[0 + i * 16 + 8] = temp[7]; - hdr[12 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF000000) >> 24); - hdr[13 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16); - hdr[14 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8); - hdr[15 + i * 16 + 8] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF); - } - else - for(int i = 0; i < header.BlockDescriptors.Length; i++) - { - if(deviceType != PeripheralDeviceTypes.DirectAccess) - hdr[0 + i * 8 + 8] = (byte)header.BlockDescriptors[i].Density; - else hdr[0 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF000000) >> 24); - hdr[1 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16); - hdr[2 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8); - hdr[3 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF); - hdr[5 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16); - hdr[6 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8); - hdr[7 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF); - } + if(header.BlockDescriptors == null) return hdr; + + if(longLBA) + for(int i = 0; i < header.BlockDescriptors.Length; i++) + { + byte[] temp = BitConverter.GetBytes(header.BlockDescriptors[i].Blocks); + hdr[7 + i * 16 + 8] = temp[0]; + hdr[6 + i * 16 + 8] = temp[1]; + hdr[5 + i * 16 + 8] = temp[2]; + hdr[4 + i * 16 + 8] = temp[3]; + hdr[3 + i * 16 + 8] = temp[4]; + hdr[2 + i * 16 + 8] = temp[5]; + hdr[1 + i * 16 + 8] = temp[6]; + hdr[0 + i * 16 + 8] = temp[7]; + hdr[12 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF000000) >> 24); + hdr[13 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16); + hdr[14 + i * 16 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8); + hdr[15 + i * 16 + 8] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF); + } + else + for(int i = 0; i < header.BlockDescriptors.Length; i++) + { + if(deviceType != PeripheralDeviceTypes.DirectAccess) + hdr[0 + i * 8 + 8] = (byte)header.BlockDescriptors[i].Density; + else hdr[0 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF000000) >> 24); + hdr[1 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16); + hdr[2 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8); + hdr[3 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF); + hdr[5 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16); + hdr[6 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8); + hdr[7 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF); + } return hdr; } @@ -282,7 +283,8 @@ namespace DiscImageChef.Decoders.SCSI Array.Copy(hdr, 0, md, 0, hdr.Length); - if(mode.Pages != null) + if(mode.Pages == null) return md; + { int offset = hdr.Length; foreach(ModePage page in mode.Pages) diff --git a/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs b/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs index 95a166f68..fc691e0c2 100644 --- a/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs +++ b/DiscImageChef.Decoders/SCSI/Modes/Mode6.cs @@ -184,20 +184,19 @@ namespace DiscImageChef.Decoders.SCSI break; } - if(header.BlockDescriptors != null) - { - hdr[3] = (byte)(header.BlockDescriptors.Length * 8); + if(header.BlockDescriptors == null) return hdr; - for(int i = 0; i < header.BlockDescriptors.Length; i++) - { - hdr[0 + i * 8 + 4] = (byte)header.BlockDescriptors[i].Density; - hdr[1 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16); - hdr[2 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8); - hdr[3 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF); - hdr[5 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16); - hdr[6 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8); - hdr[7 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF); - } + hdr[3] = (byte)(header.BlockDescriptors.Length * 8); + + for(int i = 0; i < header.BlockDescriptors.Length; i++) + { + hdr[0 + i * 8 + 4] = (byte)header.BlockDescriptors[i].Density; + hdr[1 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16); + hdr[2 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8); + hdr[3 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF); + hdr[5 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16); + hdr[6 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8); + hdr[7 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF); } return hdr; @@ -214,7 +213,8 @@ namespace DiscImageChef.Decoders.SCSI Array.Copy(hdr, 0, md, 0, hdr.Length); - if(mode.Pages != null) + if(mode.Pages == null) return md; + { int offset = hdr.Length; foreach(ModePage page in mode.Pages) diff --git a/DiscImageChef.Decoders/SCSI/Sense.cs b/DiscImageChef.Decoders/SCSI/Sense.cs index d898bda58..fbe505322 100644 --- a/DiscImageChef.Decoders/SCSI/Sense.cs +++ b/DiscImageChef.Decoders/SCSI/Sense.cs @@ -301,11 +301,10 @@ namespace DiscImageChef.Decoders.SCSI if(sense.Length >= 18) decoded.SenseKeySpecific = (uint)((sense[15] << 16) + (sense[16] << 8) + sense[17]); - if(sense.Length > 18) - { - decoded.AdditionalSense = new byte[sense.Length - 18]; - Array.Copy(sense, 18, decoded.AdditionalSense, 0, decoded.AdditionalSense.Length); - } + if(sense.Length <= 18) return decoded; + + decoded.AdditionalSense = new byte[sense.Length - 18]; + Array.Copy(sense, 18, decoded.AdditionalSense, 0, decoded.AdditionalSense.Length); return decoded; } @@ -398,33 +397,34 @@ namespace DiscImageChef.Decoders.SCSI if(decoded.AdditionalLength < 10) return sb.ToString(); - if(decoded.SKSV) - switch(decoded.SenseKey) - { - case SenseKeys.IllegalRequest: - { - if((decoded.SenseKeySpecific & 0x400000) == 0x400000) sb.AppendLine("Illegal field in CDB"); - else sb.AppendLine("Illegal field in data parameters"); + if(!decoded.SKSV) return sb.ToString(); - if((decoded.SenseKeySpecific & 0x200000) == 0x200000) - sb.AppendFormat("Invalid value in bit {0} in field {1} of CDB", - (decoded.SenseKeySpecific & 0x70000) >> 16, - decoded.SenseKeySpecific & 0xFFFF).AppendLine(); - else - sb.AppendFormat("Invalid value in field {0} of CDB", decoded.SenseKeySpecific & 0xFFFF) - .AppendLine(); - } - break; - case SenseKeys.NotReady: - sb.AppendFormat("Format progress {0:P}", (double)(decoded.SenseKeySpecific & 0xFFFF) / 65536) + switch(decoded.SenseKey) + { + case SenseKeys.IllegalRequest: + { + if((decoded.SenseKeySpecific & 0x400000) == 0x400000) sb.AppendLine("Illegal field in CDB"); + else sb.AppendLine("Illegal field in data parameters"); + + if((decoded.SenseKeySpecific & 0x200000) == 0x200000) + sb.AppendFormat("Invalid value in bit {0} in field {1} of CDB", + (decoded.SenseKeySpecific & 0x70000) >> 16, + decoded.SenseKeySpecific & 0xFFFF).AppendLine(); + else + sb.AppendFormat("Invalid value in field {0} of CDB", decoded.SenseKeySpecific & 0xFFFF) .AppendLine(); - break; - case SenseKeys.RecoveredError: - case SenseKeys.HardwareError: - case SenseKeys.MediumError: - sb.AppendFormat("Actual retry count is {0}", decoded.SenseKeySpecific & 0xFFFF).AppendLine(); - break; } + break; + case SenseKeys.NotReady: + sb.AppendFormat("Format progress {0:P}", (double)(decoded.SenseKeySpecific & 0xFFFF) / 65536) + .AppendLine(); + break; + case SenseKeys.RecoveredError: + case SenseKeys.HardwareError: + case SenseKeys.MediumError: + sb.AppendFormat("Actual retry count is {0}", decoded.SenseKeySpecific & 0xFFFF).AppendLine(); + break; + } return sb.ToString(); } diff --git a/DiscImageChef.Devices/Device/Commands.cs b/DiscImageChef.Devices/Device/Commands.cs index e8092b0a6..78233a279 100644 --- a/DiscImageChef.Devices/Device/Commands.cs +++ b/DiscImageChef.Devices/Device/Commands.cs @@ -173,8 +173,11 @@ namespace DiscImageChef.Devices } } - if((command == (MmcCommands)SecureDigitalCommands.SendOperatingCondition || - command == MmcCommands.SendOpCond) && cachedOcr != null) + if((command != (MmcCommands)SecureDigitalCommands.SendOperatingCondition && + command != MmcCommands.SendOpCond) || cachedOcr == null) + return Command.SendMmcCommand(platformId, fd, command, write, isApplication, flags, argument, blockSize, + blocks, ref buffer, out response, out duration, out sense, timeout); + { System.DateTime start = System.DateTime.Now; buffer = new byte[cachedOcr.Length]; @@ -185,9 +188,6 @@ namespace DiscImageChef.Devices duration = (end - start).TotalMilliseconds; return 0; } - - return Command.SendMmcCommand(platformId, fd, command, write, isApplication, flags, argument, blockSize, - blocks, ref buffer, out response, out duration, out sense, timeout); } } } \ No newline at end of file diff --git a/DiscImageChef.Devices/Device/Constructor.cs b/DiscImageChef.Devices/Device/Constructor.cs index 8dac57150..fbeaed039 100644 --- a/DiscImageChef.Devices/Device/Constructor.cs +++ b/DiscImageChef.Devices/Device/Constructor.cs @@ -383,59 +383,58 @@ namespace DiscImageChef.Devices while(resolvedLink.Contains("usb")) { resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink); - if(System.IO.File.Exists(resolvedLink + "/descriptors") && - System.IO.File.Exists(resolvedLink + "/idProduct") && - System.IO.File.Exists(resolvedLink + "/idVendor")) + if(!System.IO.File.Exists(resolvedLink + "/descriptors") || + !System.IO.File.Exists(resolvedLink + "/idProduct") || + !System.IO.File.Exists(resolvedLink + "/idVendor")) continue; + + System.IO.FileStream usbFs; + System.IO.StreamReader usbSr; + string usbTemp; + + usbFs = new System.IO.FileStream(resolvedLink + "/descriptors", + System.IO.FileMode.Open, + System.IO.FileAccess.Read); + byte[] usbBuf = new byte[65536]; + int usbCount = usbFs.Read(usbBuf, 0, 65536); + usbDescriptors = new byte[usbCount]; + Array.Copy(usbBuf, 0, usbDescriptors, 0, usbCount); + usbFs.Close(); + + usbSr = new System.IO.StreamReader(resolvedLink + "/idProduct"); + usbTemp = usbSr.ReadToEnd(); + ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out usbProduct); + usbSr.Close(); + + usbSr = new System.IO.StreamReader(resolvedLink + "/idVendor"); + usbTemp = usbSr.ReadToEnd(); + ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out usbVendor); + usbSr.Close(); + + if(System.IO.File.Exists(resolvedLink + "/manufacturer")) { - System.IO.FileStream usbFs; - System.IO.StreamReader usbSr; - string usbTemp; - - usbFs = new System.IO.FileStream(resolvedLink + "/descriptors", - System.IO.FileMode.Open, - System.IO.FileAccess.Read); - byte[] usbBuf = new byte[65536]; - int usbCount = usbFs.Read(usbBuf, 0, 65536); - usbDescriptors = new byte[usbCount]; - Array.Copy(usbBuf, 0, usbDescriptors, 0, usbCount); - usbFs.Close(); - - usbSr = new System.IO.StreamReader(resolvedLink + "/idProduct"); - usbTemp = usbSr.ReadToEnd(); - ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out usbProduct); + usbSr = new System.IO.StreamReader(resolvedLink + "/manufacturer"); + usbManufacturerString = usbSr.ReadToEnd().Trim(); usbSr.Close(); - - usbSr = new System.IO.StreamReader(resolvedLink + "/idVendor"); - usbTemp = usbSr.ReadToEnd(); - ushort.TryParse(usbTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out usbVendor); - usbSr.Close(); - - if(System.IO.File.Exists(resolvedLink + "/manufacturer")) - { - usbSr = new System.IO.StreamReader(resolvedLink + "/manufacturer"); - usbManufacturerString = usbSr.ReadToEnd().Trim(); - usbSr.Close(); - } - - if(System.IO.File.Exists(resolvedLink + "/product")) - { - usbSr = new System.IO.StreamReader(resolvedLink + "/product"); - usbProductString = usbSr.ReadToEnd().Trim(); - usbSr.Close(); - } - - if(System.IO.File.Exists(resolvedLink + "/serial")) - { - usbSr = new System.IO.StreamReader(resolvedLink + "/serial"); - usbSerialString = usbSr.ReadToEnd().Trim(); - usbSr.Close(); - } - - usb = true; - break; } + + if(System.IO.File.Exists(resolvedLink + "/product")) + { + usbSr = new System.IO.StreamReader(resolvedLink + "/product"); + usbProductString = usbSr.ReadToEnd().Trim(); + usbSr.Close(); + } + + if(System.IO.File.Exists(resolvedLink + "/serial")) + { + usbSr = new System.IO.StreamReader(resolvedLink + "/serial"); + usbSerialString = usbSr.ReadToEnd().Trim(); + usbSr.Close(); + } + + usb = true; + break; } } } @@ -487,49 +486,48 @@ namespace DiscImageChef.Devices while(resolvedLink.Contains("firewire")) { resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink); - if(System.IO.File.Exists(resolvedLink + "/model") && - System.IO.File.Exists(resolvedLink + "/vendor") && - System.IO.File.Exists(resolvedLink + "/guid")) + if(!System.IO.File.Exists(resolvedLink + "/model") || + !System.IO.File.Exists(resolvedLink + "/vendor") || + !System.IO.File.Exists(resolvedLink + "/guid")) continue; + + System.IO.StreamReader fwSr; + string fwTemp; + + fwSr = new System.IO.StreamReader(resolvedLink + "/model"); + fwTemp = fwSr.ReadToEnd(); + uint.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out firewireModel); + fwSr.Close(); + + fwSr = new System.IO.StreamReader(resolvedLink + "/vendor"); + fwTemp = fwSr.ReadToEnd(); + uint.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, + out firewireVendor); + fwSr.Close(); + + fwSr = new System.IO.StreamReader(resolvedLink + "/guid"); + fwTemp = fwSr.ReadToEnd(); + ulong.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber, + System.Globalization.CultureInfo.InvariantCulture, out firewireGuid); + fwSr.Close(); + + if(System.IO.File.Exists(resolvedLink + "/model_name")) { - System.IO.StreamReader fwSr; - string fwTemp; - - fwSr = new System.IO.StreamReader(resolvedLink + "/model"); - fwTemp = fwSr.ReadToEnd(); - uint.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out firewireModel); + fwSr = new System.IO.StreamReader(resolvedLink + "/model_name"); + firewireModelName = fwSr.ReadToEnd().Trim(); fwSr.Close(); - - fwSr = new System.IO.StreamReader(resolvedLink + "/vendor"); - fwTemp = fwSr.ReadToEnd(); - uint.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, - out firewireVendor); - fwSr.Close(); - - fwSr = new System.IO.StreamReader(resolvedLink + "/guid"); - fwTemp = fwSr.ReadToEnd(); - ulong.TryParse(fwTemp, System.Globalization.NumberStyles.HexNumber, - System.Globalization.CultureInfo.InvariantCulture, out firewireGuid); - fwSr.Close(); - - if(System.IO.File.Exists(resolvedLink + "/model_name")) - { - fwSr = new System.IO.StreamReader(resolvedLink + "/model_name"); - firewireModelName = fwSr.ReadToEnd().Trim(); - fwSr.Close(); - } - - if(System.IO.File.Exists(resolvedLink + "/vendor_name")) - { - fwSr = new System.IO.StreamReader(resolvedLink + "/vendor_name"); - firewireVendorName = fwSr.ReadToEnd().Trim(); - fwSr.Close(); - } - - firewire = true; - break; } + + if(System.IO.File.Exists(resolvedLink + "/vendor_name")) + { + fwSr = new System.IO.StreamReader(resolvedLink + "/vendor_name"); + firewireVendorName = fwSr.ReadToEnd().Trim(); + fwSr.Close(); + } + + firewire = true; + break; } } } @@ -554,36 +552,33 @@ namespace DiscImageChef.Devices while(resolvedLink.Contains("/sys/devices")) { resolvedLink = System.IO.Path.GetDirectoryName(resolvedLink); - if(System.IO.Directory.Exists(resolvedLink + "/pcmcia_socket")) - { - string[] subdirs = - System.IO.Directory.GetDirectories(resolvedLink + "/pcmcia_socket", - "pcmcia_socket*", - System.IO.SearchOption.TopDirectoryOnly); + if(!System.IO.Directory.Exists(resolvedLink + "/pcmcia_socket")) continue; - if(subdirs.Length > 0) - { - string possibleDir = - System.IO.Path.Combine(resolvedLink, "pcmcia_socket", subdirs[0]); - if(System.IO.File.Exists(possibleDir + "/card_type") && - System.IO.File.Exists(possibleDir + "/cis")) - { - System.IO.FileStream cisFs; + string[] subdirs = + System.IO.Directory.GetDirectories(resolvedLink + "/pcmcia_socket", + "pcmcia_socket*", + System.IO.SearchOption.TopDirectoryOnly); - cisFs = new System.IO.FileStream(possibleDir + "/cis", - System.IO.FileMode.Open, - System.IO.FileAccess.Read); - byte[] cisBuf = new byte[65536]; - int cisCount = cisFs.Read(cisBuf, 0, 65536); - cis = new byte[cisCount]; - Array.Copy(cisBuf, 0, cis, 0, cisCount); - cisFs.Close(); + if(subdirs.Length <= 0) continue; - pcmcia = true; - break; - } - } - } + string possibleDir = + System.IO.Path.Combine(resolvedLink, "pcmcia_socket", subdirs[0]); + if(!System.IO.File.Exists(possibleDir + "/card_type") || + !System.IO.File.Exists(possibleDir + "/cis")) continue; + + System.IO.FileStream cisFs; + + cisFs = new System.IO.FileStream(possibleDir + "/cis", + System.IO.FileMode.Open, + System.IO.FileAccess.Read); + byte[] cisBuf = new byte[65536]; + int cisCount = cisFs.Read(cisBuf, 0, 65536); + cis = new byte[cisCount]; + Array.Copy(cisBuf, 0, cis, 0, cisCount); + cisFs.Close(); + + pcmcia = true; + break; } } } @@ -678,13 +673,12 @@ namespace DiscImageChef.Devices else foreach(char c in serial) if(char.IsControl(c)) serial = usbSerialString; } - if(firewire) - { - if(string.IsNullOrEmpty(manufacturer)) manufacturer = firewireVendorName; - if(string.IsNullOrEmpty(model)) model = firewireModelName; - if(string.IsNullOrEmpty(serial)) serial = string.Format("{0:X16}", firewireGuid); - else foreach(char c in serial) if(char.IsControl(c)) serial = string.Format("{0:X16}", firewireGuid); - } + if(!firewire) return; + + if(string.IsNullOrEmpty(manufacturer)) manufacturer = firewireVendorName; + if(string.IsNullOrEmpty(model)) model = firewireModelName; + if(string.IsNullOrEmpty(serial)) serial = string.Format("{0:X16}", firewireGuid); + else foreach(char c in serial) if(char.IsControl(c)) serial = string.Format("{0:X16}", firewireGuid); } static int ConvertFromHexAscii(string file, out byte[] outBuf) diff --git a/DiscImageChef.Devices/Device/Destructor.cs b/DiscImageChef.Devices/Device/Destructor.cs index 34ecd47b5..69295e1b3 100644 --- a/DiscImageChef.Devices/Device/Destructor.cs +++ b/DiscImageChef.Devices/Device/Destructor.cs @@ -43,19 +43,20 @@ namespace DiscImageChef.Devices /// ~Device() { - if(fd != null) - switch(platformId) - { - case Interop.PlatformID.Win32NT: - Windows.Extern.CloseHandle((SafeFileHandle)fd); - break; - case Interop.PlatformID.Linux: - Linux.Extern.close((int)fd); - break; - case Interop.PlatformID.FreeBSD: - FreeBSD.Extern.cam_close_device((IntPtr)fd); - break; - } + if(fd == null) return; + + switch(platformId) + { + case Interop.PlatformID.Win32NT: + Windows.Extern.CloseHandle((SafeFileHandle)fd); + break; + case Interop.PlatformID.Linux: + Linux.Extern.close((int)fd); + break; + case Interop.PlatformID.FreeBSD: + FreeBSD.Extern.cam_close_device((IntPtr)fd); + break; + } } } } \ No newline at end of file diff --git a/DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs b/DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs index 63765b26c..6c7a7da50 100644 --- a/DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs +++ b/DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs @@ -233,13 +233,12 @@ namespace DiscImageChef.Devices DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR POWEREC GET SPEEDS took {0} ms.", duration); - if(!sense && !error) - { - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - selected = BigEndianBitConverter.ToUInt16(buf, 4); - max = BigEndianBitConverter.ToUInt16(buf, 6); - last = BigEndianBitConverter.ToUInt16(buf, 8); - } + if(sense || error) return sense; + + BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; + selected = BigEndianBitConverter.ToUInt16(buf, 4); + max = BigEndianBitConverter.ToUInt16(buf, 6); + last = BigEndianBitConverter.ToUInt16(buf, 8); return sense; } @@ -274,12 +273,11 @@ namespace DiscImageChef.Devices DicConsole.DebugWriteLine("SCSI Device", "PLEXTOR POWEREC GET SPEEDS took {0} ms.", duration); - if(!sense && !error) - { - BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; - enabled = buf[2] != 0; - speed = BigEndianBitConverter.ToUInt16(buf, 4); - } + if(sense || error) return sense; + + BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; + enabled = buf[2] != 0; + speed = BigEndianBitConverter.ToUInt16(buf, 4); return sense; } diff --git a/DiscImageChef.Devices/Windows/Usb.cs b/DiscImageChef.Devices/Windows/Usb.cs index f93155ed9..ea20b1e3a 100644 --- a/DiscImageChef.Devices/Windows/Usb.cs +++ b/DiscImageChef.Devices/Windows/Usb.cs @@ -494,57 +494,57 @@ namespace DiscImageChef.Devices.Windows // We start at the "root" of the device tree and look for all // devices that match the interface GUID of a Hub Controller IntPtr h = SetupDiGetClassDevs(ref hostGuid, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); - if(h.ToInt32() != INVALID_HANDLE_VALUE) + if(h.ToInt32() == INVALID_HANDLE_VALUE) + return new System.Collections.ObjectModel.ReadOnlyCollection(hostList); + + IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); + bool success; + int i = 0; + do { - IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); - bool success; - int i = 0; - do + UsbController host = new UsbController(); + host.ControllerIndex = i; + + // create a Device Interface Data structure + SpDeviceInterfaceData dia = new SpDeviceInterfaceData(); + dia.cbSize = Marshal.SizeOf(dia); + + // start the enumeration + success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref hostGuid, i, ref dia); + if(success) { - UsbController host = new UsbController(); - host.ControllerIndex = i; + // build a DevInfo Data structure + SpDevinfoData da = new SpDevinfoData(); + da.cbSize = Marshal.SizeOf(da); - // create a Device Interface Data structure - SpDeviceInterfaceData dia = new SpDeviceInterfaceData(); - dia.cbSize = Marshal.SizeOf(dia); + // build a Device Interface Detail Data structure + SpDeviceInterfaceDetailData didd = new SpDeviceInterfaceDetailData(); + didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :) - // start the enumeration - success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref hostGuid, i, ref dia); - if(success) + // now we can get some more detailed information + int nRequiredSize = 0; + int nBytes = BUFFER_SIZE; + if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da)) { - // build a DevInfo Data structure - SpDevinfoData da = new SpDevinfoData(); - da.cbSize = Marshal.SizeOf(da); + host.ControllerDevicePath = didd.DevicePath; - // build a Device Interface Detail Data structure - SpDeviceInterfaceDetailData didd = new SpDeviceInterfaceDetailData(); - didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :) + // get the Device Description and DriverKeyName + int requiredSize = 0; + int regType = REG_SZ; - // now we can get some more detailed information - int nRequiredSize = 0; - int nBytes = BUFFER_SIZE; - if(SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da)) - { - host.ControllerDevicePath = didd.DevicePath; - - // get the Device Description and DriverKeyName - int requiredSize = 0; - int regType = REG_SZ; - - if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf, - BUFFER_SIZE, ref requiredSize)) host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf); - if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, - BUFFER_SIZE, ref requiredSize)) host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf); - } - hostList.Add(host); + if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf, + BUFFER_SIZE, ref requiredSize)) host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf); + if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, + BUFFER_SIZE, ref requiredSize)) host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf); } - i++; + hostList.Add(host); } - while(success); - - Marshal.FreeHGlobal(ptrBuf); - SetupDiDestroyDeviceInfoList(h); + i++; } + while(success); + + Marshal.FreeHGlobal(ptrBuf); + SetupDiDestroyDeviceInfoList(h); // convert it into a Collection return new System.Collections.ObjectModel.ReadOnlyCollection(hostList); @@ -602,50 +602,49 @@ namespace DiscImageChef.Devices.Windows // Open a handle to the Host Controller h = CreateFile(ControllerDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h.ToInt32() != INVALID_HANDLE_VALUE) - { - int nBytesReturned; - UsbRootHubName hubName = new UsbRootHubName(); - int nBytes = Marshal.SizeOf(hubName); - IntPtr ptrHubName = Marshal.AllocHGlobal(nBytes); + if(h.ToInt32() == INVALID_HANDLE_VALUE) return root; - // get the Hub Name - if(DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, + int nBytesReturned; + UsbRootHubName hubName = new UsbRootHubName(); + int nBytes = Marshal.SizeOf(hubName); + IntPtr ptrHubName = Marshal.AllocHGlobal(nBytes); + + // get the Hub Name + if(DeviceIoControl(h, IOCTL_USB_GET_ROOT_HUB_NAME, ptrHubName, nBytes, ptrHubName, nBytes, + out nBytesReturned, IntPtr.Zero)) + { + hubName = (UsbRootHubName)Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)); + root.HubDevicePath = @"\\.\" + hubName.RootHubName; + } + + // TODO: Get DriverKeyName for Root Hub + + // Now let's open the Hub (based upon the HubName we got above) + h2 = CreateFile(root.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + IntPtr.Zero); + if(h2.ToInt32() != INVALID_HANDLE_VALUE) + { + UsbNodeInformation nodeInfo = new UsbNodeInformation(); + nodeInfo.NodeType = (int)UsbHubNode.UsbHub; + nBytes = Marshal.SizeOf(nodeInfo); + IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes); + Marshal.StructureToPtr(nodeInfo, ptrNodeInfo, true); + + // get the Hub Information + if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out nBytesReturned, IntPtr.Zero)) { - hubName = (UsbRootHubName)Marshal.PtrToStructure(ptrHubName, typeof(UsbRootHubName)); - root.HubDevicePath = @"\\.\" + hubName.RootHubName; + nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo, + typeof(UsbNodeInformation)); + root.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); + root.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; } - - // TODO: Get DriverKeyName for Root Hub - - // Now let's open the Hub (based upon the HubName we got above) - h2 = CreateFile(root.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, - IntPtr.Zero); - if(h2.ToInt32() != INVALID_HANDLE_VALUE) - { - UsbNodeInformation nodeInfo = new UsbNodeInformation(); - nodeInfo.NodeType = (int)UsbHubNode.UsbHub; - nBytes = Marshal.SizeOf(nodeInfo); - IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes); - Marshal.StructureToPtr(nodeInfo, ptrNodeInfo, true); - - // get the Hub Information - if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, - out nBytesReturned, IntPtr.Zero)) - { - nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo, - typeof(UsbNodeInformation)); - root.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); - root.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; - } - Marshal.FreeHGlobal(ptrNodeInfo); - CloseHandle(h2); - } - - Marshal.FreeHGlobal(ptrHubName); - CloseHandle(h); + Marshal.FreeHGlobal(ptrNodeInfo); + CloseHandle(h2); } + + Marshal.FreeHGlobal(ptrHubName); + CloseHandle(h); return root; } } @@ -740,50 +739,49 @@ namespace DiscImageChef.Devices.Windows // Open a handle to the Hub device IntPtr h = CreateFile(HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h.ToInt32() != INVALID_HANDLE_VALUE) + if(h.ToInt32() == INVALID_HANDLE_VALUE) + return new System.Collections.ObjectModel.ReadOnlyCollection(portList); + + int nBytes = Marshal.SizeOf(typeof(UsbNodeConnectionInformationEx)); + IntPtr ptrNodeConnection = Marshal.AllocHGlobal(nBytes); + + // loop thru all of the ports on the hub + // BTW: Ports are numbered starting at 1 + for(int i = 1; i <= HubPortCount; i++) { - int nBytes = Marshal.SizeOf(typeof(UsbNodeConnectionInformationEx)); - IntPtr ptrNodeConnection = Marshal.AllocHGlobal(nBytes); + int nBytesReturned; + UsbNodeConnectionInformationEx nodeConnection = new UsbNodeConnectionInformationEx(); + nodeConnection.ConnectionIndex = i; + Marshal.StructureToPtr(nodeConnection, ptrNodeConnection, true); - // loop thru all of the ports on the hub - // BTW: Ports are numbered starting at 1 - for(int i = 1; i <= HubPortCount; i++) - { - int nBytesReturned; - UsbNodeConnectionInformationEx nodeConnection = new UsbNodeConnectionInformationEx(); - nodeConnection.ConnectionIndex = i; - Marshal.StructureToPtr(nodeConnection, ptrNodeConnection, true); + if(!DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, ptrNodeConnection, nBytes, + ptrNodeConnection, nBytes, out nBytesReturned, IntPtr.Zero)) continue; - if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, ptrNodeConnection, nBytes, - ptrNodeConnection, nBytes, out nBytesReturned, IntPtr.Zero)) - { - nodeConnection = - (UsbNodeConnectionInformationEx)Marshal.PtrToStructure(ptrNodeConnection, - typeof( - UsbNodeConnectionInformationEx - )); + nodeConnection = + (UsbNodeConnectionInformationEx)Marshal.PtrToStructure(ptrNodeConnection, + typeof( + UsbNodeConnectionInformationEx + )); - // load up the USBPort class - UsbPort port = new UsbPort(); - port.PortPortNumber = i; - port.PortHubDevicePath = HubDevicePath; - UsbConnectionStatus status = (UsbConnectionStatus)nodeConnection.ConnectionStatus; - port.PortStatus = status.ToString(); - UsbDeviceSpeed speed = (UsbDeviceSpeed)nodeConnection.Speed; - port.PortSpeed = speed.ToString(); - port.PortIsDeviceConnected = - nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected; - port.PortIsHub = Convert.ToBoolean(nodeConnection.DeviceIsHub); - port.PortDeviceDescriptor = nodeConnection.DeviceDescriptor; + // load up the USBPort class + UsbPort port = new UsbPort(); + port.PortPortNumber = i; + port.PortHubDevicePath = HubDevicePath; + UsbConnectionStatus status = (UsbConnectionStatus)nodeConnection.ConnectionStatus; + port.PortStatus = status.ToString(); + UsbDeviceSpeed speed = (UsbDeviceSpeed)nodeConnection.Speed; + port.PortSpeed = speed.ToString(); + port.PortIsDeviceConnected = + nodeConnection.ConnectionStatus == (int)UsbConnectionStatus.DeviceConnected; + port.PortIsHub = Convert.ToBoolean(nodeConnection.DeviceIsHub); + port.PortDeviceDescriptor = nodeConnection.DeviceDescriptor; - // add it to the list - portList.Add(port); - } - } - - Marshal.FreeHGlobal(ptrNodeConnection); - CloseHandle(h); + // add it to the list + portList.Add(port); } + + Marshal.FreeHGlobal(ptrNodeConnection); + CloseHandle(h); // convert it into a Collection return new System.Collections.ObjectModel.ReadOnlyCollection(portList); } @@ -862,143 +860,142 @@ namespace DiscImageChef.Devices.Windows // Open a handle to the Hub device IntPtr h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h.ToInt32() != INVALID_HANDLE_VALUE) + if(h.ToInt32() == INVALID_HANDLE_VALUE) return device; + + int nBytesReturned; + int nBytes = BUFFER_SIZE; + // We use this to zero fill a buffer + string nullString = new string((char)0, BUFFER_SIZE / Marshal.SystemDefaultCharSize); + + // The iManufacturer, iProduct and iSerialNumber entries in the + // Device Descriptor are really just indexes. So, we have to + // request a String Descriptor to get the values for those strings. + + if(PortDeviceDescriptor.iManufacturer > 0) { - int nBytesReturned; - int nBytes = BUFFER_SIZE; - // We use this to zero fill a buffer - string nullString = new string((char)0, BUFFER_SIZE / Marshal.SystemDefaultCharSize); - - // The iManufacturer, iProduct and iSerialNumber entries in the - // Device Descriptor are really just indexes. So, we have to - // request a String Descriptor to get the values for those strings. - - if(PortDeviceDescriptor.iManufacturer > 0) - { - // build a request for string descriptor - UsbDescriptorRequest request = new UsbDescriptorRequest(); - request.ConnectionIndex = PortPortNumber; - request.SetupPacket.wValue = - (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iManufacturer); - request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request)); - request.SetupPacket.wIndex = 0x409; // Language Code - // Geez, I wish C# had a Marshal.MemSet() method - IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString); - Marshal.StructureToPtr(request, ptrRequest, true); - - // Use an IOCTL call to request the String Descriptor - if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, ptrRequest, nBytes, - ptrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) - { - // The location of the string descriptor is immediately after - // the Request structure. Because this location is not "covered" - // by the structure allocation, we're forced to zero out this - // chunk of memory by using the StringToHGlobalAuto() hack above - IntPtr ptrStringDesc = new IntPtr(ptrRequest.ToInt32() + Marshal.SizeOf(request)); - UsbStringDescriptor stringDesc = - (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, - typeof(UsbStringDescriptor)); - device.DeviceManufacturer = stringDesc.bString; - } - Marshal.FreeHGlobal(ptrRequest); - } - if(PortDeviceDescriptor.iProduct > 0) - { - // build a request for string descriptor - UsbDescriptorRequest request = new UsbDescriptorRequest(); - request.ConnectionIndex = PortPortNumber; - request.SetupPacket.wValue = - (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iProduct); - request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request)); - request.SetupPacket.wIndex = 0x409; // Language Code - // Geez, I wish C# had a Marshal.MemSet() method - IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString); - Marshal.StructureToPtr(request, ptrRequest, true); - - // Use an IOCTL call to request the String Descriptor - if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, ptrRequest, nBytes, - ptrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) - { - // the location of the string descriptor is immediately after the Request structure - IntPtr ptrStringDesc = new IntPtr(ptrRequest.ToInt32() + Marshal.SizeOf(request)); - UsbStringDescriptor stringDesc = - (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, - typeof(UsbStringDescriptor)); - device.DeviceProduct = stringDesc.bString; - } - Marshal.FreeHGlobal(ptrRequest); - } - if(PortDeviceDescriptor.iSerialNumber > 0) - { - // build a request for string descriptor - UsbDescriptorRequest request = new UsbDescriptorRequest(); - request.ConnectionIndex = PortPortNumber; - request.SetupPacket.wValue = - (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iSerialNumber); - request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request)); - request.SetupPacket.wIndex = 0x409; // Language Code - // Geez, I wish C# had a Marshal.MemSet() method - IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString); - Marshal.StructureToPtr(request, ptrRequest, true); - - // Use an IOCTL call to request the String Descriptor - if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, ptrRequest, nBytes, - ptrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) - { - // the location of the string descriptor is immediately after the Request structure - IntPtr ptrStringDesc = new IntPtr(ptrRequest.ToInt32() + Marshal.SizeOf(request)); - UsbStringDescriptor stringDesc = - (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, - typeof(UsbStringDescriptor)); - device.DeviceSerialNumber = stringDesc.bString; - } - Marshal.FreeHGlobal(ptrRequest); - } - - // build a request for configuration descriptor - UsbDescriptorRequest dcrRequest = new UsbDescriptorRequest(); - dcrRequest.ConnectionIndex = PortPortNumber; - dcrRequest.SetupPacket.wValue = (short)(USB_CONFIGURATION_DESCRIPTOR_TYPE << 8); - dcrRequest.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(dcrRequest)); - dcrRequest.SetupPacket.wIndex = 0; + // build a request for string descriptor + UsbDescriptorRequest request = new UsbDescriptorRequest(); + request.ConnectionIndex = PortPortNumber; + request.SetupPacket.wValue = + (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iManufacturer); + request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request)); + request.SetupPacket.wIndex = 0x409; // Language Code // Geez, I wish C# had a Marshal.MemSet() method - IntPtr dcrPtrRequest = Marshal.StringToHGlobalAuto(nullString); - Marshal.StructureToPtr(dcrRequest, dcrPtrRequest, true); + IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString); + Marshal.StructureToPtr(request, ptrRequest, true); // Use an IOCTL call to request the String Descriptor - if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, dcrPtrRequest, nBytes, - dcrPtrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) + if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, ptrRequest, nBytes, + ptrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) { - IntPtr ptrStringDesc = new IntPtr(dcrPtrRequest.ToInt32() + Marshal.SizeOf(dcrRequest)); - device.BinaryDeviceDescriptors = new byte[nBytesReturned]; - Marshal.Copy(ptrStringDesc, device.BinaryDeviceDescriptors, 0, nBytesReturned); + // The location of the string descriptor is immediately after + // the Request structure. Because this location is not "covered" + // by the structure allocation, we're forced to zero out this + // chunk of memory by using the StringToHGlobalAuto() hack above + IntPtr ptrStringDesc = new IntPtr(ptrRequest.ToInt32() + Marshal.SizeOf(request)); + UsbStringDescriptor stringDesc = + (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, + typeof(UsbStringDescriptor)); + device.DeviceManufacturer = stringDesc.bString; } - Marshal.FreeHGlobal(dcrPtrRequest); - - // Get the Driver Key Name (usefull in locating a device) - UsbNodeConnectionDriverkeyName driverKey = new UsbNodeConnectionDriverkeyName(); - driverKey.ConnectionIndex = PortPortNumber; - nBytes = Marshal.SizeOf(driverKey); - IntPtr ptrDriverKey = Marshal.AllocHGlobal(nBytes); - Marshal.StructureToPtr(driverKey, ptrDriverKey, true); - - // Use an IOCTL call to request the Driver Key Name - if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME, ptrDriverKey, nBytes, - ptrDriverKey, nBytes, out nBytesReturned, IntPtr.Zero)) - { - driverKey = (UsbNodeConnectionDriverkeyName)Marshal.PtrToStructure(ptrDriverKey, - typeof( - UsbNodeConnectionDriverkeyName - )); - device.DeviceDriverKey = driverKey.DriverKeyName; - - // use the DriverKeyName to get the Device Description and Instance ID - device.DeviceName = GetDescriptionByKeyName(device.DeviceDriverKey); - device.DeviceInstanceId = GetInstanceIdByKeyName(device.DeviceDriverKey); - } - Marshal.FreeHGlobal(ptrDriverKey); - CloseHandle(h); + Marshal.FreeHGlobal(ptrRequest); } + if(PortDeviceDescriptor.iProduct > 0) + { + // build a request for string descriptor + UsbDescriptorRequest request = new UsbDescriptorRequest(); + request.ConnectionIndex = PortPortNumber; + request.SetupPacket.wValue = + (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iProduct); + request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request)); + request.SetupPacket.wIndex = 0x409; // Language Code + // Geez, I wish C# had a Marshal.MemSet() method + IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString); + Marshal.StructureToPtr(request, ptrRequest, true); + + // Use an IOCTL call to request the String Descriptor + if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, ptrRequest, nBytes, + ptrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) + { + // the location of the string descriptor is immediately after the Request structure + IntPtr ptrStringDesc = new IntPtr(ptrRequest.ToInt32() + Marshal.SizeOf(request)); + UsbStringDescriptor stringDesc = + (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, + typeof(UsbStringDescriptor)); + device.DeviceProduct = stringDesc.bString; + } + Marshal.FreeHGlobal(ptrRequest); + } + if(PortDeviceDescriptor.iSerialNumber > 0) + { + // build a request for string descriptor + UsbDescriptorRequest request = new UsbDescriptorRequest(); + request.ConnectionIndex = PortPortNumber; + request.SetupPacket.wValue = + (short)((USB_STRING_DESCRIPTOR_TYPE << 8) + PortDeviceDescriptor.iSerialNumber); + request.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(request)); + request.SetupPacket.wIndex = 0x409; // Language Code + // Geez, I wish C# had a Marshal.MemSet() method + IntPtr ptrRequest = Marshal.StringToHGlobalAuto(nullString); + Marshal.StructureToPtr(request, ptrRequest, true); + + // Use an IOCTL call to request the String Descriptor + if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, ptrRequest, nBytes, + ptrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) + { + // the location of the string descriptor is immediately after the Request structure + IntPtr ptrStringDesc = new IntPtr(ptrRequest.ToInt32() + Marshal.SizeOf(request)); + UsbStringDescriptor stringDesc = + (UsbStringDescriptor)Marshal.PtrToStructure(ptrStringDesc, + typeof(UsbStringDescriptor)); + device.DeviceSerialNumber = stringDesc.bString; + } + Marshal.FreeHGlobal(ptrRequest); + } + + // build a request for configuration descriptor + UsbDescriptorRequest dcrRequest = new UsbDescriptorRequest(); + dcrRequest.ConnectionIndex = PortPortNumber; + dcrRequest.SetupPacket.wValue = (short)(USB_CONFIGURATION_DESCRIPTOR_TYPE << 8); + dcrRequest.SetupPacket.wLength = (short)(nBytes - Marshal.SizeOf(dcrRequest)); + dcrRequest.SetupPacket.wIndex = 0; + // Geez, I wish C# had a Marshal.MemSet() method + IntPtr dcrPtrRequest = Marshal.StringToHGlobalAuto(nullString); + Marshal.StructureToPtr(dcrRequest, dcrPtrRequest, true); + + // Use an IOCTL call to request the String Descriptor + if(DeviceIoControl(h, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, dcrPtrRequest, nBytes, + dcrPtrRequest, nBytes, out nBytesReturned, IntPtr.Zero)) + { + IntPtr ptrStringDesc = new IntPtr(dcrPtrRequest.ToInt32() + Marshal.SizeOf(dcrRequest)); + device.BinaryDeviceDescriptors = new byte[nBytesReturned]; + Marshal.Copy(ptrStringDesc, device.BinaryDeviceDescriptors, 0, nBytesReturned); + } + Marshal.FreeHGlobal(dcrPtrRequest); + + // Get the Driver Key Name (usefull in locating a device) + UsbNodeConnectionDriverkeyName driverKey = new UsbNodeConnectionDriverkeyName(); + driverKey.ConnectionIndex = PortPortNumber; + nBytes = Marshal.SizeOf(driverKey); + IntPtr ptrDriverKey = Marshal.AllocHGlobal(nBytes); + Marshal.StructureToPtr(driverKey, ptrDriverKey, true); + + // Use an IOCTL call to request the Driver Key Name + if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME, ptrDriverKey, nBytes, + ptrDriverKey, nBytes, out nBytesReturned, IntPtr.Zero)) + { + driverKey = (UsbNodeConnectionDriverkeyName)Marshal.PtrToStructure(ptrDriverKey, + typeof( + UsbNodeConnectionDriverkeyName + )); + device.DeviceDriverKey = driverKey.DriverKeyName; + + // use the DriverKeyName to get the Device Description and Instance ID + device.DeviceName = GetDescriptionByKeyName(device.DeviceDriverKey); + device.DeviceInstanceId = GetInstanceIdByKeyName(device.DeviceDriverKey); + } + Marshal.FreeHGlobal(ptrDriverKey); + CloseHandle(h); return device; } @@ -1015,61 +1012,59 @@ namespace DiscImageChef.Devices.Windows // Open a handle to the Host Controller h = CreateFile(PortHubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h.ToInt32() != INVALID_HANDLE_VALUE) - { - // Get the DevicePath for downstream hub - int nBytesReturned; - UsbNodeConnectionName nodeName = new UsbNodeConnectionName(); - nodeName.ConnectionIndex = PortPortNumber; - int nBytes = Marshal.SizeOf(nodeName); - IntPtr ptrNodeName = Marshal.AllocHGlobal(nBytes); - Marshal.StructureToPtr(nodeName, ptrNodeName, true); + if(h.ToInt32() == INVALID_HANDLE_VALUE) return hub; + // Get the DevicePath for downstream hub + int nBytesReturned; + UsbNodeConnectionName nodeName = new UsbNodeConnectionName(); + nodeName.ConnectionIndex = PortPortNumber; + int nBytes = Marshal.SizeOf(nodeName); + IntPtr ptrNodeName = Marshal.AllocHGlobal(nBytes); + Marshal.StructureToPtr(nodeName, ptrNodeName, true); - // Use an IOCTL call to request the Node Name - if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes, + // Use an IOCTL call to request the Node Name + if(DeviceIoControl(h, IOCTL_USB_GET_NODE_CONNECTION_NAME, ptrNodeName, nBytes, ptrNodeName, nBytes, + out nBytesReturned, IntPtr.Zero)) + { + nodeName = (UsbNodeConnectionName)Marshal.PtrToStructure(ptrNodeName, + typeof(UsbNodeConnectionName)); + hub.HubDevicePath = @"\\.\" + nodeName.NodeName; + } + + // Now let's open the Hub (based upon the HubName we got above) + h2 = CreateFile(hub.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, + IntPtr.Zero); + if(h2.ToInt32() != INVALID_HANDLE_VALUE) + { + UsbNodeInformation nodeInfo = new UsbNodeInformation(); + nodeInfo.NodeType = (int)UsbHubNode.UsbHub; + nBytes = Marshal.SizeOf(nodeInfo); + IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes); + Marshal.StructureToPtr(nodeInfo, ptrNodeInfo, true); + + // get the Hub Information + if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, out nBytesReturned, IntPtr.Zero)) { - nodeName = (UsbNodeConnectionName)Marshal.PtrToStructure(ptrNodeName, - typeof(UsbNodeConnectionName)); - hub.HubDevicePath = @"\\.\" + nodeName.NodeName; + nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo, + typeof(UsbNodeInformation)); + hub.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); + hub.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; } - - // Now let's open the Hub (based upon the HubName we got above) - h2 = CreateFile(hub.HubDevicePath, GENERIC_WRITE, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, - IntPtr.Zero); - if(h2.ToInt32() != INVALID_HANDLE_VALUE) - { - UsbNodeInformation nodeInfo = new UsbNodeInformation(); - nodeInfo.NodeType = (int)UsbHubNode.UsbHub; - nBytes = Marshal.SizeOf(nodeInfo); - IntPtr ptrNodeInfo = Marshal.AllocHGlobal(nBytes); - Marshal.StructureToPtr(nodeInfo, ptrNodeInfo, true); - - // get the Hub Information - if(DeviceIoControl(h2, IOCTL_USB_GET_NODE_INFORMATION, ptrNodeInfo, nBytes, ptrNodeInfo, nBytes, - out nBytesReturned, IntPtr.Zero)) - { - nodeInfo = (UsbNodeInformation)Marshal.PtrToStructure(ptrNodeInfo, - typeof(UsbNodeInformation)); - hub.HubIsBusPowered = Convert.ToBoolean(nodeInfo.HubInformation.HubIsBusPowered); - hub.HubPortCount = nodeInfo.HubInformation.HubDescriptor.bNumberOfPorts; - } - Marshal.FreeHGlobal(ptrNodeInfo); - CloseHandle(h2); - } - - // Fill in the missing Manufacture, Product, and SerialNumber values - // values by just creating a Device instance and copying the values - UsbDevice device = GetDevice(); - hub.HubInstanceId = device.DeviceInstanceId; - hub.HubManufacturer = device.Manufacturer; - hub.HubProduct = device.Product; - hub.HubSerialNumber = device.SerialNumber; - hub.HubDriverKey = device.DriverKey; - - Marshal.FreeHGlobal(ptrNodeName); - CloseHandle(h); + Marshal.FreeHGlobal(ptrNodeInfo); + CloseHandle(h2); } + + // Fill in the missing Manufacture, Product, and SerialNumber values + // values by just creating a Device instance and copying the values + UsbDevice device = GetDevice(); + hub.HubInstanceId = device.DeviceInstanceId; + hub.HubManufacturer = device.Manufacturer; + hub.HubProduct = device.Product; + hub.HubSerialNumber = device.SerialNumber; + hub.HubDriverKey = device.DriverKey; + + Marshal.FreeHGlobal(ptrNodeName); + CloseHandle(h); return hub; } } @@ -1161,46 +1156,45 @@ namespace DiscImageChef.Devices.Windows // Use the "enumerator form" of the SetupDiGetClassDevs API // to generate a list of all USB devices IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES); - if(h.ToInt32() != INVALID_HANDLE_VALUE) + if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans; + + IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); + string keyName; + + bool success; + int i = 0; + do { - IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); - string keyName; + // create a Device Interface Data structure + SpDevinfoData da = new SpDevinfoData(); + da.cbSize = Marshal.SizeOf(da); - bool success; - int i = 0; - do + // start the enumeration + success = SetupDiEnumDeviceInfo(h, i, ref da); + if(success) { - // create a Device Interface Data structure - SpDevinfoData da = new SpDevinfoData(); - da.cbSize = Marshal.SizeOf(da); + int requiredSize = 0; + int regType = REG_SZ; + keyName = ""; - // start the enumeration - success = SetupDiEnumDeviceInfo(h, i, ref da); - if(success) + if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE, + ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf); + + // is it a match? + if(keyName == driverKeyName) { - int requiredSize = 0; - int regType = REG_SZ; - keyName = ""; - - if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE, - ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf); - - // is it a match? - if(keyName == driverKeyName) - { - if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf, - BUFFER_SIZE, ref requiredSize)) ans = Marshal.PtrToStringAuto(ptrBuf); - break; - } + if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref regType, ptrBuf, + BUFFER_SIZE, ref requiredSize)) ans = Marshal.PtrToStringAuto(ptrBuf); + break; } - - i++; } - while(success); - Marshal.FreeHGlobal(ptrBuf); - SetupDiDestroyDeviceInfoList(h); + i++; } + while(success); + + Marshal.FreeHGlobal(ptrBuf); + SetupDiDestroyDeviceInfoList(h); return ans; } @@ -1216,48 +1210,47 @@ namespace DiscImageChef.Devices.Windows // Use the "enumerator form" of the SetupDiGetClassDevs API // to generate a list of all USB devices IntPtr h = SetupDiGetClassDevs(0, devEnum, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES); - if(h.ToInt32() != INVALID_HANDLE_VALUE) + if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans; + + IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); + string keyName; + + bool success; + int i = 0; + do { - IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); - string keyName; + // create a Device Interface Data structure + SpDevinfoData da = new SpDevinfoData(); + da.cbSize = Marshal.SizeOf(da); - bool success; - int i = 0; - do + // start the enumeration + success = SetupDiEnumDeviceInfo(h, i, ref da); + if(success) { - // create a Device Interface Data structure - SpDevinfoData da = new SpDevinfoData(); - da.cbSize = Marshal.SizeOf(da); + int requiredSize = 0; + int regType = REG_SZ; - // start the enumeration - success = SetupDiEnumDeviceInfo(h, i, ref da); - if(success) + keyName = ""; + if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE, + ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf); + + // is it a match? + if(keyName == driverKeyName) { - int requiredSize = 0; - int regType = REG_SZ; - - keyName = ""; - if(SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref regType, ptrBuf, BUFFER_SIZE, - ref requiredSize)) keyName = Marshal.PtrToStringAuto(ptrBuf); - - // is it a match? - if(keyName == driverKeyName) - { - int nBytes = BUFFER_SIZE; - StringBuilder sb = new StringBuilder(nBytes); - SetupDiGetDeviceInstanceId(h, ref da, sb, nBytes, out requiredSize); - ans = sb.ToString(); - break; - } + int nBytes = BUFFER_SIZE; + StringBuilder sb = new StringBuilder(nBytes); + SetupDiGetDeviceInstanceId(h, ref da, sb, nBytes, out requiredSize); + ans = sb.ToString(); + break; } - - i++; } - while(success); - Marshal.FreeHGlobal(ptrBuf); - SetupDiDestroyDeviceInfoList(h); + i++; } + while(success); + + Marshal.FreeHGlobal(ptrBuf); + SetupDiDestroyDeviceInfoList(h); return ans; } diff --git a/DiscImageChef.Devices/Windows/UsbFunctions.cs b/DiscImageChef.Devices/Windows/UsbFunctions.cs index 87d211b35..f63b9efaa 100644 --- a/DiscImageChef.Devices/Windows/UsbFunctions.cs +++ b/DiscImageChef.Devices/Windows/UsbFunctions.cs @@ -86,15 +86,13 @@ namespace DiscImageChef.Devices.Windows if(port.IsHub) SearchHubDriverKeyName(port.GetHub(), ref foundDevice, driverKeyName); else { - if(port.IsDeviceConnected) - { - UsbDevice device = port.GetDevice(); - if(device.DeviceDriverKey == driverKeyName) - { - foundDevice = device; - break; - } - } + if(!port.IsDeviceConnected) continue; + + UsbDevice device = port.GetDevice(); + if(device.DeviceDriverKey != driverKeyName) continue; + + foundDevice = device; + break; } } @@ -121,15 +119,13 @@ namespace DiscImageChef.Devices.Windows if(port.IsHub) SearchHubInstanceId(port.GetHub(), ref foundDevice, instanceId); else { - if(port.IsDeviceConnected) - { - UsbDevice device = port.GetDevice(); - if(device.InstanceId == instanceId) - { - foundDevice = device; - break; - } - } + if(!port.IsDeviceConnected) continue; + + UsbDevice device = port.GetDevice(); + if(device.InstanceId != instanceId) continue; + + foundDevice = device; + break; } } @@ -273,24 +269,23 @@ namespace DiscImageChef.Devices.Windows int ans = -1; IntPtr h = CreateFile(devicePath.TrimEnd('\\'), 0, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); - if(h.ToInt32() != INVALID_HANDLE_VALUE) - { - int requiredSize; - StorageDeviceNumber sdn = new StorageDeviceNumber(); - int nBytes = Marshal.SizeOf(sdn); - IntPtr ptrSdn = Marshal.AllocHGlobal(nBytes); + if(h.ToInt32() == INVALID_HANDLE_VALUE) return ans; - if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out requiredSize, - IntPtr.Zero)) - { - sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber)); - // just my way of combining the relevant parts of the - // STORAGE_DEVICE_NUMBER into a single number - ans = (sdn.DeviceType << 8) + sdn.DeviceNumber; - } - Marshal.FreeHGlobal(ptrSdn); - CloseHandle(h); + int requiredSize; + StorageDeviceNumber sdn = new StorageDeviceNumber(); + int nBytes = Marshal.SizeOf(sdn); + IntPtr ptrSdn = Marshal.AllocHGlobal(nBytes); + + if(DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, IntPtr.Zero, 0, ptrSdn, nBytes, out requiredSize, + IntPtr.Zero)) + { + sdn = (StorageDeviceNumber)Marshal.PtrToStructure(ptrSdn, typeof(StorageDeviceNumber)); + // just my way of combining the relevant parts of the + // STORAGE_DEVICE_NUMBER into a single number + ans = (sdn.DeviceType << 8) + sdn.DeviceNumber; } + Marshal.FreeHGlobal(ptrSdn); + CloseHandle(h); return ans; } } diff --git a/DiscImageChef.DiscImages/Alcohol120.cs b/DiscImageChef.DiscImages/Alcohol120.cs index cab796d73..5a893d8c6 100644 --- a/DiscImageChef.DiscImages/Alcohol120.cs +++ b/DiscImageChef.DiscImages/Alcohol120.cs @@ -828,9 +828,10 @@ namespace DiscImageChef.DiscImages { AlcoholTrackExtra extra; - if(track.point == kvp.Key && alcTrackExtras.TryGetValue(track.point, out extra)) - if(sectorAddress - kvp.Value < extra.sectors) - return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key); + if(track.point != kvp.Key || !alcTrackExtras.TryGetValue(track.point, out extra)) continue; + + if(sectorAddress - kvp.Value < extra.sectors) + return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key); } throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found"); @@ -844,9 +845,10 @@ namespace DiscImageChef.DiscImages { AlcoholTrackExtra extra; - if(track.point == kvp.Key && alcTrackExtras.TryGetValue(track.point, out extra)) - if(sectorAddress - kvp.Value < extra.sectors) - return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag); + if(track.point != kvp.Key || !alcTrackExtras.TryGetValue(track.point, out extra)) continue; + + if(sectorAddress - kvp.Value < extra.sectors) + return ReadSectorsTag(sectorAddress - kvp.Value, length, kvp.Key, tag); } throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found"); @@ -1296,9 +1298,10 @@ namespace DiscImageChef.DiscImages { AlcoholTrackExtra extra; - if(track.point == kvp.Key && alcTrackExtras.TryGetValue(track.point, out extra)) - if(sectorAddress - kvp.Value < extra.sectors) - return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key); + if(track.point != kvp.Key || !alcTrackExtras.TryGetValue(track.point, out extra)) continue; + + if(sectorAddress - kvp.Value < extra.sectors) + return ReadSectorsLong(sectorAddress - kvp.Value, length, kvp.Key); } throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found"); @@ -1393,40 +1396,39 @@ namespace DiscImageChef.DiscImages } AlcoholTrackExtra extra; - if(alcTrackExtras.TryGetValue(track.point, out extra)) + if(!alcTrackExtras.TryGetValue(track.point, out extra)) continue; + + Track _track = new Track(); + + _track.Indexes = new Dictionary(); + _track.Indexes.Add(1, track.startLba); + _track.TrackStartSector = track.startLba; + _track.TrackEndSector = extra.sectors - 1; + _track.TrackPregap = extra.pregap; + _track.TrackSession = sessionNo; + _track.TrackSequence = track.point; + _track.TrackType = AlcoholTrackTypeToTrackType(track.mode); + _track.TrackFilter = alcImage; + _track.TrackFile = alcImage.GetFilename(); + _track.TrackFileOffset = track.startOffset; + _track.TrackFileType = "BINARY"; + _track.TrackRawBytesPerSector = track.sectorSize; + _track.TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(track.mode); + switch(track.subMode) { - Track _track = new Track(); - - _track.Indexes = new Dictionary(); - _track.Indexes.Add(1, track.startLba); - _track.TrackStartSector = track.startLba; - _track.TrackEndSector = extra.sectors - 1; - _track.TrackPregap = extra.pregap; - _track.TrackSession = sessionNo; - _track.TrackSequence = track.point; - _track.TrackType = AlcoholTrackTypeToTrackType(track.mode); - _track.TrackFilter = alcImage; - _track.TrackFile = alcImage.GetFilename(); - _track.TrackFileOffset = track.startOffset; - _track.TrackFileType = "BINARY"; - _track.TrackRawBytesPerSector = track.sectorSize; - _track.TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(track.mode); - switch(track.subMode) - { - case AlcoholSubchannelMode.Interleaved: - _track.TrackSubchannelFilter = alcImage; - _track.TrackSubchannelFile = alcImage.GetFilename(); - _track.TrackSubchannelOffset = track.startOffset; - _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; - _track.TrackRawBytesPerSector += 96; - break; - case AlcoholSubchannelMode.None: - _track.TrackSubchannelType = TrackSubchannelType.None; - break; - } - - tracks.Add(_track); + case AlcoholSubchannelMode.Interleaved: + _track.TrackSubchannelFilter = alcImage; + _track.TrackSubchannelFile = alcImage.GetFilename(); + _track.TrackSubchannelOffset = track.startOffset; + _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; + _track.TrackRawBytesPerSector += 96; + break; + case AlcoholSubchannelMode.None: + _track.TrackSubchannelType = TrackSubchannelType.None; + break; } + + tracks.Add(_track); } return tracks; @@ -1455,40 +1457,39 @@ namespace DiscImageChef.DiscImages } AlcoholTrackExtra extra; - if(alcTrackExtras.TryGetValue(track.point, out extra) && session == sessionNo) + if(!alcTrackExtras.TryGetValue(track.point, out extra) || session != sessionNo) continue; + + Track _track = new Track(); + + _track.Indexes = new Dictionary(); + _track.Indexes.Add(1, track.startLba); + _track.TrackStartSector = track.startLba; + _track.TrackEndSector = extra.sectors - 1; + _track.TrackPregap = extra.pregap; + _track.TrackSession = sessionNo; + _track.TrackSequence = track.point; + _track.TrackType = AlcoholTrackTypeToTrackType(track.mode); + _track.TrackFilter = alcImage; + _track.TrackFile = alcImage.GetFilename(); + _track.TrackFileOffset = track.startOffset; + _track.TrackFileType = "BINARY"; + _track.TrackRawBytesPerSector = track.sectorSize; + _track.TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(track.mode); + switch(track.subMode) { - Track _track = new Track(); - - _track.Indexes = new Dictionary(); - _track.Indexes.Add(1, track.startLba); - _track.TrackStartSector = track.startLba; - _track.TrackEndSector = extra.sectors - 1; - _track.TrackPregap = extra.pregap; - _track.TrackSession = sessionNo; - _track.TrackSequence = track.point; - _track.TrackType = AlcoholTrackTypeToTrackType(track.mode); - _track.TrackFilter = alcImage; - _track.TrackFile = alcImage.GetFilename(); - _track.TrackFileOffset = track.startOffset; - _track.TrackFileType = "BINARY"; - _track.TrackRawBytesPerSector = track.sectorSize; - _track.TrackBytesPerSector = AlcoholTrackModeToCookedBytesPerSector(track.mode); - switch(track.subMode) - { - case AlcoholSubchannelMode.Interleaved: - _track.TrackSubchannelFilter = alcImage; - _track.TrackSubchannelFile = alcImage.GetFilename(); - _track.TrackSubchannelOffset = track.startOffset; - _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; - _track.TrackRawBytesPerSector += 96; - break; - case AlcoholSubchannelMode.None: - _track.TrackSubchannelType = TrackSubchannelType.None; - break; - } - - tracks.Add(_track); + case AlcoholSubchannelMode.Interleaved: + _track.TrackSubchannelFilter = alcImage; + _track.TrackSubchannelFile = alcImage.GetFilename(); + _track.TrackSubchannelOffset = track.startOffset; + _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; + _track.TrackRawBytesPerSector += 96; + break; + case AlcoholSubchannelMode.None: + _track.TrackSubchannelType = TrackSubchannelType.None; + break; } + + tracks.Add(_track); } return tracks; diff --git a/DiscImageChef.DiscImages/BlindWrite5.cs b/DiscImageChef.DiscImages/BlindWrite5.cs index c65a75415..6d2782384 100644 --- a/DiscImageChef.DiscImages/BlindWrite5.cs +++ b/DiscImageChef.DiscImages/BlindWrite5.cs @@ -593,12 +593,15 @@ namespace DiscImageChef.DiscImages session.Tracks[tSeq].session); DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown8 = 0x{2:X4}", ses, tSeq, session.Tracks[tSeq].unknown8); - if(session.Tracks[tSeq].type != Bw5TrackType.Dvd && - session.Tracks[tSeq].type != Bw5TrackType.NotData) + if(session.Tracks[tSeq].type == Bw5TrackType.Dvd || + session.Tracks[tSeq].type == Bw5TrackType.NotData) continue; + + { for(int i = 0; i < session.Tracks[tSeq].unknown9.Length; i++) DicConsole.DebugWriteLine("BlindWrite5 plugin", "session[{0}].track[{1}].unknown9[{2}] = 0x{3:X8}", ses, tSeq, i, session.Tracks[tSeq].unknown9[i]); + } } bwSessions.Add(session); @@ -795,121 +798,120 @@ namespace DiscImageChef.DiscImages fullTocStream.WriteByte(trk.psec); fullTocStream.WriteByte(trk.pframe); - if(trk.point < 0xA0) + if(trk.point >= 0xA0) continue; + + Track track = new Track(); + Partition partition = new Partition(); + + trackFlags.Add(trk.point, trk.ctl); + + switch(trk.type) { - Track track = new Track(); - Partition partition = new Partition(); + case Bw5TrackType.Audio: + track.TrackBytesPerSector = 2352; + track.TrackRawBytesPerSector = 2352; + if(ImageInfo.SectorSize < 2352) ImageInfo.SectorSize = 2352; + break; + case Bw5TrackType.Mode1: + case Bw5TrackType.Mode2F1: + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc); + track.TrackBytesPerSector = 2048; + track.TrackRawBytesPerSector = 2352; + if(ImageInfo.SectorSize < 2048) ImageInfo.SectorSize = 2048; + break; + case Bw5TrackType.Mode2: + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); + track.TrackBytesPerSector = 2336; + track.TrackRawBytesPerSector = 2352; + if(ImageInfo.SectorSize < 2336) ImageInfo.SectorSize = 2336; + break; + case Bw5TrackType.Mode2F2: + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader); + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc); + track.TrackBytesPerSector = 2336; + track.TrackRawBytesPerSector = 2352; + if(ImageInfo.SectorSize < 2324) ImageInfo.SectorSize = 2324; + break; + case Bw5TrackType.Dvd: + track.TrackBytesPerSector = 2048; + track.TrackRawBytesPerSector = 2048; + if(ImageInfo.SectorSize < 2048) ImageInfo.SectorSize = 2048; + isDvd = true; + break; + } - trackFlags.Add(trk.point, trk.ctl); + track.TrackDescription = string.Format("Track {0}", trk.point); + track.TrackStartSector = (ulong)(trk.startLba + trk.pregap); + track.TrackEndSector = (ulong)(trk.sectors + trk.startLba); - switch(trk.type) + foreach(DataFileCharacteristics chars in filePaths) + if(trk.startLba >= chars.StartLba && + trk.startLba + trk.sectors <= chars.StartLba + chars.Sectors) { - case Bw5TrackType.Audio: - track.TrackBytesPerSector = 2352; - track.TrackRawBytesPerSector = 2352; - if(ImageInfo.SectorSize < 2352) ImageInfo.SectorSize = 2352; - break; - case Bw5TrackType.Mode1: - case Bw5TrackType.Mode2F1: - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEcc)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEcc); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccP)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccP); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEccQ)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEccQ); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc); - track.TrackBytesPerSector = 2048; - track.TrackRawBytesPerSector = 2352; - if(ImageInfo.SectorSize < 2048) ImageInfo.SectorSize = 2048; - break; - case Bw5TrackType.Mode2: - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); - track.TrackBytesPerSector = 2336; - track.TrackRawBytesPerSector = 2352; - if(ImageInfo.SectorSize < 2336) ImageInfo.SectorSize = 2336; - break; - case Bw5TrackType.Mode2F2: - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSync)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSync); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorHeader)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorHeader); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubHeader)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubHeader); - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorEdc)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorEdc); - track.TrackBytesPerSector = 2336; - track.TrackRawBytesPerSector = 2352; - if(ImageInfo.SectorSize < 2324) ImageInfo.SectorSize = 2324; - break; - case Bw5TrackType.Dvd: - track.TrackBytesPerSector = 2048; - track.TrackRawBytesPerSector = 2048; - if(ImageInfo.SectorSize < 2048) ImageInfo.SectorSize = 2048; - isDvd = true; - break; - } - - track.TrackDescription = string.Format("Track {0}", trk.point); - track.TrackStartSector = (ulong)(trk.startLba + trk.pregap); - track.TrackEndSector = (ulong)(trk.sectors + trk.startLba); - - foreach(DataFileCharacteristics chars in filePaths) - if(trk.startLba >= chars.StartLba && - trk.startLba + trk.sectors <= chars.StartLba + chars.Sectors) + track.TrackFilter = chars.FileFilter; + track.TrackFile = chars.FileFilter.GetFilename(); + if(trk.startLba >= 0) + track.TrackFileOffset = (ulong)((trk.startLba - chars.StartLba) * chars.SectorSize); + else track.TrackFileOffset = (ulong)(trk.startLba * -1 * chars.SectorSize); + track.TrackFileType = "BINARY"; + if(chars.Subchannel != TrackSubchannelType.None) { - track.TrackFilter = chars.FileFilter; - track.TrackFile = chars.FileFilter.GetFilename(); - if(trk.startLba >= 0) - track.TrackFileOffset = (ulong)((trk.startLba - chars.StartLba) * chars.SectorSize); - else track.TrackFileOffset = (ulong)(trk.startLba * -1 * chars.SectorSize); - track.TrackFileType = "BINARY"; - if(chars.Subchannel != TrackSubchannelType.None) - { - track.TrackSubchannelFilter = track.TrackFilter; - track.TrackSubchannelFile = track.TrackFile; - track.TrackSubchannelType = chars.Subchannel; - track.TrackSubchannelOffset = track.TrackFileOffset; + track.TrackSubchannelFilter = track.TrackFilter; + track.TrackSubchannelFile = track.TrackFile; + track.TrackSubchannelType = chars.Subchannel; + track.TrackSubchannelOffset = track.TrackFileOffset; - if(chars.Subchannel == TrackSubchannelType.PackedInterleaved) - if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel)) - ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel); - } - - break; + if(chars.Subchannel == TrackSubchannelType.PackedInterleaved) + if(!ImageInfo.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel)) + ImageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel); } - track.TrackPregap = trk.pregap; - track.TrackSequence = trk.point; - track.TrackType = BlindWriteTrackTypeToTrackType(trk.type); - track.Indexes = new Dictionary(); - track.Indexes.Add(1, track.TrackStartSector); + break; + } - partition.Description = track.TrackDescription; - partition.Size = (track.TrackEndSector - track.TrackStartSector) * - (ulong)track.TrackRawBytesPerSector; - partition.Length = track.TrackEndSector - track.TrackStartSector; - partition.Sequence = track.TrackSequence; - partition.Offset = offsetBytes; - partition.Start = track.TrackStartSector; - partition.Type = track.TrackType.ToString(); + track.TrackPregap = trk.pregap; + track.TrackSequence = trk.point; + track.TrackType = BlindWriteTrackTypeToTrackType(trk.type); + track.Indexes = new Dictionary(); + track.Indexes.Add(1, track.TrackStartSector); - offsetBytes += partition.Size; + partition.Description = track.TrackDescription; + partition.Size = (track.TrackEndSector - track.TrackStartSector) * + (ulong)track.TrackRawBytesPerSector; + partition.Length = track.TrackEndSector - track.TrackStartSector; + partition.Sequence = track.TrackSequence; + partition.Offset = offsetBytes; + partition.Start = track.TrackStartSector; + partition.Type = track.TrackType.ToString(); - tracks.Add(track); - partitions.Add(partition); - offsetmap.Add(track.TrackSequence, track.TrackStartSector); - ImageInfo.Sectors += partition.Length; - } + offsetBytes += partition.Size; + + tracks.Add(track); + partitions.Add(partition); + offsetmap.Add(track.TrackSequence, track.TrackStartSector); + ImageInfo.Sectors += partition.Length; } } diff --git a/DiscImageChef.DiscImages/CDRDAO.cs b/DiscImageChef.DiscImages/CDRDAO.cs index 6904eac5e..10e3fc35d 100644 --- a/DiscImageChef.DiscImages/CDRDAO.cs +++ b/DiscImageChef.DiscImages/CDRDAO.cs @@ -446,12 +446,12 @@ namespace DiscImageChef.DiscImages if(matchComment.Success) { // Ignore "// Track X" comments - if(!matchComment.Groups["comment"].Value.StartsWith(" Track ", StringComparison.Ordinal)) - { - DicConsole.DebugWriteLine("CDRDAO plugin", "Found comment \"{1}\" at line {0}", line, - matchComment.Groups["comment"].Value.Trim()); - commentBuilder.AppendLine(matchComment.Groups["comment"].Value.Trim()); - } + if(matchComment.Groups["comment"].Value.StartsWith(" Track ", StringComparison.Ordinal)) + continue; + + DicConsole.DebugWriteLine("CDRDAO plugin", "Found comment \"{1}\" at line {0}", line, + matchComment.Groups["comment"].Value.Trim()); + commentBuilder.AppendLine(matchComment.Groups["comment"].Value.Trim()); } else if(matchDiskType.Success) { @@ -1241,31 +1241,31 @@ namespace DiscImageChef.DiscImages { case CDRDAO_TRACK_TYPE_MODE1: case CDRDAO_TRACK_TYPE_MODE2_FORM1: - if(tag == SectorTagType.CdSectorSubchannel) - { - sectorOffset = 2048; - sectorSize = 96; - break; - } + if(tag != SectorTagType.CdSectorSubchannel) + throw new ArgumentException("No tags in image for requested track", nameof(tag)); + + sectorOffset = 2048; + sectorSize = 96; + break; throw new ArgumentException("No tags in image for requested track", nameof(tag)); case CDRDAO_TRACK_TYPE_MODE2_FORM2: case CDRDAO_TRACK_TYPE_MODE2_MIX: - if(tag == SectorTagType.CdSectorSubchannel) - { - sectorOffset = 2336; - sectorSize = 96; - break; - } + if(tag != SectorTagType.CdSectorSubchannel) + throw new ArgumentException("No tags in image for requested track", nameof(tag)); + + sectorOffset = 2336; + sectorSize = 96; + break; throw new ArgumentException("No tags in image for requested track", nameof(tag)); case CDRDAO_TRACK_TYPE_AUDIO: - if(tag == SectorTagType.CdSectorSubchannel) - { - sectorOffset = 2352; - sectorSize = 96; - break; - } + if(tag != SectorTagType.CdSectorSubchannel) + throw new ArgumentException("No tags in image for requested track", nameof(tag)); + + sectorOffset = 2352; + sectorSize = 96; + break; throw new ArgumentException("No tags in image for requested track", nameof(tag)); case CDRDAO_TRACK_TYPE_MODE1_RAW: @@ -1328,12 +1328,12 @@ namespace DiscImageChef.DiscImages break; } case CDRDAO_TRACK_TYPE_MODE2_RAW: // Requires reading sector - if(tag == SectorTagType.CdSectorSubchannel) - { - sectorOffset = 2352; - sectorSize = 96; - break; - } + if(tag != SectorTagType.CdSectorSubchannel) + throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented"); + + sectorOffset = 2352; + sectorSize = 96; + break; throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented"); default: throw new FeatureSupportedButNotImplementedImageException("Unsupported track type"); diff --git a/DiscImageChef.DiscImages/CDRWin.cs b/DiscImageChef.DiscImages/CDRWin.cs index 18e98c61d..3f4247022 100644 --- a/DiscImageChef.DiscImages/CDRWin.cs +++ b/DiscImageChef.DiscImages/CDRWin.cs @@ -453,17 +453,16 @@ namespace DiscImageChef.DiscImages string _line = cueStream.ReadLine(); matchTrack = regexTrack.Match(_line); - if(matchTrack.Success) - { - uint trackSeq = uint.Parse(matchTrack.Groups[1].Value); - if(trackCount + 1 != trackSeq) - throw new - FeatureUnsupportedImageException(string - .Format("Found TRACK {0} out of order in line {1}", - trackSeq, line)); + if(!matchTrack.Success) continue; - trackCount++; - } + uint trackSeq = uint.Parse(matchTrack.Groups[1].Value); + if(trackCount + 1 != trackSeq) + throw new + FeatureUnsupportedImageException(string + .Format("Found TRACK {0} out of order in line {1}", + trackSeq, line)); + + trackCount++; } if(trackCount == 0) throw new FeatureUnsupportedImageException("No tracks found"); diff --git a/DiscImageChef.DiscImages/CHD.cs b/DiscImageChef.DiscImages/CHD.cs index 3b7646839..bc364f87c 100644 --- a/DiscImageChef.DiscImages/CHD.cs +++ b/DiscImageChef.DiscImages/CHD.cs @@ -1647,127 +1647,126 @@ namespace DiscImageChef.DiscImages { byte[] hunk; - if(!hunkCache.TryGetValue(hunkNo, out hunk)) + if(hunkCache.TryGetValue(hunkNo, out hunk)) return hunk; + + switch(mapVersion) { - switch(mapVersion) - { - case 1: - ulong offset = hunkTable[hunkNo] & 0x00000FFFFFFFFFFF; - ulong length = hunkTable[hunkNo] >> 44; + case 1: + ulong offset = hunkTable[hunkNo] & 0x00000FFFFFFFFFFF; + ulong length = hunkTable[hunkNo] >> 44; - byte[] compHunk = new byte[length]; - imageStream.Seek((long)offset, SeekOrigin.Begin); - imageStream.Read(compHunk, 0, compHunk.Length); + byte[] compHunk = new byte[length]; + imageStream.Seek((long)offset, SeekOrigin.Begin); + imageStream.Read(compHunk, 0, compHunk.Length); - if(length == sectorsPerHunk * ImageInfo.SectorSize) hunk = compHunk; - else if((ChdCompression)hdrCompression > ChdCompression.Zlib) - throw new ImageNotSupportedException(string.Format("Unsupported compression {0}", - (ChdCompression)hdrCompression)); - else - { - DeflateStream zStream = - new DeflateStream(new MemoryStream(compHunk), CompressionMode.Decompress); - hunk = new byte[sectorsPerHunk * ImageInfo.SectorSize]; - int read = zStream.Read(hunk, 0, (int)(sectorsPerHunk * ImageInfo.SectorSize)); - if(read != sectorsPerHunk * ImageInfo.SectorSize) - throw new - IOException(string - .Format("Unable to decompress hunk correctly, got {0} bytes, expected {1}", - read, sectorsPerHunk * ImageInfo.SectorSize)); + if(length == sectorsPerHunk * ImageInfo.SectorSize) hunk = compHunk; + else if((ChdCompression)hdrCompression > ChdCompression.Zlib) + throw new ImageNotSupportedException(string.Format("Unsupported compression {0}", + (ChdCompression)hdrCompression)); + else + { + DeflateStream zStream = + new DeflateStream(new MemoryStream(compHunk), CompressionMode.Decompress); + hunk = new byte[sectorsPerHunk * ImageInfo.SectorSize]; + int read = zStream.Read(hunk, 0, (int)(sectorsPerHunk * ImageInfo.SectorSize)); + if(read != sectorsPerHunk * ImageInfo.SectorSize) + throw new + IOException(string + .Format("Unable to decompress hunk correctly, got {0} bytes, expected {1}", + read, sectorsPerHunk * ImageInfo.SectorSize)); - zStream.Close(); - zStream = null; - } + zStream.Close(); + zStream = null; + } - break; - case 3: - byte[] entryBytes = new byte[16]; - Array.Copy(hunkMap, (int)(hunkNo * 16), entryBytes, 0, 16); - ChdMapV3Entry entry = BigEndianMarshal.ByteArrayToStructureBigEndian(entryBytes); - switch((Chdv3EntryFlags)(entry.flags & 0x0F)) - { - case Chdv3EntryFlags.Invalid: throw new ArgumentException("Invalid hunk found."); - case Chdv3EntryFlags.Compressed: - switch((ChdCompression)hdrCompression) - { - case ChdCompression.None: goto uncompressedV3; - case ChdCompression.Zlib: - case ChdCompression.ZlibPlus: - if(isHdd) - { - byte[] zHunk = new byte[(entry.lengthLsb << 16) + entry.lengthLsb]; - imageStream.Seek((long)entry.offset, SeekOrigin.Begin); - imageStream.Read(zHunk, 0, zHunk.Length); - DeflateStream zStream = - new DeflateStream(new MemoryStream(zHunk), CompressionMode.Decompress); - hunk = new byte[bytesPerHunk]; - int read = zStream.Read(hunk, 0, (int)bytesPerHunk); - if(read != bytesPerHunk) - throw new - IOException(string - .Format("Unable to decompress hunk correctly, got {0} bytes, expected {1}", - read, bytesPerHunk)); - - zStream.Close(); - zStream = null; - } - // TODO: Guess wth is MAME doing with these hunks - else + break; + case 3: + byte[] entryBytes = new byte[16]; + Array.Copy(hunkMap, (int)(hunkNo * 16), entryBytes, 0, 16); + ChdMapV3Entry entry = BigEndianMarshal.ByteArrayToStructureBigEndian(entryBytes); + switch((Chdv3EntryFlags)(entry.flags & 0x0F)) + { + case Chdv3EntryFlags.Invalid: throw new ArgumentException("Invalid hunk found."); + case Chdv3EntryFlags.Compressed: + switch((ChdCompression)hdrCompression) + { + case ChdCompression.None: goto uncompressedV3; + case ChdCompression.Zlib: + case ChdCompression.ZlibPlus: + if(isHdd) + { + byte[] zHunk = new byte[(entry.lengthLsb << 16) + entry.lengthLsb]; + imageStream.Seek((long)entry.offset, SeekOrigin.Begin); + imageStream.Read(zHunk, 0, zHunk.Length); + DeflateStream zStream = + new DeflateStream(new MemoryStream(zHunk), CompressionMode.Decompress); + hunk = new byte[bytesPerHunk]; + int read = zStream.Read(hunk, 0, (int)bytesPerHunk); + if(read != bytesPerHunk) throw new - ImageNotSupportedException("Compressed CD/GD-ROM hunks are not yet supported"); + IOException(string + .Format("Unable to decompress hunk correctly, got {0} bytes, expected {1}", + read, bytesPerHunk)); - break; - case ChdCompression.Av: + zStream.Close(); + zStream = null; + } + // TODO: Guess wth is MAME doing with these hunks + else throw new - ImageNotSupportedException(string.Format("Unsupported compression {0}", - (ChdCompression)hdrCompression)); - } + ImageNotSupportedException("Compressed CD/GD-ROM hunks are not yet supported"); - break; - case Chdv3EntryFlags.Uncompressed: - uncompressedV3: - hunk = new byte[bytesPerHunk]; - imageStream.Seek((long)entry.offset, SeekOrigin.Begin); - imageStream.Read(hunk, 0, hunk.Length); - break; - case Chdv3EntryFlags.Mini: - hunk = new byte[bytesPerHunk]; - byte[] mini = new byte[8]; - mini = BigEndianBitConverter.GetBytes(entry.offset); - for(int i = 0; i < bytesPerHunk; i++) hunk[i] = mini[i % 8]; + break; + case ChdCompression.Av: + throw new + ImageNotSupportedException(string.Format("Unsupported compression {0}", + (ChdCompression)hdrCompression)); + } - break; - case Chdv3EntryFlags.SelfHunk: return GetHunk(entry.offset); - case Chdv3EntryFlags.ParentHunk: - throw new ImageNotSupportedException("Parent images are not supported"); - case Chdv3EntryFlags.SecondCompressed: - throw new ImageNotSupportedException("FLAC is not supported"); - default: - throw new ImageNotSupportedException(string.Format("Hunk type {0} is not supported", - entry.flags & 0xF)); - } - - break; - case 5: - if(hdrCompression == 0) - { + break; + case Chdv3EntryFlags.Uncompressed: + uncompressedV3: hunk = new byte[bytesPerHunk]; - imageStream.Seek(hunkTableSmall[hunkNo] * bytesPerHunk, SeekOrigin.Begin); + imageStream.Seek((long)entry.offset, SeekOrigin.Begin); imageStream.Read(hunk, 0, hunk.Length); - } - else throw new ImageNotSupportedException("Compressed v5 hunks not yet supported"); + break; + case Chdv3EntryFlags.Mini: + hunk = new byte[bytesPerHunk]; + byte[] mini = new byte[8]; + mini = BigEndianBitConverter.GetBytes(entry.offset); + for(int i = 0; i < bytesPerHunk; i++) hunk[i] = mini[i % 8]; - break; - default: - throw new ImageNotSupportedException(string.Format("Unsupported hunk map version {0}", - mapVersion)); - } + break; + case Chdv3EntryFlags.SelfHunk: return GetHunk(entry.offset); + case Chdv3EntryFlags.ParentHunk: + throw new ImageNotSupportedException("Parent images are not supported"); + case Chdv3EntryFlags.SecondCompressed: + throw new ImageNotSupportedException("FLAC is not supported"); + default: + throw new ImageNotSupportedException(string.Format("Hunk type {0} is not supported", + entry.flags & 0xF)); + } - if(hunkCache.Count >= maxBlockCache) hunkCache.Clear(); + break; + case 5: + if(hdrCompression == 0) + { + hunk = new byte[bytesPerHunk]; + imageStream.Seek(hunkTableSmall[hunkNo] * bytesPerHunk, SeekOrigin.Begin); + imageStream.Read(hunk, 0, hunk.Length); + } + else throw new ImageNotSupportedException("Compressed v5 hunks not yet supported"); - hunkCache.Add(hunkNo, hunk); + break; + default: + throw new ImageNotSupportedException(string.Format("Unsupported hunk map version {0}", + mapVersion)); } + if(hunkCache.Count >= maxBlockCache) hunkCache.Clear(); + + hunkCache.Add(hunkNo, hunk); + return hunk; } diff --git a/DiscImageChef.DiscImages/CloneCD.cs b/DiscImageChef.DiscImages/CloneCD.cs index 4061225f3..02aa00cfb 100644 --- a/DiscImageChef.DiscImages/CloneCD.cs +++ b/DiscImageChef.DiscImages/CloneCD.cs @@ -304,16 +304,15 @@ namespace DiscImageChef.DiscImages { ccdVerMatch = ccdVerRegex.Match(_line); - if(ccdVerMatch.Success) - { - DicConsole.DebugWriteLine("CloneCD plugin", "Found Version at line {0}", line); + if(!ccdVerMatch.Success) continue; - ImageInfo.ImageVersion = ccdVerMatch.Groups["value"].Value; - if(ImageInfo.ImageVersion != "2" && ImageInfo.ImageVersion != "3") - DicConsole - .ErrorWriteLine("(CloneCD plugin): Warning! Unknown CCD image version {0}, may not work!", - ImageInfo.ImageVersion); - } + DicConsole.DebugWriteLine("CloneCD plugin", "Found Version at line {0}", line); + + ImageInfo.ImageVersion = ccdVerMatch.Groups["value"].Value; + if(ImageInfo.ImageVersion != "2" && ImageInfo.ImageVersion != "3") + DicConsole + .ErrorWriteLine("(CloneCD plugin): Warning! Unknown CCD image version {0}, may not work!", + ImageInfo.ImageVersion); } else if(inDisk) { diff --git a/DiscImageChef.DiscImages/D88.cs b/DiscImageChef.DiscImages/D88.cs index 3464a220a..1734c95e1 100644 --- a/DiscImageChef.DiscImages/D88.cs +++ b/DiscImageChef.DiscImages/D88.cs @@ -376,13 +376,12 @@ namespace DiscImageChef.DiscImages sechdr = (SectorHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SectorHeader)); handle.Free(); - if(sechdr.spt != spt || sechdr.n != bps) - { - DicConsole.DebugWriteLine("D88 plugin", - "Disk tracks are not same size. spt = {0} (expected {1}), bps = {2} (expected {3}) at track {4} sector {5}", - sechdr.spt, spt, sechdr.n, bps, i, j, sechdr.deleted_mark); - allEqual = false; - } + if(sechdr.spt == spt && sechdr.n == bps) continue; + + DicConsole.DebugWriteLine("D88 plugin", + "Disk tracks are not same size. spt = {0} (expected {1}), bps = {2} (expected {3}) at track {4} sector {5}", + sechdr.spt, spt, sechdr.n, bps, i, j, sechdr.deleted_mark); + allEqual = false; } secB = new byte[sechdr.size_of_data]; diff --git a/DiscImageChef.DiscImages/DiscJuggler.cs b/DiscImageChef.DiscImages/DiscJuggler.cs index 1fe6e1382..4fb01cf09 100644 --- a/DiscImageChef.DiscImages/DiscJuggler.cs +++ b/DiscImageChef.DiscImages/DiscJuggler.cs @@ -218,19 +218,17 @@ namespace DiscImageChef.DiscImages int bLen = descriptor[position]; position++; DicConsole.DebugWriteLine("DiscJuggler plugin", "\tc[{1}][{2}].Length = {0}", bLen, c, cb); - if(bLen > 0) - { - byte[] textBlk = new byte[bLen]; - Array.Copy(descriptor, position, textBlk, 0, bLen); - position += bLen; - // Track title - if(cb == 10) - { - track.TrackDescription = Encoding.Default.GetString(textBlk, 0, bLen); - DicConsole.DebugWriteLine("DiscJuggler plugin", "\tTrack title = {0}", - track.TrackDescription); - } - } + if(bLen <= 0) continue; + + byte[] textBlk = new byte[bLen]; + Array.Copy(descriptor, position, textBlk, 0, bLen); + position += bLen; + // Track title + if(cb != 10) continue; + + track.TrackDescription = Encoding.Default.GetString(textBlk, 0, bLen); + DicConsole.DebugWriteLine("DiscJuggler plugin", "\tTrack title = {0}", + track.TrackDescription); } } @@ -519,17 +517,16 @@ namespace DiscImageChef.DiscImages addedATrack = true; } - if(addedATrack) - { - lastSessionTrack = session.EndTrack; - sessions.Add(session); - DicConsole.DebugWriteLine("DiscJuggler plugin", "session.StartTrack = {0}", session.StartTrack); - DicConsole.DebugWriteLine("DiscJuggler plugin", "session.StartSector = {0}", session.StartSector); - DicConsole.DebugWriteLine("DiscJuggler plugin", "session.EndTrack = {0}", session.EndTrack); - DicConsole.DebugWriteLine("DiscJuggler plugin", "session.EndSector = {0}", session.EndSector); - DicConsole.DebugWriteLine("DiscJuggler plugin", "session.SessionSequence = {0}", - session.SessionSequence); - } + if(!addedATrack) continue; + + lastSessionTrack = session.EndTrack; + sessions.Add(session); + DicConsole.DebugWriteLine("DiscJuggler plugin", "session.StartTrack = {0}", session.StartTrack); + DicConsole.DebugWriteLine("DiscJuggler plugin", "session.StartSector = {0}", session.StartSector); + DicConsole.DebugWriteLine("DiscJuggler plugin", "session.EndTrack = {0}", session.EndTrack); + DicConsole.DebugWriteLine("DiscJuggler plugin", "session.EndSector = {0}", session.EndSector); + DicConsole.DebugWriteLine("DiscJuggler plugin", "session.SessionSequence = {0}", + session.SessionSequence); } // Skip unknown diff --git a/DiscImageChef.DiscImages/DiskCopy42.cs b/DiscImageChef.DiscImages/DiskCopy42.cs index 7d197fe8b..16a5ebeb5 100644 --- a/DiscImageChef.DiscImages/DiskCopy42.cs +++ b/DiscImageChef.DiscImages/DiskCopy42.cs @@ -231,14 +231,11 @@ namespace DiscImageChef.DiscImages return false; } - if(tmpHeader.FmtByte == kInvalidFmtByte) - { - DicConsole.DebugWriteLine("DC42 plugin", "Image says it's unformatted"); + if(tmpHeader.FmtByte != kInvalidFmtByte) return true; - return false; - } + DicConsole.DebugWriteLine("DC42 plugin", "Image says it's unformatted"); - return true; + return false; } public override bool OpenImage(Filter imageFilter) @@ -646,18 +643,17 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("DC42 plugin", "Calculated data checksum = 0x{0:X8}", dataChk); DicConsole.DebugWriteLine("DC42 plugin", "Stored data checksum = 0x{0:X8}", header.DataChecksum); - if(header.TagSize > 0) - { - DicConsole.DebugWriteLine("DC42 plugin", "Reading tags"); - Stream tagstream = dc42ImageFilter.GetDataForkStream(); - tagstream.Seek(tagOffset, SeekOrigin.Begin); - tagstream.Read(tags, 0, (int)header.TagSize); + if(header.TagSize <= 0) return dataChk == header.DataChecksum && tagsChk == header.TagChecksum; - DicConsole.DebugWriteLine("DC42 plugin", "Calculating tag checksum"); - tagsChk = DC42CheckSum(tags); - DicConsole.DebugWriteLine("DC42 plugin", "Calculated tag checksum = 0x{0:X8}", tagsChk); - DicConsole.DebugWriteLine("DC42 plugin", "Stored tag checksum = 0x{0:X8}", header.TagChecksum); - } + DicConsole.DebugWriteLine("DC42 plugin", "Reading tags"); + Stream tagstream = dc42ImageFilter.GetDataForkStream(); + tagstream.Seek(tagOffset, SeekOrigin.Begin); + tagstream.Read(tags, 0, (int)header.TagSize); + + DicConsole.DebugWriteLine("DC42 plugin", "Calculating tag checksum"); + tagsChk = DC42CheckSum(tags); + DicConsole.DebugWriteLine("DC42 plugin", "Calculated tag checksum = 0x{0:X8}", tagsChk); + DicConsole.DebugWriteLine("DC42 plugin", "Stored tag checksum = 0x{0:X8}", header.TagChecksum); return dataChk == header.DataChecksum && tagsChk == header.TagChecksum; } diff --git a/DiscImageChef.DiscImages/Nero.cs b/DiscImageChef.DiscImages/Nero.cs index 8c1047c91..585f9f0fc 100644 --- a/DiscImageChef.DiscImages/Nero.cs +++ b/DiscImageChef.DiscImages/Nero.cs @@ -1572,128 +1572,128 @@ namespace DiscImageChef.DiscImages for(uint i = 1; i <= neroTracks.Count; i++) { NeroTrack neroTrack; - if(neroTracks.TryGetValue(i, out neroTrack)) + if(!neroTracks.TryGetValue(i, out neroTrack)) continue; + + DicConsole.DebugWriteLine("Nero plugin", "\tcurrentsession = {0}", currentsession); + DicConsole.DebugWriteLine("Nero plugin", "\tcurrentsessionmaxtrack = {0}", + currentsessionmaxtrack); + DicConsole.DebugWriteLine("Nero plugin", "\tcurrentsessioncurrenttrack = {0}", + currentsessioncurrenttrack); + + Track _track = new Track(); + if(neroTrack.Sequence == 1) neroTrack.Index0 = neroTrack.Index1; + + _track.Indexes = new Dictionary(); + if(neroTrack.Index0 < neroTrack.Index1) + _track.Indexes.Add(0, neroTrack.Index0 / neroTrack.SectorSize); + _track.Indexes.Add(1, neroTrack.Index1 / neroTrack.SectorSize); + _track.TrackDescription = StringHandlers.CToString(neroTrack.Isrc); + _track.TrackEndSector = neroTrack.Length / neroTrack.SectorSize + neroTrack.StartLba - 1; + _track.TrackPregap = (neroTrack.Index1 - neroTrack.Index0) / neroTrack.SectorSize; + _track.TrackSequence = neroTrack.Sequence; + _track.TrackSession = currentsession; + _track.TrackStartSector = neroTrack.StartLba; + _track.TrackType = NeroTrackModeToTrackType((DaoMode)neroTrack.Mode); + _track.TrackFile = imageFilter.GetFilename(); + _track.TrackFilter = imageFilter; + _track.TrackFileOffset = neroTrack.Offset; + _track.TrackFileType = "BINARY"; + _track.TrackSubchannelType = TrackSubchannelType.None; + switch((DaoMode)neroTrack.Mode) { - DicConsole.DebugWriteLine("Nero plugin", "\tcurrentsession = {0}", currentsession); - DicConsole.DebugWriteLine("Nero plugin", "\tcurrentsessionmaxtrack = {0}", - currentsessionmaxtrack); - DicConsole.DebugWriteLine("Nero plugin", "\tcurrentsessioncurrenttrack = {0}", - currentsessioncurrenttrack); + case DaoMode.Audio: + _track.TrackBytesPerSector = 2352; + _track.TrackRawBytesPerSector = 2352; + break; + case DaoMode.AudioSub: + _track.TrackBytesPerSector = 2352; + _track.TrackRawBytesPerSector = 2448; + _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; + break; + case DaoMode.Data: + case DaoMode.DataM2F1: + _track.TrackBytesPerSector = 2048; + _track.TrackRawBytesPerSector = 2048; + break; + case DaoMode.DataM2F2: + _track.TrackBytesPerSector = 2336; + _track.TrackRawBytesPerSector = 2336; + break; + case DaoMode.DataM2Raw: + _track.TrackBytesPerSector = 2352; + _track.TrackRawBytesPerSector = 2352; + break; + case DaoMode.DataM2RawSub: + _track.TrackBytesPerSector = 2352; + _track.TrackRawBytesPerSector = 2448; + _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; + break; + case DaoMode.DataRaw: + _track.TrackBytesPerSector = 2048; + _track.TrackRawBytesPerSector = 2352; + break; + case DaoMode.DataRawSub: + _track.TrackBytesPerSector = 2048; + _track.TrackRawBytesPerSector = 2448; + _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; + break; + } - Track _track = new Track(); - if(neroTrack.Sequence == 1) neroTrack.Index0 = neroTrack.Index1; + if(_track.TrackSubchannelType == TrackSubchannelType.RawInterleaved) + { + _track.TrackSubchannelFilter = imageFilter; + _track.TrackSubchannelFile = imageFilter.GetFilename(); + _track.TrackSubchannelOffset = neroTrack.Offset; + } - _track.Indexes = new Dictionary(); - if(neroTrack.Index0 < neroTrack.Index1) - _track.Indexes.Add(0, neroTrack.Index0 / neroTrack.SectorSize); - _track.Indexes.Add(1, neroTrack.Index1 / neroTrack.SectorSize); - _track.TrackDescription = StringHandlers.CToString(neroTrack.Isrc); - _track.TrackEndSector = neroTrack.Length / neroTrack.SectorSize + neroTrack.StartLba - 1; - _track.TrackPregap = (neroTrack.Index1 - neroTrack.Index0) / neroTrack.SectorSize; - _track.TrackSequence = neroTrack.Sequence; - _track.TrackSession = currentsession; - _track.TrackStartSector = neroTrack.StartLba; - _track.TrackType = NeroTrackModeToTrackType((DaoMode)neroTrack.Mode); - _track.TrackFile = imageFilter.GetFilename(); - _track.TrackFilter = imageFilter; - _track.TrackFileOffset = neroTrack.Offset; - _track.TrackFileType = "BINARY"; - _track.TrackSubchannelType = TrackSubchannelType.None; - switch((DaoMode)neroTrack.Mode) - { - case DaoMode.Audio: - _track.TrackBytesPerSector = 2352; - _track.TrackRawBytesPerSector = 2352; - break; - case DaoMode.AudioSub: - _track.TrackBytesPerSector = 2352; - _track.TrackRawBytesPerSector = 2448; - _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; - break; - case DaoMode.Data: - case DaoMode.DataM2F1: - _track.TrackBytesPerSector = 2048; - _track.TrackRawBytesPerSector = 2048; - break; - case DaoMode.DataM2F2: - _track.TrackBytesPerSector = 2336; - _track.TrackRawBytesPerSector = 2336; - break; - case DaoMode.DataM2Raw: - _track.TrackBytesPerSector = 2352; - _track.TrackRawBytesPerSector = 2352; - break; - case DaoMode.DataM2RawSub: - _track.TrackBytesPerSector = 2352; - _track.TrackRawBytesPerSector = 2448; - _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; - break; - case DaoMode.DataRaw: - _track.TrackBytesPerSector = 2048; - _track.TrackRawBytesPerSector = 2352; - break; - case DaoMode.DataRawSub: - _track.TrackBytesPerSector = 2048; - _track.TrackRawBytesPerSector = 2448; - _track.TrackSubchannelType = TrackSubchannelType.RawInterleaved; - break; - } + imageTracks.Add(_track); - if(_track.TrackSubchannelType == TrackSubchannelType.RawInterleaved) - { - _track.TrackSubchannelFilter = imageFilter; - _track.TrackSubchannelFile = imageFilter.GetFilename(); - _track.TrackSubchannelOffset = neroTrack.Offset; - } + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackDescription = {0}", + _track.TrackDescription); + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackEndSector = {0}", + _track.TrackEndSector); + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackPregap = {0}", _track.TrackPregap); + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackSequence = {0}", + _track.TrackSequence); + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackSession = {0}", _track.TrackSession); + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackStartSector = {0}", + _track.TrackStartSector); + DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackType = {0}", _track.TrackType); - imageTracks.Add(_track); + if(currentsessioncurrenttrack == 1) + { + currentsessionstruct = new Session(); + currentsessionstruct.SessionSequence = currentsession; + currentsessionstruct.StartSector = _track.TrackStartSector; + currentsessionstruct.StartTrack = _track.TrackSequence; + } + currentsessioncurrenttrack++; + if(currentsessioncurrenttrack > currentsessionmaxtrack) + { + currentsession++; + neroSessions.TryGetValue(currentsession, out currentsessionmaxtrack); + currentsessioncurrenttrack = 1; + currentsessionstruct.EndTrack = _track.TrackSequence; + currentsessionstruct.EndSector = _track.TrackEndSector; + imageSessions.Add(currentsessionstruct); + } - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackDescription = {0}", - _track.TrackDescription); - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackEndSector = {0}", - _track.TrackEndSector); - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackPregap = {0}", _track.TrackPregap); - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackSequence = {0}", - _track.TrackSequence); - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackSession = {0}", _track.TrackSession); - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackStartSector = {0}", - _track.TrackStartSector); - DicConsole.DebugWriteLine("Nero plugin", "\t\t _track.TrackType = {0}", _track.TrackType); + if(i == neroTracks.Count) + { + neroSessions.TryGetValue(currentsession, out currentsessionmaxtrack); + currentsessioncurrenttrack = 1; + currentsessionstruct.EndTrack = _track.TrackSequence; + currentsessionstruct.EndSector = _track.TrackEndSector; + imageSessions.Add(currentsessionstruct); + } - if(currentsessioncurrenttrack == 1) - { - currentsessionstruct = new Session(); - currentsessionstruct.SessionSequence = currentsession; - currentsessionstruct.StartSector = _track.TrackStartSector; - currentsessionstruct.StartTrack = _track.TrackSequence; - } - currentsessioncurrenttrack++; - if(currentsessioncurrenttrack > currentsessionmaxtrack) - { - currentsession++; - neroSessions.TryGetValue(currentsession, out currentsessionmaxtrack); - currentsessioncurrenttrack = 1; - currentsessionstruct.EndTrack = _track.TrackSequence; - currentsessionstruct.EndSector = _track.TrackEndSector; - imageSessions.Add(currentsessionstruct); - } + offsetmap.Add(_track.TrackSequence, _track.TrackStartSector); + DicConsole.DebugWriteLine("Nero plugin", "\t\t Offset[{0}]: {1}", _track.TrackSequence, + _track.TrackStartSector); - if(i == neroTracks.Count) - { - neroSessions.TryGetValue(currentsession, out currentsessionmaxtrack); - currentsessioncurrenttrack = 1; - currentsessionstruct.EndTrack = _track.TrackSequence; - currentsessionstruct.EndSector = _track.TrackEndSector; - imageSessions.Add(currentsessionstruct); - } + Partition partition; - offsetmap.Add(_track.TrackSequence, _track.TrackStartSector); - DicConsole.DebugWriteLine("Nero plugin", "\t\t Offset[{0}]: {1}", _track.TrackSequence, - _track.TrackStartSector); - - Partition partition; - - /*if(_neroTrack.Index0 < _neroTrack.Index1) + /*if(_neroTrack.Index0 < _neroTrack.Index1) { partition = new Partition(); partition.PartitionDescription = string.Format("Track {0} Index 0", _track.TrackSequence); @@ -1708,20 +1708,19 @@ namespace DiscImageChef.DiscImages PartitionSequence++; }*/ - partition = new Partition(); - partition.Description = string.Format("Track {0} Index 1", _track.TrackSequence); - partition.Size = neroTrack.EndOfTrack - neroTrack.Index1; - partition.Name = StringHandlers.CToString(neroTrack.Isrc); - partition.Length = partition.Size / neroTrack.SectorSize; - partition.Sequence = partitionSequence; - partition.Offset = partitionStartByte; - partition.Start = neroTrack.StartLba + - (neroTrack.Index1 - neroTrack.Index0) / neroTrack.SectorSize; - partition.Type = NeroTrackModeToTrackType((DaoMode)neroTrack.Mode).ToString(); - imagePartitions.Add(partition); - partitionSequence++; - partitionStartByte += partition.Size; - } + partition = new Partition(); + partition.Description = string.Format("Track {0} Index 1", _track.TrackSequence); + partition.Size = neroTrack.EndOfTrack - neroTrack.Index1; + partition.Name = StringHandlers.CToString(neroTrack.Isrc); + partition.Length = partition.Size / neroTrack.SectorSize; + partition.Sequence = partitionSequence; + partition.Offset = partitionStartByte; + partition.Start = neroTrack.StartLba + + (neroTrack.Index1 - neroTrack.Index0) / neroTrack.SectorSize; + partition.Type = NeroTrackModeToTrackType((DaoMode)neroTrack.Mode).ToString(); + imagePartitions.Add(partition); + partitionSequence++; + partitionStartByte += partition.Size; } this.imageFilter = imageFilter; diff --git a/DiscImageChef.DiscImages/QCOW.cs b/DiscImageChef.DiscImages/QCOW.cs index e2bbdcc55..56502282c 100644 --- a/DiscImageChef.DiscImages/QCOW.cs +++ b/DiscImageChef.DiscImages/QCOW.cs @@ -250,11 +250,10 @@ namespace DiscImageChef.DiscImages { l1Mask <<= 1; - if(c < 64 - l1Shift) - { - l1Mask += 1; - c++; - } + if(c >= 64 - l1Shift) continue; + + l1Mask += 1; + c++; } l2Mask = 0; diff --git a/DiscImageChef.DiscImages/QCOW2.cs b/DiscImageChef.DiscImages/QCOW2.cs index 146e5742a..465ca18a8 100644 --- a/DiscImageChef.DiscImages/QCOW2.cs +++ b/DiscImageChef.DiscImages/QCOW2.cs @@ -297,11 +297,10 @@ namespace DiscImageChef.DiscImages { l1Mask <<= 1; - if(c < 64 - l1Shift) - { - l1Mask += 1; - c++; - } + if(c >= 64 - l1Shift) continue; + + l1Mask += 1; + c++; } l2Mask = 0; diff --git a/DiscImageChef.DiscImages/QED.cs b/DiscImageChef.DiscImages/QED.cs index 82aeca90f..137b75894 100644 --- a/DiscImageChef.DiscImages/QED.cs +++ b/DiscImageChef.DiscImages/QED.cs @@ -264,11 +264,10 @@ namespace DiscImageChef.DiscImages { l1Mask <<= 1; - if(c < 64 - l1Shift) - { - l1Mask += 1; - c++; - } + if(c >= 64 - l1Shift) continue; + + l1Mask += 1; + c++; } sectorMask = 0; diff --git a/DiscImageChef.DiscImages/RsIde.cs b/DiscImageChef.DiscImages/RsIde.cs index 1f33f0480..9caa89823 100644 --- a/DiscImageChef.DiscImages/RsIde.cs +++ b/DiscImageChef.DiscImages/RsIde.cs @@ -261,14 +261,12 @@ namespace DiscImageChef.DiscImages #region Unsupported features public override byte[] ReadDiskTag(MediaTagType tag) { - if(ImageInfo.ReadableMediaTags.Contains(tag) && tag == MediaTagType.ATA_IDENTIFY) - { - byte[] buffer = new byte[512]; - Array.Copy(identify, 0, buffer, 0, 512); - return buffer; - } + if(!ImageInfo.ReadableMediaTags.Contains(tag) || tag != MediaTagType.ATA_IDENTIFY) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + byte[] buffer = new byte[512]; + Array.Copy(identify, 0, buffer, 0, 512); + return buffer; } public override byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) diff --git a/DiscImageChef.DiscImages/TeleDisk.cs b/DiscImageChef.DiscImages/TeleDisk.cs index dbdaf03eb..faf579d0f 100644 --- a/DiscImageChef.DiscImages/TeleDisk.cs +++ b/DiscImageChef.DiscImages/TeleDisk.cs @@ -546,16 +546,15 @@ namespace DiscImageChef.DiscImages teleDiskSector.Flags = (byte)stream.ReadByte(); teleDiskSector.Crc = (byte)stream.ReadByte(); - if((teleDiskSector.Flags & FLAGS_SECTOR_DATALESS) != FLAGS_SECTOR_DATALESS && - (teleDiskSector.Flags & FLAGS_SECTOR_SKIPPED) != FLAGS_SECTOR_SKIPPED) - { - stream.Read(dataSizeBytes, 0, 2); - teleDiskData.DataSize = BitConverter.ToUInt16(dataSizeBytes, 0); - teleDiskData.DataSize--; // Sydex decided to including dataEncoding byte as part of it - teleDiskData.DataEncoding = (byte)stream.ReadByte(); - data = new byte[teleDiskData.DataSize]; - stream.Read(data, 0, teleDiskData.DataSize); - } + if((teleDiskSector.Flags & FLAGS_SECTOR_DATALESS) == FLAGS_SECTOR_DATALESS || + (teleDiskSector.Flags & FLAGS_SECTOR_SKIPPED) == FLAGS_SECTOR_SKIPPED) continue; + + stream.Read(dataSizeBytes, 0, 2); + teleDiskData.DataSize = BitConverter.ToUInt16(dataSizeBytes, 0); + teleDiskData.DataSize--; // Sydex decided to including dataEncoding byte as part of it + teleDiskData.DataEncoding = (byte)stream.ReadByte(); + data = new byte[teleDiskData.DataSize]; + stream.Read(data, 0, teleDiskData.DataSize); } } @@ -671,21 +670,22 @@ namespace DiscImageChef.DiscImages DicConsole.DebugWriteLine("TeleDisk plugin", "\t\tLBA: {0}", lba); - if((teleDiskSector.Flags & FLAGS_SECTOR_NO_ID) != FLAGS_SECTOR_NO_ID) - if(sectorsData[teleDiskTrack.Cylinder][teleDiskTrack.Head][teleDiskSector.SectorNumber] != null) - if((teleDiskSector.Flags & FLAGS_SECTOR_DUPLICATE) == FLAGS_SECTOR_DUPLICATE) - DicConsole.DebugWriteLine("TeleDisk plugin", - "\t\tSector {0} on cylinder {1} head {2} is duplicate, and marked so", - teleDiskSector.SectorNumber, teleDiskSector.Cylinder, teleDiskSector.Head); - else - DicConsole.DebugWriteLine("TeleDisk plugin", - "\t\tSector {0} on cylinder {1} head {2} is duplicate, but is not marked so", - teleDiskSector.SectorNumber, teleDiskSector.Cylinder, teleDiskSector.Head); + if((teleDiskSector.Flags & FLAGS_SECTOR_NO_ID) == FLAGS_SECTOR_NO_ID) continue; + + if(sectorsData[teleDiskTrack.Cylinder][teleDiskTrack.Head][teleDiskSector.SectorNumber] != null) + if((teleDiskSector.Flags & FLAGS_SECTOR_DUPLICATE) == FLAGS_SECTOR_DUPLICATE) + DicConsole.DebugWriteLine("TeleDisk plugin", + "\t\tSector {0} on cylinder {1} head {2} is duplicate, and marked so", + teleDiskSector.SectorNumber, teleDiskSector.Cylinder, teleDiskSector.Head); else - { - sectorsData[teleDiskTrack.Cylinder][teleDiskTrack.Head][teleDiskSector.SectorNumber] = decodedData; - totalDiskSize += (uint)decodedData.Length; - } + DicConsole.DebugWriteLine("TeleDisk plugin", + "\t\tSector {0} on cylinder {1} head {2} is duplicate, but is not marked so", + teleDiskSector.SectorNumber, teleDiskSector.Cylinder, teleDiskSector.Head); + else + { + sectorsData[teleDiskTrack.Cylinder][teleDiskTrack.Head][teleDiskSector.SectorNumber] = decodedData; + totalDiskSize += (uint)decodedData.Length; + } } } @@ -1147,14 +1147,12 @@ namespace DiscImageChef.DiscImages public override byte[] ReadDiskTag(MediaTagType tag) { - if(tag == MediaTagType.Floppy_LeadOut) - { - if(leadOut != null) return leadOut; + if(tag != MediaTagType.Floppy_LeadOut) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - throw new FeatureNotPresentImageException("Lead-out not present in disk image"); - } + if(leadOut != null) return leadOut; - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + throw new FeatureNotPresentImageException("Lead-out not present in disk image"); } #endregion @@ -1538,28 +1536,26 @@ namespace DiscImageChef.DiscImages k = ++freq[c]; /* swap nodes to keep the tree freq-ordered */ - if(k > freq[l = c + 1]) - { - while(k > freq[++l]) { } + if(k <= freq[l = c + 1]) continue; - ; - l--; - freq[c] = freq[l]; - freq[l] = (ushort)k; + while(k > freq[++l]) { } - i = son[c]; - prnt[i] = (short)l; - if(i < T) prnt[i + 1] = (short)l; + l--; + freq[c] = freq[l]; + freq[l] = (ushort)k; - j = son[l]; - son[l] = (short)i; + i = son[c]; + prnt[i] = (short)l; + if(i < T) prnt[i + 1] = (short)l; - prnt[j] = (short)c; - if(j < T) prnt[j + 1] = (short)c; - son[c] = (short)j; + j = son[l]; + son[l] = (short)i; - c = l; - } + prnt[j] = (short)c; + if(j < T) prnt[j + 1] = (short)c; + son[c] = (short)j; + + c = l; } while((c = prnt[c]) != 0); /* do it until reaching the root */ } diff --git a/DiscImageChef.DiscImages/UkvFdi.cs b/DiscImageChef.DiscImages/UkvFdi.cs index 6b7e08ba7..8ba2157e9 100644 --- a/DiscImageChef.DiscImages/UkvFdi.cs +++ b/DiscImageChef.DiscImages/UkvFdi.cs @@ -237,16 +237,17 @@ namespace DiscImageChef.DiscImages } // For empty cylinders - if(sectorsOff[cyl][head].Length == 0) - if(cyl + 1 == hdr.cylinders || - // Next cylinder is also empty - sectorsOff[cyl + 1][head].Length == 0) emptyCyl = true; - // Create empty sectors - else - { - sectorsData[cyl][head] = new byte[spt][]; - for(int i = 0; i < spt; i++) sectorsData[cyl][head][i] = new byte[ImageInfo.SectorSize]; - } + if(sectorsOff[cyl][head].Length != 0) continue; + + if(cyl + 1 == hdr.cylinders || + // Next cylinder is also empty + sectorsOff[cyl + 1][head].Length == 0) emptyCyl = true; + // Create empty sectors + else + { + sectorsData[cyl][head] = new byte[spt][]; + for(int i = 0; i < spt; i++) sectorsData[cyl][head][i] = new byte[ImageInfo.SectorSize]; + } } if(emptyCyl) ImageInfo.Cylinders--; diff --git a/DiscImageChef.DiscImages/VHD.cs b/DiscImageChef.DiscImages/VHD.cs index 67ec5dbb5..fa5531417 100644 --- a/DiscImageChef.DiscImages/VHD.cs +++ b/DiscImageChef.DiscImages/VHD.cs @@ -1081,28 +1081,25 @@ namespace DiscImageChef.DiscImages */ // Sector has been written, read from child image - if(dirty) - { - /* Too noisy + if(!dirty) return parentImage.ReadSector(sectorAddress); + /* Too noisy DicConsole.DebugWriteLine("VirtualPC plugin", "Sector {0} is dirty", sectorAddress); */ - byte[] data = new byte[512]; - uint sectorOffset = blockAllocationTable[blockNumber] + bitmapSize + sectorInBlock; - thisStream = thisFilter.GetDataForkStream(); + byte[] data = new byte[512]; + uint sectorOffset = blockAllocationTable[blockNumber] + bitmapSize + sectorInBlock; + thisStream = thisFilter.GetDataForkStream(); - thisStream.Seek(sectorOffset * 512, SeekOrigin.Begin); - thisStream.Read(data, 0, 512); + thisStream.Seek(sectorOffset * 512, SeekOrigin.Begin); + thisStream.Read(data, 0, 512); - return data; - } + return data; /* Too noisy DicConsole.DebugWriteLine("VirtualPC plugin", "Sector {0} is clean", sectorAddress); */ // Read sector from parent image - return parentImage.ReadSector(sectorAddress); } default: return ReadSectors(sectorAddress, 1); } @@ -1170,15 +1167,12 @@ namespace DiscImageChef.DiscImages else Array.Clear(prefix, 0, prefix.Length); // If we needed to read from another block, join all the data - if(suffix != null) - { - byte[] data = new byte[512 * length]; - Array.Copy(prefix, 0, data, 0, prefix.Length); - Array.Copy(suffix, 0, data, prefix.Length, suffix.Length); - return data; - } + if(suffix == null) return prefix; - return prefix; + byte[] data = new byte[512 * length]; + Array.Copy(prefix, 0, data, 0, prefix.Length); + Array.Copy(suffix, 0, data, prefix.Length, suffix.Length); + return data; } case TYPE_DIFFERENCING: { diff --git a/DiscImageChef.DiscImages/VHDX.cs b/DiscImageChef.DiscImages/VHDX.cs index 36777bf0e..73bf1a6ee 100644 --- a/DiscImageChef.DiscImages/VHDX.cs +++ b/DiscImageChef.DiscImages/VHDX.cs @@ -614,11 +614,10 @@ namespace DiscImageChef.DiscImages { parentFilter = new FiltersList().GetFilter(Path.Combine(imageFilter.GetParentFolder(), relEntry)); - if(parentFilter != null && parentImage.OpenImage(parentFilter)) - { - parentWorks = true; - break; - } + if(parentFilter == null || !parentImage.OpenImage(parentFilter)) continue; + + parentWorks = true; + break; } catch { continue; } } @@ -634,11 +633,10 @@ namespace DiscImageChef.DiscImages { parentFilter = new FiltersList().GetFilter(Path.Combine(imageFilter.GetParentFolder(), entryValue)); - if(parentFilter != null && parentImage.OpenImage(parentFilter)) - { - parentWorks = true; - break; - } + if(parentFilter == null || !parentImage.OpenImage(parentFilter)) continue; + + parentWorks = true; + break; } catch { continue; } } diff --git a/DiscImageChef.DiscImages/VMware.cs b/DiscImageChef.DiscImages/VMware.cs index 95b32f812..b72a026e4 100644 --- a/DiscImageChef.DiscImages/VMware.cs +++ b/DiscImageChef.DiscImages/VMware.cs @@ -234,16 +234,17 @@ namespace DiscImageChef.DiscImages stream.Read(ddfMagic, 0, 0x15); vmCHdr = new VMwareCowHeader(); - if(stream.Length > Marshal.SizeOf(vmCHdr)) - { - stream.Seek(0, SeekOrigin.Begin); - byte[] vmCHdrB = new byte[Marshal.SizeOf(vmCHdr)]; - stream.Read(vmCHdrB, 0, Marshal.SizeOf(vmCHdr)); - headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vmCHdr)); - Marshal.Copy(vmCHdrB, 0, headerPtr, Marshal.SizeOf(vmCHdr)); - vmCHdr = (VMwareCowHeader)Marshal.PtrToStructure(headerPtr, typeof(VMwareCowHeader)); - Marshal.FreeHGlobal(headerPtr); - } + if(stream.Length <= Marshal.SizeOf(vmCHdr)) + return ddfMagicBytes.SequenceEqual(ddfMagic) || vmEHdr.magic == VMWARE_EXTENT_MAGIC || + vmCHdr.magic == VMWARE_COW_MAGIC; + + stream.Seek(0, SeekOrigin.Begin); + byte[] vmCHdrB = new byte[Marshal.SizeOf(vmCHdr)]; + stream.Read(vmCHdrB, 0, Marshal.SizeOf(vmCHdr)); + headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vmCHdr)); + Marshal.Copy(vmCHdrB, 0, headerPtr, Marshal.SizeOf(vmCHdr)); + vmCHdr = (VMwareCowHeader)Marshal.PtrToStructure(headerPtr, typeof(VMwareCowHeader)); + Marshal.FreeHGlobal(headerPtr); return ddfMagicBytes.SequenceEqual(ddfMagic) || vmEHdr.magic == VMWARE_EXTENT_MAGIC || vmCHdr.magic == VMWARE_COW_MAGIC; @@ -522,43 +523,42 @@ namespace DiscImageChef.DiscImages if(extent.Access == "NOACCESS") throw new Exception("Cannot access NOACCESS extents ;)."); - if(extent.Type != "FLAT" && extent.Type != "ZERO" && extent.Type != "VMFS" && !cowD) + if(extent.Type == "FLAT" || extent.Type == "ZERO" || extent.Type == "VMFS" || cowD) continue; + + Stream extentStream = extent.Filter.GetDataForkStream(); + extentStream.Seek(0, SeekOrigin.Begin); + + if(extentStream.Length < SECTOR_SIZE) + throw new Exception(string.Format("Extent {0} is too small.", extent.Filename)); + + VMwareExtentHeader extentHdr = new VMwareExtentHeader(); + byte[] extentHdrB = new byte[Marshal.SizeOf(extentHdr)]; + extentStream.Read(extentHdrB, 0, Marshal.SizeOf(extentHdr)); + IntPtr extentHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(extentHdr)); + Marshal.Copy(extentHdrB, 0, extentHdrPtr, Marshal.SizeOf(extentHdr)); + extentHdr = (VMwareExtentHeader)Marshal.PtrToStructure(extentHdrPtr, typeof(VMwareExtentHeader)); + Marshal.FreeHGlobal(extentHdrPtr); + + if(extentHdr.magic != VMWARE_EXTENT_MAGIC) + throw new Exception(string.Format("{0} is not an VMware extent.", extent.Filter)); + + if(extentHdr.capacity < extent.Sectors) + throw new + Exception(string.Format("Extent contains incorrect number of sectors, {0}. {1} were expected", + extentHdr.capacity, extent.Sectors)); + + // TODO: Support compressed extents + if(extentHdr.compression != COMPRESSION_NONE) + throw new ImageNotSupportedException("Compressed extents are not yet supported."); + + if(!vmEHdrSet) { - Stream extentStream = extent.Filter.GetDataForkStream(); - extentStream.Seek(0, SeekOrigin.Begin); - - if(extentStream.Length < SECTOR_SIZE) - throw new Exception(string.Format("Extent {0} is too small.", extent.Filename)); - - VMwareExtentHeader extentHdr = new VMwareExtentHeader(); - byte[] extentHdrB = new byte[Marshal.SizeOf(extentHdr)]; - extentStream.Read(extentHdrB, 0, Marshal.SizeOf(extentHdr)); - IntPtr extentHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(extentHdr)); - Marshal.Copy(extentHdrB, 0, extentHdrPtr, Marshal.SizeOf(extentHdr)); - extentHdr = (VMwareExtentHeader)Marshal.PtrToStructure(extentHdrPtr, typeof(VMwareExtentHeader)); - Marshal.FreeHGlobal(extentHdrPtr); - - if(extentHdr.magic != VMWARE_EXTENT_MAGIC) - throw new Exception(string.Format("{0} is not an VMware extent.", extent.Filter)); - - if(extentHdr.capacity < extent.Sectors) - throw new - Exception(string.Format("Extent contains incorrect number of sectors, {0}. {1} were expected", - extentHdr.capacity, extent.Sectors)); - - // TODO: Support compressed extents - if(extentHdr.compression != COMPRESSION_NONE) - throw new ImageNotSupportedException("Compressed extents are not yet supported."); - - if(!vmEHdrSet) - { - vmEHdr = extentHdr; - gdFilter = extent.Filter; - vmEHdrSet = true; - } - - oneNoFlat = true; + vmEHdr = extentHdr; + gdFilter = extent.Filter; + vmEHdrSet = true; } + + oneNoFlat = true; } if(oneNoFlat && !vmEHdrSet && !cowD) diff --git a/DiscImageChef.DiscImages/ZZZRawImage.cs b/DiscImageChef.DiscImages/ZZZRawImage.cs index 3349284b8..1924a9ca4 100644 --- a/DiscImageChef.DiscImages/ZZZRawImage.cs +++ b/DiscImageChef.DiscImages/ZZZRawImage.cs @@ -78,40 +78,39 @@ namespace DiscImageChef.DiscImages public override bool IdentifyImage(Filter imageFilter) { // Check if file is not multiple of 512 - if(imageFilter.GetDataForkLength() % 512 != 0) + if(imageFilter.GetDataForkLength() % 512 == 0) return true; + + extension = Path.GetExtension(imageFilter.GetFilename()).ToLower(); + + if(extension == ".hdf" && ImageInfo.ImageSize % 256 == 0) return true; + + // Check known disk sizes with sectors smaller than 512 + switch(imageFilter.GetDataForkLength()) { - extension = Path.GetExtension(imageFilter.GetFilename()).ToLower(); + #region Commodore + case 174848: + case 175531: + case 197376: + case 351062: + case 822400: + #endregion Commodore - if(extension == ".hdf" && ImageInfo.ImageSize % 256 == 0) return true; - - // Check known disk sizes with sectors smaller than 512 - switch(imageFilter.GetDataForkLength()) - { - #region Commodore - case 174848: - case 175531: - case 197376: - case 351062: - case 822400: - #endregion Commodore - - case 81664: - case 116480: - case 242944: - case 256256: - case 287488: - case 306432: - case 495872: - case 988416: - case 995072: - case 1021696: - case 1146624: - case 1177344: - case 1222400: - case 1304320: - case 1255168: return true; - default: return false; - } + case 81664: + case 116480: + case 242944: + case 256256: + case 287488: + case 306432: + case 495872: + case 988416: + case 995072: + case 1021696: + case 1146624: + case 1177344: + case 1222400: + case 1304320: + case 1255168: return true; + default: return false; } return true; @@ -761,148 +760,132 @@ namespace DiscImageChef.DiscImages public override List GetTracks() { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - Track trk = new Track(); - trk.TrackBytesPerSector = (int)ImageInfo.SectorSize; - trk.TrackEndSector = ImageInfo.Sectors - 1; - trk.TrackFile = rawImageFilter.GetFilename(); - trk.TrackFileOffset = 0; - trk.TrackFileType = "BINARY"; - trk.TrackRawBytesPerSector = (int)ImageInfo.SectorSize; - trk.TrackSequence = 1; - trk.TrackStartSector = 0; - trk.TrackSubchannelType = TrackSubchannelType.None; - trk.TrackType = TrackType.Data; - trk.TrackSession = 1; - List lst = new List(); - lst.Add(trk); - return lst; - } + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + Track trk = new Track(); + trk.TrackBytesPerSector = (int)ImageInfo.SectorSize; + trk.TrackEndSector = ImageInfo.Sectors - 1; + trk.TrackFile = rawImageFilter.GetFilename(); + trk.TrackFileOffset = 0; + trk.TrackFileType = "BINARY"; + trk.TrackRawBytesPerSector = (int)ImageInfo.SectorSize; + trk.TrackSequence = 1; + trk.TrackStartSector = 0; + trk.TrackSubchannelType = TrackSubchannelType.None; + trk.TrackType = TrackType.Data; + trk.TrackSession = 1; + List lst = new List(); + lst.Add(trk); + return lst; } public override List GetSessionTracks(Session session) { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - if(session.SessionSequence != 1) - throw new ArgumentOutOfRangeException(nameof(session), "Only a single session is supported"); + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - Track trk = new Track(); - trk.TrackBytesPerSector = (int)ImageInfo.SectorSize; - trk.TrackEndSector = ImageInfo.Sectors - 1; - trk.TrackFilter = rawImageFilter; - trk.TrackFile = rawImageFilter.GetFilename(); - trk.TrackFileOffset = 0; - trk.TrackFileType = "BINARY"; - trk.TrackRawBytesPerSector = (int)ImageInfo.SectorSize; - trk.TrackSequence = 1; - trk.TrackStartSector = 0; - trk.TrackSubchannelType = TrackSubchannelType.None; - trk.TrackType = TrackType.Data; - trk.TrackSession = 1; - List lst = new List(); - lst.Add(trk); - return lst; - } + if(session.SessionSequence != 1) + throw new ArgumentOutOfRangeException(nameof(session), "Only a single session is supported"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + Track trk = new Track(); + trk.TrackBytesPerSector = (int)ImageInfo.SectorSize; + trk.TrackEndSector = ImageInfo.Sectors - 1; + trk.TrackFilter = rawImageFilter; + trk.TrackFile = rawImageFilter.GetFilename(); + trk.TrackFileOffset = 0; + trk.TrackFileType = "BINARY"; + trk.TrackRawBytesPerSector = (int)ImageInfo.SectorSize; + trk.TrackSequence = 1; + trk.TrackStartSector = 0; + trk.TrackSubchannelType = TrackSubchannelType.None; + trk.TrackType = TrackType.Data; + trk.TrackSession = 1; + List lst = new List(); + lst.Add(trk); + return lst; } public override List GetSessionTracks(ushort session) { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - if(session != 1) - throw new ArgumentOutOfRangeException(nameof(session), "Only a single session is supported"); + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - Track trk = new Track(); - trk.TrackBytesPerSector = (int)ImageInfo.SectorSize; - trk.TrackEndSector = ImageInfo.Sectors - 1; - trk.TrackFilter = rawImageFilter; - trk.TrackFile = rawImageFilter.GetFilename(); - trk.TrackFileOffset = 0; - trk.TrackFileType = "BINARY"; - trk.TrackRawBytesPerSector = (int)ImageInfo.SectorSize; - trk.TrackSequence = 1; - trk.TrackStartSector = 0; - trk.TrackSubchannelType = TrackSubchannelType.None; - trk.TrackType = TrackType.Data; - trk.TrackSession = 1; - List lst = new List(); - lst.Add(trk); - return lst; - } + if(session != 1) + throw new ArgumentOutOfRangeException(nameof(session), "Only a single session is supported"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + Track trk = new Track(); + trk.TrackBytesPerSector = (int)ImageInfo.SectorSize; + trk.TrackEndSector = ImageInfo.Sectors - 1; + trk.TrackFilter = rawImageFilter; + trk.TrackFile = rawImageFilter.GetFilename(); + trk.TrackFileOffset = 0; + trk.TrackFileType = "BINARY"; + trk.TrackRawBytesPerSector = (int)ImageInfo.SectorSize; + trk.TrackSequence = 1; + trk.TrackStartSector = 0; + trk.TrackSubchannelType = TrackSubchannelType.None; + trk.TrackType = TrackType.Data; + trk.TrackSession = 1; + List lst = new List(); + lst.Add(trk); + return lst; } public override List GetSessions() { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - Session sess = new Session(); - sess.EndSector = ImageInfo.Sectors - 1; - sess.EndTrack = 1; - sess.SessionSequence = 1; - sess.StartSector = 0; - sess.StartTrack = 1; - List lst = new List(); - lst.Add(sess); - return lst; - } + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + Session sess = new Session(); + sess.EndSector = ImageInfo.Sectors - 1; + sess.EndTrack = 1; + sess.SessionSequence = 1; + sess.StartSector = 0; + sess.StartTrack = 1; + List lst = new List(); + lst.Add(sess); + return lst; } public override byte[] ReadSector(ulong sectorAddress, uint track) { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - return ReadSector(sectorAddress); - } + if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + return ReadSector(sectorAddress); } public override byte[] ReadSectors(ulong sectorAddress, uint length, uint track) { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - return ReadSectors(sectorAddress, length); - } + if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + return ReadSectors(sectorAddress, length); } public override byte[] ReadSectorLong(ulong sectorAddress, uint track) { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - return ReadSector(sectorAddress); - } + if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + return ReadSector(sectorAddress); } public override byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track) { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - return ReadSectors(sectorAddress, length); - } + if(track != 1) throw new ArgumentOutOfRangeException(nameof(track), "Only a single track is supported"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + return ReadSectors(sectorAddress, length); } #region Private methods @@ -1124,23 +1107,21 @@ namespace DiscImageChef.DiscImages public override List GetPartitions() { - if(ImageInfo.XmlMediaType == XmlMediaType.OpticalDisc) - { - List parts = new List(); - Partition part = new Partition - { - Start = 0, - Length = ImageInfo.Sectors, - Offset = 0, - Sequence = 0, - Type = "MODE1/2048", - Size = ImageInfo.Sectors * ImageInfo.SectorSize - }; - parts.Add(part); - return parts; - } + if(ImageInfo.XmlMediaType != XmlMediaType.OpticalDisc) + throw new FeatureUnsupportedImageException("Feature not supported by image format"); - throw new FeatureUnsupportedImageException("Feature not supported by image format"); + List parts = new List(); + Partition part = new Partition + { + Start = 0, + Length = ImageInfo.Sectors, + Offset = 0, + Sequence = 0, + Type = "MODE1/2048", + Size = ImageInfo.Sectors * ImageInfo.SectorSize + }; + parts.Add(part); + return parts; } public override byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag) diff --git a/DiscImageChef.Filesystems/AmigaDOS.cs b/DiscImageChef.Filesystems/AmigaDOS.cs index 543df094d..ecb5ac06a 100644 --- a/DiscImageChef.Filesystems/AmigaDOS.cs +++ b/DiscImageChef.Filesystems/AmigaDOS.cs @@ -385,12 +385,11 @@ namespace DiscImageChef.Filesystems rootBlk.sec_type = BigEndianBitConverter.ToUInt32(RootBlockSector, RootBlockSector.Length - 4); DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.sec_type = {0}", rootBlk.sec_type); - if(rootBlk.sec_type == SubTypeRoot && rootBlk.checksum == rsum) - { - RootBlockSector = imagePlugin.ReadSectors(root_ptr, sectorsPerBlock); - root_found = true; - break; - } + if(rootBlk.sec_type != SubTypeRoot || rootBlk.checksum != rsum) continue; + + RootBlockSector = imagePlugin.ReadSectors(root_ptr, sectorsPerBlock); + root_found = true; + break; } if(!root_found) return; diff --git a/DiscImageChef.Filesystems/AppleDOS/Xattr.cs b/DiscImageChef.Filesystems/AppleDOS/Xattr.cs index 3e79f914c..066f6619b 100644 --- a/DiscImageChef.Filesystems/AppleDOS/Xattr.cs +++ b/DiscImageChef.Filesystems/AppleDOS/Xattr.cs @@ -103,17 +103,15 @@ namespace DiscImageChef.Filesystems.AppleDOS return Errno.NoError; } - if(string.Compare(xattr, "com.apple.dos.tracksectorlist", StringComparison.InvariantCulture) == 0 && debug) - { - byte[] ts; - if(!extentCache.TryGetValue(filename, out ts)) return Errno.InvalidArgument; + if(string.Compare(xattr, "com.apple.dos.tracksectorlist", StringComparison.InvariantCulture) != 0 || !debug) + return Errno.NoSuchExtendedAttribute; - buf = new byte[ts.Length]; - Array.Copy(ts, 0, buf, 0, buf.Length); - return Errno.NoError; - } + byte[] ts; + if(!extentCache.TryGetValue(filename, out ts)) return Errno.InvalidArgument; - return Errno.NoSuchExtendedAttribute; + buf = new byte[ts.Length]; + Array.Copy(ts, 0, buf, 0, buf.Length); + return Errno.NoError; } } } \ No newline at end of file diff --git a/DiscImageChef.Filesystems/AppleHFS.cs b/DiscImageChef.Filesystems/AppleHFS.cs index 418f929e4..bfaa2b545 100644 --- a/DiscImageChef.Filesystems/AppleHFS.cs +++ b/DiscImageChef.Filesystems/AppleHFS.cs @@ -93,14 +93,13 @@ namespace DiscImageChef.Filesystems foreach(int offset in new[] {0, 0x200, 0x400, 0x600, 0x800, 0xA00}) { drSigWord = BigEndianBitConverter.ToUInt16(mdb_sector, offset); - if(drSigWord == HFS_MAGIC) - { - drSigWord = - BigEndianBitConverter - .ToUInt16(mdb_sector, offset + 0x7C); // Seek to embedded HFS+ signature + if(drSigWord != HFS_MAGIC) continue; - return drSigWord != HFSP_MAGIC; - } + drSigWord = + BigEndianBitConverter + .ToUInt16(mdb_sector, offset + 0x7C); // Seek to embedded HFS+ signature + + return drSigWord != HFSP_MAGIC; } } else @@ -108,12 +107,11 @@ namespace DiscImageChef.Filesystems mdb_sector = imagePlugin.ReadSector(2 + partition.Start); drSigWord = BigEndianBitConverter.ToUInt16(mdb_sector, 0); - if(drSigWord == HFS_MAGIC) - { - drSigWord = BigEndianBitConverter.ToUInt16(mdb_sector, 0x7C); // Seek to embedded HFS+ signature + if(drSigWord != HFS_MAGIC) return false; - return drSigWord != HFSP_MAGIC; - } + drSigWord = BigEndianBitConverter.ToUInt16(mdb_sector, 0x7C); // Seek to embedded HFS+ signature + + return drSigWord != HFSP_MAGIC; } return false; @@ -143,15 +141,14 @@ namespace DiscImageChef.Filesystems foreach(int offset in new[] {0, 0x200, 0x400, 0x600, 0x800, 0xA00}) { drSigWord = BigEndianBitConverter.ToUInt16(tmp_sector, offset); - if(drSigWord == HFS_MAGIC) - { - bb_sector = new byte[1024]; - mdb_sector = new byte[512]; - if(offset >= 0x400) Array.Copy(tmp_sector, offset - 0x400, bb_sector, 0, 1024); - Array.Copy(tmp_sector, offset, mdb_sector, 0, 512); - APMFromHDDOnCD = true; - break; - } + if(drSigWord != HFS_MAGIC) continue; + + bb_sector = new byte[1024]; + mdb_sector = new byte[512]; + if(offset >= 0x400) Array.Copy(tmp_sector, offset - 0x400, bb_sector, 0, 1024); + Array.Copy(tmp_sector, offset, mdb_sector, 0, 512); + APMFromHDDOnCD = true; + break; } if(!APMFromHDDOnCD) return; diff --git a/DiscImageChef.Filesystems/AppleMFS/Xattr.cs b/DiscImageChef.Filesystems/AppleMFS/Xattr.cs index 60b131d24..f1c8bfe05 100644 --- a/DiscImageChef.Filesystems/AppleMFS/Xattr.cs +++ b/DiscImageChef.Filesystems/AppleMFS/Xattr.cs @@ -159,14 +159,12 @@ namespace DiscImageChef.Filesystems.AppleMFS return Errno.NoError; } - if(debug && device.ImageInfo.ReadableSectorTags.Contains(DiscImages.SectorTagType.AppleSectorTag) && - string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) == 0) - { - error = ReadFile(path, out buf, false, true); - return error; - } + if(!debug || !device.ImageInfo.ReadableSectorTags.Contains(DiscImages.SectorTagType.AppleSectorTag) || + string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) != 0) + return Errno.NoSuchExtendedAttribute; - return Errno.NoSuchExtendedAttribute; + error = ReadFile(path, out buf, false, true); + return error; } } } \ No newline at end of file diff --git a/DiscImageChef.Filesystems/CPM/Definitions.cs b/DiscImageChef.Filesystems/CPM/Definitions.cs index 2ab842e82..530fd3fc6 100644 --- a/DiscImageChef.Filesystems/CPM/Definitions.cs +++ b/DiscImageChef.Filesystems/CPM/Definitions.cs @@ -65,7 +65,8 @@ namespace DiscImageChef.Filesystems.CPM for(int i = 0; i < def.sectorsPerTrack; i++) def.side1.sectorIds[i] = i + 1; } - if(def.sides == 2 && def.side2 == null) + if(def.sides != 2 || def.side2 != null) continue; + { def.side2 = new Side(); def.side2.sideId = 1; diff --git a/DiscImageChef.Filesystems/CPM/File.cs b/DiscImageChef.Filesystems/CPM/File.cs index 70e7a91e0..16ad43cb1 100644 --- a/DiscImageChef.Filesystems/CPM/File.cs +++ b/DiscImageChef.Filesystems/CPM/File.cs @@ -53,13 +53,10 @@ namespace DiscImageChef.Filesystems.CPM return Errno.NoError; } - if(statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out fInfo)) - { - attributes = fInfo.Attributes; - return Errno.NoError; - } + if(!statCache.TryGetValue(pathElements[0].ToUpperInvariant(), out fInfo)) return Errno.NoSuchFile; - return Errno.NoSuchFile; + attributes = fInfo.Attributes; + return Errno.NoError; } public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock) diff --git a/DiscImageChef.Filesystems/CPM/Info.cs b/DiscImageChef.Filesystems/CPM/Info.cs index 60bb48f2a..d67e55558 100644 --- a/DiscImageChef.Filesystems/CPM/Info.cs +++ b/DiscImageChef.Filesystems/CPM/Info.cs @@ -794,166 +794,166 @@ namespace DiscImageChef.Filesystems.CPM { ulong sectors = (ulong)(def.cylinders * def.sides * def.sectorsPerTrack); + if(sectors != imagePlugin.GetSectors() || def.bytesPerSector != imagePlugin.GetSectorSize()) + continue; + // Definition seems to describe current disk, at least, same number of volume sectors and bytes per sector - if(sectors == imagePlugin.GetSectors() && def.bytesPerSector == imagePlugin.GetSectorSize()) + DicConsole.DebugWriteLine("CP/M Plugin", "Trying definition \"{0}\"", def.comment); + ulong offset; + if(def.sofs != 0) offset = (ulong)def.sofs; + else offset = (ulong)(def.ofs * def.sectorsPerTrack); + + int dirLen = (def.drm + 1) * 32 / def.bytesPerSector; + + if(def.sides == 1) { - DicConsole.DebugWriteLine("CP/M Plugin", "Trying definition \"{0}\"", def.comment); - ulong offset; - if(def.sofs != 0) offset = (ulong)def.sofs; - else offset = (ulong)(def.ofs * def.sectorsPerTrack); - - int dirLen = (def.drm + 1) * 32 / def.bytesPerSector; - - if(def.sides == 1) + sectorMask = new int[def.side1.sectorIds.Length]; + for(int m = 0; m < sectorMask.Length; m++) + sectorMask[m] = def.side1.sectorIds[m] - def.side1.sectorIds[0]; + } + else + { + // Head changes after every track + if(string.Compare(def.order, "SIDES", + StringComparison.InvariantCultureIgnoreCase) == 0) { - sectorMask = new int[def.side1.sectorIds.Length]; - for(int m = 0; m < sectorMask.Length; m++) + sectorMask = new int[def.side1.sectorIds.Length + def.side2.sectorIds.Length]; + for(int m = 0; m < def.side1.sectorIds.Length; m++) sectorMask[m] = def.side1.sectorIds[m] - def.side1.sectorIds[0]; + // Skip first track (first side) + for(int m = 0; m < def.side2.sectorIds.Length; m++) + sectorMask[m + def.side1.sectorIds.Length] = + def.side2.sectorIds[m] - def.side2.sectorIds[0] + + def.side1.sectorIds.Length; + } + // Head changes after whole side + else if(string.Compare(def.order, "CYLINDERS", + StringComparison.InvariantCultureIgnoreCase) == 0) + { + for(int m = 0; m < def.side1.sectorIds.Length; m++) + sectorMask[m] = def.side1.sectorIds[m] - def.side1.sectorIds[0]; + // Skip first track (first side) and first track (second side) + for(int m = 0; m < def.side1.sectorIds.Length; m++) + sectorMask[m + def.side1.sectorIds.Length] = + def.side1.sectorIds[m] - def.side1.sectorIds[0] + + def.side1.sectorIds.Length + def.side2.sectorIds.Length; + } + // TODO: Implement COLUMBIA ordering + else if(string.Compare(def.order, "COLUMBIA", + StringComparison.InvariantCultureIgnoreCase) == 0) + { + DicConsole.DebugWriteLine("CP/M Plugin", + "Don't know how to handle COLUMBIA ordering, not proceeding with this definition."); + continue; + } + // TODO: Implement EAGLE ordering + else if(string.Compare(def.order, "EAGLE", + StringComparison.InvariantCultureIgnoreCase) == 0) + { + DicConsole.DebugWriteLine("CP/M Plugin", + "Don't know how to handle EAGLE ordering, not proceeding with this definition."); + continue; } else { - // Head changes after every track - if(string.Compare(def.order, "SIDES", - StringComparison.InvariantCultureIgnoreCase) == 0) - { - sectorMask = new int[def.side1.sectorIds.Length + def.side2.sectorIds.Length]; - for(int m = 0; m < def.side1.sectorIds.Length; m++) - sectorMask[m] = def.side1.sectorIds[m] - def.side1.sectorIds[0]; - // Skip first track (first side) - for(int m = 0; m < def.side2.sectorIds.Length; m++) - sectorMask[m + def.side1.sectorIds.Length] = - def.side2.sectorIds[m] - def.side2.sectorIds[0] + - def.side1.sectorIds.Length; - } - // Head changes after whole side - else if(string.Compare(def.order, "CYLINDERS", - StringComparison.InvariantCultureIgnoreCase) == 0) - { - for(int m = 0; m < def.side1.sectorIds.Length; m++) - sectorMask[m] = def.side1.sectorIds[m] - def.side1.sectorIds[0]; - // Skip first track (first side) and first track (second side) - for(int m = 0; m < def.side1.sectorIds.Length; m++) - sectorMask[m + def.side1.sectorIds.Length] = - def.side1.sectorIds[m] - def.side1.sectorIds[0] + - def.side1.sectorIds.Length + def.side2.sectorIds.Length; - } - // TODO: Implement COLUMBIA ordering - else if(string.Compare(def.order, "COLUMBIA", - StringComparison.InvariantCultureIgnoreCase) == 0) - { - DicConsole.DebugWriteLine("CP/M Plugin", - "Don't know how to handle COLUMBIA ordering, not proceeding with this definition."); - continue; - } - // TODO: Implement EAGLE ordering - else if(string.Compare(def.order, "EAGLE", - StringComparison.InvariantCultureIgnoreCase) == 0) - { - DicConsole.DebugWriteLine("CP/M Plugin", - "Don't know how to handle EAGLE ordering, not proceeding with this definition."); - continue; - } - else - { - DicConsole.DebugWriteLine("CP/M Plugin", - "Unknown order type \"{0}\", not proceeding with this definition.", - def.order); - continue; - } - } - - // Read the directory marked by this definition - MemoryStream ms = new MemoryStream(); - for(int p = 0; p < dirLen; p++) - { - byte[] dirSector = - imagePlugin.ReadSector((ulong)((int)offset + (int)partition.Start + - p / sectorMask.Length * sectorMask.Length + - sectorMask[p % sectorMask.Length])); - ms.Write(dirSector, 0, dirSector.Length); - } - - directory = ms.ToArray(); - - if(def.evenOdd) DicConsole.DebugWriteLine("CP/M Plugin", - "Definition contains EVEN-ODD field, with unknown meaning, detection may be wrong."); - - // Complement of the directory bytes if needed - if(def.complement) - for(int b = 0; b < directory.Length; b++) - directory[b] = (byte)(~directory[b] & 0xFF); - - // Check the directory - if(CheckDir(directory)) - { - DicConsole.DebugWriteLine("CP/M Plugin", - "Definition \"{0}\" has a correct directory", - def.comment); - - // Build a Disc Parameter Block - workingDefinition = def; - dpb = new DiscParameterBlock(); - dpb.al0 = (byte)def.al0; - dpb.al1 = (byte)def.al1; - dpb.blm = (byte)def.blm; - dpb.bsh = (byte)def.bsh; - dpb.cks = 0; // Needed? - dpb.drm = (ushort)def.drm; - dpb.dsm = (ushort)def.dsm; - dpb.exm = (byte)def.exm; - dpb.off = (ushort)def.ofs; - switch(def.bytesPerSector) - { - case 128: - dpb.psh = 0; - dpb.phm = 0; - break; - case 256: - dpb.psh = 1; - dpb.phm = 1; - break; - case 512: - dpb.psh = 2; - dpb.phm = 3; - break; - case 1024: - dpb.psh = 3; - dpb.phm = 7; - break; - case 2048: - dpb.psh = 4; - dpb.phm = 15; - break; - case 4096: - dpb.psh = 5; - dpb.phm = 31; - break; - case 8192: - dpb.psh = 6; - dpb.phm = 63; - break; - case 16384: - dpb.psh = 7; - dpb.phm = 127; - break; - case 32768: - dpb.psh = 8; - dpb.phm = 255; - break; - } - - dpb.spt = (ushort)(def.sectorsPerTrack * def.bytesPerSector / 128); - cpmFound = true; - workingDefinition = def; - - return true; + "Unknown order type \"{0}\", not proceeding with this definition.", + def.order); + continue; } - - label = null; - labelCreationDate = null; - labelUpdateDate = null; } + + // Read the directory marked by this definition + MemoryStream ms = new MemoryStream(); + for(int p = 0; p < dirLen; p++) + { + byte[] dirSector = + imagePlugin.ReadSector((ulong)((int)offset + (int)partition.Start + + p / sectorMask.Length * sectorMask.Length + + sectorMask[p % sectorMask.Length])); + ms.Write(dirSector, 0, dirSector.Length); + } + + directory = ms.ToArray(); + + if(def.evenOdd) + DicConsole.DebugWriteLine("CP/M Plugin", + "Definition contains EVEN-ODD field, with unknown meaning, detection may be wrong."); + + // Complement of the directory bytes if needed + if(def.complement) + for(int b = 0; b < directory.Length; b++) + directory[b] = (byte)(~directory[b] & 0xFF); + + // Check the directory + if(CheckDir(directory)) + { + DicConsole.DebugWriteLine("CP/M Plugin", + "Definition \"{0}\" has a correct directory", + def.comment); + + // Build a Disc Parameter Block + workingDefinition = def; + dpb = new DiscParameterBlock(); + dpb.al0 = (byte)def.al0; + dpb.al1 = (byte)def.al1; + dpb.blm = (byte)def.blm; + dpb.bsh = (byte)def.bsh; + dpb.cks = 0; // Needed? + dpb.drm = (ushort)def.drm; + dpb.dsm = (ushort)def.dsm; + dpb.exm = (byte)def.exm; + dpb.off = (ushort)def.ofs; + switch(def.bytesPerSector) + { + case 128: + dpb.psh = 0; + dpb.phm = 0; + break; + case 256: + dpb.psh = 1; + dpb.phm = 1; + break; + case 512: + dpb.psh = 2; + dpb.phm = 3; + break; + case 1024: + dpb.psh = 3; + dpb.phm = 7; + break; + case 2048: + dpb.psh = 4; + dpb.phm = 15; + break; + case 4096: + dpb.psh = 5; + dpb.phm = 31; + break; + case 8192: + dpb.psh = 6; + dpb.phm = 63; + break; + case 16384: + dpb.psh = 7; + dpb.phm = 127; + break; + case 32768: + dpb.psh = 8; + dpb.phm = 255; + break; + } + + dpb.spt = (ushort)(def.sectorsPerTrack * def.bytesPerSector / 128); + cpmFound = true; + workingDefinition = def; + + return true; + } + + label = null; + labelCreationDate = null; + labelUpdateDate = null; } } } diff --git a/DiscImageChef.Filesystems/CPM/Super.cs b/DiscImageChef.Filesystems/CPM/Super.cs index 82b19f595..94a81d730 100644 --- a/DiscImageChef.Filesystems/CPM/Super.cs +++ b/DiscImageChef.Filesystems/CPM/Super.cs @@ -164,12 +164,11 @@ namespace DiscImageChef.Filesystems.CPM blockMs.Write(sector, 0, sector.Length); sectorsPerBlock++; - if(sectorsPerBlock == blockSize / sector.Length) - { - allocationBlocks.Add(blockNo++, blockMs.ToArray()); - sectorsPerBlock = 0; - blockMs = new MemoryStream(); - } + if(sectorsPerBlock != blockSize / sector.Length) continue; + + allocationBlocks.Add(blockNo++, blockMs.ToArray()); + sectorsPerBlock = 0; + blockMs = new MemoryStream(); } // CP/M blocks are same size than physical sectors else allocationBlocks.Add(blockNo++, sector); @@ -628,14 +627,15 @@ namespace DiscImageChef.Filesystems.CPM { List alBlks; - if(extents.TryGetValue(ex, out alBlks)) - foreach(ushort alBlk in alBlks) - { - byte[] blk = new byte[blockSize]; - allocationBlocks.TryGetValue(alBlk, out blk); - fileMs.Write(blk, 0, blk.Length); - fInfo.Blocks++; - } + if(!extents.TryGetValue(ex, out alBlks)) continue; + + foreach(ushort alBlk in alBlks) + { + byte[] blk = new byte[blockSize]; + allocationBlocks.TryGetValue(alBlk, out blk); + fileMs.Write(blk, 0, blk.Length); + fInfo.Blocks++; + } } // If you insist to call CP/M "extent based" diff --git a/DiscImageChef.Filesystems/CPM/Xattr.cs b/DiscImageChef.Filesystems/CPM/Xattr.cs index 0d8f3dc60..0e7438a79 100644 --- a/DiscImageChef.Filesystems/CPM/Xattr.cs +++ b/DiscImageChef.Filesystems/CPM/Xattr.cs @@ -55,7 +55,10 @@ namespace DiscImageChef.Filesystems.CPM if(string.Compare(xattr, "com.caldera.cpm.password", StringComparison.InvariantCulture) == 0) if(!passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)) return Errno.NoError; - if(string.Compare(xattr, "com.caldera.cpm.password.text", StringComparison.InvariantCulture) == 0) if(!passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)) return Errno.NoError; + if(string.Compare(xattr, "com.caldera.cpm.password.text", StringComparison.InvariantCulture) != 0) + return Errno.NoSuchExtendedAttribute; + + if(!passwordCache.TryGetValue(pathElements[0].ToUpperInvariant(), out buf)) return Errno.NoError; return Errno.NoSuchExtendedAttribute; } diff --git a/DiscImageChef.Filesystems/ISO9660/Info.cs b/DiscImageChef.Filesystems/ISO9660/Info.cs index 811b428ce..0bc990559 100644 --- a/DiscImageChef.Filesystems/ISO9660/Info.cs +++ b/DiscImageChef.Filesystems/ISO9660/Info.cs @@ -708,20 +708,21 @@ namespace DiscImageChef.Filesystems.ISO9660 ISOMetadata.AppendLine("\t\tImage contains ATAPI drivers"); if(flags.HasFlag(ElToritoFlags.SCSI)) ISOMetadata.AppendLine("\t\tImage contains SCSI drivers"); - if(flags.HasFlag(ElToritoFlags.Continued)) - while(true && torito_off < vd_sector.Length) - { - ElToritoSectionEntryExtension section_extension = new ElToritoSectionEntryExtension(); - ptr = Marshal.AllocHGlobal(ElToritoEntrySize); - Marshal.Copy(vd_sector, torito_off, ptr, ElToritoEntrySize); - section_extension = - (ElToritoSectionEntryExtension) - Marshal.PtrToStructure(ptr, typeof(ElToritoSectionEntryExtension)); - Marshal.FreeHGlobal(ptr); - torito_off += ElToritoEntrySize; + if(!flags.HasFlag(ElToritoFlags.Continued)) continue; - if(!section_extension.extension_flags.HasFlag(ElToritoFlags.Continued)) break; - } + while(true && torito_off < vd_sector.Length) + { + ElToritoSectionEntryExtension section_extension = new ElToritoSectionEntryExtension(); + ptr = Marshal.AllocHGlobal(ElToritoEntrySize); + Marshal.Copy(vd_sector, torito_off, ptr, ElToritoEntrySize); + section_extension = + (ElToritoSectionEntryExtension) + Marshal.PtrToStructure(ptr, typeof(ElToritoSectionEntryExtension)); + Marshal.FreeHGlobal(ptr); + torito_off += ElToritoEntrySize; + + if(!section_extension.extension_flags.HasFlag(ElToritoFlags.Continued)) break; + } } if(section_header.header_id == ElToritoIndicator.LastHeader) break; diff --git a/DiscImageChef.Filesystems/LisaFS/Dir.cs b/DiscImageChef.Filesystems/LisaFS/Dir.cs index a4f973c6c..33a77007a 100644 --- a/DiscImageChef.Filesystems/LisaFS/Dir.cs +++ b/DiscImageChef.Filesystems/LisaFS/Dir.cs @@ -145,19 +145,18 @@ namespace DiscImageChef.Filesystems.LisaFS { ExtentFile ext; error = ReadExtentsFile(entV2.fileID, out ext); - if(error == Errno.NoError) - { - CatalogEntry entV3 = new CatalogEntry(); - entV3.fileID = entV2.fileID; - entV3.filename = new byte[32]; - Array.Copy(entV2.filename, 0, entV3.filename, 0, entV2.filenameLen); - entV3.fileType = entV2.fileType; - entV3.length = (int)srecords[entV2.fileID].filesize; - entV3.dtc = ext.dtc; - entV3.dtm = ext.dtm; + if(error != Errno.NoError) continue; - catalogCache.Add(entV3); - } + CatalogEntry entV3 = new CatalogEntry(); + entV3.fileID = entV2.fileID; + entV3.filename = new byte[32]; + Array.Copy(entV2.filename, 0, entV3.filename, 0, entV2.filenameLen); + entV3.fileType = entV2.fileType; + entV3.length = (int)srecords[entV2.fileID].filesize; + entV3.dtc = ext.dtc; + entV3.dtm = ext.dtm; + + catalogCache.Add(entV3); } return Errno.NoError; @@ -173,11 +172,10 @@ namespace DiscImageChef.Filesystems.LisaFS LisaTag.PriamTag catTag; DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out catTag); - if(catTag.fileID == FILEID_CATALOG && catTag.relPage == 0) - { - firstCatalogBlock = device.ReadSectors(i, 4); - break; - } + if(catTag.fileID != FILEID_CATALOG || catTag.relPage != 0) continue; + + firstCatalogBlock = device.ReadSectors(i, 4); + break; } // Catalog not found diff --git a/DiscImageChef.Filesystems/LisaFS/Extent.cs b/DiscImageChef.Filesystems/LisaFS/Extent.cs index 4f2b901ca..5f4aa0246 100644 --- a/DiscImageChef.Filesystems/LisaFS/Extent.cs +++ b/DiscImageChef.Filesystems/LisaFS/Extent.cs @@ -85,11 +85,10 @@ namespace DiscImageChef.Filesystems.LisaFS for(ulong i = 0; i < device.ImageInfo.Sectors; i++) { DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out extTag); - if(extTag.fileID == fileId * -1) - { - ptr = i; - break; - } + if(extTag.fileID != fileId * -1) continue; + + ptr = i; + break; } if(!found) return Errno.InvalidArgument; @@ -98,180 +97,169 @@ namespace DiscImageChef.Filesystems.LisaFS // Checks that the sector tag indicates its the Extents File we are searching for DecodeTag(device.ReadSectorTag(ptr, SectorTagType.AppleSectorTag), out extTag); - if(extTag.fileID == (short)(-1 * fileId)) + if(extTag.fileID != (short)(-1 * fileId)) return Errno.NoSuchFile; + + byte[] sector; + + if(mddf.fsversion == LisaFSv1) sector = device.ReadSectors(ptr, 2); + else sector = device.ReadSector(ptr); + + if(sector[0] >= 32 || sector[0] == 0) return Errno.InvalidArgument; + + file.filenameLen = sector[0]; + file.filename = new byte[file.filenameLen]; + Array.Copy(sector, 0x01, file.filename, 0, file.filenameLen); + file.unknown1 = BigEndianBitConverter.ToUInt16(sector, 0x20); + file.file_uid = BigEndianBitConverter.ToUInt64(sector, 0x22); + file.unknown2 = sector[0x2A]; + file.etype = sector[0x2B]; + file.ftype = (FileType)sector[0x2C]; + file.unknown3 = sector[0x2D]; + file.dtc = BigEndianBitConverter.ToUInt32(sector, 0x2E); + file.dta = BigEndianBitConverter.ToUInt32(sector, 0x32); + file.dtm = BigEndianBitConverter.ToUInt32(sector, 0x36); + file.dtb = BigEndianBitConverter.ToUInt32(sector, 0x3A); + file.dts = BigEndianBitConverter.ToUInt32(sector, 0x3E); + file.serial = BigEndianBitConverter.ToUInt32(sector, 0x42); + file.unknown4 = sector[0x46]; + file.locked = sector[0x47]; + file.protect = sector[0x48]; + file.master = sector[0x49]; + file.scavenged = sector[0x4A]; + file.closed = sector[0x4B]; + file.open = sector[0x4C]; + file.unknown5 = new byte[11]; + Array.Copy(sector, 0x4D, file.unknown5, 0, 11); + file.release = BigEndianBitConverter.ToUInt16(sector, 0x58); + file.build = BigEndianBitConverter.ToUInt16(sector, 0x5A); + file.compatibility = BigEndianBitConverter.ToUInt16(sector, 0x5C); + file.revision = BigEndianBitConverter.ToUInt16(sector, 0x5E); + file.unknown6 = BigEndianBitConverter.ToUInt16(sector, 0x60); + file.password_valid = sector[0x62]; + file.password = new byte[8]; + Array.Copy(sector, 0x63, file.password, 0, 8); + file.unknown7 = new byte[3]; + Array.Copy(sector, 0x6B, file.unknown7, 0, 3); + file.overhead = BigEndianBitConverter.ToUInt16(sector, 0x6E); + file.unknown8 = new byte[16]; + Array.Copy(sector, 0x70, file.unknown8, 0, 16); + file.unknown10 = BigEndianBitConverter.ToInt16(sector, 0x17E); + file.LisaInfo = new byte[128]; + Array.Copy(sector, 0x180, file.LisaInfo, 0, 128); + + int extentsCount = 0; + int extentsOffset; + + if(mddf.fsversion == LisaFSv1) { - byte[] sector; - - if(mddf.fsversion == LisaFSv1) sector = device.ReadSectors(ptr, 2); - else sector = device.ReadSector(ptr); - - if(sector[0] >= 32 || sector[0] == 0) return Errno.InvalidArgument; - - file.filenameLen = sector[0]; - file.filename = new byte[file.filenameLen]; - Array.Copy(sector, 0x01, file.filename, 0, file.filenameLen); - file.unknown1 = BigEndianBitConverter.ToUInt16(sector, 0x20); - file.file_uid = BigEndianBitConverter.ToUInt64(sector, 0x22); - file.unknown2 = sector[0x2A]; - file.etype = sector[0x2B]; - file.ftype = (FileType)sector[0x2C]; - file.unknown3 = sector[0x2D]; - file.dtc = BigEndianBitConverter.ToUInt32(sector, 0x2E); - file.dta = BigEndianBitConverter.ToUInt32(sector, 0x32); - file.dtm = BigEndianBitConverter.ToUInt32(sector, 0x36); - file.dtb = BigEndianBitConverter.ToUInt32(sector, 0x3A); - file.dts = BigEndianBitConverter.ToUInt32(sector, 0x3E); - file.serial = BigEndianBitConverter.ToUInt32(sector, 0x42); - file.unknown4 = sector[0x46]; - file.locked = sector[0x47]; - file.protect = sector[0x48]; - file.master = sector[0x49]; - file.scavenged = sector[0x4A]; - file.closed = sector[0x4B]; - file.open = sector[0x4C]; - file.unknown5 = new byte[11]; - Array.Copy(sector, 0x4D, file.unknown5, 0, 11); - file.release = BigEndianBitConverter.ToUInt16(sector, 0x58); - file.build = BigEndianBitConverter.ToUInt16(sector, 0x5A); - file.compatibility = BigEndianBitConverter.ToUInt16(sector, 0x5C); - file.revision = BigEndianBitConverter.ToUInt16(sector, 0x5E); - file.unknown6 = BigEndianBitConverter.ToUInt16(sector, 0x60); - file.password_valid = sector[0x62]; - file.password = new byte[8]; - Array.Copy(sector, 0x63, file.password, 0, 8); - file.unknown7 = new byte[3]; - Array.Copy(sector, 0x6B, file.unknown7, 0, 3); - file.overhead = BigEndianBitConverter.ToUInt16(sector, 0x6E); - file.unknown8 = new byte[16]; - Array.Copy(sector, 0x70, file.unknown8, 0, 16); - file.unknown10 = BigEndianBitConverter.ToInt16(sector, 0x17E); - file.LisaInfo = new byte[128]; - Array.Copy(sector, 0x180, file.LisaInfo, 0, 128); - - int extentsCount = 0; - int extentsOffset; - - if(mddf.fsversion == LisaFSv1) - { - file.length = BigEndianBitConverter.ToInt32(sector, 0x200); - file.unknown9 = BigEndianBitConverter.ToInt32(sector, 0x204); - extentsOffset = 0x208; - } - else - { - file.length = BigEndianBitConverter.ToInt32(sector, 0x80); - file.unknown9 = BigEndianBitConverter.ToInt32(sector, 0x84); - extentsOffset = 0x88; - } - - for(int j = 0; j < 41; j++) - { - if(BigEndianBitConverter.ToInt16(sector, extentsOffset + j * 6 + 4) == 0) break; - - extentsCount++; - } - - file.extents = new Extent[extentsCount]; - - for(int j = 0; j < extentsCount; j++) - { - file.extents[j] = new Extent(); - file.extents[j].start = BigEndianBitConverter.ToInt32(sector, extentsOffset + j * 6); - file.extents[j].length = BigEndianBitConverter.ToInt16(sector, extentsOffset + j * 6 + 4); - } - - extentCache.Add(fileId, file); - - if(debug) - if(!printedExtents.Contains(fileId)) - { - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filenameLen = {1}", fileId, - file.filenameLen); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filename = {1}", fileId, - StringHandlers.CToString(file.filename, CurrentEncoding)); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown1 = 0x{1:X4}", fileId, - file.unknown1); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].file_uid = 0x{1:X16}", fileId, - file.file_uid); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown2 = 0x{1:X2}", fileId, - file.unknown2); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].etype = 0x{1:X2}", fileId, - file.etype); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].ftype = {1}", fileId, file.ftype); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown3 = 0x{1:X2}", fileId, - file.unknown3); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtc = {1}", fileId, file.dtc); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dta = {1}", fileId, file.dta); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtm = {1}", fileId, file.dtm); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtb = {1}", fileId, file.dtb); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dts = {1}", fileId, file.dts); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].serial = {1}", fileId, file.serial); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown4 = 0x{1:X2}", fileId, - file.unknown4); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].locked = {1}", fileId, - file.locked > 0); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].protect = {1}", fileId, - file.protect > 0); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].master = {1}", fileId, - file.master > 0); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].scavenged = {1}", fileId, - file.scavenged > 0); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].closed = {1}", fileId, - file.closed > 0); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].open = {1}", fileId, file.open > 0); - DicConsole.DebugWriteLine("LisaFS plugin", - "ExtentFile[{0}].unknown5 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" + - "{10:X2}{11:X2}", fileId, file.unknown5[0], file.unknown5[1], - file.unknown5[2], file.unknown5[3], file.unknown5[4], - file.unknown5[5], file.unknown5[6], file.unknown5[7], - file.unknown5[8], file.unknown5[9], file.unknown5[10]); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].release = {1}", fileId, - file.release); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].build = {1}", fileId, file.build); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].compatibility = {1}", fileId, - file.compatibility); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].revision = {1}", fileId, - file.revision); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown6 = 0x{1:X4}", fileId, - file.unknown6); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password_valid = {1}", fileId, - file.password_valid > 0); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password = {1}", fileId, - CurrentEncoding.GetString(file.password)); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown7 = 0x{1:X2}{2:X2}{3:X2}", - fileId, file.unknown7[0], file.unknown7[1], file.unknown7[2]); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].overhead = {1}", fileId, - file.overhead); - DicConsole.DebugWriteLine("LisaFS plugin", - "ExtentFile[{0}].unknown8 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" + - "{10:X2}{11:X2}{12:X2}{13:X2}{14:X2}{15:X2}{16:X2}", fileId, - file.unknown8[0], file.unknown8[1], file.unknown8[2], - file.unknown8[3], file.unknown8[4], file.unknown8[5], - file.unknown8[6], file.unknown8[7], file.unknown8[8], - file.unknown8[9], file.unknown8[10], file.unknown8[11], - file.unknown8[12], file.unknown8[13], file.unknown8[14], - file.unknown8[15]); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].length = {1}", fileId, file.length); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown9 = 0x{1:X8}", fileId, - file.unknown9); - for(int ext = 0; ext < file.extents.Length; ext++) - { - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].start = {2}", - fileId, ext, file.extents[ext].start); - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].length = {2}", - fileId, ext, file.extents[ext].length); - } - - DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown10 = 0x{1:X4}", fileId, - file.unknown10); - - printedExtents.Add(fileId); - } - - return Errno.NoError; + file.length = BigEndianBitConverter.ToInt32(sector, 0x200); + file.unknown9 = BigEndianBitConverter.ToInt32(sector, 0x204); + extentsOffset = 0x208; + } + else + { + file.length = BigEndianBitConverter.ToInt32(sector, 0x80); + file.unknown9 = BigEndianBitConverter.ToInt32(sector, 0x84); + extentsOffset = 0x88; } - return Errno.NoSuchFile; + for(int j = 0; j < 41; j++) + { + if(BigEndianBitConverter.ToInt16(sector, extentsOffset + j * 6 + 4) == 0) break; + + extentsCount++; + } + + file.extents = new Extent[extentsCount]; + + for(int j = 0; j < extentsCount; j++) + { + file.extents[j] = new Extent(); + file.extents[j].start = BigEndianBitConverter.ToInt32(sector, extentsOffset + j * 6); + file.extents[j].length = BigEndianBitConverter.ToInt16(sector, extentsOffset + j * 6 + 4); + } + + extentCache.Add(fileId, file); + + if(!debug) return Errno.NoError; + + if(printedExtents.Contains(fileId)) return Errno.NoError; + + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filenameLen = {1}", fileId, + file.filenameLen); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].filename = {1}", fileId, + StringHandlers.CToString(file.filename, CurrentEncoding)); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown1 = 0x{1:X4}", fileId, + file.unknown1); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].file_uid = 0x{1:X16}", fileId, + file.file_uid); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown2 = 0x{1:X2}", fileId, + file.unknown2); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].etype = 0x{1:X2}", fileId, file.etype); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].ftype = {1}", fileId, file.ftype); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown3 = 0x{1:X2}", fileId, + file.unknown3); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtc = {1}", fileId, file.dtc); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dta = {1}", fileId, file.dta); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtm = {1}", fileId, file.dtm); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dtb = {1}", fileId, file.dtb); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].dts = {1}", fileId, file.dts); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].serial = {1}", fileId, file.serial); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown4 = 0x{1:X2}", fileId, + file.unknown4); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].locked = {1}", fileId, file.locked > 0); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].protect = {1}", fileId, + file.protect > 0); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].master = {1}", fileId, file.master > 0); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].scavenged = {1}", fileId, + file.scavenged > 0); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].closed = {1}", fileId, file.closed > 0); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].open = {1}", fileId, file.open > 0); + DicConsole.DebugWriteLine("LisaFS plugin", + "ExtentFile[{0}].unknown5 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" + + "{10:X2}{11:X2}", fileId, file.unknown5[0], file.unknown5[1], + file.unknown5[2], file.unknown5[3], file.unknown5[4], file.unknown5[5], + file.unknown5[6], file.unknown5[7], file.unknown5[8], file.unknown5[9], + file.unknown5[10]); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].release = {1}", fileId, file.release); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].build = {1}", fileId, file.build); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].compatibility = {1}", fileId, + file.compatibility); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].revision = {1}", fileId, file.revision); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown6 = 0x{1:X4}", fileId, + file.unknown6); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password_valid = {1}", fileId, + file.password_valid > 0); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].password = {1}", fileId, + CurrentEncoding.GetString(file.password)); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown7 = 0x{1:X2}{2:X2}{3:X2}", + fileId, file.unknown7[0], file.unknown7[1], file.unknown7[2]); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].overhead = {1}", fileId, file.overhead); + DicConsole.DebugWriteLine("LisaFS plugin", + "ExtentFile[{0}].unknown8 = 0x{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}" + + "{10:X2}{11:X2}{12:X2}{13:X2}{14:X2}{15:X2}{16:X2}", fileId, + file.unknown8[0], file.unknown8[1], file.unknown8[2], file.unknown8[3], + file.unknown8[4], file.unknown8[5], file.unknown8[6], file.unknown8[7], + file.unknown8[8], file.unknown8[9], file.unknown8[10], file.unknown8[11], + file.unknown8[12], file.unknown8[13], file.unknown8[14], + file.unknown8[15]); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].length = {1}", fileId, file.length); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown9 = 0x{1:X8}", fileId, + file.unknown9); + for(int ext = 0; ext < file.extents.Length; ext++) + { + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].start = {2}", fileId, + ext, file.extents[ext].start); + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].extents[{1}].length = {2}", fileId, + ext, file.extents[ext].length); + } + + DicConsole.DebugWriteLine("LisaFS plugin", "ExtentFile[{0}].unknown10 = 0x{1:X4}", fileId, + file.unknown10); + + printedExtents.Add(fileId); + + return Errno.NoError; } /// diff --git a/DiscImageChef.Filesystems/LisaFS/File.cs b/DiscImageChef.Filesystems/LisaFS/File.cs index 62b522a79..65a02e689 100644 --- a/DiscImageChef.Filesystems/LisaFS/File.cs +++ b/DiscImageChef.Filesystems/LisaFS/File.cs @@ -208,18 +208,17 @@ namespace DiscImageChef.Filesystems.LisaFS { DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out sysTag); - if(sysTag.fileID == fileId) - { - byte[] sector; + if(sysTag.fileID != fileId) continue; - if(!tags) sector = device.ReadSector(i); - else sector = device.ReadSectorTag(i, SectorTagType.AppleSectorTag); + byte[] sector; - // Relative block for $Loader starts at $Boot block - if(sysTag.fileID == FILEID_LOADER_SIGNED) sysTag.relPage--; + if(!tags) sector = device.ReadSector(i); + else sector = device.ReadSectorTag(i, SectorTagType.AppleSectorTag); - Array.Copy(sector, 0, buf, sector.Length * sysTag.relPage, sector.Length); - } + // Relative block for $Loader starts at $Boot block + if(sysTag.fileID == FILEID_LOADER_SIGNED) sysTag.relPage--; + + Array.Copy(sector, 0, buf, sector.Length * sysTag.relPage, sector.Length); } if(!tags) systemFileCache.Add(fileId, buf); @@ -445,18 +444,17 @@ namespace DiscImageChef.Filesystems.LisaFS string filename = StringHandlers.CToString(entry.filename, CurrentEncoding); // LisaOS is case insensitive - if(string.Compare(wantedFilename, filename, StringComparison.InvariantCultureIgnoreCase) == 0 && - entry.parentID == fileId) - { - fileId = entry.fileID; - isDir = entry.fileType == 0x01; + if(string.Compare(wantedFilename, filename, StringComparison.InvariantCultureIgnoreCase) != 0 || + entry.parentID != fileId) continue; - // Not last path element, and it's not a directory - if(lvl != pathElements.Length - 1 && !isDir) return Errno.NotDirectory; + fileId = entry.fileID; + isDir = entry.fileType == 0x01; - // Arrived last path element - if(lvl == pathElements.Length - 1) return Errno.NoError; - } + // Not last path element, and it's not a directory + if(lvl != pathElements.Length - 1 && !isDir) return Errno.NotDirectory; + + // Arrived last path element + if(lvl == pathElements.Length - 1) return Errno.NoError; } } diff --git a/DiscImageChef.Filesystems/LisaFS/Info.cs b/DiscImageChef.Filesystems/LisaFS/Info.cs index fce7d4ed4..5862a8c76 100644 --- a/DiscImageChef.Filesystems/LisaFS/Info.cs +++ b/DiscImageChef.Filesystems/LisaFS/Info.cs @@ -67,48 +67,44 @@ namespace DiscImageChef.Filesystems.LisaFS if(before_mddf == -1 && searchTag.fileID == FILEID_LOADER_SIGNED) before_mddf = i - 1; - if(searchTag.fileID == FILEID_MDDF) - { - byte[] sector = imagePlugin.ReadSector((ulong)i); - MDDF info_mddf = new MDDF(); + if(searchTag.fileID != FILEID_MDDF) continue; - info_mddf.mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C); - info_mddf.volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70); - info_mddf.volsize_minus_mddf_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x74); - info_mddf.vol_size = BigEndianBitConverter.ToUInt32(sector, 0x78); - info_mddf.blocksize = BigEndianBitConverter.ToUInt16(sector, 0x7C); - info_mddf.datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E); + byte[] sector = imagePlugin.ReadSector((ulong)i); + MDDF info_mddf = new MDDF(); - DicConsole.DebugWriteLine("LisaFS plugin", "Current sector = {0}", i); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.mddf_block = {0}", info_mddf.mddf_block); - DicConsole.DebugWriteLine("LisaFS plugin", "Disk size = {0} sectors", imagePlugin.GetSectors()); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size = {0} sectors", info_mddf.vol_size); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - 1 = {0}", - info_mddf.volsize_minus_one); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - mddf.mddf_block -1 = {0}", - info_mddf.volsize_minus_mddf_minus_one); - DicConsole.DebugWriteLine("LisaFS plugin", "Disk sector = {0} bytes", - imagePlugin.GetSectorSize()); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.blocksize = {0} bytes", info_mddf.blocksize); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.datasize = {0} bytes", info_mddf.datasize); + info_mddf.mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C); + info_mddf.volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70); + info_mddf.volsize_minus_mddf_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x74); + info_mddf.vol_size = BigEndianBitConverter.ToUInt32(sector, 0x78); + info_mddf.blocksize = BigEndianBitConverter.ToUInt16(sector, 0x7C); + info_mddf.datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E); - if(info_mddf.mddf_block != i - before_mddf) return false; + DicConsole.DebugWriteLine("LisaFS plugin", "Current sector = {0}", i); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.mddf_block = {0}", info_mddf.mddf_block); + DicConsole.DebugWriteLine("LisaFS plugin", "Disk size = {0} sectors", imagePlugin.GetSectors()); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size = {0} sectors", info_mddf.vol_size); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - 1 = {0}", info_mddf.volsize_minus_one); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.vol_size - mddf.mddf_block -1 = {0}", + info_mddf.volsize_minus_mddf_minus_one); + DicConsole.DebugWriteLine("LisaFS plugin", "Disk sector = {0} bytes", imagePlugin.GetSectorSize()); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.blocksize = {0} bytes", info_mddf.blocksize); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.datasize = {0} bytes", info_mddf.datasize); - if(info_mddf.vol_size > imagePlugin.GetSectors()) return false; + if(info_mddf.mddf_block != i - before_mddf) return false; - if(info_mddf.vol_size - 1 != info_mddf.volsize_minus_one) return false; + if(info_mddf.vol_size > imagePlugin.GetSectors()) return false; - if(info_mddf.vol_size - i - 1 != info_mddf.volsize_minus_mddf_minus_one - before_mddf) - return false; + if(info_mddf.vol_size - 1 != info_mddf.volsize_minus_one) return false; - if(info_mddf.datasize > info_mddf.blocksize) return false; + if(info_mddf.vol_size - i - 1 != info_mddf.volsize_minus_mddf_minus_one - before_mddf) return false; - if(info_mddf.blocksize < imagePlugin.GetSectorSize()) return false; + if(info_mddf.datasize > info_mddf.blocksize) return false; - if(info_mddf.datasize != imagePlugin.GetSectorSize()) return false; + if(info_mddf.blocksize < imagePlugin.GetSectorSize()) return false; - return true; - } + if(info_mddf.datasize != imagePlugin.GetSectorSize()) return false; + + return true; } return false; @@ -149,272 +145,233 @@ namespace DiscImageChef.Filesystems.LisaFS if(before_mddf == -1 && searchTag.fileID == FILEID_LOADER_SIGNED) before_mddf = i - 1; - if(searchTag.fileID == FILEID_MDDF) + if(searchTag.fileID != FILEID_MDDF) continue; + + byte[] sector = imagePlugin.ReadSector((ulong)i); + MDDF info_mddf = new MDDF(); + byte[] pString = new byte[33]; + uint lisa_time; + + info_mddf.fsversion = BigEndianBitConverter.ToUInt16(sector, 0x00); + info_mddf.volid = BigEndianBitConverter.ToUInt64(sector, 0x02); + info_mddf.volnum = BigEndianBitConverter.ToUInt16(sector, 0x0A); + Array.Copy(sector, 0x0C, pString, 0, 33); + info_mddf.volname = StringHandlers.PascalToString(pString, CurrentEncoding); + info_mddf.unknown1 = sector[0x2D]; + Array.Copy(sector, 0x2E, pString, 0, 33); + // Prevent garbage + if(pString[0] <= 32) info_mddf.password = StringHandlers.PascalToString(pString, CurrentEncoding); + else info_mddf.password = ""; + info_mddf.unknown2 = sector[0x4F]; + info_mddf.machine_id = BigEndianBitConverter.ToUInt32(sector, 0x50); + info_mddf.master_copy_id = BigEndianBitConverter.ToUInt32(sector, 0x54); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x58); + info_mddf.dtvc = DateHandlers.LisaToDateTime(lisa_time); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x5C); + info_mddf.dtcc = DateHandlers.LisaToDateTime(lisa_time); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x60); + info_mddf.dtvb = DateHandlers.LisaToDateTime(lisa_time); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x64); + info_mddf.dtvs = DateHandlers.LisaToDateTime(lisa_time); + info_mddf.unknown3 = BigEndianBitConverter.ToUInt32(sector, 0x68); + info_mddf.mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C); + info_mddf.volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70); + info_mddf.volsize_minus_mddf_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x74); + info_mddf.vol_size = BigEndianBitConverter.ToUInt32(sector, 0x78); + info_mddf.blocksize = BigEndianBitConverter.ToUInt16(sector, 0x7C); + info_mddf.datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E); + info_mddf.unknown4 = BigEndianBitConverter.ToUInt16(sector, 0x80); + info_mddf.unknown5 = BigEndianBitConverter.ToUInt32(sector, 0x82); + info_mddf.unknown6 = BigEndianBitConverter.ToUInt32(sector, 0x86); + info_mddf.clustersize = BigEndianBitConverter.ToUInt16(sector, 0x8A); + info_mddf.fs_size = BigEndianBitConverter.ToUInt32(sector, 0x8C); + info_mddf.unknown7 = BigEndianBitConverter.ToUInt32(sector, 0x90); + info_mddf.srec_ptr = BigEndianBitConverter.ToUInt32(sector, 0x94); + info_mddf.unknown9 = BigEndianBitConverter.ToUInt16(sector, 0x98); + info_mddf.srec_len = BigEndianBitConverter.ToUInt16(sector, 0x9A); + info_mddf.unknown10 = BigEndianBitConverter.ToUInt32(sector, 0x9C); + info_mddf.unknown11 = BigEndianBitConverter.ToUInt32(sector, 0xA0); + info_mddf.unknown12 = BigEndianBitConverter.ToUInt32(sector, 0xA4); + info_mddf.unknown13 = BigEndianBitConverter.ToUInt32(sector, 0xA8); + info_mddf.unknown14 = BigEndianBitConverter.ToUInt32(sector, 0xAC); + info_mddf.filecount = BigEndianBitConverter.ToUInt16(sector, 0xB0); + info_mddf.unknown15 = BigEndianBitConverter.ToUInt32(sector, 0xB2); + info_mddf.unknown16 = BigEndianBitConverter.ToUInt32(sector, 0xB6); + info_mddf.freecount = BigEndianBitConverter.ToUInt32(sector, 0xBA); + info_mddf.unknown17 = BigEndianBitConverter.ToUInt16(sector, 0xBE); + info_mddf.unknown18 = BigEndianBitConverter.ToUInt32(sector, 0xC0); + info_mddf.overmount_stamp = BigEndianBitConverter.ToUInt64(sector, 0xC4); + info_mddf.serialization = BigEndianBitConverter.ToUInt32(sector, 0xCC); + info_mddf.unknown19 = BigEndianBitConverter.ToUInt32(sector, 0xD0); + info_mddf.unknown_timestamp = BigEndianBitConverter.ToUInt32(sector, 0xD4); + info_mddf.unknown20 = BigEndianBitConverter.ToUInt32(sector, 0xD8); + info_mddf.unknown21 = BigEndianBitConverter.ToUInt32(sector, 0xDC); + info_mddf.unknown22 = BigEndianBitConverter.ToUInt32(sector, 0xE0); + info_mddf.unknown23 = BigEndianBitConverter.ToUInt32(sector, 0xE4); + info_mddf.unknown24 = BigEndianBitConverter.ToUInt32(sector, 0xE8); + info_mddf.unknown25 = BigEndianBitConverter.ToUInt32(sector, 0xEC); + info_mddf.unknown26 = BigEndianBitConverter.ToUInt32(sector, 0xF0); + info_mddf.unknown27 = BigEndianBitConverter.ToUInt32(sector, 0xF4); + info_mddf.unknown28 = BigEndianBitConverter.ToUInt32(sector, 0xF8); + info_mddf.unknown29 = BigEndianBitConverter.ToUInt32(sector, 0xFC); + info_mddf.unknown30 = BigEndianBitConverter.ToUInt32(sector, 0x100); + info_mddf.unknown31 = BigEndianBitConverter.ToUInt32(sector, 0x104); + info_mddf.unknown32 = BigEndianBitConverter.ToUInt32(sector, 0x108); + info_mddf.unknown33 = BigEndianBitConverter.ToUInt32(sector, 0x10C); + info_mddf.unknown34 = BigEndianBitConverter.ToUInt32(sector, 0x110); + info_mddf.unknown35 = BigEndianBitConverter.ToUInt32(sector, 0x114); + info_mddf.backup_volid = BigEndianBitConverter.ToUInt64(sector, 0x118); + info_mddf.label_size = BigEndianBitConverter.ToUInt16(sector, 0x120); + info_mddf.fs_overhead = BigEndianBitConverter.ToUInt16(sector, 0x122); + info_mddf.result_scavenge = BigEndianBitConverter.ToUInt16(sector, 0x124); + info_mddf.boot_code = BigEndianBitConverter.ToUInt16(sector, 0x126); + info_mddf.boot_environ = BigEndianBitConverter.ToUInt16(sector, 0x6C); + info_mddf.unknown36 = BigEndianBitConverter.ToUInt32(sector, 0x12A); + info_mddf.unknown37 = BigEndianBitConverter.ToUInt32(sector, 0x12E); + info_mddf.unknown38 = BigEndianBitConverter.ToUInt32(sector, 0x132); + info_mddf.vol_sequence = BigEndianBitConverter.ToUInt16(sector, 0x136); + info_mddf.vol_left_mounted = sector[0x138]; + + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown1 = 0x{0:X2} ({0})", info_mddf.unknown1); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown2 = 0x{0:X2} ({0})", info_mddf.unknown2); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown3 = 0x{0:X8} ({0})", info_mddf.unknown3); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown4 = 0x{0:X4} ({0})", info_mddf.unknown4); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown5 = 0x{0:X8} ({0})", info_mddf.unknown5); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown6 = 0x{0:X8} ({0})", info_mddf.unknown6); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown7 = 0x{0:X8} ({0})", info_mddf.unknown7); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown9 = 0x{0:X4} ({0})", info_mddf.unknown9); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown10 = 0x{0:X8} ({0})", info_mddf.unknown10); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown11 = 0x{0:X8} ({0})", info_mddf.unknown11); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown12 = 0x{0:X8} ({0})", info_mddf.unknown12); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown13 = 0x{0:X8} ({0})", info_mddf.unknown13); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown14 = 0x{0:X8} ({0})", info_mddf.unknown14); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown15 = 0x{0:X8} ({0})", info_mddf.unknown15); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown16 = 0x{0:X8} ({0})", info_mddf.unknown16); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown17 = 0x{0:X4} ({0})", info_mddf.unknown17); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown18 = 0x{0:X8} ({0})", info_mddf.unknown18); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown19 = 0x{0:X8} ({0})", info_mddf.unknown19); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown20 = 0x{0:X8} ({0})", info_mddf.unknown20); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown21 = 0x{0:X8} ({0})", info_mddf.unknown21); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown22 = 0x{0:X8} ({0})", info_mddf.unknown22); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown23 = 0x{0:X8} ({0})", info_mddf.unknown23); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown24 = 0x{0:X8} ({0})", info_mddf.unknown24); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown25 = 0x{0:X8} ({0})", info_mddf.unknown25); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown26 = 0x{0:X8} ({0})", info_mddf.unknown26); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown27 = 0x{0:X8} ({0})", info_mddf.unknown27); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown28 = 0x{0:X8} ({0})", info_mddf.unknown28); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown29 = 0x{0:X8} ({0})", info_mddf.unknown29); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown30 = 0x{0:X8} ({0})", info_mddf.unknown30); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown31 = 0x{0:X8} ({0})", info_mddf.unknown31); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown32 = 0x{0:X8} ({0})", info_mddf.unknown32); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown33 = 0x{0:X8} ({0})", info_mddf.unknown33); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown34 = 0x{0:X8} ({0})", info_mddf.unknown34); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown35 = 0x{0:X8} ({0})", info_mddf.unknown35); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown36 = 0x{0:X8} ({0})", info_mddf.unknown36); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown37 = 0x{0:X8} ({0})", info_mddf.unknown37); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown38 = 0x{0:X8} ({0})", info_mddf.unknown38); + DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown_timestamp = 0x{0:X8} ({0}, {1})", + info_mddf.unknown_timestamp, + DateHandlers.LisaToDateTime(info_mddf.unknown_timestamp)); + + if(info_mddf.mddf_block != i - before_mddf) return; + + if(info_mddf.vol_size > imagePlugin.GetSectors()) return; + + if(info_mddf.vol_size - 1 != info_mddf.volsize_minus_one) return; + + if(info_mddf.vol_size - i - 1 != info_mddf.volsize_minus_mddf_minus_one - before_mddf) return; + + if(info_mddf.datasize > info_mddf.blocksize) return; + + if(info_mddf.blocksize < imagePlugin.GetSectorSize()) return; + + if(info_mddf.datasize != imagePlugin.GetSectorSize()) return; + + switch(info_mddf.fsversion) { - byte[] sector = imagePlugin.ReadSector((ulong)i); - MDDF info_mddf = new MDDF(); - byte[] pString = new byte[33]; - uint lisa_time; - - info_mddf.fsversion = BigEndianBitConverter.ToUInt16(sector, 0x00); - info_mddf.volid = BigEndianBitConverter.ToUInt64(sector, 0x02); - info_mddf.volnum = BigEndianBitConverter.ToUInt16(sector, 0x0A); - Array.Copy(sector, 0x0C, pString, 0, 33); - info_mddf.volname = StringHandlers.PascalToString(pString, CurrentEncoding); - info_mddf.unknown1 = sector[0x2D]; - Array.Copy(sector, 0x2E, pString, 0, 33); - // Prevent garbage - if(pString[0] <= 32) - info_mddf.password = StringHandlers.PascalToString(pString, CurrentEncoding); - else info_mddf.password = ""; - info_mddf.unknown2 = sector[0x4F]; - info_mddf.machine_id = BigEndianBitConverter.ToUInt32(sector, 0x50); - info_mddf.master_copy_id = BigEndianBitConverter.ToUInt32(sector, 0x54); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x58); - info_mddf.dtvc = DateHandlers.LisaToDateTime(lisa_time); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x5C); - info_mddf.dtcc = DateHandlers.LisaToDateTime(lisa_time); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x60); - info_mddf.dtvb = DateHandlers.LisaToDateTime(lisa_time); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x64); - info_mddf.dtvs = DateHandlers.LisaToDateTime(lisa_time); - info_mddf.unknown3 = BigEndianBitConverter.ToUInt32(sector, 0x68); - info_mddf.mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C); - info_mddf.volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70); - info_mddf.volsize_minus_mddf_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x74); - info_mddf.vol_size = BigEndianBitConverter.ToUInt32(sector, 0x78); - info_mddf.blocksize = BigEndianBitConverter.ToUInt16(sector, 0x7C); - info_mddf.datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E); - info_mddf.unknown4 = BigEndianBitConverter.ToUInt16(sector, 0x80); - info_mddf.unknown5 = BigEndianBitConverter.ToUInt32(sector, 0x82); - info_mddf.unknown6 = BigEndianBitConverter.ToUInt32(sector, 0x86); - info_mddf.clustersize = BigEndianBitConverter.ToUInt16(sector, 0x8A); - info_mddf.fs_size = BigEndianBitConverter.ToUInt32(sector, 0x8C); - info_mddf.unknown7 = BigEndianBitConverter.ToUInt32(sector, 0x90); - info_mddf.srec_ptr = BigEndianBitConverter.ToUInt32(sector, 0x94); - info_mddf.unknown9 = BigEndianBitConverter.ToUInt16(sector, 0x98); - info_mddf.srec_len = BigEndianBitConverter.ToUInt16(sector, 0x9A); - info_mddf.unknown10 = BigEndianBitConverter.ToUInt32(sector, 0x9C); - info_mddf.unknown11 = BigEndianBitConverter.ToUInt32(sector, 0xA0); - info_mddf.unknown12 = BigEndianBitConverter.ToUInt32(sector, 0xA4); - info_mddf.unknown13 = BigEndianBitConverter.ToUInt32(sector, 0xA8); - info_mddf.unknown14 = BigEndianBitConverter.ToUInt32(sector, 0xAC); - info_mddf.filecount = BigEndianBitConverter.ToUInt16(sector, 0xB0); - info_mddf.unknown15 = BigEndianBitConverter.ToUInt32(sector, 0xB2); - info_mddf.unknown16 = BigEndianBitConverter.ToUInt32(sector, 0xB6); - info_mddf.freecount = BigEndianBitConverter.ToUInt32(sector, 0xBA); - info_mddf.unknown17 = BigEndianBitConverter.ToUInt16(sector, 0xBE); - info_mddf.unknown18 = BigEndianBitConverter.ToUInt32(sector, 0xC0); - info_mddf.overmount_stamp = BigEndianBitConverter.ToUInt64(sector, 0xC4); - info_mddf.serialization = BigEndianBitConverter.ToUInt32(sector, 0xCC); - info_mddf.unknown19 = BigEndianBitConverter.ToUInt32(sector, 0xD0); - info_mddf.unknown_timestamp = BigEndianBitConverter.ToUInt32(sector, 0xD4); - info_mddf.unknown20 = BigEndianBitConverter.ToUInt32(sector, 0xD8); - info_mddf.unknown21 = BigEndianBitConverter.ToUInt32(sector, 0xDC); - info_mddf.unknown22 = BigEndianBitConverter.ToUInt32(sector, 0xE0); - info_mddf.unknown23 = BigEndianBitConverter.ToUInt32(sector, 0xE4); - info_mddf.unknown24 = BigEndianBitConverter.ToUInt32(sector, 0xE8); - info_mddf.unknown25 = BigEndianBitConverter.ToUInt32(sector, 0xEC); - info_mddf.unknown26 = BigEndianBitConverter.ToUInt32(sector, 0xF0); - info_mddf.unknown27 = BigEndianBitConverter.ToUInt32(sector, 0xF4); - info_mddf.unknown28 = BigEndianBitConverter.ToUInt32(sector, 0xF8); - info_mddf.unknown29 = BigEndianBitConverter.ToUInt32(sector, 0xFC); - info_mddf.unknown30 = BigEndianBitConverter.ToUInt32(sector, 0x100); - info_mddf.unknown31 = BigEndianBitConverter.ToUInt32(sector, 0x104); - info_mddf.unknown32 = BigEndianBitConverter.ToUInt32(sector, 0x108); - info_mddf.unknown33 = BigEndianBitConverter.ToUInt32(sector, 0x10C); - info_mddf.unknown34 = BigEndianBitConverter.ToUInt32(sector, 0x110); - info_mddf.unknown35 = BigEndianBitConverter.ToUInt32(sector, 0x114); - info_mddf.backup_volid = BigEndianBitConverter.ToUInt64(sector, 0x118); - info_mddf.label_size = BigEndianBitConverter.ToUInt16(sector, 0x120); - info_mddf.fs_overhead = BigEndianBitConverter.ToUInt16(sector, 0x122); - info_mddf.result_scavenge = BigEndianBitConverter.ToUInt16(sector, 0x124); - info_mddf.boot_code = BigEndianBitConverter.ToUInt16(sector, 0x126); - info_mddf.boot_environ = BigEndianBitConverter.ToUInt16(sector, 0x6C); - info_mddf.unknown36 = BigEndianBitConverter.ToUInt32(sector, 0x12A); - info_mddf.unknown37 = BigEndianBitConverter.ToUInt32(sector, 0x12E); - info_mddf.unknown38 = BigEndianBitConverter.ToUInt32(sector, 0x132); - info_mddf.vol_sequence = BigEndianBitConverter.ToUInt16(sector, 0x136); - info_mddf.vol_left_mounted = sector[0x138]; - - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown1 = 0x{0:X2} ({0})", - info_mddf.unknown1); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown2 = 0x{0:X2} ({0})", - info_mddf.unknown2); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown3 = 0x{0:X8} ({0})", - info_mddf.unknown3); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown4 = 0x{0:X4} ({0})", - info_mddf.unknown4); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown5 = 0x{0:X8} ({0})", - info_mddf.unknown5); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown6 = 0x{0:X8} ({0})", - info_mddf.unknown6); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown7 = 0x{0:X8} ({0})", - info_mddf.unknown7); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown9 = 0x{0:X4} ({0})", - info_mddf.unknown9); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown10 = 0x{0:X8} ({0})", - info_mddf.unknown10); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown11 = 0x{0:X8} ({0})", - info_mddf.unknown11); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown12 = 0x{0:X8} ({0})", - info_mddf.unknown12); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown13 = 0x{0:X8} ({0})", - info_mddf.unknown13); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown14 = 0x{0:X8} ({0})", - info_mddf.unknown14); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown15 = 0x{0:X8} ({0})", - info_mddf.unknown15); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown16 = 0x{0:X8} ({0})", - info_mddf.unknown16); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown17 = 0x{0:X4} ({0})", - info_mddf.unknown17); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown18 = 0x{0:X8} ({0})", - info_mddf.unknown18); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown19 = 0x{0:X8} ({0})", - info_mddf.unknown19); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown20 = 0x{0:X8} ({0})", - info_mddf.unknown20); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown21 = 0x{0:X8} ({0})", - info_mddf.unknown21); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown22 = 0x{0:X8} ({0})", - info_mddf.unknown22); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown23 = 0x{0:X8} ({0})", - info_mddf.unknown23); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown24 = 0x{0:X8} ({0})", - info_mddf.unknown24); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown25 = 0x{0:X8} ({0})", - info_mddf.unknown25); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown26 = 0x{0:X8} ({0})", - info_mddf.unknown26); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown27 = 0x{0:X8} ({0})", - info_mddf.unknown27); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown28 = 0x{0:X8} ({0})", - info_mddf.unknown28); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown29 = 0x{0:X8} ({0})", - info_mddf.unknown29); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown30 = 0x{0:X8} ({0})", - info_mddf.unknown30); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown31 = 0x{0:X8} ({0})", - info_mddf.unknown31); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown32 = 0x{0:X8} ({0})", - info_mddf.unknown32); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown33 = 0x{0:X8} ({0})", - info_mddf.unknown33); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown34 = 0x{0:X8} ({0})", - info_mddf.unknown34); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown35 = 0x{0:X8} ({0})", - info_mddf.unknown35); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown36 = 0x{0:X8} ({0})", - info_mddf.unknown36); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown37 = 0x{0:X8} ({0})", - info_mddf.unknown37); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown38 = 0x{0:X8} ({0})", - info_mddf.unknown38); - DicConsole.DebugWriteLine("LisaFS plugin", "mddf.unknown_timestamp = 0x{0:X8} ({0}, {1})", - info_mddf.unknown_timestamp, - DateHandlers.LisaToDateTime(info_mddf.unknown_timestamp)); - - if(info_mddf.mddf_block != i - before_mddf) return; - - if(info_mddf.vol_size > imagePlugin.GetSectors()) return; - - if(info_mddf.vol_size - 1 != info_mddf.volsize_minus_one) return; - - if(info_mddf.vol_size - i - 1 != info_mddf.volsize_minus_mddf_minus_one - before_mddf) return; - - if(info_mddf.datasize > info_mddf.blocksize) return; - - if(info_mddf.blocksize < imagePlugin.GetSectorSize()) return; - - if(info_mddf.datasize != imagePlugin.GetSectorSize()) return; - - switch(info_mddf.fsversion) - { - case LisaFSv1: - sb.AppendLine("LisaFS v1"); - break; - case LisaFSv2: - sb.AppendLine("LisaFS v2"); - break; - case LisaFSv3: - sb.AppendLine("LisaFS v3"); - break; - default: - sb.AppendFormat("Uknown LisaFS version {0}", info_mddf.fsversion).AppendLine(); - break; - } - - sb.AppendFormat("Volume name: \"{0}\"", info_mddf.volname).AppendLine(); - sb.AppendFormat("Volume password: \"{0}\"", info_mddf.password).AppendLine(); - sb.AppendFormat("Volume ID: 0x{0:X16}", info_mddf.volid).AppendLine(); - sb.AppendFormat("Backup volume ID: 0x{0:X16}", info_mddf.backup_volid).AppendLine(); - - sb.AppendFormat("Master copy ID: 0x{0:X8}", info_mddf.master_copy_id).AppendLine(); - - sb.AppendFormat("Volume is number {0} of {1}", info_mddf.volnum, info_mddf.vol_sequence) - .AppendLine(); - - sb.AppendFormat("Serial number of Lisa computer that created this volume: {0}", - info_mddf.machine_id).AppendLine(); - sb.AppendFormat("Serial number of Lisa computer that can use this volume's software {0}", - info_mddf.serialization).AppendLine(); - - sb.AppendFormat("Volume created on {0}", info_mddf.dtvc).AppendLine(); - sb.AppendFormat("Some timestamp, says {0}", info_mddf.dtcc).AppendLine(); - sb.AppendFormat("Volume backed up on {0}", info_mddf.dtvb).AppendLine(); - sb.AppendFormat("Volume scavenged on {0}", info_mddf.dtvs).AppendLine(); - sb.AppendFormat("MDDF is in block {0}", info_mddf.mddf_block + before_mddf).AppendLine(); - sb.AppendFormat("There are {0} reserved blocks before volume", before_mddf).AppendLine(); - sb.AppendFormat("{0} blocks minus one", info_mddf.volsize_minus_one).AppendLine(); - sb.AppendFormat("{0} blocks minus one minus MDDF offset", - info_mddf.volsize_minus_mddf_minus_one).AppendLine(); - sb.AppendFormat("{0} blocks in volume", info_mddf.vol_size).AppendLine(); - sb.AppendFormat("{0} bytes per sector (uncooked)", info_mddf.blocksize).AppendLine(); - sb.AppendFormat("{0} bytes per sector", info_mddf.datasize).AppendLine(); - sb.AppendFormat("{0} blocks per cluster", info_mddf.clustersize).AppendLine(); - sb.AppendFormat("{0} blocks in filesystem", info_mddf.fs_size).AppendLine(); - sb.AppendFormat("{0} files in volume", info_mddf.filecount).AppendLine(); - sb.AppendFormat("{0} blocks free", info_mddf.freecount).AppendLine(); - sb.AppendFormat("{0} bytes in LisaInfo", info_mddf.label_size).AppendLine(); - sb.AppendFormat("Filesystem overhead: {0}", info_mddf.fs_overhead).AppendLine(); - sb.AppendFormat("Scanvenger result code: 0x{0:X8}", info_mddf.result_scavenge).AppendLine(); - sb.AppendFormat("Boot code: 0x{0:X8}", info_mddf.boot_code).AppendLine(); - sb.AppendFormat("Boot environment: 0x{0:X8}", info_mddf.boot_environ).AppendLine(); - sb.AppendFormat("Overmount stamp: 0x{0:X16}", info_mddf.overmount_stamp).AppendLine(); - sb.AppendFormat("S-Records start at {0} and spans for {1} blocks", - info_mddf.srec_ptr + info_mddf.mddf_block + before_mddf, info_mddf.srec_len) - .AppendLine(); - - if(info_mddf.vol_left_mounted == 0) sb.AppendLine("Volume is clean"); - else sb.AppendLine("Volume is dirty"); - - information = sb.ToString(); - - xmlFSType = new Schemas.FileSystemType(); - if(DateTime.Compare(info_mddf.dtvb, DateHandlers.LisaToDateTime(0)) > 0) - { - xmlFSType.BackupDate = info_mddf.dtvb; - xmlFSType.BackupDateSpecified = true; - } - xmlFSType.Clusters = info_mddf.vol_size; - xmlFSType.ClusterSize = info_mddf.clustersize * info_mddf.datasize; - if(DateTime.Compare(info_mddf.dtvc, DateHandlers.LisaToDateTime(0)) > 0) - { - xmlFSType.CreationDate = info_mddf.dtvc; - xmlFSType.CreationDateSpecified = true; - } - xmlFSType.Dirty = info_mddf.vol_left_mounted != 0; - xmlFSType.Files = info_mddf.filecount; - xmlFSType.FilesSpecified = true; - xmlFSType.FreeClusters = info_mddf.freecount; - xmlFSType.FreeClustersSpecified = true; - xmlFSType.Type = "LisaFS"; - xmlFSType.VolumeName = info_mddf.volname; - xmlFSType.VolumeSerial = string.Format("{0:X16}", info_mddf.volid); - - return; + case LisaFSv1: + sb.AppendLine("LisaFS v1"); + break; + case LisaFSv2: + sb.AppendLine("LisaFS v2"); + break; + case LisaFSv3: + sb.AppendLine("LisaFS v3"); + break; + default: + sb.AppendFormat("Uknown LisaFS version {0}", info_mddf.fsversion).AppendLine(); + break; } + + sb.AppendFormat("Volume name: \"{0}\"", info_mddf.volname).AppendLine(); + sb.AppendFormat("Volume password: \"{0}\"", info_mddf.password).AppendLine(); + sb.AppendFormat("Volume ID: 0x{0:X16}", info_mddf.volid).AppendLine(); + sb.AppendFormat("Backup volume ID: 0x{0:X16}", info_mddf.backup_volid).AppendLine(); + + sb.AppendFormat("Master copy ID: 0x{0:X8}", info_mddf.master_copy_id).AppendLine(); + + sb.AppendFormat("Volume is number {0} of {1}", info_mddf.volnum, info_mddf.vol_sequence) + .AppendLine(); + + sb.AppendFormat("Serial number of Lisa computer that created this volume: {0}", + info_mddf.machine_id).AppendLine(); + sb.AppendFormat("Serial number of Lisa computer that can use this volume's software {0}", + info_mddf.serialization).AppendLine(); + + sb.AppendFormat("Volume created on {0}", info_mddf.dtvc).AppendLine(); + sb.AppendFormat("Some timestamp, says {0}", info_mddf.dtcc).AppendLine(); + sb.AppendFormat("Volume backed up on {0}", info_mddf.dtvb).AppendLine(); + sb.AppendFormat("Volume scavenged on {0}", info_mddf.dtvs).AppendLine(); + sb.AppendFormat("MDDF is in block {0}", info_mddf.mddf_block + before_mddf).AppendLine(); + sb.AppendFormat("There are {0} reserved blocks before volume", before_mddf).AppendLine(); + sb.AppendFormat("{0} blocks minus one", info_mddf.volsize_minus_one).AppendLine(); + sb.AppendFormat("{0} blocks minus one minus MDDF offset", info_mddf.volsize_minus_mddf_minus_one) + .AppendLine(); + sb.AppendFormat("{0} blocks in volume", info_mddf.vol_size).AppendLine(); + sb.AppendFormat("{0} bytes per sector (uncooked)", info_mddf.blocksize).AppendLine(); + sb.AppendFormat("{0} bytes per sector", info_mddf.datasize).AppendLine(); + sb.AppendFormat("{0} blocks per cluster", info_mddf.clustersize).AppendLine(); + sb.AppendFormat("{0} blocks in filesystem", info_mddf.fs_size).AppendLine(); + sb.AppendFormat("{0} files in volume", info_mddf.filecount).AppendLine(); + sb.AppendFormat("{0} blocks free", info_mddf.freecount).AppendLine(); + sb.AppendFormat("{0} bytes in LisaInfo", info_mddf.label_size).AppendLine(); + sb.AppendFormat("Filesystem overhead: {0}", info_mddf.fs_overhead).AppendLine(); + sb.AppendFormat("Scanvenger result code: 0x{0:X8}", info_mddf.result_scavenge).AppendLine(); + sb.AppendFormat("Boot code: 0x{0:X8}", info_mddf.boot_code).AppendLine(); + sb.AppendFormat("Boot environment: 0x{0:X8}", info_mddf.boot_environ).AppendLine(); + sb.AppendFormat("Overmount stamp: 0x{0:X16}", info_mddf.overmount_stamp).AppendLine(); + sb.AppendFormat("S-Records start at {0} and spans for {1} blocks", + info_mddf.srec_ptr + info_mddf.mddf_block + before_mddf, info_mddf.srec_len) + .AppendLine(); + + if(info_mddf.vol_left_mounted == 0) sb.AppendLine("Volume is clean"); + else sb.AppendLine("Volume is dirty"); + + information = sb.ToString(); + + xmlFSType = new Schemas.FileSystemType(); + if(DateTime.Compare(info_mddf.dtvb, DateHandlers.LisaToDateTime(0)) > 0) + { + xmlFSType.BackupDate = info_mddf.dtvb; + xmlFSType.BackupDateSpecified = true; + } + xmlFSType.Clusters = info_mddf.vol_size; + xmlFSType.ClusterSize = info_mddf.clustersize * info_mddf.datasize; + if(DateTime.Compare(info_mddf.dtvc, DateHandlers.LisaToDateTime(0)) > 0) + { + xmlFSType.CreationDate = info_mddf.dtvc; + xmlFSType.CreationDateSpecified = true; + } + xmlFSType.Dirty = info_mddf.vol_left_mounted != 0; + xmlFSType.Files = info_mddf.filecount; + xmlFSType.FilesSpecified = true; + xmlFSType.FreeClusters = info_mddf.freecount; + xmlFSType.FreeClustersSpecified = true; + xmlFSType.Type = "LisaFS"; + xmlFSType.VolumeName = info_mddf.volname; + xmlFSType.VolumeSerial = string.Format("{0:X16}", info_mddf.volid); + + return; } return; diff --git a/DiscImageChef.Filesystems/LisaFS/Super.cs b/DiscImageChef.Filesystems/LisaFS/Super.cs index 26e70524d..ce33bf16d 100644 --- a/DiscImageChef.Filesystems/LisaFS/Super.cs +++ b/DiscImageChef.Filesystems/LisaFS/Super.cs @@ -89,230 +89,229 @@ namespace DiscImageChef.Filesystems.LisaFS if(volumePrefix == device.ImageInfo.Sectors && searchTag.fileID == FILEID_LOADER_SIGNED) volumePrefix = i - 1; - if(searchTag.fileID == FILEID_MDDF) + if(searchTag.fileID != FILEID_MDDF) continue; + + devTagSize = device.ReadSectorTag(i, SectorTagType.AppleSectorTag).Length; + + byte[] sector = device.ReadSector(i); + mddf = new MDDF(); + byte[] pString = new byte[33]; + uint lisa_time; + + mddf.fsversion = BigEndianBitConverter.ToUInt16(sector, 0x00); + mddf.volid = BigEndianBitConverter.ToUInt64(sector, 0x02); + mddf.volnum = BigEndianBitConverter.ToUInt16(sector, 0x0A); + Array.Copy(sector, 0x0C, pString, 0, 33); + mddf.volname = StringHandlers.PascalToString(pString, CurrentEncoding); + mddf.unknown1 = sector[0x2D]; + Array.Copy(sector, 0x2E, pString, 0, 33); + // Prevent garbage + if(pString[0] <= 32) mddf.password = StringHandlers.PascalToString(pString, CurrentEncoding); + else mddf.password = ""; + mddf.unknown2 = sector[0x4F]; + mddf.machine_id = BigEndianBitConverter.ToUInt32(sector, 0x50); + mddf.master_copy_id = BigEndianBitConverter.ToUInt32(sector, 0x54); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x58); + mddf.dtvc = DateHandlers.LisaToDateTime(lisa_time); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x5C); + mddf.dtcc = DateHandlers.LisaToDateTime(lisa_time); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x60); + mddf.dtvb = DateHandlers.LisaToDateTime(lisa_time); + lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x64); + mddf.dtvs = DateHandlers.LisaToDateTime(lisa_time); + mddf.unknown3 = BigEndianBitConverter.ToUInt32(sector, 0x68); + mddf.mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C); + mddf.volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70); + mddf.volsize_minus_mddf_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x74); + mddf.vol_size = BigEndianBitConverter.ToUInt32(sector, 0x78); + mddf.blocksize = BigEndianBitConverter.ToUInt16(sector, 0x7C); + mddf.datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E); + mddf.unknown4 = BigEndianBitConverter.ToUInt16(sector, 0x80); + mddf.unknown5 = BigEndianBitConverter.ToUInt32(sector, 0x82); + mddf.unknown6 = BigEndianBitConverter.ToUInt32(sector, 0x86); + mddf.clustersize = BigEndianBitConverter.ToUInt16(sector, 0x8A); + mddf.fs_size = BigEndianBitConverter.ToUInt32(sector, 0x8C); + mddf.unknown7 = BigEndianBitConverter.ToUInt32(sector, 0x90); + mddf.srec_ptr = BigEndianBitConverter.ToUInt32(sector, 0x94); + mddf.unknown9 = BigEndianBitConverter.ToUInt16(sector, 0x98); + mddf.srec_len = BigEndianBitConverter.ToUInt16(sector, 0x9A); + mddf.unknown10 = BigEndianBitConverter.ToUInt32(sector, 0x9C); + mddf.unknown11 = BigEndianBitConverter.ToUInt32(sector, 0xA0); + mddf.unknown12 = BigEndianBitConverter.ToUInt32(sector, 0xA4); + mddf.unknown13 = BigEndianBitConverter.ToUInt32(sector, 0xA8); + mddf.unknown14 = BigEndianBitConverter.ToUInt32(sector, 0xAC); + mddf.filecount = BigEndianBitConverter.ToUInt16(sector, 0xB0); + mddf.unknown15 = BigEndianBitConverter.ToUInt32(sector, 0xB2); + mddf.unknown16 = BigEndianBitConverter.ToUInt32(sector, 0xB6); + mddf.freecount = BigEndianBitConverter.ToUInt32(sector, 0xBA); + mddf.unknown17 = BigEndianBitConverter.ToUInt16(sector, 0xBE); + mddf.unknown18 = BigEndianBitConverter.ToUInt32(sector, 0xC0); + mddf.overmount_stamp = BigEndianBitConverter.ToUInt64(sector, 0xC4); + mddf.serialization = BigEndianBitConverter.ToUInt32(sector, 0xCC); + mddf.unknown19 = BigEndianBitConverter.ToUInt32(sector, 0xD0); + mddf.unknown_timestamp = BigEndianBitConverter.ToUInt32(sector, 0xD4); + mddf.unknown20 = BigEndianBitConverter.ToUInt32(sector, 0xD8); + mddf.unknown21 = BigEndianBitConverter.ToUInt32(sector, 0xDC); + mddf.unknown22 = BigEndianBitConverter.ToUInt32(sector, 0xE0); + mddf.unknown23 = BigEndianBitConverter.ToUInt32(sector, 0xE4); + mddf.unknown24 = BigEndianBitConverter.ToUInt32(sector, 0xE8); + mddf.unknown25 = BigEndianBitConverter.ToUInt32(sector, 0xEC); + mddf.unknown26 = BigEndianBitConverter.ToUInt32(sector, 0xF0); + mddf.unknown27 = BigEndianBitConverter.ToUInt32(sector, 0xF4); + mddf.unknown28 = BigEndianBitConverter.ToUInt32(sector, 0xF8); + mddf.unknown29 = BigEndianBitConverter.ToUInt32(sector, 0xFC); + mddf.unknown30 = BigEndianBitConverter.ToUInt32(sector, 0x100); + mddf.unknown31 = BigEndianBitConverter.ToUInt32(sector, 0x104); + mddf.unknown32 = BigEndianBitConverter.ToUInt32(sector, 0x108); + mddf.unknown33 = BigEndianBitConverter.ToUInt32(sector, 0x10C); + mddf.unknown34 = BigEndianBitConverter.ToUInt32(sector, 0x110); + mddf.unknown35 = BigEndianBitConverter.ToUInt32(sector, 0x114); + mddf.backup_volid = BigEndianBitConverter.ToUInt64(sector, 0x118); + mddf.label_size = BigEndianBitConverter.ToUInt16(sector, 0x120); + mddf.fs_overhead = BigEndianBitConverter.ToUInt16(sector, 0x122); + mddf.result_scavenge = BigEndianBitConverter.ToUInt16(sector, 0x124); + mddf.boot_code = BigEndianBitConverter.ToUInt16(sector, 0x126); + mddf.boot_environ = BigEndianBitConverter.ToUInt16(sector, 0x6C); + mddf.unknown36 = BigEndianBitConverter.ToUInt32(sector, 0x12A); + mddf.unknown37 = BigEndianBitConverter.ToUInt32(sector, 0x12E); + mddf.unknown38 = BigEndianBitConverter.ToUInt32(sector, 0x132); + mddf.vol_sequence = BigEndianBitConverter.ToUInt16(sector, 0x136); + mddf.vol_left_mounted = sector[0x138]; + + // Check that the MDDF is correct + if(mddf.mddf_block != i - volumePrefix || mddf.vol_size > device.GetSectors() || + mddf.vol_size - 1 != mddf.volsize_minus_one || + mddf.vol_size - i - 1 != mddf.volsize_minus_mddf_minus_one - volumePrefix || + mddf.datasize > mddf.blocksize || mddf.blocksize < device.GetSectorSize() || + mddf.datasize != device.GetSectorSize()) { - devTagSize = device.ReadSectorTag(i, SectorTagType.AppleSectorTag).Length; + DicConsole.DebugWriteLine("LisaFS plugin", "Incorrect MDDF found"); + return Errno.InvalidArgument; + } - byte[] sector = device.ReadSector(i); - mddf = new MDDF(); - byte[] pString = new byte[33]; - uint lisa_time; + // Check MDDF version + switch(mddf.fsversion) + { + case LisaFSv1: + DicConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v1"); + break; + case LisaFSv2: + DicConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v2"); + break; + case LisaFSv3: + DicConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v3"); + break; + default: + DicConsole.ErrorWriteLine("Cannot mount LisaFS version {0}", mddf.fsversion.ToString()); + return Errno.NotSupported; + } - mddf.fsversion = BigEndianBitConverter.ToUInt16(sector, 0x00); - mddf.volid = BigEndianBitConverter.ToUInt64(sector, 0x02); - mddf.volnum = BigEndianBitConverter.ToUInt16(sector, 0x0A); - Array.Copy(sector, 0x0C, pString, 0, 33); - mddf.volname = StringHandlers.PascalToString(pString, CurrentEncoding); - mddf.unknown1 = sector[0x2D]; - Array.Copy(sector, 0x2E, pString, 0, 33); - // Prevent garbage - if(pString[0] <= 32) mddf.password = StringHandlers.PascalToString(pString, CurrentEncoding); - else mddf.password = ""; - mddf.unknown2 = sector[0x4F]; - mddf.machine_id = BigEndianBitConverter.ToUInt32(sector, 0x50); - mddf.master_copy_id = BigEndianBitConverter.ToUInt32(sector, 0x54); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x58); - mddf.dtvc = DateHandlers.LisaToDateTime(lisa_time); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x5C); - mddf.dtcc = DateHandlers.LisaToDateTime(lisa_time); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x60); - mddf.dtvb = DateHandlers.LisaToDateTime(lisa_time); - lisa_time = BigEndianBitConverter.ToUInt32(sector, 0x64); - mddf.dtvs = DateHandlers.LisaToDateTime(lisa_time); - mddf.unknown3 = BigEndianBitConverter.ToUInt32(sector, 0x68); - mddf.mddf_block = BigEndianBitConverter.ToUInt32(sector, 0x6C); - mddf.volsize_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x70); - mddf.volsize_minus_mddf_minus_one = BigEndianBitConverter.ToUInt32(sector, 0x74); - mddf.vol_size = BigEndianBitConverter.ToUInt32(sector, 0x78); - mddf.blocksize = BigEndianBitConverter.ToUInt16(sector, 0x7C); - mddf.datasize = BigEndianBitConverter.ToUInt16(sector, 0x7E); - mddf.unknown4 = BigEndianBitConverter.ToUInt16(sector, 0x80); - mddf.unknown5 = BigEndianBitConverter.ToUInt32(sector, 0x82); - mddf.unknown6 = BigEndianBitConverter.ToUInt32(sector, 0x86); - mddf.clustersize = BigEndianBitConverter.ToUInt16(sector, 0x8A); - mddf.fs_size = BigEndianBitConverter.ToUInt32(sector, 0x8C); - mddf.unknown7 = BigEndianBitConverter.ToUInt32(sector, 0x90); - mddf.srec_ptr = BigEndianBitConverter.ToUInt32(sector, 0x94); - mddf.unknown9 = BigEndianBitConverter.ToUInt16(sector, 0x98); - mddf.srec_len = BigEndianBitConverter.ToUInt16(sector, 0x9A); - mddf.unknown10 = BigEndianBitConverter.ToUInt32(sector, 0x9C); - mddf.unknown11 = BigEndianBitConverter.ToUInt32(sector, 0xA0); - mddf.unknown12 = BigEndianBitConverter.ToUInt32(sector, 0xA4); - mddf.unknown13 = BigEndianBitConverter.ToUInt32(sector, 0xA8); - mddf.unknown14 = BigEndianBitConverter.ToUInt32(sector, 0xAC); - mddf.filecount = BigEndianBitConverter.ToUInt16(sector, 0xB0); - mddf.unknown15 = BigEndianBitConverter.ToUInt32(sector, 0xB2); - mddf.unknown16 = BigEndianBitConverter.ToUInt32(sector, 0xB6); - mddf.freecount = BigEndianBitConverter.ToUInt32(sector, 0xBA); - mddf.unknown17 = BigEndianBitConverter.ToUInt16(sector, 0xBE); - mddf.unknown18 = BigEndianBitConverter.ToUInt32(sector, 0xC0); - mddf.overmount_stamp = BigEndianBitConverter.ToUInt64(sector, 0xC4); - mddf.serialization = BigEndianBitConverter.ToUInt32(sector, 0xCC); - mddf.unknown19 = BigEndianBitConverter.ToUInt32(sector, 0xD0); - mddf.unknown_timestamp = BigEndianBitConverter.ToUInt32(sector, 0xD4); - mddf.unknown20 = BigEndianBitConverter.ToUInt32(sector, 0xD8); - mddf.unknown21 = BigEndianBitConverter.ToUInt32(sector, 0xDC); - mddf.unknown22 = BigEndianBitConverter.ToUInt32(sector, 0xE0); - mddf.unknown23 = BigEndianBitConverter.ToUInt32(sector, 0xE4); - mddf.unknown24 = BigEndianBitConverter.ToUInt32(sector, 0xE8); - mddf.unknown25 = BigEndianBitConverter.ToUInt32(sector, 0xEC); - mddf.unknown26 = BigEndianBitConverter.ToUInt32(sector, 0xF0); - mddf.unknown27 = BigEndianBitConverter.ToUInt32(sector, 0xF4); - mddf.unknown28 = BigEndianBitConverter.ToUInt32(sector, 0xF8); - mddf.unknown29 = BigEndianBitConverter.ToUInt32(sector, 0xFC); - mddf.unknown30 = BigEndianBitConverter.ToUInt32(sector, 0x100); - mddf.unknown31 = BigEndianBitConverter.ToUInt32(sector, 0x104); - mddf.unknown32 = BigEndianBitConverter.ToUInt32(sector, 0x108); - mddf.unknown33 = BigEndianBitConverter.ToUInt32(sector, 0x10C); - mddf.unknown34 = BigEndianBitConverter.ToUInt32(sector, 0x110); - mddf.unknown35 = BigEndianBitConverter.ToUInt32(sector, 0x114); - mddf.backup_volid = BigEndianBitConverter.ToUInt64(sector, 0x118); - mddf.label_size = BigEndianBitConverter.ToUInt16(sector, 0x120); - mddf.fs_overhead = BigEndianBitConverter.ToUInt16(sector, 0x122); - mddf.result_scavenge = BigEndianBitConverter.ToUInt16(sector, 0x124); - mddf.boot_code = BigEndianBitConverter.ToUInt16(sector, 0x126); - mddf.boot_environ = BigEndianBitConverter.ToUInt16(sector, 0x6C); - mddf.unknown36 = BigEndianBitConverter.ToUInt32(sector, 0x12A); - mddf.unknown37 = BigEndianBitConverter.ToUInt32(sector, 0x12E); - mddf.unknown38 = BigEndianBitConverter.ToUInt32(sector, 0x132); - mddf.vol_sequence = BigEndianBitConverter.ToUInt16(sector, 0x136); - mddf.vol_left_mounted = sector[0x138]; + // Initialize caches + extentCache = new Dictionary(); + systemFileCache = new Dictionary(); + fileCache = new Dictionary(); + //catalogCache = new Dictionary>(); + fileSizeCache = new Dictionary(); - // Check that the MDDF is correct - if(mddf.mddf_block != i - volumePrefix || mddf.vol_size > device.GetSectors() || - mddf.vol_size - 1 != mddf.volsize_minus_one || - mddf.vol_size - i - 1 != mddf.volsize_minus_mddf_minus_one - volumePrefix || - mddf.datasize > mddf.blocksize || mddf.blocksize < device.GetSectorSize() || - mddf.datasize != device.GetSectorSize()) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Incorrect MDDF found"); - return Errno.InvalidArgument; - } + Errno error; - // Check MDDF version - switch(mddf.fsversion) - { - case LisaFSv1: - DicConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v1"); - break; - case LisaFSv2: - DicConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v2"); - break; - case LisaFSv3: - DicConsole.DebugWriteLine("LisaFS plugin", "Mounting LisaFS v3"); - break; - default: - DicConsole.ErrorWriteLine("Cannot mount LisaFS version {0}", mddf.fsversion.ToString()); - return Errno.NotSupported; - } + mounted = true; + this.debug = debug; - // Initialize caches - extentCache = new Dictionary(); - systemFileCache = new Dictionary(); - fileCache = new Dictionary(); - //catalogCache = new Dictionary>(); - fileSizeCache = new Dictionary(); + if(debug) printedExtents = new List(); - Errno error; + // Read the S-Records file + error = ReadSRecords(); + if(error != Errno.NoError) + { + DicConsole.ErrorWriteLine("Error {0} reading S-Records file.", error); + return error; + } - mounted = true; - this.debug = debug; + directoryDTCCache = new Dictionary(); + directoryDTCCache.Add(DIRID_ROOT, mddf.dtcc); - if(debug) printedExtents = new List(); + // Read the Catalog File + error = ReadCatalog(); - // Read the S-Records file - error = ReadSRecords(); + if(error != Errno.NoError) + { + DicConsole.DebugWriteLine("LisaFS plugin", "Cannot read Catalog File, error {0}", + error.ToString()); + mounted = false; + return error; + } + + // If debug, cache system files + if(debug) + { + byte[] temp; + + error = ReadSystemFile(FILEID_BOOT_SIGNED, out temp); if(error != Errno.NoError) { - DicConsole.ErrorWriteLine("Error {0} reading S-Records file.", error); - return error; - } - - directoryDTCCache = new Dictionary(); - directoryDTCCache.Add(DIRID_ROOT, mddf.dtcc); - - // Read the Catalog File - error = ReadCatalog(); - - if(error != Errno.NoError) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Cannot read Catalog File, error {0}", - error.ToString()); + DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read boot blocks"); mounted = false; return error; } - // If debug, cache system files - if(debug) + error = ReadSystemFile(FILEID_LOADER_SIGNED, out temp); + if(error != Errno.NoError) { - byte[] temp; - - error = ReadSystemFile(FILEID_BOOT_SIGNED, out temp); - if(error != Errno.NoError) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read boot blocks"); - mounted = false; - return error; - } - - error = ReadSystemFile(FILEID_LOADER_SIGNED, out temp); - if(error != Errno.NoError) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read boot loader"); - mounted = false; - return error; - } - - error = ReadSystemFile((short)FILEID_MDDF, out temp); - if(error != Errno.NoError) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read MDDF"); - mounted = false; - return error; - } - - error = ReadSystemFile((short)FILEID_BITMAP, out temp); - if(error != Errno.NoError) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read volume bitmap"); - mounted = false; - return error; - } - - error = ReadSystemFile((short)FILEID_SRECORD, out temp); - if(error != Errno.NoError) - { - DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read S-Records file"); - mounted = false; - return error; - } + DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read boot loader"); + mounted = false; + return error; } - // Create XML metadata for mounted filesystem - xmlFSType = new Schemas.FileSystemType(); - if(DateTime.Compare(mddf.dtvb, DateHandlers.LisaToDateTime(0)) > 0) + error = ReadSystemFile((short)FILEID_MDDF, out temp); + if(error != Errno.NoError) { - xmlFSType.BackupDate = mddf.dtvb; - xmlFSType.BackupDateSpecified = true; + DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read MDDF"); + mounted = false; + return error; } - xmlFSType.Clusters = mddf.vol_size; - xmlFSType.ClusterSize = mddf.clustersize * mddf.datasize; - if(DateTime.Compare(mddf.dtvc, DateHandlers.LisaToDateTime(0)) > 0) - { - xmlFSType.CreationDate = mddf.dtvc; - xmlFSType.CreationDateSpecified = true; - } - xmlFSType.Dirty = mddf.vol_left_mounted != 0; - xmlFSType.Files = mddf.filecount; - xmlFSType.FilesSpecified = true; - xmlFSType.FreeClusters = mddf.freecount; - xmlFSType.FreeClustersSpecified = true; - xmlFSType.Type = "LisaFS"; - xmlFSType.VolumeName = mddf.volname; - xmlFSType.VolumeSerial = string.Format("{0:X16}", mddf.volid); - return Errno.NoError; + error = ReadSystemFile((short)FILEID_BITMAP, out temp); + if(error != Errno.NoError) + { + DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read volume bitmap"); + mounted = false; + return error; + } + + error = ReadSystemFile((short)FILEID_SRECORD, out temp); + if(error != Errno.NoError) + { + DicConsole.DebugWriteLine("LisaFS plugin", "Unable to read S-Records file"); + mounted = false; + return error; + } } + + // Create XML metadata for mounted filesystem + xmlFSType = new Schemas.FileSystemType(); + if(DateTime.Compare(mddf.dtvb, DateHandlers.LisaToDateTime(0)) > 0) + { + xmlFSType.BackupDate = mddf.dtvb; + xmlFSType.BackupDateSpecified = true; + } + xmlFSType.Clusters = mddf.vol_size; + xmlFSType.ClusterSize = mddf.clustersize * mddf.datasize; + if(DateTime.Compare(mddf.dtvc, DateHandlers.LisaToDateTime(0)) > 0) + { + xmlFSType.CreationDate = mddf.dtvc; + xmlFSType.CreationDateSpecified = true; + } + xmlFSType.Dirty = mddf.vol_left_mounted != 0; + xmlFSType.Files = mddf.filecount; + xmlFSType.FilesSpecified = true; + xmlFSType.FreeClusters = mddf.freecount; + xmlFSType.FreeClustersSpecified = true; + xmlFSType.Type = "LisaFS"; + xmlFSType.VolumeName = mddf.volname; + xmlFSType.VolumeSerial = string.Format("{0:X16}", mddf.volid); + + return Errno.NoError; } DicConsole.DebugWriteLine("LisaFS plugin", "Not a Lisa filesystem"); diff --git a/DiscImageChef.Filesystems/ODS.cs b/DiscImageChef.Filesystems/ODS.cs index 25eacdc12..bc2cf774b 100644 --- a/DiscImageChef.Filesystems/ODS.cs +++ b/DiscImageChef.Filesystems/ODS.cs @@ -91,19 +91,18 @@ namespace DiscImageChef.Filesystems if(magic == "DECFILE11A " || magic == "DECFILE11B ") return true; // Optical disc - if(imagePlugin.ImageInfo.XmlMediaType == DiscImages.XmlMediaType.OpticalDisc) - { - if(hb_sector.Length < 0x400) return false; + if(imagePlugin.ImageInfo.XmlMediaType != DiscImages.XmlMediaType.OpticalDisc) return false; - hb_sector = imagePlugin.ReadSector(partition.Start); + if(hb_sector.Length < 0x400) return false; - Array.Copy(hb_sector, 0x3F0, magic_b, 0, 12); - magic = Encoding.ASCII.GetString(magic_b); + hb_sector = imagePlugin.ReadSector(partition.Start); - DicConsole.DebugWriteLine("Files-11 plugin", "unaligned magic: \"{0}\"", magic); + Array.Copy(hb_sector, 0x3F0, magic_b, 0, 12); + magic = Encoding.ASCII.GetString(magic_b); - if(magic == "DECFILE11A " || magic == "DECFILE11B ") return true; - } + DicConsole.DebugWriteLine("Files-11 plugin", "unaligned magic: \"{0}\"", magic); + + if(magic == "DECFILE11A " || magic == "DECFILE11B ") return true; return false; } diff --git a/DiscImageChef.Filesystems/Reiser.cs b/DiscImageChef.Filesystems/Reiser.cs index ada2d06a2..ed1438da7 100644 --- a/DiscImageChef.Filesystems/Reiser.cs +++ b/DiscImageChef.Filesystems/Reiser.cs @@ -191,11 +191,10 @@ namespace DiscImageChef.Filesystems xmlFSType.FreeClusters = reiserSb.free_blocks; xmlFSType.FreeClustersSpecified = true; xmlFSType.Dirty = reiserSb.umount_state == 2; - if(reiserSb.version >= 2) - { - xmlFSType.VolumeName = CurrentEncoding.GetString(reiserSb.label); - xmlFSType.VolumeSerial = reiserSb.uuid.ToString(); - } + if(reiserSb.version < 2) return; + + xmlFSType.VolumeName = CurrentEncoding.GetString(reiserSb.label); + xmlFSType.VolumeSerial = reiserSb.uuid.ToString(); } public override Errno Mount() diff --git a/DiscImageChef.Filesystems/SysV.cs b/DiscImageChef.Filesystems/SysV.cs index 59cd25d9c..77da910f6 100644 --- a/DiscImageChef.Filesystems/SysV.cs +++ b/DiscImageChef.Filesystems/SysV.cs @@ -165,24 +165,26 @@ namespace DiscImageChef.Filesystems s_nfree = BitConverter.ToUInt16(sb_sector, 0x006); // 7th edition's s_nfree s_ninode = BitConverter.ToUInt16(sb_sector, 0x0D0); // 7th edition's s_ninode - if(s_fsize > 0 && s_fsize < 0xFFFFFFFF && s_nfree > 0 && s_nfree < 0xFFFF && s_ninode > 0 && - s_ninode < 0xFFFF) - { - if((s_fsize & 0xFF) == 0x00 && (s_nfree & 0xFF) == 0x00 && (s_ninode & 0xFF) == 0x00) - { - // Byteswap - s_fsize = ((s_fsize & 0xFF) << 24) + ((s_fsize & 0xFF00) << 8) + ((s_fsize & 0xFF0000) >> 8) + - ((s_fsize & 0xFF000000) >> 24); - s_nfree = (ushort)(s_nfree >> 8); - s_ninode = (ushort)(s_ninode >> 8); - } + if(s_fsize <= 0 || s_fsize >= 0xFFFFFFFF || s_nfree <= 0 || s_nfree >= 0xFFFF || s_ninode <= 0 || + s_ninode >= 0xFFFF) continue; - if((s_fsize & 0xFF000000) == 0x00 && (s_nfree & 0xFF00) == 0x00 && (s_ninode & 0xFF00) == 0x00) - if(s_fsize < V7_MAXSIZE && s_nfree < V7_NICFREE && s_ninode < V7_NICINOD) - if(s_fsize * 1024 == (partition.End - partition.Start) * imagePlugin.GetSectorSize() || - s_fsize * 512 == (partition.End - partition.Start) * imagePlugin.GetSectorSize()) - return true; + if((s_fsize & 0xFF) == 0x00 && (s_nfree & 0xFF) == 0x00 && (s_ninode & 0xFF) == 0x00) + { + // Byteswap + s_fsize = ((s_fsize & 0xFF) << 24) + ((s_fsize & 0xFF00) << 8) + ((s_fsize & 0xFF0000) >> 8) + + ((s_fsize & 0xFF000000) >> 24); + s_nfree = (ushort)(s_nfree >> 8); + s_ninode = (ushort)(s_ninode >> 8); } + + if((s_fsize & 0xFF000000) != 0x00 || (s_nfree & 0xFF00) != 0x00 || + (s_ninode & 0xFF00) != 0x00) continue; + + if(s_fsize >= V7_MAXSIZE || s_nfree >= V7_NICFREE || s_ninode >= V7_NICINOD) continue; + + if(s_fsize * 1024 == (partition.End - partition.Start) * imagePlugin.GetSectorSize() || + s_fsize * 512 == (partition.End - partition.Start) * imagePlugin.GetSectorSize()) + return true; } return false; @@ -313,29 +315,30 @@ namespace DiscImageChef.Filesystems s_nfree = BitConverter.ToUInt16(sb_sector, 0x006); // 7th edition's s_nfree s_ninode = BitConverter.ToUInt16(sb_sector, 0x0D0); // 7th edition's s_ninode - if(s_fsize > 0 && s_fsize < 0xFFFFFFFF && s_nfree > 0 && s_nfree < 0xFFFF && s_ninode > 0 && - s_ninode < 0xFFFF) - { - if((s_fsize & 0xFF) == 0x00 && (s_nfree & 0xFF) == 0x00 && (s_ninode & 0xFF) == 0x00) - { - // Byteswap - s_fsize = ((s_fsize & 0xFF) << 24) + ((s_fsize & 0xFF00) << 8) + ((s_fsize & 0xFF0000) >> 8) + - ((s_fsize & 0xFF000000) >> 24); - s_nfree = (ushort)(s_nfree >> 8); - s_ninode = (ushort)(s_ninode >> 8); - } + if(s_fsize <= 0 || s_fsize >= 0xFFFFFFFF || s_nfree <= 0 || s_nfree >= 0xFFFF || s_ninode <= 0 || + s_ninode >= 0xFFFF) continue; - if((s_fsize & 0xFF000000) == 0x00 && (s_nfree & 0xFF00) == 0x00 && (s_ninode & 0xFF00) == 0x00) - if(s_fsize < V7_MAXSIZE && s_nfree < V7_NICFREE && s_ninode < V7_NICINOD) - if(s_fsize * 1024 == (partition.End - partition.Start) * imagePlugin.GetSectorSize() || - s_fsize * 512 == (partition.End - partition.Start) * imagePlugin.GetSectorSize()) - { - sys7th = true; - BigEndianBitConverter.IsLittleEndian = true; - start = i; - break; - } + if((s_fsize & 0xFF) == 0x00 && (s_nfree & 0xFF) == 0x00 && (s_ninode & 0xFF) == 0x00) + { + // Byteswap + s_fsize = ((s_fsize & 0xFF) << 24) + ((s_fsize & 0xFF00) << 8) + ((s_fsize & 0xFF0000) >> 8) + + ((s_fsize & 0xFF000000) >> 24); + s_nfree = (ushort)(s_nfree >> 8); + s_ninode = (ushort)(s_ninode >> 8); } + + if((s_fsize & 0xFF000000) != 0x00 || (s_nfree & 0xFF00) != 0x00 || + (s_ninode & 0xFF00) != 0x00) continue; + + if(s_fsize >= V7_MAXSIZE || s_nfree >= V7_NICFREE || s_ninode >= V7_NICINOD) continue; + + if(s_fsize * 1024 != (partition.End - partition.Start) * imagePlugin.GetSectorSize() && + s_fsize * 512 != (partition.End - partition.Start) * imagePlugin.GetSectorSize()) continue; + + sys7th = true; + BigEndianBitConverter.IsLittleEndian = true; + start = i; + break; } if(!sys7th && !sysv && !coherent && !xenix && !xenix3) return; diff --git a/DiscImageChef.Filesystems/UCSDPascal/File.cs b/DiscImageChef.Filesystems/UCSDPascal/File.cs index 23351e23a..733300919 100644 --- a/DiscImageChef.Filesystems/UCSDPascal/File.cs +++ b/DiscImageChef.Filesystems/UCSDPascal/File.cs @@ -54,11 +54,10 @@ namespace DiscImageChef.Filesystems.UCSDPascal PascalFileEntry entry; Errno error = GetFileEntry(path, out entry); - if(error == Errno.NoError) - { - attributes = new FileAttributes(); - attributes = FileAttributes.File; - } + if(error != Errno.NoError) return error; + + attributes = new FileAttributes(); + attributes = FileAttributes.File; return error; } diff --git a/DiscImageChef.Filesystems/UDF.cs b/DiscImageChef.Filesystems/UDF.cs index 304a7f1b2..bcc631194 100644 --- a/DiscImageChef.Filesystems/UDF.cs +++ b/DiscImageChef.Filesystems/UDF.cs @@ -278,13 +278,12 @@ namespace DiscImageChef.Filesystems DicConsole.DebugWriteLine("UDF Plugin", "anchor.reserveVolumeDescriptorSequenceExtent.location = {0}", anchor.reserveVolumeDescriptorSequenceExtent.location); - if(anchor.tag.tagIdentifier == TagIdentifier.AnchorVolumeDescriptorPointer && - anchor.tag.tagLocation == position && - anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start < partition.End) - { - anchorFound = true; - break; - } + if(anchor.tag.tagIdentifier != TagIdentifier.AnchorVolumeDescriptorPointer || + anchor.tag.tagLocation != position || + anchor.mainVolumeDescriptorSequenceExtent.location + partition.Start >= partition.End) continue; + + anchorFound = true; + break; } if(!anchorFound) return false; diff --git a/DiscImageChef.Filesystems/ZFS.cs b/DiscImageChef.Filesystems/ZFS.cs index b2ff8e893..3b3815489 100644 --- a/DiscImageChef.Filesystems/ZFS.cs +++ b/DiscImageChef.Filesystems/ZFS.cs @@ -259,12 +259,11 @@ namespace DiscImageChef.Filesystems if(magic == ZEC_Magic || magic == ZEC_Cigam) return true; } - if(partition.Start + 16 < partition.End) - { - sector = imagePlugin.ReadSector(partition.Start + 16); - magic = BitConverter.ToUInt64(sector, 0x1D8); - if(magic == ZEC_Magic || magic == ZEC_Cigam) return true; - } + if(partition.Start + 16 >= partition.End) return false; + + sector = imagePlugin.ReadSector(partition.Start + 16); + magic = BitConverter.ToUInt64(sector, 0x1D8); + if(magic == ZEC_Magic || magic == ZEC_Cigam) return true; return false; } diff --git a/DiscImageChef.Filters/AppleDouble.cs b/DiscImageChef.Filters/AppleDouble.cs index 8bc871e9c..d0875bb35 100644 --- a/DiscImageChef.Filters/AppleDouble.cs +++ b/DiscImageChef.Filters/AppleDouble.cs @@ -371,19 +371,17 @@ namespace DiscImageChef.Filters } // Check AppleDouble created by UnAr (from The Unarchiver) - if(File.Exists(UnArAppleDouble)) - { - FileStream unarStream = new FileStream(UnArAppleDouble, FileMode.Open, FileAccess.Read); - if(unarStream != null && unarStream.Length > 26) - { - byte[] unar_b = new byte[26]; - unarStream.Read(unar_b, 0, 26); - header = BigEndianMarshal.ByteArrayToStructureBigEndian(unar_b); - unarStream.Close(); - if(header.magic == AppleDoubleMagic && - (header.version == AppleDoubleVersion || header.version == AppleDoubleVersion2)) return true; - } - } + if(!File.Exists(UnArAppleDouble)) return false; + + FileStream unarStream = new FileStream(UnArAppleDouble, FileMode.Open, FileAccess.Read); + if(unarStream == null || unarStream.Length <= 26) return false; + + byte[] unar_b = new byte[26]; + unarStream.Read(unar_b, 0, 26); + header = BigEndianMarshal.ByteArrayToStructureBigEndian(unar_b); + unarStream.Close(); + if(header.magic == AppleDoubleMagic && + (header.version == AppleDoubleVersion || header.version == AppleDoubleVersion2)) return true; return false; } diff --git a/DiscImageChef.Filters/BZip2.cs b/DiscImageChef.Filters/BZip2.cs index bf1b5d9c0..c2c18936f 100644 --- a/DiscImageChef.Filters/BZip2.cs +++ b/DiscImageChef.Filters/BZip2.cs @@ -88,16 +88,15 @@ namespace DiscImageChef.Filters public override bool Identify(byte[] buffer) { - if(buffer[0] == 0x42 && buffer[1] == 0x5A && buffer[2] == 0x68 && buffer[3] >= 0x31 && buffer[3] <= 0x39) - { - if(buffer.Length > 512) - if(buffer[buffer.Length - 512] == 0x6B && buffer[buffer.Length - 511] == 0x6F && - buffer[buffer.Length - 510] == 0x6C && buffer[buffer.Length - 509] == 0x79) return false; + if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 || + buffer[3] > 0x39) return false; - return true; - } + if(buffer.Length <= 512) return true; - return false; + if(buffer[buffer.Length - 512] == 0x6B && buffer[buffer.Length - 511] == 0x6F && + buffer[buffer.Length - 510] == 0x6C && buffer[buffer.Length - 509] == 0x79) return false; + + return true; } public override bool Identify(Stream stream) @@ -108,52 +107,44 @@ namespace DiscImageChef.Filters stream.Read(buffer, 0, 4); stream.Seek(0, SeekOrigin.Begin); - if(buffer[0] == 0x42 && buffer[1] == 0x5A && buffer[2] == 0x68 && buffer[3] >= 0x31 && buffer[3] <= 0x39) - { - if(stream.Length > 512) - { - stream.Seek(-512, SeekOrigin.End); - stream.Read(buffer, 0, 4); - stream.Seek(0, SeekOrigin.Begin); - // Check it is not an UDIF - if(buffer[0] == 0x6B && buffer[1] == 0x6F && buffer[2] == 0x6C && buffer[3] == 0x79) return false; - } + if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 || + buffer[3] > 0x39) return false; - return true; - } + if(stream.Length <= 512) return true; - return false; + stream.Seek(-512, SeekOrigin.End); + stream.Read(buffer, 0, 4); + stream.Seek(0, SeekOrigin.Begin); + // Check it is not an UDIF + if(buffer[0] == 0x6B && buffer[1] == 0x6F && buffer[2] == 0x6C && buffer[3] == 0x79) return false; + + return true; } public override bool Identify(string path) { - if(File.Exists(path)) - { - FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); - byte[] buffer = new byte[4]; + if(!File.Exists(path)) return false; - stream.Seek(0, SeekOrigin.Begin); - stream.Read(buffer, 0, 4); - stream.Seek(0, SeekOrigin.Begin); + FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); + byte[] buffer = new byte[4]; - if(buffer[0] == 0x42 && buffer[1] == 0x5A && buffer[2] == 0x68 && buffer[3] >= 0x31 && buffer[3] <= 0x39 - ) - { - if(stream.Length > 512) - { - stream.Seek(-512, SeekOrigin.End); - stream.Read(buffer, 0, 4); - stream.Seek(0, SeekOrigin.Begin); - // Check it is not an UDIF - if(buffer[0] == 0x6B && buffer[1] == 0x6F && buffer[2] == 0x6C && buffer[3] == 0x79) - return false; - } + stream.Seek(0, SeekOrigin.Begin); + stream.Read(buffer, 0, 4); + stream.Seek(0, SeekOrigin.Begin); - return true; - } - } + if(buffer[0] != 0x42 || buffer[1] != 0x5A || buffer[2] != 0x68 || buffer[3] < 0x31 || + buffer[3] > 0x39) return false; - return false; + if(stream.Length <= 512) return true; + + stream.Seek(-512, SeekOrigin.End); + stream.Read(buffer, 0, 4); + stream.Seek(0, SeekOrigin.Begin); + // Check it is not an UDIF + if(buffer[0] == 0x6B && buffer[1] == 0x6F && buffer[2] == 0x6C && buffer[3] == 0x79) + return false; + + return true; } public override void Open(byte[] buffer) diff --git a/DiscImageChef.Filters/Filters.cs b/DiscImageChef.Filters/Filters.cs index 7b3b3d34f..87270b90a 100644 --- a/DiscImageChef.Filters/Filters.cs +++ b/DiscImageChef.Filters/Filters.cs @@ -49,11 +49,10 @@ namespace DiscImageChef.Filters foreach(Type type in assembly.GetTypes()) try { - if(type.IsSubclassOf(typeof(Filter))) - { - Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); - if(!filtersList.ContainsKey(filter.Name.ToLower())) filtersList.Add(filter.Name.ToLower(), filter); - } + if(!type.IsSubclassOf(typeof(Filter))) continue; + + Filter filter = (Filter)type.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); + if(!filtersList.ContainsKey(filter.Name.ToLower())) filtersList.Add(filter.Name.ToLower(), filter); } catch(Exception exception) { DicConsole.ErrorWriteLine("Exception {0}", exception); } } @@ -65,23 +64,21 @@ namespace DiscImageChef.Filters foreach(Filter filter in filtersList.Values) if(filter.UUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) { - if(filter.Identify(path)) - { - Filter foundFilter = - (Filter)filter.GetType().GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); - foundFilter.Open(path); + if(!filter.Identify(path)) continue; - if(foundFilter.IsOpened()) return foundFilter; - } + Filter foundFilter = + (Filter)filter.GetType().GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); + foundFilter.Open(path); + + if(foundFilter.IsOpened()) return foundFilter; } else noFilter = filter; - if(noFilter.Identify(path)) - { - noFilter.Open(path); + if(!noFilter.Identify(path)) return noFilter; - if(noFilter.IsOpened()) return noFilter; - } + noFilter.Open(path); + + if(noFilter.IsOpened()) return noFilter; return noFilter; } diff --git a/DiscImageChef.Filters/ForcedSeekStream.cs b/DiscImageChef.Filters/ForcedSeekStream.cs index fb47391d6..386c1675f 100644 --- a/DiscImageChef.Filters/ForcedSeekStream.cs +++ b/DiscImageChef.Filters/ForcedSeekStream.cs @@ -160,22 +160,20 @@ namespace DiscImageChef.Filters public override int Read(byte[] buffer, int offset, int count) { - if(backStream.Position + count > backStream.Length) - { - SetPosition(backStream.Position + count); - SetPosition(backStream.Position - count); - } + if(backStream.Position + count <= backStream.Length) return backStream.Read(buffer, offset, count); + + SetPosition(backStream.Position + count); + SetPosition(backStream.Position - count); return backStream.Read(buffer, offset, count); } public override int ReadByte() { - if(backStream.Position + 1 > backStream.Length) - { - SetPosition(backStream.Position + 1); - SetPosition(backStream.Position - 1); - } + if(backStream.Position + 1 <= backStream.Length) return backStream.ReadByte(); + + SetPosition(backStream.Position + 1); + SetPosition(backStream.Position - 1); return backStream.ReadByte(); } diff --git a/DiscImageChef.Filters/GZip.cs b/DiscImageChef.Filters/GZip.cs index 0fc49f8f1..a440e799c 100644 --- a/DiscImageChef.Filters/GZip.cs +++ b/DiscImageChef.Filters/GZip.cs @@ -103,19 +103,16 @@ namespace DiscImageChef.Filters public override bool Identify(string path) { - if(File.Exists(path)) - { - FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); - byte[] buffer = new byte[3]; + if(!File.Exists(path)) return false; - stream.Seek(0, SeekOrigin.Begin); - stream.Read(buffer, 0, 3); - stream.Seek(0, SeekOrigin.Begin); + FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); + byte[] buffer = new byte[3]; - return buffer[0] == 0x1F && buffer[1] == 0x8B && buffer[2] == 0x08; - } + stream.Seek(0, SeekOrigin.Begin); + stream.Read(buffer, 0, 3); + stream.Seek(0, SeekOrigin.Begin); - return false; + return buffer[0] == 0x1F && buffer[1] == 0x8B && buffer[2] == 0x08; } public override void Open(byte[] buffer) diff --git a/DiscImageChef.Filters/LZip.cs b/DiscImageChef.Filters/LZip.cs index 76fbed737..f82db8e16 100644 --- a/DiscImageChef.Filters/LZip.cs +++ b/DiscImageChef.Filters/LZip.cs @@ -106,20 +106,17 @@ namespace DiscImageChef.Filters public override bool Identify(string path) { - if(File.Exists(path)) - { - FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); - byte[] buffer = new byte[5]; + if(!File.Exists(path)) return false; - stream.Seek(0, SeekOrigin.Begin); - stream.Read(buffer, 0, 5); - stream.Seek(0, SeekOrigin.Begin); + FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); + byte[] buffer = new byte[5]; - return buffer[0] == 0x4C && buffer[1] == 0x5A && buffer[2] == 0x49 && buffer[3] == 0x50 && - buffer[4] == 0x01; - } + stream.Seek(0, SeekOrigin.Begin); + stream.Read(buffer, 0, 5); + stream.Seek(0, SeekOrigin.Begin); - return false; + return buffer[0] == 0x4C && buffer[1] == 0x5A && buffer[2] == 0x49 && buffer[3] == 0x50 && + buffer[4] == 0x01; } public override void Open(byte[] buffer) diff --git a/DiscImageChef.Filters/PCExchange.cs b/DiscImageChef.Filters/PCExchange.cs index 26ad5f688..536cebd8c 100644 --- a/DiscImageChef.Filters/PCExchange.cs +++ b/DiscImageChef.Filters/PCExchange.cs @@ -228,17 +228,16 @@ namespace DiscImageChef.Filters Encoding.ASCII.GetString(tmpDosExt_b).Trim(); string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture); - if(baseFilename == macName || baseFilename == dosName || baseFilename == dosNameLow) - { - dataFound |= File.Exists(Path.Combine(parentFolder, macName)) || - File.Exists(Path.Combine(parentFolder, dosName)) || - File.Exists(Path.Combine(parentFolder, dosNameLow)); + if(baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow) continue; - rsrcFound |= File.Exists(Path.Combine(parentFolder, Resources, dosName)) || - File.Exists(Path.Combine(parentFolder, Resources, dosNameLow)); + dataFound |= File.Exists(Path.Combine(parentFolder, macName)) || + File.Exists(Path.Combine(parentFolder, dosName)) || + File.Exists(Path.Combine(parentFolder, dosNameLow)); - break; - } + rsrcFound |= File.Exists(Path.Combine(parentFolder, Resources, dosName)) || + File.Exists(Path.Combine(parentFolder, Resources, dosNameLow)); + + break; } finderDatStream.Close(); @@ -284,26 +283,25 @@ namespace DiscImageChef.Filters Encoding.ASCII.GetString(tmpDosExt_b).Trim(); string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture); - if(baseFilename == macName || baseFilename == dosName || baseFilename == dosNameLow) - { - if(File.Exists(Path.Combine(parentFolder, macName))) dataPath = Path.Combine(parentFolder, macName); - else if(File.Exists(Path.Combine(parentFolder, dosName))) - dataPath = Path.Combine(parentFolder, dosName); - else if(File.Exists(Path.Combine(parentFolder, dosNameLow))) - dataPath = Path.Combine(parentFolder, dosNameLow); - else dataPath = null; + if(baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow) continue; - if(File.Exists(Path.Combine(parentFolder, Resources, dosName))) - rsrcPath = Path.Combine(parentFolder, Resources, dosName); - else if(File.Exists(Path.Combine(parentFolder, Resources, dosNameLow))) - rsrcPath = Path.Combine(parentFolder, Resources, dosNameLow); - else rsrcPath = null; + if(File.Exists(Path.Combine(parentFolder, macName))) dataPath = Path.Combine(parentFolder, macName); + else if(File.Exists(Path.Combine(parentFolder, dosName))) + dataPath = Path.Combine(parentFolder, dosName); + else if(File.Exists(Path.Combine(parentFolder, dosNameLow))) + dataPath = Path.Combine(parentFolder, dosNameLow); + else dataPath = null; - lastWriteTime = DateHandlers.MacToDateTime(datEntry.modificationDate); - creationTime = DateHandlers.MacToDateTime(datEntry.creationDate); + if(File.Exists(Path.Combine(parentFolder, Resources, dosName))) + rsrcPath = Path.Combine(parentFolder, Resources, dosName); + else if(File.Exists(Path.Combine(parentFolder, Resources, dosNameLow))) + rsrcPath = Path.Combine(parentFolder, Resources, dosNameLow); + else rsrcPath = null; - break; - } + lastWriteTime = DateHandlers.MacToDateTime(datEntry.modificationDate); + creationTime = DateHandlers.MacToDateTime(datEntry.creationDate); + + break; } dataLen = new FileInfo(dataPath).Length; diff --git a/DiscImageChef.Filters/XZ.cs b/DiscImageChef.Filters/XZ.cs index baa387932..6ca6fb9d4 100644 --- a/DiscImageChef.Filters/XZ.cs +++ b/DiscImageChef.Filters/XZ.cs @@ -109,24 +109,21 @@ namespace DiscImageChef.Filters public override bool Identify(string path) { - if(File.Exists(path)) - { - FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); - byte[] buffer = new byte[6]; - byte[] footer = new byte[2]; + if(!File.Exists(path)) return false; - stream.Seek(0, SeekOrigin.Begin); - stream.Read(buffer, 0, 6); - stream.Seek(0, SeekOrigin.Begin); - stream.Seek(-2, SeekOrigin.End); - stream.Read(footer, 0, 2); - stream.Seek(0, SeekOrigin.Begin); + FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); + byte[] buffer = new byte[6]; + byte[] footer = new byte[2]; - return buffer[0] == 0xFD && buffer[1] == 0x37 && buffer[2] == 0x7A && buffer[3] == 0x58 && - buffer[4] == 0x5A && buffer[5] == 0x00 && footer[0] == 0x59 && footer[1] == 0x5A; - } + stream.Seek(0, SeekOrigin.Begin); + stream.Read(buffer, 0, 6); + stream.Seek(0, SeekOrigin.Begin); + stream.Seek(-2, SeekOrigin.End); + stream.Read(footer, 0, 2); + stream.Seek(0, SeekOrigin.Begin); - return false; + return buffer[0] == 0xFD && buffer[1] == 0x37 && buffer[2] == 0x7A && buffer[3] == 0x58 && + buffer[4] == 0x5A && buffer[5] == 0x00 && footer[0] == 0x59 && footer[1] == 0x5A; } void GuessSize() diff --git a/DiscImageChef.Helpers/Extents/ExtentsByte.cs b/DiscImageChef.Helpers/Extents/ExtentsByte.cs index b7efb0f71..ad6e549bf 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsByte.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsByte.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsInt.cs b/DiscImageChef.Helpers/Extents/ExtentsInt.cs index ee6b2d3cd..ad651ff6e 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsInt.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsInt.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsLong.cs b/DiscImageChef.Helpers/Extents/ExtentsLong.cs index 1e2979ce4..85fdf56d6 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsLong.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsLong.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsSByte.cs b/DiscImageChef.Helpers/Extents/ExtentsSByte.cs index 8ecd6093d..2444eb27e 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsSByte.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsSByte.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsShort.cs b/DiscImageChef.Helpers/Extents/ExtentsShort.cs index 2e5f40158..ac32f34b5 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsShort.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsShort.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsUInt.cs b/DiscImageChef.Helpers/Extents/ExtentsUInt.cs index 8fb27ffc6..27a0e8b00 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsUInt.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsUInt.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsULong.cs b/DiscImageChef.Helpers/Extents/ExtentsULong.cs index 68d5a3b64..7fcea95c2 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsULong.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsULong.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/Extents/ExtentsUShort.cs b/DiscImageChef.Helpers/Extents/ExtentsUShort.cs index e74f0287c..e9e11d4ce 100644 --- a/DiscImageChef.Helpers/Extents/ExtentsUShort.cs +++ b/DiscImageChef.Helpers/Extents/ExtentsUShort.cs @@ -82,19 +82,18 @@ namespace Extents } // Expands existing extent end - if(item == backend[i].Item2 + 1) + if(item != backend[i].Item2 + 1) continue; + + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) { - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -171,11 +170,10 @@ namespace Extents } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/DiscImageChef.Helpers/StringHandlers.cs b/DiscImageChef.Helpers/StringHandlers.cs index 839cfea8f..728715e05 100644 --- a/DiscImageChef.Helpers/StringHandlers.cs +++ b/DiscImageChef.Helpers/StringHandlers.cs @@ -145,11 +145,10 @@ namespace DiscImageChef { if(i == start) return ""; - if(SpacePaddedString[i - 1] != 0x20) - { - len = i; - break; - } + if(SpacePaddedString[i - 1] == 0x20) continue; + + len = i; + break; } return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); diff --git a/DiscImageChef.Interop/DetectOS.cs b/DiscImageChef.Interop/DetectOS.cs index a2bbec3b4..bfa17bc4a 100644 --- a/DiscImageChef.Interop/DetectOS.cs +++ b/DiscImageChef.Interop/DetectOS.cs @@ -195,16 +195,17 @@ namespace DiscImageChef.Interop switch(GetRealPlatformID()) { case PlatformID.MacOSX: - if(Environment.OSVersion.Version.Major == 1) - { - switch(Environment.OSVersion.Version.Minor) { - case 3: return "10.0"; - case 4: return "10.1"; - } + if(Environment.OSVersion.Version.Major != 1) + return string.Format("10.{0}.{1}", Environment.OSVersion.Version.Major - 4, + Environment.OSVersion.Version.Minor); - goto default; + switch(Environment.OSVersion.Version.Minor) { + case 3: return "10.0"; + case 4: return "10.1"; } + goto default; + return string.Format("10.{0}.{1}", Environment.OSVersion.Version.Major - 4, Environment.OSVersion.Version.Minor); case PlatformID.Win32NT: @@ -235,19 +236,16 @@ namespace DiscImageChef.Interop case PlatformID.IRIX: return "IRIX"; case PlatformID.Linux: return "Linux"; case PlatformID.MacOSX: - if(!string.IsNullOrEmpty(version)) - { - string[] pieces = version.Split(new[] {'.'}); - if(pieces.Length >= 2 && int.TryParse(pieces[1], out int minor)) - { - if(minor >= 12) return "macOS"; - if(minor >= 8) return "OS X"; + if(string.IsNullOrEmpty(version)) return "macOS"; - return "Mac OS X"; - } - } + string[] pieces = version.Split(new[] {'.'}); + if(pieces.Length < 2 || !int.TryParse(pieces[1], out int minor)) return "macOS"; + + if(minor >= 12) return "macOS"; + if(minor >= 8) return "OS X"; + + return "Mac OS X"; - return "macOS"; case PlatformID.Minix: return "MINIX"; case PlatformID.NetBSD: return "NetBSD"; case PlatformID.NonStop: return "NonStop OS"; diff --git a/DiscImageChef.Partitions/Acorn.cs b/DiscImageChef.Partitions/Acorn.cs index 0c6af2b92..e2628ad7e 100644 --- a/DiscImageChef.Partitions/Acorn.cs +++ b/DiscImageChef.Partitions/Acorn.cs @@ -129,11 +129,10 @@ namespace DiscImageChef.Partitions Scheme = Name }; part.Offset = part.Start * (ulong)sector.Length; - if(entry.magic == LINUX_MAGIC || entry.magic == SWAP_MAGIC) - { - partitions.Add(part); - counter++; - } + if(entry.magic != LINUX_MAGIC && entry.magic != SWAP_MAGIC) continue; + + partitions.Add(part); + counter++; } break; @@ -160,11 +159,10 @@ namespace DiscImageChef.Partitions Scheme = Name }; part.Offset = part.Start * (ulong)sector.Length; - if(entry.length > 0) - { - partitions.Add(part); - counter++; - } + if(entry.length <= 0) continue; + + partitions.Add(part); + counter++; } break; diff --git a/DiscImageChef.Partitions/AppleMap.cs b/DiscImageChef.Partitions/AppleMap.cs index 74a926f7d..dd978c86f 100644 --- a/DiscImageChef.Partitions/AppleMap.cs +++ b/DiscImageChef.Partitions/AppleMap.cs @@ -243,101 +243,99 @@ namespace DiscImageChef.Partitions byte[] tmp = new byte[entry_size]; Array.Copy(entries, i * entry_size, tmp, 0, entry_size); entry = BigEndianMarshal.ByteArrayToStructureBigEndian(tmp); - if(entry.signature == APM_MAGIC) + if(entry.signature != APM_MAGIC) continue; + + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].signature = 0x{1:X4}", i, entry.signature); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].reserved1 = 0x{1:X4}", i, entry.reserved1); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entries = {1}", i, entry.entries); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].start = {1}", i, entry.start); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].sectors = {1}", i, entry.sectors); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i, + StringHandlers.CToString(entry.name)); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i, + StringHandlers.CToString(entry.type)); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i, + entry.first_data_block); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].data_sectors = {1}", i, entry.data_sectors); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i, + (AppleMapFlags)entry.flags); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i, + entry.first_boot_block); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].boot_size = {1}", i, entry.boot_size); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i, + entry.load_address); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i, + entry.load_address2); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i, + entry.entry_point); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i, + entry.entry_point2); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum); + DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i, + StringHandlers.CToString(entry.processor)); + + AppleMapFlags flags = (AppleMapFlags)entry.flags; + + // BeOS doesn't mark its partitions as valid + //if(flags.HasFlag(AppleMapFlags.Valid) && + if(StringHandlers.CToString(entry.type) == "Apple_partition_map" || entry.sectors <= 0) continue; + + StringBuilder sb = new StringBuilder(); + + CommonTypes.Partition _partition = new CommonTypes.Partition { - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].signature = 0x{1:X4}", i, entry.signature); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].reserved1 = 0x{1:X4}", i, entry.reserved1); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entries = {1}", i, entry.entries); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].start = {1}", i, entry.start); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].sectors = {1}", i, entry.sectors); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i, - StringHandlers.CToString(entry.name)); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i, - StringHandlers.CToString(entry.type)); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i, - entry.first_data_block); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].data_sectors = {1}", i, entry.data_sectors); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i, - (AppleMapFlags)entry.flags); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i, - entry.first_boot_block); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].boot_size = {1}", i, entry.boot_size); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i, - entry.load_address); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i, - entry.load_address2); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i, - entry.entry_point); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i, - entry.entry_point2); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum); - DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i, - StringHandlers.CToString(entry.processor)); + Sequence = sequence, + Type = StringHandlers.CToString(entry.type), + Name = StringHandlers.CToString(entry.name), + Offset = entry.start * entry_size, + Size = entry.sectors * entry_size, + Start = entry.start * entry_size / sector_size + sectorOffset, + Length = entry.sectors * entry_size / sector_size, + Scheme = Name + }; + sb.AppendLine("Partition flags:"); + if(flags.HasFlag(AppleMapFlags.Valid)) sb.AppendLine("Partition is valid."); + if(flags.HasFlag(AppleMapFlags.Allocated)) sb.AppendLine("Partition entry is allocated."); + if(flags.HasFlag(AppleMapFlags.InUse)) sb.AppendLine("Partition is in use."); + if(flags.HasFlag(AppleMapFlags.Bootable)) sb.AppendLine("Partition is bootable."); + if(flags.HasFlag(AppleMapFlags.Readable)) sb.AppendLine("Partition is readable."); + if(flags.HasFlag(AppleMapFlags.Writable)) sb.AppendLine("Partition is writable."); - AppleMapFlags flags = (AppleMapFlags)entry.flags; + if(flags.HasFlag(AppleMapFlags.Bootable)) + { + sb.AppendFormat("First boot sector: {0}", + entry.first_boot_block * entry_size / sector_size).AppendLine(); + sb.AppendFormat("Boot is {0} bytes.", entry.boot_size).AppendLine(); + sb.AppendFormat("Boot load address: 0x{0:X8}", entry.load_address).AppendLine(); + sb.AppendFormat("Boot entry point: 0x{0:X8}", entry.entry_point).AppendLine(); + sb.AppendFormat("Boot code checksum: 0x{0:X8}", entry.checksum).AppendLine(); + sb.AppendFormat("Processor: {0}", StringHandlers.CToString(entry.processor)).AppendLine(); - // BeOS doesn't mark its partitions as valid - //if(flags.HasFlag(AppleMapFlags.Valid) && - if(StringHandlers.CToString(entry.type) != "Apple_partition_map" && entry.sectors > 0) - { - StringBuilder sb = new StringBuilder(); - - CommonTypes.Partition _partition = new CommonTypes.Partition - { - Sequence = sequence, - Type = StringHandlers.CToString(entry.type), - Name = StringHandlers.CToString(entry.name), - Offset = entry.start * entry_size, - Size = entry.sectors * entry_size, - Start = entry.start * entry_size / sector_size + sectorOffset, - Length = entry.sectors * entry_size / sector_size, - Scheme = Name - }; - sb.AppendLine("Partition flags:"); - if(flags.HasFlag(AppleMapFlags.Valid)) sb.AppendLine("Partition is valid."); - if(flags.HasFlag(AppleMapFlags.Allocated)) sb.AppendLine("Partition entry is allocated."); - if(flags.HasFlag(AppleMapFlags.InUse)) sb.AppendLine("Partition is in use."); - if(flags.HasFlag(AppleMapFlags.Bootable)) sb.AppendLine("Partition is bootable."); - if(flags.HasFlag(AppleMapFlags.Readable)) sb.AppendLine("Partition is readable."); - if(flags.HasFlag(AppleMapFlags.Writable)) sb.AppendLine("Partition is writable."); - - if(flags.HasFlag(AppleMapFlags.Bootable)) - { - sb.AppendFormat("First boot sector: {0}", - entry.first_boot_block * entry_size / sector_size).AppendLine(); - sb.AppendFormat("Boot is {0} bytes.", entry.boot_size).AppendLine(); - sb.AppendFormat("Boot load address: 0x{0:X8}", entry.load_address).AppendLine(); - sb.AppendFormat("Boot entry point: 0x{0:X8}", entry.entry_point).AppendLine(); - sb.AppendFormat("Boot code checksum: 0x{0:X8}", entry.checksum).AppendLine(); - sb.AppendFormat("Processor: {0}", StringHandlers.CToString(entry.processor)).AppendLine(); - - if(flags.HasFlag(AppleMapFlags.PicCode)) - sb.AppendLine("Partition's boot code is position independent."); - } - - _partition.Description = sb.ToString(); - if(_partition.Start < imagePlugin.ImageInfo.Sectors && - _partition.End < imagePlugin.ImageInfo.Sectors) - { - partitions.Add(_partition); - sequence++; - } - // Some CD and DVDs end with an Apple_Free that expands beyond the disc size... - else if(_partition.Start < imagePlugin.ImageInfo.Sectors) - { - DicConsole.DebugWriteLine("AppleMap Plugin", - "Cutting last partition end ({0}) to media size ({1})", - _partition.End, imagePlugin.ImageInfo.Sectors - 1); - _partition.Length = imagePlugin.ImageInfo.Sectors - _partition.Start; - partitions.Add(_partition); - sequence++; - } - else - DicConsole.DebugWriteLine("AppleMap Plugin", - "Not adding partition becaus start ({0}) is outside media size ({1})", - _partition.Start, imagePlugin.ImageInfo.Sectors - 1); - } + if(flags.HasFlag(AppleMapFlags.PicCode)) + sb.AppendLine("Partition's boot code is position independent."); } + + _partition.Description = sb.ToString(); + if(_partition.Start < imagePlugin.ImageInfo.Sectors && + _partition.End < imagePlugin.ImageInfo.Sectors) + { + partitions.Add(_partition); + sequence++; + } + // Some CD and DVDs end with an Apple_Free that expands beyond the disc size... + else if(_partition.Start < imagePlugin.ImageInfo.Sectors) + { + DicConsole.DebugWriteLine("AppleMap Plugin", + "Cutting last partition end ({0}) to media size ({1})", + _partition.End, imagePlugin.ImageInfo.Sectors - 1); + _partition.Length = imagePlugin.ImageInfo.Sectors - _partition.Start; + partitions.Add(_partition); + sequence++; + } + else + DicConsole.DebugWriteLine("AppleMap Plugin", + "Not adding partition becaus start ({0}) is outside media size ({1})", + _partition.Start, imagePlugin.ImageInfo.Sectors - 1); } return partitions.Count > 0; diff --git a/DiscImageChef.Partitions/Atari.cs b/DiscImageChef.Partitions/Atari.cs index c23143ee2..7ee0725bb 100644 --- a/DiscImageChef.Partitions/Atari.cs +++ b/DiscImageChef.Partitions/Atari.cs @@ -140,7 +140,8 @@ namespace DiscImageChef.Partitions { uint type = table.entries[i].type & 0x00FFFFFF; - switch(type) { + switch(type) + { case TypeGEMDOS: case TypeBigGEMDOS: case TypeLinux: @@ -241,97 +242,17 @@ namespace DiscImageChef.Partitions { uint extendedType = extendedTable.entries[j].type & 0x00FFFFFF; - if(extendedType == TypeGEMDOS || extendedType == TypeBigGEMDOS || extendedType == TypeLinux || - extendedType == TypeSwap || extendedType == TypeRAW || extendedType == TypeNetBSD || - extendedType == TypeNetBSDSwap || extendedType == TypeSysV || extendedType == TypeMac || - extendedType == TypeMinix || extendedType == TypeMinix2) - { - validTable = true; - if(extendedTable.entries[j].start <= imagePlugin.GetSectors()) - { - if(extendedTable.entries[j].start + extendedTable.entries[j].length > - imagePlugin.GetSectors()) - DicConsole.DebugWriteLine("Atari partition plugin", - "WARNING: End of partition goes beyond device size"); + if(extendedType != TypeGEMDOS && extendedType != TypeBigGEMDOS && + extendedType != TypeLinux && extendedType != TypeSwap && extendedType != TypeRAW && + extendedType != TypeNetBSD && extendedType != TypeNetBSDSwap && + extendedType != TypeSysV && extendedType != TypeMac && extendedType != TypeMinix && + extendedType != TypeMinix2) continue; - ulong sectorSize = imagePlugin.GetSectorSize(); - if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; + validTable = true; + if(extendedTable.entries[j].start > imagePlugin.GetSectors()) continue; - byte[] partType = new byte[3]; - partType[0] = (byte)((extendedType & 0xFF0000) >> 16); - partType[1] = (byte)((extendedType & 0x00FF00) >> 8); - partType[2] = (byte)(extendedType & 0x0000FF); - - CommonTypes.Partition part = new CommonTypes.Partition - { - Size = extendedTable.entries[j].length * sectorSize, - Length = extendedTable.entries[j].length, - Sequence = partitionSequence, - Name = "", - Offset = extendedTable.entries[j].start * sectorSize, - Start = extendedTable.entries[j].start, - Type = Encoding.ASCII.GetString(partType), - Scheme = Name - }; - switch(extendedType) - { - case TypeGEMDOS: - part.Description = "Atari GEMDOS partition"; - break; - case TypeBigGEMDOS: - part.Description = "Atari GEMDOS partition bigger than 32 MiB"; - break; - case TypeLinux: - part.Description = "Linux partition"; - break; - case TypeSwap: - part.Description = "Swap partition"; - break; - case TypeRAW: - part.Description = "RAW partition"; - break; - case TypeNetBSD: - part.Description = "NetBSD partition"; - break; - case TypeNetBSDSwap: - part.Description = "NetBSD swap partition"; - break; - case TypeSysV: - part.Description = "Atari UNIX partition"; - break; - case TypeMac: - part.Description = "Macintosh partition"; - break; - case TypeMinix: - case TypeMinix2: - part.Description = "MINIX partition"; - break; - default: - part.Description = "Unknown partition type"; - break; - } - - partitions.Add(part); - partitionSequence++; - } - } - } - - break; - } - } - - if(validTable) - for(int i = 0; i < 8; i++) - { - uint type = table.icdEntries[i].type & 0x00FFFFFF; - - if(type == TypeGEMDOS || type == TypeBigGEMDOS || type == TypeLinux || type == TypeSwap || - type == TypeRAW || type == TypeNetBSD || type == TypeNetBSDSwap || type == TypeSysV || - type == TypeMac || type == TypeMinix || type == TypeMinix2) - if(table.icdEntries[i].start <= imagePlugin.GetSectors()) - { - if(table.icdEntries[i].start + table.icdEntries[i].length > imagePlugin.GetSectors()) + if(extendedTable.entries[j].start + extendedTable.entries[j].length > + imagePlugin.GetSectors()) DicConsole.DebugWriteLine("Atari partition plugin", "WARNING: End of partition goes beyond device size"); @@ -339,22 +260,22 @@ namespace DiscImageChef.Partitions if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; byte[] partType = new byte[3]; - partType[0] = (byte)((type & 0xFF0000) >> 16); - partType[1] = (byte)((type & 0x00FF00) >> 8); - partType[2] = (byte)(type & 0x0000FF); + partType[0] = (byte)((extendedType & 0xFF0000) >> 16); + partType[1] = (byte)((extendedType & 0x00FF00) >> 8); + partType[2] = (byte)(extendedType & 0x0000FF); CommonTypes.Partition part = new CommonTypes.Partition { - Size = table.icdEntries[i].length * sectorSize, - Length = table.icdEntries[i].length, + Size = extendedTable.entries[j].length * sectorSize, + Length = extendedTable.entries[j].length, Sequence = partitionSequence, Name = "", - Offset = table.icdEntries[i].start * sectorSize, - Start = table.icdEntries[i].start, + Offset = extendedTable.entries[j].start * sectorSize, + Start = extendedTable.entries[j].start, Type = Encoding.ASCII.GetString(partType), Scheme = Name }; - switch(type) + switch(extendedType) { case TypeGEMDOS: part.Description = "Atari GEMDOS partition"; @@ -395,7 +316,87 @@ namespace DiscImageChef.Partitions partitions.Add(part); partitionSequence++; } + + break; } + } + + if(!validTable) return partitions.Count > 0; + + for(int i = 0; i < 8; i++) + { + uint type = table.icdEntries[i].type & 0x00FFFFFF; + + if(type != TypeGEMDOS && type != TypeBigGEMDOS && type != TypeLinux && type != TypeSwap && + type != TypeRAW && type != TypeNetBSD && type != TypeNetBSDSwap && type != TypeSysV && + type != TypeMac && type != TypeMinix && type != TypeMinix2) continue; + + if(table.icdEntries[i].start > imagePlugin.GetSectors()) continue; + + if(table.icdEntries[i].start + table.icdEntries[i].length > imagePlugin.GetSectors()) + DicConsole.DebugWriteLine("Atari partition plugin", + "WARNING: End of partition goes beyond device size"); + + ulong sectorSize = imagePlugin.GetSectorSize(); + if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; + + byte[] partType = new byte[3]; + partType[0] = (byte)((type & 0xFF0000) >> 16); + partType[1] = (byte)((type & 0x00FF00) >> 8); + partType[2] = (byte)(type & 0x0000FF); + + CommonTypes.Partition part = new CommonTypes.Partition + { + Size = table.icdEntries[i].length * sectorSize, + Length = table.icdEntries[i].length, + Sequence = partitionSequence, + Name = "", + Offset = table.icdEntries[i].start * sectorSize, + Start = table.icdEntries[i].start, + Type = Encoding.ASCII.GetString(partType), + Scheme = Name + }; + switch(type) + { + case TypeGEMDOS: + part.Description = "Atari GEMDOS partition"; + break; + case TypeBigGEMDOS: + part.Description = "Atari GEMDOS partition bigger than 32 MiB"; + break; + case TypeLinux: + part.Description = "Linux partition"; + break; + case TypeSwap: + part.Description = "Swap partition"; + break; + case TypeRAW: + part.Description = "RAW partition"; + break; + case TypeNetBSD: + part.Description = "NetBSD partition"; + break; + case TypeNetBSDSwap: + part.Description = "NetBSD swap partition"; + break; + case TypeSysV: + part.Description = "Atari UNIX partition"; + break; + case TypeMac: + part.Description = "Macintosh partition"; + break; + case TypeMinix: + case TypeMinix2: + part.Description = "MINIX partition"; + break; + default: + part.Description = "Unknown partition type"; + break; + } + + partitions.Add(part); + partitionSequence++; + } return partitions.Count > 0; } diff --git a/DiscImageChef.Partitions/BSD.cs b/DiscImageChef.Partitions/BSD.cs index 7735c48ba..c3805cb72 100644 --- a/DiscImageChef.Partitions/BSD.cs +++ b/DiscImageChef.Partitions/BSD.cs @@ -80,12 +80,11 @@ namespace DiscImageChef.Partitions DicConsole.DebugWriteLine("BSD plugin", "dl.magic on sector {0} at offset {1} = 0x{2:X8} (expected 0x{3:X8})", location + sectorOffset, offset, dl.d_magic, DISKMAGIC); - if(dl.d_magic == DISKMAGIC && dl.d_magic2 == DISKMAGIC || - dl.d_magic == DISKCIGAM && dl.d_magic2 == DISKCIGAM) - { - found = true; - break; - } + if((dl.d_magic != DISKMAGIC || dl.d_magic2 != DISKMAGIC) && + (dl.d_magic != DISKCIGAM || dl.d_magic2 != DISKCIGAM)) continue; + + found = true; + break; } if(found) break; @@ -151,21 +150,19 @@ namespace DiscImageChef.Partitions Sequence = counter, Scheme = Name }; - if(dl.d_partitions[i].p_fstype != fsType.Unused) - { - // Crude and dirty way to know if the disklabel is relative to its parent partition... - if(dl.d_partitions[i].p_offset < sectorOffset && !addSectorOffset) addSectorOffset = true; + if(dl.d_partitions[i].p_fstype == fsType.Unused) continue; + // Crude and dirty way to know if the disklabel is relative to its parent partition... + if(dl.d_partitions[i].p_offset < sectorOffset && !addSectorOffset) addSectorOffset = true; - if(addSectorOffset) - { - part.Start += sectorOffset; - part.Offset += sectorOffset * imagePlugin.GetSectorSize(); - } - DicConsole.DebugWriteLine("BSD plugin", "part.start = {0}", part.Start); - DicConsole.DebugWriteLine("BSD plugin", "Adding it..."); - partitions.Add(part); - counter++; + if(addSectorOffset) + { + part.Start += sectorOffset; + part.Offset += sectorOffset * imagePlugin.GetSectorSize(); } + DicConsole.DebugWriteLine("BSD plugin", "part.start = {0}", part.Start); + DicConsole.DebugWriteLine("BSD plugin", "Adding it..."); + partitions.Add(part); + counter++; } return partitions.Count > 0; diff --git a/DiscImageChef.Partitions/DEC.cs b/DiscImageChef.Partitions/DEC.cs index 595c783ae..b596cb9a6 100644 --- a/DiscImageChef.Partitions/DEC.cs +++ b/DiscImageChef.Partitions/DEC.cs @@ -79,11 +79,10 @@ namespace DiscImageChef.Partitions Sequence = counter, Scheme = Name }; - if(part.Size > 0) - { - partitions.Add(part); - counter++; - } + if(part.Size <= 0) continue; + + partitions.Add(part); + counter++; } return true; diff --git a/DiscImageChef.Partitions/DragonFlyBSD.cs b/DiscImageChef.Partitions/DragonFlyBSD.cs index 5346c9c9d..9a1ef630a 100644 --- a/DiscImageChef.Partitions/DragonFlyBSD.cs +++ b/DiscImageChef.Partitions/DragonFlyBSD.cs @@ -86,11 +86,10 @@ namespace DiscImageChef.Partitions if((BSD.fsType)entry.p_fstype == BSD.fsType.Other) part.Type = entry.p_type_uuid.ToString(); else part.Type = BSD.fsTypeToString((BSD.fsType)entry.p_fstype); - if(entry.p_bsize > 0 && entry.p_boffset > 0) - { - partitions.Add(part); - counter++; - } + if(entry.p_bsize <= 0 || entry.p_boffset <= 0) continue; + + partitions.Add(part); + counter++; } return true; diff --git a/DiscImageChef.Partitions/Human68k.cs b/DiscImageChef.Partitions/Human68k.cs index a78acd893..a61b1eeaa 100644 --- a/DiscImageChef.Partitions/Human68k.cs +++ b/DiscImageChef.Partitions/Human68k.cs @@ -112,11 +112,10 @@ namespace DiscImageChef.Partitions }; part.Offset = part.Start * (ulong)sector.Length; part.Size = part.Length * (ulong)sector.Length; - if(entry.length > 0) - { - partitions.Add(part); - counter++; - } + if(entry.length <= 0) continue; + + partitions.Add(part); + counter++; } return true; diff --git a/DiscImageChef.Partitions/MBR.cs b/DiscImageChef.Partitions/MBR.cs index d03534927..82c7a726a 100644 --- a/DiscImageChef.Partitions/MBR.cs +++ b/DiscImageChef.Partitions/MBR.cs @@ -222,128 +222,123 @@ namespace DiscImageChef.Partitions DicConsole.DebugWriteLine("MBR plugin", "entry.extended = {0}", extended); - if(extended) // Let's extend the fun + if(!extended) continue; + + bool processing_extended = true; + ulong chain_start = lba_start; + + while(processing_extended) { - bool processing_extended = true; - ulong chain_start = lba_start; + sector = imagePlugin.ReadSector(lba_start); - while(processing_extended) + handle = GCHandle.Alloc(sector, GCHandleType.Pinned); + ExtendedBootRecord ebr = + (ExtendedBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), + typeof(ExtendedBootRecord)); + handle.Free(); + + DicConsole.DebugWriteLine("MBR plugin", "ebr.magic == MBR_Magic = {0}", ebr.magic == MBR_Magic); + + if(ebr.magic != MBR_Magic) break; + + ulong next_start = 0; + + foreach(MBRPartitionEntry ebr_entry in ebr.entries) { - sector = imagePlugin.ReadSector(lba_start); + bool ext_valid = true; + start_sector = (byte)(ebr_entry.start_sector & 0x3F); + start_cylinder = (ushort)(((ebr_entry.start_sector & 0xC0) << 2) | ebr_entry.start_cylinder); + end_sector = (byte)(ebr_entry.end_sector & 0x3F); + end_cylinder = (ushort)(((ebr_entry.end_sector & 0xC0) << 2) | ebr_entry.end_cylinder); + ulong ext_start = ebr_entry.lba_start; + ulong ext_sectors = ebr_entry.lba_sectors; + bool ext_minix = false; - handle = GCHandle.Alloc(sector, GCHandleType.Pinned); - ExtendedBootRecord ebr = - (ExtendedBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), - typeof(ExtendedBootRecord)); - handle.Free(); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.status {0}", ebr_entry.status); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.type {0}", ebr_entry.type); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_start {0}", ebr_entry.lba_start); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_sectors {0}", ebr_entry.lba_sectors); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_cylinder {0}", start_cylinder); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_head {0}", ebr_entry.start_head); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_sector {0}", start_sector); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_cylinder {0}", end_cylinder); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_head {0}", ebr_entry.end_head); + DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_sector {0}", end_sector); - DicConsole.DebugWriteLine("MBR plugin", "ebr.magic == MBR_Magic = {0}", ebr.magic == MBR_Magic); - - if(ebr.magic != MBR_Magic) break; - - ulong next_start = 0; - - foreach(MBRPartitionEntry ebr_entry in ebr.entries) + // Let's start the fun... + ext_valid &= ebr_entry.status == 0x00 || ebr_entry.status == 0x80; + ext_valid &= ebr_entry.type != 0x00; + ext_valid &= ebr_entry.lba_start != 0 || ebr_entry.lba_sectors != 0 || + ebr_entry.start_cylinder != 0 || ebr_entry.start_head != 0 || + ebr_entry.start_sector != 0 || ebr_entry.end_cylinder != 0 || + ebr_entry.end_head != 0 || ebr_entry.end_sector != 0; + if(ebr_entry.lba_start == 0 && ebr_entry.lba_sectors == 0 && ext_valid) { - bool ext_valid = true; - start_sector = (byte)(ebr_entry.start_sector & 0x3F); - start_cylinder = - (ushort)(((ebr_entry.start_sector & 0xC0) << 2) | ebr_entry.start_cylinder); - end_sector = (byte)(ebr_entry.end_sector & 0x3F); - end_cylinder = (ushort)(((ebr_entry.end_sector & 0xC0) << 2) | ebr_entry.end_cylinder); - ulong ext_start = ebr_entry.lba_start; - ulong ext_sectors = ebr_entry.lba_sectors; - bool ext_minix = false; + ext_start = Helpers.CHS.ToLBA(start_cylinder, ebr_entry.start_head, start_sector, + imagePlugin.ImageInfo.Heads, + imagePlugin.ImageInfo.SectorsPerTrack); + ext_sectors = Helpers.CHS.ToLBA(end_cylinder, ebr_entry.end_head, ebr_entry.end_sector, + imagePlugin.ImageInfo.Heads, + imagePlugin.ImageInfo.SectorsPerTrack) - ext_start; + } + ext_minix |= ebr_entry.type == 0x81 || ebr_entry.type == 0x80; - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.status {0}", ebr_entry.status); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.type {0}", ebr_entry.type); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_start {0}", ebr_entry.lba_start); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.lba_sectors {0}", ebr_entry.lba_sectors); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_cylinder {0}", start_cylinder); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_head {0}", ebr_entry.start_head); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.start_sector {0}", start_sector); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_cylinder {0}", end_cylinder); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_head {0}", ebr_entry.end_head); - DicConsole.DebugWriteLine("MBR plugin", "ebr_entry.end_sector {0}", end_sector); + // For optical media + ext_start /= divider; + ext_sectors /= divider; - // Let's start the fun... - ext_valid &= ebr_entry.status == 0x00 || ebr_entry.status == 0x80; - ext_valid &= ebr_entry.type != 0x00; - ext_valid &= ebr_entry.lba_start != 0 || ebr_entry.lba_sectors != 0 || - ebr_entry.start_cylinder != 0 || ebr_entry.start_head != 0 || - ebr_entry.start_sector != 0 || ebr_entry.end_cylinder != 0 || - ebr_entry.end_head != 0 || ebr_entry.end_sector != 0; - if(ebr_entry.lba_start == 0 && ebr_entry.lba_sectors == 0 && ext_valid) - { - ext_start = Helpers.CHS.ToLBA(start_cylinder, ebr_entry.start_head, start_sector, - imagePlugin.ImageInfo.Heads, - imagePlugin.ImageInfo.SectorsPerTrack); - ext_sectors = - Helpers.CHS.ToLBA(end_cylinder, ebr_entry.end_head, ebr_entry.end_sector, - imagePlugin.ImageInfo.Heads, - imagePlugin.ImageInfo.SectorsPerTrack) - ext_start; - } - ext_minix |= ebr_entry.type == 0x81 || ebr_entry.type == 0x80; + DicConsole.DebugWriteLine("MBR plugin", "ext_start {0}", ext_start); + DicConsole.DebugWriteLine("MBR plugin", "ext_sectors {0}", ext_sectors); - // For optical media - ext_start /= divider; - ext_sectors /= divider; - - DicConsole.DebugWriteLine("MBR plugin", "ext_start {0}", ext_start); - DicConsole.DebugWriteLine("MBR plugin", "ext_sectors {0}", ext_sectors); - - if(ebr_entry.type == 0x05 || ebr_entry.type == 0x0F || ebr_entry.type == 0x15 || - ebr_entry.type == 0x1F || ebr_entry.type == 0x85 || ebr_entry.type == 0x91 || - ebr_entry.type == 0x9B || ebr_entry.type == 0xC5 || ebr_entry.type == 0xCF || - ebr_entry.type == 0xD5) - { - ext_valid = false; - next_start = chain_start + ext_start; - } - - ext_start += lba_start; - ext_valid &= ext_start <= imagePlugin.GetSectors(); - - // Some buggy implementations do some rounding errors getting a few sectors beyond device size - if(ext_start + ext_sectors > imagePlugin.GetSectors()) - ext_sectors = imagePlugin.GetSectors() - ext_start; - - if(ext_valid && ext_minix) // Let's mix the fun - if(GetMinix(imagePlugin, lba_start, divider, sectorOffset, sectorSize, - out List mnx_parts)) partitions.AddRange(mnx_parts); - else ext_minix = false; - - if(ext_valid && !ext_minix) - { - Partition part = new Partition(); - if(ext_start > 0 && ext_sectors > 0) - { - part.Start = ext_start + sectorOffset; - part.Length = ext_sectors; - part.Offset = part.Start * sectorSize; - part.Size = part.Length * sectorSize; - } - else ext_valid = false; - - if(ext_valid) - { - part.Type = string.Format("0x{0:X2}", ebr_entry.type); - part.Name = DecodeMBRType(ebr_entry.type); - part.Sequence = counter; - part.Description = ebr_entry.status == 0x80 ? "Partition is bootable." : ""; - part.Scheme = Name; - counter++; - - partitions.Add(part); - } - } + if(ebr_entry.type == 0x05 || ebr_entry.type == 0x0F || ebr_entry.type == 0x15 || + ebr_entry.type == 0x1F || ebr_entry.type == 0x85 || ebr_entry.type == 0x91 || + ebr_entry.type == 0x9B || ebr_entry.type == 0xC5 || ebr_entry.type == 0xCF || + ebr_entry.type == 0xD5) + { + ext_valid = false; + next_start = chain_start + ext_start; } - DicConsole.DebugWriteLine("MBR plugin", "next_start {0}", next_start); - processing_extended &= next_start != 0; - processing_extended &= next_start <= imagePlugin.GetSectors(); - lba_start = next_start; + ext_start += lba_start; + ext_valid &= ext_start <= imagePlugin.GetSectors(); + + // Some buggy implementations do some rounding errors getting a few sectors beyond device size + if(ext_start + ext_sectors > imagePlugin.GetSectors()) + ext_sectors = imagePlugin.GetSectors() - ext_start; + + if(ext_valid && ext_minix) // Let's mix the fun + if(GetMinix(imagePlugin, lba_start, divider, sectorOffset, sectorSize, + out List mnx_parts)) partitions.AddRange(mnx_parts); + else ext_minix = false; + + if(!ext_valid || ext_minix) continue; + + Partition part = new Partition(); + if(ext_start > 0 && ext_sectors > 0) + { + part.Start = ext_start + sectorOffset; + part.Length = ext_sectors; + part.Offset = part.Start * sectorSize; + part.Size = part.Length * sectorSize; + } + else ext_valid = false; + + if(!ext_valid) continue; + + part.Type = string.Format("0x{0:X2}", ebr_entry.type); + part.Name = DecodeMBRType(ebr_entry.type); + part.Sequence = counter; + part.Description = ebr_entry.status == 0x80 ? "Partition is bootable." : ""; + part.Scheme = Name; + counter++; + + partitions.Add(part); } + + DicConsole.DebugWriteLine("MBR plugin", "next_start {0}", next_start); + processing_extended &= next_start != 0; + processing_extended &= next_start <= imagePlugin.GetSectors(); + lba_start = next_start; } } @@ -411,29 +406,27 @@ namespace DiscImageChef.Partitions DicConsole.DebugWriteLine("MBR plugin", "mnx_start {0}", mnx_start); DicConsole.DebugWriteLine("MBR plugin", "mnx_sectors {0}", mnx_sectors); - if(mnx_valid) + if(!mnx_valid) continue; + + CommonTypes.Partition part = new CommonTypes.Partition(); + if(mnx_start > 0 && mnx_sectors > 0) { - CommonTypes.Partition part = new CommonTypes.Partition(); - if(mnx_start > 0 && mnx_sectors > 0) - { - part.Start = mnx_start + sectorOffset; - part.Length = mnx_sectors; - part.Offset = part.Start * sectorSize; - part.Size = part.Length * sectorSize; - } - else mnx_valid = false; - - if(mnx_valid) - { - any_mnx = true; - part.Type = "MINIX"; - part.Name = "MINIX"; - part.Description = mnx_entry.status == 0x80 ? "Partition is bootable." : ""; - part.Scheme = "MINIX"; - - partitions.Add(part); - } + part.Start = mnx_start + sectorOffset; + part.Length = mnx_sectors; + part.Offset = part.Start * sectorSize; + part.Size = part.Length * sectorSize; } + else mnx_valid = false; + + if(!mnx_valid) continue; + + any_mnx = true; + part.Type = "MINIX"; + part.Name = "MINIX"; + part.Description = mnx_entry.status == 0x80 ? "Partition is bootable." : ""; + part.Scheme = "MINIX"; + + partitions.Add(part); } return any_mnx; diff --git a/DiscImageChef.Partitions/NeXT.cs b/DiscImageChef.Partitions/NeXT.cs index 43bcc12e8..00f664363 100644 --- a/DiscImageChef.Partitions/NeXT.cs +++ b/DiscImageChef.Partitions/NeXT.cs @@ -82,12 +82,11 @@ namespace DiscImageChef.Partitions label_sector = imagePlugin.ReadSector(i + sectorOffset); magic = BigEndianBitConverter.ToUInt32(label_sector, 0x00); - if(magic == NEXT_MAGIC1 || magic == NEXT_MAGIC2 || magic == NEXT_MAGIC3) - { - magic_found = true; - label_position = i + sectorOffset; - break; - } + if(magic != NEXT_MAGIC1 && magic != NEXT_MAGIC2 && magic != NEXT_MAGIC3) continue; + + magic_found = true; + label_position = i + sectorOffset; + break; } if(!magic_found) return false; @@ -166,52 +165,51 @@ namespace DiscImageChef.Partitions DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_type = \"{1}\"", i, StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type)); - if(label.dl_dt.d_partitions[i].p_size > 0 && label.dl_dt.d_partitions[i].p_base >= 0 && - label.dl_dt.d_partitions[i].p_bsize >= 0) + if(label.dl_dt.d_partitions[i].p_size <= 0 || label.dl_dt.d_partitions[i].p_base < 0 || + label.dl_dt.d_partitions[i].p_bsize < 0) continue; + + StringBuilder sb = new StringBuilder(); + + CommonTypes.Partition part = new CommonTypes.Partition { - StringBuilder sb = new StringBuilder(); + Size = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize), + Offset = + (ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) * label.dl_dt.d_secsize), + Type = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type), + Sequence = (ulong)i, + Name = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_mountpt), + Length = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize / sector_size), + Start = (ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) * + label.dl_dt.d_secsize / sector_size), + Scheme = Name + }; - CommonTypes.Partition part = new CommonTypes.Partition - { - Size = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize), - Offset = - (ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) * label.dl_dt.d_secsize), - Type = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_type), - Sequence = (ulong)i, - Name = StringHandlers.CToString(label.dl_dt.d_partitions[i].p_mountpt), - Length = (ulong)(label.dl_dt.d_partitions[i].p_size * label.dl_dt.d_secsize / sector_size), - Start = (ulong)((label.dl_dt.d_partitions[i].p_base + label.dl_dt.d_front) * - label.dl_dt.d_secsize / sector_size), - Scheme = Name - }; - - if(part.Start + part.Length > imagePlugin.ImageInfo.Sectors) - { - DicConsole.DebugWriteLine("NeXT Plugin", "Partition bigger than device, reducing..."); - part.Length = imagePlugin.ImageInfo.Sectors - part.Start; - part.Size = part.Length * sector_size; - DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_size = {1}", i, - part.Length); - } - - sb.AppendFormat("{0} bytes per block", label.dl_dt.d_partitions[i].p_bsize).AppendLine(); - sb.AppendFormat("{0} bytes per fragment", label.dl_dt.d_partitions[i].p_fsize).AppendLine(); - if(label.dl_dt.d_partitions[i].p_opt == 's') sb.AppendLine("Space optimized"); - else if(label.dl_dt.d_partitions[i].p_opt == 't') sb.AppendLine("Time optimized"); - else sb.AppendFormat("Unknown optimization {0:X2}", label.dl_dt.d_partitions[i].p_opt).AppendLine(); - sb.AppendFormat("{0} cylinders per group", label.dl_dt.d_partitions[i].p_cpg).AppendLine(); - sb.AppendFormat("{0} bytes per inode", label.dl_dt.d_partitions[i].p_density).AppendLine(); - sb.AppendFormat("{0}% of space must be free at minimum", label.dl_dt.d_partitions[i].p_minfree) - .AppendLine(); - if(label.dl_dt.d_partitions[i].p_newfs != 1) - sb.AppendLine("Filesystem should be formatted at start"); - if(label.dl_dt.d_partitions[i].p_automnt == 1) - sb.AppendLine("Filesystem should be automatically mounted"); - - part.Description = sb.ToString(); - - partitions.Add(part); + if(part.Start + part.Length > imagePlugin.ImageInfo.Sectors) + { + DicConsole.DebugWriteLine("NeXT Plugin", "Partition bigger than device, reducing..."); + part.Length = imagePlugin.ImageInfo.Sectors - part.Start; + part.Size = part.Length * sector_size; + DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_size = {1}", i, + part.Length); } + + sb.AppendFormat("{0} bytes per block", label.dl_dt.d_partitions[i].p_bsize).AppendLine(); + sb.AppendFormat("{0} bytes per fragment", label.dl_dt.d_partitions[i].p_fsize).AppendLine(); + if(label.dl_dt.d_partitions[i].p_opt == 's') sb.AppendLine("Space optimized"); + else if(label.dl_dt.d_partitions[i].p_opt == 't') sb.AppendLine("Time optimized"); + else sb.AppendFormat("Unknown optimization {0:X2}", label.dl_dt.d_partitions[i].p_opt).AppendLine(); + sb.AppendFormat("{0} cylinders per group", label.dl_dt.d_partitions[i].p_cpg).AppendLine(); + sb.AppendFormat("{0} bytes per inode", label.dl_dt.d_partitions[i].p_density).AppendLine(); + sb.AppendFormat("{0}% of space must be free at minimum", label.dl_dt.d_partitions[i].p_minfree) + .AppendLine(); + if(label.dl_dt.d_partitions[i].p_newfs != 1) + sb.AppendLine("Filesystem should be formatted at start"); + if(label.dl_dt.d_partitions[i].p_automnt == 1) + sb.AppendLine("Filesystem should be automatically mounted"); + + part.Description = sb.ToString(); + + partitions.Add(part); } return true; diff --git a/DiscImageChef.Partitions/PC98.cs b/DiscImageChef.Partitions/PC98.cs index 9707b0e0c..6b661697e 100644 --- a/DiscImageChef.Partitions/PC98.cs +++ b/DiscImageChef.Partitions/PC98.cs @@ -86,43 +86,41 @@ namespace DiscImageChef.Partitions DicConsole.DebugWriteLine("PC98 plugin", "entry.dp_name = \"{0}\"", StringHandlers.CToString(entry.dp_name, Encoding.GetEncoding(932))); - if(entry.dp_scyl != entry.dp_ecyl && entry.dp_ecyl > 0 && - entry.dp_scyl <= imagePlugin.ImageInfo.Cylinders && - entry.dp_ecyl <= imagePlugin.ImageInfo.Cylinders && entry.dp_shd <= imagePlugin.ImageInfo.Heads && - entry.dp_ehd <= imagePlugin.ImageInfo.Heads && - entry.dp_ssect <= imagePlugin.ImageInfo.SectorsPerTrack && - entry.dp_esect <= imagePlugin.ImageInfo.SectorsPerTrack) + if(entry.dp_scyl == entry.dp_ecyl || entry.dp_ecyl <= 0 || + entry.dp_scyl > imagePlugin.ImageInfo.Cylinders || entry.dp_ecyl > imagePlugin.ImageInfo.Cylinders || + entry.dp_shd > imagePlugin.ImageInfo.Heads || entry.dp_ehd > imagePlugin.ImageInfo.Heads || + entry.dp_ssect > imagePlugin.ImageInfo.SectorsPerTrack || + entry.dp_esect > imagePlugin.ImageInfo.SectorsPerTrack) continue; + + Partition part = new Partition { - Partition part = new Partition - { - Start = Helpers.CHS.ToLBA(entry.dp_scyl, entry.dp_shd, (uint)(entry.dp_ssect + 1), - imagePlugin.ImageInfo.Heads, imagePlugin.ImageInfo.SectorsPerTrack), - Type = DecodePC98Sid(entry.dp_sid), - Name = StringHandlers.CToString(entry.dp_name, Encoding.GetEncoding(932)).Trim(), - Sequence = counter, - Scheme = Name - }; - part.Offset = part.Start * imagePlugin.GetSectorSize(); - part.Length = Helpers.CHS.ToLBA(entry.dp_ecyl, entry.dp_ehd, (uint)(entry.dp_esect + 1), - imagePlugin.ImageInfo.Heads, - imagePlugin.ImageInfo.SectorsPerTrack) - part.Start; - part.Size = part.Length * imagePlugin.GetSectorSize(); + Start = Helpers.CHS.ToLBA(entry.dp_scyl, entry.dp_shd, (uint)(entry.dp_ssect + 1), + imagePlugin.ImageInfo.Heads, imagePlugin.ImageInfo.SectorsPerTrack), + Type = DecodePC98Sid(entry.dp_sid), + Name = StringHandlers.CToString(entry.dp_name, Encoding.GetEncoding(932)).Trim(), + Sequence = counter, + Scheme = Name + }; + part.Offset = part.Start * imagePlugin.GetSectorSize(); + part.Length = Helpers.CHS.ToLBA(entry.dp_ecyl, entry.dp_ehd, (uint)(entry.dp_esect + 1), + imagePlugin.ImageInfo.Heads, + imagePlugin.ImageInfo.SectorsPerTrack) - part.Start; + part.Size = part.Length * imagePlugin.GetSectorSize(); - DicConsole.DebugWriteLine("PC98 plugin", "part.Start = {0}", part.Start); - DicConsole.DebugWriteLine("PC98 plugin", "part.Type = {0}", part.Type); - DicConsole.DebugWriteLine("PC98 plugin", "part.Name = {0}", part.Name); - DicConsole.DebugWriteLine("PC98 plugin", "part.Sequence = {0}", part.Sequence); - DicConsole.DebugWriteLine("PC98 plugin", "part.Offset = {0}", part.Offset); - DicConsole.DebugWriteLine("PC98 plugin", "part.Length = {0}", part.Length); - DicConsole.DebugWriteLine("PC98 plugin", "part.Size = {0}", part.Size); + DicConsole.DebugWriteLine("PC98 plugin", "part.Start = {0}", part.Start); + DicConsole.DebugWriteLine("PC98 plugin", "part.Type = {0}", part.Type); + DicConsole.DebugWriteLine("PC98 plugin", "part.Name = {0}", part.Name); + DicConsole.DebugWriteLine("PC98 plugin", "part.Sequence = {0}", part.Sequence); + DicConsole.DebugWriteLine("PC98 plugin", "part.Offset = {0}", part.Offset); + DicConsole.DebugWriteLine("PC98 plugin", "part.Length = {0}", part.Length); + DicConsole.DebugWriteLine("PC98 plugin", "part.Size = {0}", part.Size); - if(((entry.dp_mid & 0x20) == 0x20 || (entry.dp_mid & 0x44) == 0x44) && - part.Start < imagePlugin.ImageInfo.Sectors && part.End <= imagePlugin.ImageInfo.Sectors) - { - partitions.Add(part); - counter++; - } - } + if(((entry.dp_mid & 0x20) != 0x20 && (entry.dp_mid & 0x44) != 0x44) || + part.Start >= imagePlugin.ImageInfo.Sectors || + part.End > imagePlugin.ImageInfo.Sectors) continue; + + partitions.Add(part); + counter++; } return partitions.Count > 0; diff --git a/DiscImageChef.Partitions/RioKarma.cs b/DiscImageChef.Partitions/RioKarma.cs index 99094039f..23ac90b5b 100644 --- a/DiscImageChef.Partitions/RioKarma.cs +++ b/DiscImageChef.Partitions/RioKarma.cs @@ -40,8 +40,8 @@ namespace DiscImageChef.Partitions { public class RioKarma : PartitionPlugin { - const ushort KarmaMagic = 0xAB56; - const byte EntryMagic = 0x4D; + const ushort KARMA_MAGIC = 0xAB56; + const byte ENTRY_MAGIC = 0x4D; public RioKarma() { @@ -62,7 +62,7 @@ namespace DiscImageChef.Partitions table = (RioKarmaTable)Marshal.PtrToStructure(tablePtr, typeof(RioKarmaTable)); Marshal.FreeHGlobal(tablePtr); - if(table.magic != KarmaMagic) return false; + if(table.magic != KARMA_MAGIC) return false; ulong counter = 0; @@ -78,11 +78,10 @@ namespace DiscImageChef.Partitions Sequence = counter, Scheme = Name }; - if(entry.type == EntryMagic) - { - partitions.Add(part); - counter++; - } + if(entry.type != ENTRY_MAGIC) continue; + + partitions.Add(part); + counter++; } return true; diff --git a/DiscImageChef.Partitions/SGI.cs b/DiscImageChef.Partitions/SGI.cs index 9374dfe77..4c8dbdb2c 100644 --- a/DiscImageChef.Partitions/SGI.cs +++ b/DiscImageChef.Partitions/SGI.cs @@ -126,12 +126,11 @@ namespace DiscImageChef.Partitions Sequence = counter, Scheme = Name }; - if(part.Size > 0 && dvh.partitions[i].type != SGIType.Header && dvh.partitions[i].type != SGIType.Volume - ) - { - partitions.Add(part); - counter++; - } + if(part.Size <= 0 || dvh.partitions[i].type == SGIType.Header || + dvh.partitions[i].type == SGIType.Volume) continue; + + partitions.Add(part); + counter++; } return true; diff --git a/DiscImageChef.Partitions/VTOC.cs b/DiscImageChef.Partitions/VTOC.cs index 4360b456e..0e973f3b4 100644 --- a/DiscImageChef.Partitions/VTOC.cs +++ b/DiscImageChef.Partitions/VTOC.cs @@ -72,12 +72,11 @@ namespace DiscImageChef.Partitions magic = BitConverter.ToUInt32(pdsector, 4); DicConsole.DebugWriteLine("VTOC plugin", "sanity at {0} is 0x{1:X8} (should be 0x{2:X8} or 0x{3:X8})", i + sectorOffset, magic, PD_MAGIC, PD_CIGAM); - if(magic == PD_MAGIC || magic == PD_CIGAM) - { - magic_found = true; - pdloc = i; - break; - } + if(magic != PD_MAGIC && magic != PD_CIGAM) continue; + + magic_found = true; + pdloc = i; + break; } if(!magic_found) return false; diff --git a/DiscImageChef.Partitions/XENIX.cs b/DiscImageChef.Partitions/XENIX.cs index d531da8b5..c57db4553 100644 --- a/DiscImageChef.Partitions/XENIX.cs +++ b/DiscImageChef.Partitions/XENIX.cs @@ -75,25 +75,24 @@ namespace DiscImageChef.Partitions { DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p[{0}].p_off = {1}", i, xnxtbl.p[i].p_off); DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p[{0}].p_size = {1}", i, xnxtbl.p[i].p_size); - if(xnxtbl.p[i].p_size > 0) - { - Partition part = new Partition - { - Start = - (ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) / imagePlugin.GetSectorSize() + - sectorOffset, - Length = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE) / imagePlugin.GetSectorSize(), - Offset = - (ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) + - imagePlugin.GetSectorSize() * sectorOffset, - Size = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE), - Sequence = (ulong)i, - Type = "XENIX", - Scheme = Name - }; + if(xnxtbl.p[i].p_size <= 0) continue; - if(part.End < imagePlugin.GetSectors()) partitions.Add(part); - } + Partition part = new Partition + { + Start = + (ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) / imagePlugin.GetSectorSize() + + sectorOffset, + Length = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE) / imagePlugin.GetSectorSize(), + Offset = + (ulong)((xnxtbl.p[i].p_off + XENIX_OFFSET) * XENIX_BSIZE) + + imagePlugin.GetSectorSize() * sectorOffset, + Size = (ulong)(xnxtbl.p[i].p_size * XENIX_BSIZE), + Sequence = (ulong)i, + Type = "XENIX", + Scheme = Name + }; + + if(part.End < imagePlugin.GetSectors()) partitions.Add(part); } return partitions.Count > 0; diff --git a/DiscImageChef.Partitions/Xbox.cs b/DiscImageChef.Partitions/Xbox.cs index 1a4571a00..b5642aa79 100644 --- a/DiscImageChef.Partitions/Xbox.cs +++ b/DiscImageChef.Partitions/Xbox.cs @@ -161,103 +161,102 @@ namespace DiscImageChef.Partitions } } - if(imagePlugin.ImageInfo.Sectors > (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize)) + if(imagePlugin.ImageInfo.Sectors <= (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize)) + return false; + { sector = imagePlugin.ReadSector((ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize)); temp = BitConverter.ToUInt32(sector, 0); - if(temp == XboxCigam) + if(temp != XboxCigam) return false; + + Partition securityPart = new Partition { - Partition securityPart = new Partition - { - Description = "Security sectors", - Size = Xbox360SecuritySectorLen, - Length = (ulong)(Xbox360SecuritySectorLen / imagePlugin.ImageInfo.SectorSize), - Sequence = 1, - Offset = Xbox360SecuritySectorOff, - Start = (ulong)(Xbox360SecuritySectorOff / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; + Description = "Security sectors", + Size = Xbox360SecuritySectorLen, + Length = (ulong)(Xbox360SecuritySectorLen / imagePlugin.ImageInfo.SectorSize), + Sequence = 1, + Offset = Xbox360SecuritySectorOff, + Start = (ulong)(Xbox360SecuritySectorOff / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; - Partition sysCachePart = new Partition - { - Description = "System cache", - Size = Xbox360SystemCacheLen, - Length = (ulong)(Xbox360SystemCacheLen / imagePlugin.ImageInfo.SectorSize), - Sequence = 2, - Offset = Xbox360SystemCacheOff, - Start = (ulong)(Xbox360SystemCacheOff / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; + Partition sysCachePart = new Partition + { + Description = "System cache", + Size = Xbox360SystemCacheLen, + Length = (ulong)(Xbox360SystemCacheLen / imagePlugin.ImageInfo.SectorSize), + Sequence = 2, + Offset = Xbox360SystemCacheOff, + Start = (ulong)(Xbox360SystemCacheOff / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; - Partition gameCachePart = new Partition - { - Description = "Game cache", - Size = Xbox360GameCacheLen, - Length = (ulong)(Xbox360GameCacheLen / imagePlugin.ImageInfo.SectorSize), - Sequence = 3, - Offset = Xbox360GameCacheOff, - Start = (ulong)(Xbox360GameCacheOff / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; + Partition gameCachePart = new Partition + { + Description = "Game cache", + Size = Xbox360GameCacheLen, + Length = (ulong)(Xbox360GameCacheLen / imagePlugin.ImageInfo.SectorSize), + Sequence = 3, + Offset = Xbox360GameCacheOff, + Start = (ulong)(Xbox360GameCacheOff / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; - Partition sysExtPart = new Partition - { - Description = "System volume", - Size = Xbox368SysExtLen, - Length = (ulong)(Xbox368SysExtLen / imagePlugin.ImageInfo.SectorSize), - Sequence = 4, - Offset = Xbox368SysExtOff, - Start = (ulong)(Xbox368SysExtOff / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; + Partition sysExtPart = new Partition + { + Description = "System volume", + Size = Xbox368SysExtLen, + Length = (ulong)(Xbox368SysExtLen / imagePlugin.ImageInfo.SectorSize), + Sequence = 4, + Offset = Xbox368SysExtOff, + Start = (ulong)(Xbox368SysExtOff / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; - Partition sysExt2Part = new Partition - { - Description = "System volume 2", - Size = Xbox360SysExt2Len, - Length = (ulong)(Xbox360SysExt2Len / imagePlugin.ImageInfo.SectorSize), - Sequence = 5, - Offset = Xbox360SysExt2Off, - Start = (ulong)(Xbox360SysExt2Off / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; + Partition sysExt2Part = new Partition + { + Description = "System volume 2", + Size = Xbox360SysExt2Len, + Length = (ulong)(Xbox360SysExt2Len / imagePlugin.ImageInfo.SectorSize), + Sequence = 5, + Offset = Xbox360SysExt2Off, + Start = (ulong)(Xbox360SysExt2Off / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; - Partition xbox1Part = new Partition - { - Description = "Xbox backwards compatibility", - Size = Xbox360CompatLen, - Length = (ulong)(Xbox360CompatLen / imagePlugin.ImageInfo.SectorSize), - Sequence = 6, - Offset = Xbox360CompatOff, - Start = (ulong)(Xbox360CompatOff / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; + Partition xbox1Part = new Partition + { + Description = "Xbox backwards compatibility", + Size = Xbox360CompatLen, + Length = (ulong)(Xbox360CompatLen / imagePlugin.ImageInfo.SectorSize), + Sequence = 6, + Offset = Xbox360CompatOff, + Start = (ulong)(Xbox360CompatOff / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; - Partition dataPart = new Partition - { - Description = "Data volume", - Sequence = 7, - Offset = Xbox360DataOff, - Start = (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize), - Scheme = Name - }; - dataPart.Length = imagePlugin.ImageInfo.Sectors - dataPart.Start; - dataPart.Size = dataPart.Length * imagePlugin.ImageInfo.SectorSize; + Partition dataPart = new Partition + { + Description = "Data volume", + Sequence = 7, + Offset = Xbox360DataOff, + Start = (ulong)(Xbox360DataOff / imagePlugin.ImageInfo.SectorSize), + Scheme = Name + }; + dataPart.Length = imagePlugin.ImageInfo.Sectors - dataPart.Start; + dataPart.Size = dataPart.Length * imagePlugin.ImageInfo.SectorSize; - partitions.Add(securityPart); - partitions.Add(sysCachePart); - partitions.Add(gameCachePart); - partitions.Add(sysExtPart); - partitions.Add(sysExt2Part); - partitions.Add(xbox1Part); - partitions.Add(dataPart); + partitions.Add(securityPart); + partitions.Add(sysCachePart); + partitions.Add(gameCachePart); + partitions.Add(sysExtPart); + partitions.Add(sysExt2Part); + partitions.Add(xbox1Part); + partitions.Add(dataPart); - return true; - } + return true; } - - return false; } } } \ No newline at end of file diff --git a/DiscImageChef.Server/App_Start/ScsiInquiry.cs b/DiscImageChef.Server/App_Start/ScsiInquiry.cs index 5440b64d7..867c613fd 100644 --- a/DiscImageChef.Server/App_Start/ScsiInquiry.cs +++ b/DiscImageChef.Server/App_Start/ScsiInquiry.cs @@ -267,1438 +267,1439 @@ namespace DiscImageChef.Server.App_Start break; } - if(inquiry.VersionDescriptors != null) - 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(string.Format("Device complies with iSCSI revision {0}", - 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(string.Format("Device complies with unknown standard code 0x{0:X4}", - VersionDescriptor)); - 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(string.Format("Device complies with iSCSI revision {0}", + 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(string.Format("Device complies with unknown standard code 0x{0:X4}", + VersionDescriptor)); + break; + } return scsiOneValue; } diff --git a/DiscImageChef.Server/App_Start/ScsiModeSense.cs b/DiscImageChef.Server/App_Start/ScsiModeSense.cs index d05a8d84d..80fd270f5 100644 --- a/DiscImageChef.Server/App_Start/ScsiModeSense.cs +++ b/DiscImageChef.Server/App_Start/ScsiModeSense.cs @@ -70,348 +70,347 @@ namespace DiscImageChef.Server.App_Start break; } - if(modeSense.ModePages != null) - { - foreach(modePageType page in modeSense.ModePages) - switch(page.page) + if(modeSense.ModePages == null) return; + + foreach(modePageType page in modeSense.ModePages) + switch(page.page) + { + case 0x00: { - case 0x00: - { - if(deviceType == PeripheralDeviceTypes.MultiMediaDevice && page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_00_SFF(page.value)); - else - { - if(page.subpage != 0) - modePages - .Add(string.Format("MODE page {0:X2}h subpage {1:X2}h", page.page, page.subpage), - "Unknown vendor mode page"); - else - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - "Unknown vendor mode page"); - } - break; - } - case 0x01: - { - if(page.subpage == 0) - if(deviceType == PeripheralDeviceTypes.MultiMediaDevice) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_01_MMC(page.value)); - else - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_01(page.value)); - else goto default; - - break; - } - case 0x02: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_02(page.value)); - else goto default; - - break; - } - case 0x03: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_03(page.value)); - else goto default; - - break; - } - case 0x04: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_04(page.value)); - else goto default; - - break; - } - case 0x05: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_05(page.value)); - else goto default; - - break; - } - case 0x06: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_06(page.value)); - else goto default; - - break; - } - case 0x07: - { - if(page.subpage == 0) - if(deviceType == PeripheralDeviceTypes.MultiMediaDevice) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_07_MMC(page.value)); - else - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_07(page.value)); - else goto default; - - break; - } - case 0x08: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_08(page.value)); - else goto default; - - break; - } - case 0x0A: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_0A(page.value)); - else if(page.subpage == 1) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_0A_S01(page.value)); - else goto default; - - break; - } - case 0x0B: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_0B(page.value)); - else goto default; - - break; - } - case 0x0D: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_0D(page.value)); - else goto default; - - break; - } - case 0x0E: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_0E(page.value)); - else goto default; - - break; - } - case 0x0F: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_0F(page.value)); - else goto default; - - break; - } - case 0x10: - { - if(page.subpage == 0) - if(deviceType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_10_SSC(page.value)); - else - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_10(page.value)); - else goto default; - - break; - } - case 0x11: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_11(page.value)); - else goto default; - - break; - } - case 0x12: - case 0x13: - case 0x14: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_12_13_14(page.value)); - else goto default; - - break; - } - case 0x1A: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1A(page.value)); - else if(page.subpage == 1) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1A_S01(page.value)); - else goto default; - - break; - } - case 0x1B: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1B(page.value)); - else goto default; - - break; - } - case 0x1C: - { - if(page.subpage == 0) - if(deviceType == PeripheralDeviceTypes.MultiMediaDevice) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1C_SFF(page.value)); - else - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1C(page.value)); - else if(page.subpage == 1) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1C_S01(page.value)); - else goto default; - - break; - } - case 0x1D: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_1D(page.value)); - else goto default; - - break; - } - case 0x21: - { - if(vendor == "CERTANCE") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyCertanceModePage_21(page.value)); - else goto default; - - break; - } - case 0x22: - { - if(vendor == "CERTANCE") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyCertanceModePage_22(page.value)); - else goto default; - - break; - } - case 0x24: - { - if(vendor == "IBM") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyIBMModePage_24(page.value)); - else goto default; - - break; - } - case 0x2A: - { - if(page.subpage == 0) - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyModePage_2A(page.value)); - else goto default; - - break; - } - case 0x2F: - { - if(vendor == "IBM") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - 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(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyHPModePage_3B(page.value)); - else goto default; - - break; - } - case 0x3C: - { - if(vendor == "HP") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyHPModePage_3C(page.value)); - else goto default; - - break; - } - case 0x3D: - { - if(vendor == "IBM") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyIBMModePage_3D(page.value)); - else if(vendor == "HP") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyHPModePage_3D(page.value)); - else goto default; - - break; - } - case 0x3E: - { - if(vendor == "FUJITSU") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyFujitsuModePage_3E(page.value)); - else if(vendor == "HP") - modePages.Add(string.Format("MODE page {0:X2}h", page.page), - Modes.PrettifyHPModePage_3E(page.value)); - else goto default; - - break; - } - default: + if(deviceType == PeripheralDeviceTypes.MultiMediaDevice && page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_00_SFF(page.value)); + else { if(page.subpage != 0) modePages .Add(string.Format("MODE page {0:X2}h subpage {1:X2}h", page.page, page.subpage), - "Unknown mode page"); - else modePages.Add(string.Format("MODE page {0:X2}h", page.page), "Unknown mode page"); + "Unknown vendor mode page"); + else + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + "Unknown vendor mode page"); } - break; + break; } + case 0x01: + { + if(page.subpage == 0) + if(deviceType == PeripheralDeviceTypes.MultiMediaDevice) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_01_MMC(page.value)); + else + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_01(page.value)); + else goto default; - Dictionary newModePages = new Dictionary(); - foreach(KeyValuePair kvp in modePages) - if(string.IsNullOrWhiteSpace(kvp.Value)) newModePages.Add(kvp.Key, "Undecoded"); - else newModePages.Add(kvp.Key, kvp.Value.Replace("\n", "
")); + break; + } + case 0x02: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_02(page.value)); + else goto default; - modePages = newModePages; - } + break; + } + case 0x03: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_03(page.value)); + else goto default; + + break; + } + case 0x04: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_04(page.value)); + else goto default; + + break; + } + case 0x05: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_05(page.value)); + else goto default; + + break; + } + case 0x06: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_06(page.value)); + else goto default; + + break; + } + case 0x07: + { + if(page.subpage == 0) + if(deviceType == PeripheralDeviceTypes.MultiMediaDevice) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_07_MMC(page.value)); + else + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_07(page.value)); + else goto default; + + break; + } + case 0x08: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_08(page.value)); + else goto default; + + break; + } + case 0x0A: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_0A(page.value)); + else if(page.subpage == 1) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_0A_S01(page.value)); + else goto default; + + break; + } + case 0x0B: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_0B(page.value)); + else goto default; + + break; + } + case 0x0D: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_0D(page.value)); + else goto default; + + break; + } + case 0x0E: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_0E(page.value)); + else goto default; + + break; + } + case 0x0F: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_0F(page.value)); + else goto default; + + break; + } + case 0x10: + { + if(page.subpage == 0) + if(deviceType == Decoders.SCSI.PeripheralDeviceTypes.SequentialAccess) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_10_SSC(page.value)); + else + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_10(page.value)); + else goto default; + + break; + } + case 0x11: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_11(page.value)); + else goto default; + + break; + } + case 0x12: + case 0x13: + case 0x14: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_12_13_14(page.value)); + else goto default; + + break; + } + case 0x1A: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1A(page.value)); + else if(page.subpage == 1) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1A_S01(page.value)); + else goto default; + + break; + } + case 0x1B: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1B(page.value)); + else goto default; + + break; + } + case 0x1C: + { + if(page.subpage == 0) + if(deviceType == PeripheralDeviceTypes.MultiMediaDevice) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1C_SFF(page.value)); + else + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1C(page.value)); + else if(page.subpage == 1) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1C_S01(page.value)); + else goto default; + + break; + } + case 0x1D: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_1D(page.value)); + else goto default; + + break; + } + case 0x21: + { + if(vendor == "CERTANCE") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyCertanceModePage_21(page.value)); + else goto default; + + break; + } + case 0x22: + { + if(vendor == "CERTANCE") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyCertanceModePage_22(page.value)); + else goto default; + + break; + } + case 0x24: + { + if(vendor == "IBM") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyIBMModePage_24(page.value)); + else goto default; + + break; + } + case 0x2A: + { + if(page.subpage == 0) + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyModePage_2A(page.value)); + else goto default; + + break; + } + case 0x2F: + { + if(vendor == "IBM") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + 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(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyHPModePage_3B(page.value)); + else goto default; + + break; + } + case 0x3C: + { + if(vendor == "HP") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyHPModePage_3C(page.value)); + else goto default; + + break; + } + case 0x3D: + { + if(vendor == "IBM") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyIBMModePage_3D(page.value)); + else if(vendor == "HP") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyHPModePage_3D(page.value)); + else goto default; + + break; + } + case 0x3E: + { + if(vendor == "FUJITSU") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyFujitsuModePage_3E(page.value)); + else if(vendor == "HP") + modePages.Add(string.Format("MODE page {0:X2}h", page.page), + Modes.PrettifyHPModePage_3E(page.value)); + else goto default; + + break; + } + default: + { + if(page.subpage != 0) + modePages + .Add(string.Format("MODE page {0:X2}h subpage {1:X2}h", page.page, page.subpage), + "Unknown mode page"); + else modePages.Add(string.Format("MODE page {0:X2}h", page.page), "Unknown mode page"); + } + break; + } + + Dictionary newModePages = new Dictionary(); + foreach(KeyValuePair kvp in modePages) + if(string.IsNullOrWhiteSpace(kvp.Value)) newModePages.Add(kvp.Key, "Undecoded"); + else newModePages.Add(kvp.Key, kvp.Value.Replace("\n", "
")); + + modePages = newModePages; } } } \ No newline at end of file diff --git a/DiscImageChef.Server/ViewReport.aspx.cs b/DiscImageChef.Server/ViewReport.aspx.cs index 04d975cb1..831e0d061 100644 --- a/DiscImageChef.Server/ViewReport.aspx.cs +++ b/DiscImageChef.Server/ViewReport.aspx.cs @@ -584,11 +584,10 @@ namespace DiscImageChef.Server number = Convert.ToUInt16(_line.Substring(1, 4), 16); - if(number == product) - { - productDescription = _line.Substring(7); - return; - } + if(number != product) continue; + + productDescription = _line.Substring(7); + return; } else { @@ -598,11 +597,10 @@ namespace DiscImageChef.Server try { number = Convert.ToUInt16(_line.Substring(0, 4), 16); } catch(FormatException) { continue; } - if(number == vendor) - { - vendorDescription = _line.Substring(6); - inManufacturer = true; - } + if(number != vendor) continue; + + vendorDescription = _line.Substring(6); + inManufacturer = true; } } } diff --git a/DiscImageChef/Commands/Analyze.cs b/DiscImageChef/Commands/Analyze.cs index 6e4d019ac..7bbfdb283 100644 --- a/DiscImageChef/Commands/Analyze.cs +++ b/DiscImageChef/Commands/Analyze.cs @@ -162,33 +162,32 @@ namespace DiscImageChef.Commands DicConsole.WriteLine("Partition description:"); DicConsole.WriteLine(partitions[i].Description); - if(options.SearchForFilesystems) + if(!options.SearchForFilesystems) continue; + + DicConsole.WriteLine("Identifying filesystem on partition"); + + Core.Filesystems.Identify(imageFormat, out idPlugins, partitions[i]); + if(idPlugins.Count == 0) DicConsole.WriteLine("Filesystem not identified"); + else if(idPlugins.Count > 1) { - DicConsole.WriteLine("Identifying filesystem on partition"); + DicConsole.WriteLine(string.Format("Identified by {0} plugins", idPlugins.Count)); - Core.Filesystems.Identify(imageFormat, out idPlugins, partitions[i]); - if(idPlugins.Count == 0) DicConsole.WriteLine("Filesystem not identified"); - else if(idPlugins.Count > 1) - { - DicConsole.WriteLine(string.Format("Identified by {0} plugins", idPlugins.Count)); - - foreach(string pluginName in idPlugins) - if(plugins.PluginsList.TryGetValue(pluginName, out plugin)) - { - DicConsole.WriteLine(string.Format("As identified by {0}.", plugin.Name)); - plugin.GetInformation(imageFormat, partitions[i], out information); - DicConsole.Write(information); - Core.Statistics.AddFilesystem(plugin.XmlFSType.Type); - } - } - else - { - plugins.PluginsList.TryGetValue(idPlugins[0], out plugin); - DicConsole.WriteLine(string.Format("Identified by {0}.", plugin.Name)); - plugin.GetInformation(imageFormat, partitions[i], out information); - DicConsole.Write(information); - Core.Statistics.AddFilesystem(plugin.XmlFSType.Type); - } + foreach(string pluginName in idPlugins) + if(plugins.PluginsList.TryGetValue(pluginName, out plugin)) + { + DicConsole.WriteLine(string.Format("As identified by {0}.", plugin.Name)); + plugin.GetInformation(imageFormat, partitions[i], out information); + DicConsole.Write(information); + Core.Statistics.AddFilesystem(plugin.XmlFSType.Type); + } + } + else + { + plugins.PluginsList.TryGetValue(idPlugins[0], out plugin); + DicConsole.WriteLine(string.Format("Identified by {0}.", plugin.Name)); + plugin.GetInformation(imageFormat, partitions[i], out information); + DicConsole.Write(information); + Core.Statistics.AddFilesystem(plugin.XmlFSType.Type); } } } diff --git a/DiscImageChef/Commands/DeviceInfo.cs b/DiscImageChef/Commands/DeviceInfo.cs index f138327fd..4ee811ac0 100644 --- a/DiscImageChef/Commands/DeviceInfo.cs +++ b/DiscImageChef/Commands/DeviceInfo.cs @@ -289,164 +289,150 @@ namespace DiscImageChef.Commands if(page >= 0x01 && page <= 0x7F) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("ASCII Page {0:X2}h: {1}", page, - Decoders.SCSI.EVPD.DecodeASCIIPage(inqBuf)); + if(sense) continue; - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + DicConsole.WriteLine("ASCII Page {0:X2}h: {1}", page, + Decoders.SCSI.EVPD.DecodeASCIIPage(inqBuf)); + + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x80) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("Unit Serial Number: {0}", - Decoders.SCSI.EVPD.DecodePage80(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("Unit Serial Number: {0}", + Decoders.SCSI.EVPD.DecodePage80(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x81) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_81(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_81(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x82) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("ASCII implemented operating definitions: {0}", - Decoders.SCSI.EVPD.DecodePage82(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("ASCII implemented operating definitions: {0}", + Decoders.SCSI.EVPD.DecodePage82(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x83) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_83(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_83(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x84) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_84(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_84(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x85) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_85(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_85(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x86) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_86(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_86(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0x89) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_89(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_89(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xB0) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_B0(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_B0(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xB1) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("Manufacturer-assigned Serial Number: {0}", - Decoders.SCSI.EVPD.DecodePageB1(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("Manufacturer-assigned Serial Number: {0}", + Decoders.SCSI.EVPD.DecodePageB1(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xB2) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("TapeAlert Supported Flags Bitmap: 0x{0:X16}", - Decoders.SCSI.EVPD.DecodePageB2(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("TapeAlert Supported Flags Bitmap: 0x{0:X16}", + Decoders.SCSI.EVPD.DecodePageB2(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xB3) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("Automation Device Serial Number: {0}", - Decoders.SCSI.EVPD.DecodePageB3(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("Automation Device Serial Number: {0}", + Decoders.SCSI.EVPD.DecodePageB3(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xB4) { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("Data Transfer Device Element Address: 0x{0}", - Decoders.SCSI.EVPD.DecodePageB4(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("Data Transfer Device Element Address: 0x{0}", + Decoders.SCSI.EVPD.DecodePageB4(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xC0 && StringHandlers @@ -454,13 +440,12 @@ namespace DiscImageChef.Commands "quantum") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C0_Quantum(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C0_Quantum(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xC0 && StringHandlers @@ -468,13 +453,12 @@ namespace DiscImageChef.Commands "seagate") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C0_Seagate(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C0_Seagate(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xC0 && StringHandlers @@ -482,13 +466,12 @@ namespace DiscImageChef.Commands "ibm") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C0_IBM(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C0_IBM(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xC1 && StringHandlers @@ -496,13 +479,12 @@ namespace DiscImageChef.Commands "ibm") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C1_IBM(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", Decoders.SCSI.EVPD.PrettifyPage_C1_IBM(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if((page == 0xC0 || page == 0xC1) && StringHandlers @@ -510,14 +492,13 @@ namespace DiscImageChef.Commands "certance") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", - Decoders.SCSI.EVPD.PrettifyPage_C0_C1_Certance(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", + Decoders.SCSI.EVPD.PrettifyPage_C0_C1_Certance(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if( (page == 0xC2 || page == 0xC3 || page == 0xC4 || page == 0xC5 || page == 0xC6) && @@ -525,16 +506,15 @@ namespace DiscImageChef.Commands .Trim() == "certance") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", - Decoders - .SCSI.EVPD - .PrettifyPage_C2_C3_C4_C5_C6_Certance(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", + Decoders + .SCSI.EVPD + .PrettifyPage_C2_C3_C4_C5_C6_Certance(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if((page == 0xC0 || page == 0xC1 || page == 0xC2 || page == 0xC3 || page == 0xC4 || page == 0xC5) && @@ -543,14 +523,13 @@ namespace DiscImageChef.Commands "hp") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", - Decoders.SCSI.EVPD.PrettifyPage_C0_to_C5_HP(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", + Decoders.SCSI.EVPD.PrettifyPage_C0_to_C5_HP(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else if(page == 0xDF && StringHandlers @@ -558,28 +537,26 @@ namespace DiscImageChef.Commands "certance") { sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - { - DicConsole.WriteLine("{0}", - Decoders.SCSI.EVPD.PrettifyPage_DF_Certance(inqBuf)); - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + if(sense) continue; + + DicConsole.WriteLine("{0}", + Decoders.SCSI.EVPD.PrettifyPage_DF_Certance(inqBuf)); + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } else { - if(page != 0x00) - { - DicConsole.DebugWriteLine("Device-Info command", - "Found undecoded SCSI VPD page 0x{0:X2}", page); + if(page == 0x00) continue; - sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); - if(!sense) - DataFile.WriteTo("Device-Info command", options.OutputPrefix, - string.Format("_scsi_evpd_{0:X2}h.bin", page), - string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); - } + DicConsole.DebugWriteLine("Device-Info command", + "Found undecoded SCSI VPD page 0x{0:X2}", page); + + sense = dev.ScsiInquiry(out inqBuf, out senseBuf, page); + if(!sense) + DataFile.WriteTo("Device-Info command", options.OutputPrefix, + string.Format("_scsi_evpd_{0:X2}h.bin", page), + string.Format("SCSI INQUIRY EVPD {0:X2}h", page), inqBuf); } } diff --git a/DiscImageChef/Commands/Entropy.cs b/DiscImageChef/Commands/Entropy.cs index 1c4c00de0..2d3e26b03 100644 --- a/DiscImageChef/Commands/Entropy.cs +++ b/DiscImageChef/Commands/Entropy.cs @@ -72,6 +72,9 @@ namespace DiscImageChef.Commands Core.Statistics.AddMediaFormat(inputFormat.GetImageFormat()); Core.Statistics.AddMedia(inputFormat.ImageInfo.MediaType, false); Core.Statistics.AddFilter(inputFilter.Name); + double entropy = 0; + ulong[] entTable; + ulong sectors; if(options.SeparatedTracks) try @@ -81,11 +84,11 @@ namespace DiscImageChef.Commands foreach(Track currentTrack in inputTracks) { Sha1Context sha1CtxTrack = new Sha1Context(); - ulong[] entTable = new ulong[256]; + entTable = new ulong[256]; ulong trackSize = 0; List uniqueSectorsPerTrack = new List(); - ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1; + sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1; DicConsole.WriteLine("Track {0} has {1} sectors", currentTrack.TrackSequence, sectors); for(ulong i = currentTrack.TrackStartSector; i <= currentTrack.TrackEndSector; i++) @@ -105,7 +108,6 @@ namespace DiscImageChef.Commands trackSize += (ulong)sector.LongLength; } - double entropy = 0; foreach(ulong l in entTable) { #pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created @@ -132,56 +134,54 @@ namespace DiscImageChef.Commands else DicConsole.ErrorWriteLine("Unable to get separate tracks, not calculating their entropy"); } - if(options.WholeDisc) + if(!options.WholeDisc) return; + + Sha1Context sha1Ctx = new Sha1Context(); + entTable = new ulong[256]; + ulong diskSize = 0; + List uniqueSectors = new List(); + + sectors = inputFormat.GetSectors(); + DicConsole.WriteLine("Sectors {0}", sectors); + + sha1Ctx.Init(); + + for(ulong i = 0; i < sectors; i++) { - Sha1Context sha1Ctx = new Sha1Context(); - ulong[] entTable = new ulong[256]; - ulong diskSize = 0; - List uniqueSectors = new List(); - - ulong sectors = inputFormat.GetSectors(); - DicConsole.WriteLine("Sectors {0}", sectors); - - sha1Ctx.Init(); - - for(ulong i = 0; i < sectors; i++) - { - DicConsole.Write("\rEntropying sector {0}", i + 1); - byte[] sector = inputFormat.ReadSector(i); - - if(options.DuplicatedSectors) - { - byte[] garbage; - string sectorHash = sha1Ctx.Data(sector, out garbage); - if(!uniqueSectors.Contains(sectorHash)) uniqueSectors.Add(sectorHash); - } - - foreach(byte b in sector) entTable[b]++; - - diskSize += (ulong)sector.LongLength; - } - - double entropy = 0; - foreach(ulong l in entTable) - { -#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created - double frequency = (double)l / (double)diskSize; -#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created - entropy += -(frequency * Math.Log(frequency, 2)); - } - - DicConsole.WriteLine(); - - DicConsole.WriteLine("Entropy for disk is {0:F4}.", entropy); + DicConsole.Write("\rEntropying sector {0}", i + 1); + byte[] sector = inputFormat.ReadSector(i); if(options.DuplicatedSectors) + { + byte[] garbage; + string sectorHash = sha1Ctx.Data(sector, out garbage); + if(!uniqueSectors.Contains(sectorHash)) uniqueSectors.Add(sectorHash); + } + + foreach(byte b in sector) entTable[b]++; + + diskSize += (ulong)sector.LongLength; + } + + foreach(ulong l in entTable) + { #pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created - DicConsole.WriteLine("Disk has {0} unique sectors ({1:P3})", uniqueSectors.Count, - (double)uniqueSectors.Count / (double)sectors); + double frequency = (double)l / (double)diskSize; +#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created + entropy += -(frequency * Math.Log(frequency, 2)); + } + + DicConsole.WriteLine(); + + DicConsole.WriteLine("Entropy for disk is {0:F4}.", entropy); + + if(options.DuplicatedSectors) +#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created + DicConsole.WriteLine("Disk has {0} unique sectors ({1:P3})", uniqueSectors.Count, + (double)uniqueSectors.Count / (double)sectors); #pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created - Core.Statistics.AddCommand("entropy"); - } + Core.Statistics.AddCommand("entropy"); } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/ExtractFiles.cs b/DiscImageChef/Commands/ExtractFiles.cs index 6ce0636e7..de8a73e24 100644 --- a/DiscImageChef/Commands/ExtractFiles.cs +++ b/DiscImageChef/Commands/ExtractFiles.cs @@ -198,57 +198,56 @@ namespace DiscImageChef.Commands { byte[] xattrBuf = new byte[0]; error = fs.GetXattr(entry, xattr, ref xattrBuf); - if(error == Errno.NoError) + if(error != Errno.NoError) continue; + + Directory + .CreateDirectory(Path.Combine(options.OutputDir, + fs.XmlFSType.Type, + volumeName, + ".xattrs", + xattr)); + + outputPath = + Path.Combine(options.OutputDir, + fs.XmlFSType.Type, volumeName, + ".xattrs", xattr, entry); + + if(!File.Exists(outputPath)) { - Directory - .CreateDirectory(Path.Combine(options.OutputDir, - fs.XmlFSType.Type, - volumeName, - ".xattrs", - xattr)); - - outputPath = - Path.Combine(options.OutputDir, - fs.XmlFSType.Type, volumeName, - ".xattrs", xattr, entry); - - if(!File.Exists(outputPath)) - { - outputFile = - new FileStream(outputPath, - FileMode.CreateNew, - FileAccess.ReadWrite, - FileShare.None); - outputFile.Write(xattrBuf, 0, xattrBuf.Length); - outputFile.Close(); - FileInfo fi = new FileInfo(outputPath); + outputFile = + new FileStream(outputPath, + FileMode.CreateNew, + FileAccess.ReadWrite, + FileShare.None); + outputFile.Write(xattrBuf, 0, xattrBuf.Length); + outputFile.Close(); + FileInfo fi = new FileInfo(outputPath); #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body - try - { - fi.CreationTimeUtc = stat.CreationTimeUtc; - } - catch { } - try - { - fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; - } - catch { } - try - { - fi.LastAccessTimeUtc = stat.AccessTimeUtc; - } - catch { } -#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body - DicConsole - .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", - xattrBuf.Length, xattr, entry, - outputPath); + try + { + fi.CreationTimeUtc = stat.CreationTimeUtc; } - else - DicConsole - .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", - xattr, entry); + catch { } + try + { + fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; + } + catch { } + try + { + fi.LastAccessTimeUtc = stat.AccessTimeUtc; + } + catch { } +#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body + DicConsole + .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", + xattrBuf.Length, xattr, entry, + outputPath); } + else + DicConsole + .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", + xattr, entry); } } @@ -345,44 +344,43 @@ namespace DiscImageChef.Commands { byte[] xattrBuf = new byte[0]; error = fs.GetXattr(entry, xattr, ref xattrBuf); - if(error == Errno.NoError) + if(error != Errno.NoError) continue; + + Directory.CreateDirectory(Path.Combine(options.OutputDir, + fs.XmlFSType.Type, + volumeName, + ".xattrs", xattr)); + + outputPath = + Path.Combine(options.OutputDir, fs.XmlFSType.Type, + volumeName, ".xattrs", xattr, entry); + + if(!File.Exists(outputPath)) { - Directory.CreateDirectory(Path.Combine(options.OutputDir, - fs.XmlFSType.Type, - volumeName, - ".xattrs", xattr)); - - outputPath = - Path.Combine(options.OutputDir, fs.XmlFSType.Type, - volumeName, ".xattrs", xattr, entry); - - if(!File.Exists(outputPath)) - { - outputFile = - new FileStream(outputPath, FileMode.CreateNew, - FileAccess.ReadWrite, - FileShare.None); - outputFile.Write(xattrBuf, 0, xattrBuf.Length); - outputFile.Close(); - FileInfo fi = new FileInfo(outputPath); + outputFile = + new FileStream(outputPath, FileMode.CreateNew, + FileAccess.ReadWrite, + FileShare.None); + outputFile.Write(xattrBuf, 0, xattrBuf.Length); + outputFile.Close(); + FileInfo fi = new FileInfo(outputPath); #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body - try { fi.CreationTimeUtc = stat.CreationTimeUtc; } - catch { } - try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; } - catch { } - try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; } - catch { } + try { fi.CreationTimeUtc = stat.CreationTimeUtc; } + catch { } + try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; } + catch { } + try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; } + catch { } #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body - DicConsole - .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", - xattrBuf.Length, xattr, entry, - outputPath); - } - else - DicConsole - .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", - xattr, entry); + DicConsole + .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", + xattrBuf.Length, xattr, entry, + outputPath); } + else + DicConsole + .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", + xattr, entry); } } @@ -488,44 +486,43 @@ namespace DiscImageChef.Commands { byte[] xattrBuf = new byte[0]; error = fs.GetXattr(entry, xattr, ref xattrBuf); - if(error == Errno.NoError) + if(error != Errno.NoError) continue; + + Directory.CreateDirectory(Path.Combine(options.OutputDir, + fs.XmlFSType.Type, + volumeName, + ".xattrs", xattr)); + + outputPath = + Path.Combine(options.OutputDir, fs.XmlFSType.Type, + volumeName, ".xattrs", xattr, entry); + + if(!File.Exists(outputPath)) { - Directory.CreateDirectory(Path.Combine(options.OutputDir, - fs.XmlFSType.Type, - volumeName, - ".xattrs", xattr)); - - outputPath = - Path.Combine(options.OutputDir, fs.XmlFSType.Type, - volumeName, ".xattrs", xattr, entry); - - if(!File.Exists(outputPath)) - { - outputFile = - new FileStream(outputPath, FileMode.CreateNew, - FileAccess.ReadWrite, - FileShare.None); - outputFile.Write(xattrBuf, 0, xattrBuf.Length); - outputFile.Close(); - FileInfo fi = new FileInfo(outputPath); + outputFile = + new FileStream(outputPath, FileMode.CreateNew, + FileAccess.ReadWrite, + FileShare.None); + outputFile.Write(xattrBuf, 0, xattrBuf.Length); + outputFile.Close(); + FileInfo fi = new FileInfo(outputPath); #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body - try { fi.CreationTimeUtc = stat.CreationTimeUtc; } - catch { } - try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; } - catch { } - try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; } - catch { } + try { fi.CreationTimeUtc = stat.CreationTimeUtc; } + catch { } + try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; } + catch { } + try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; } + catch { } #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body - DicConsole - .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", - xattrBuf.Length, xattr, entry, - outputPath); - } - else - DicConsole - .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", - xattr, entry); + DicConsole + .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", + xattrBuf.Length, xattr, entry, + outputPath); } + else + DicConsole + .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", + xattr, entry); } } @@ -616,42 +613,41 @@ namespace DiscImageChef.Commands { byte[] xattrBuf = new byte[0]; error = fs.GetXattr(entry, xattr, ref xattrBuf); - if(error == Errno.NoError) + if(error != Errno.NoError) continue; + + Directory.CreateDirectory(Path.Combine(options.OutputDir, + fs.XmlFSType.Type, + volumeName, ".xattrs", + xattr)); + + outputPath = + Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName, + ".xattrs", xattr, entry); + + if(!File.Exists(outputPath)) { - Directory.CreateDirectory(Path.Combine(options.OutputDir, - fs.XmlFSType.Type, - volumeName, ".xattrs", - xattr)); - - outputPath = - Path.Combine(options.OutputDir, fs.XmlFSType.Type, volumeName, - ".xattrs", xattr, entry); - - if(!File.Exists(outputPath)) - { - outputFile = - new FileStream(outputPath, FileMode.CreateNew, - FileAccess.ReadWrite, FileShare.None); - outputFile.Write(xattrBuf, 0, xattrBuf.Length); - outputFile.Close(); - FileInfo fi = new FileInfo(outputPath); + outputFile = + new FileStream(outputPath, FileMode.CreateNew, + FileAccess.ReadWrite, FileShare.None); + outputFile.Write(xattrBuf, 0, xattrBuf.Length); + outputFile.Close(); + FileInfo fi = new FileInfo(outputPath); #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body - try { fi.CreationTimeUtc = stat.CreationTimeUtc; } - catch { } - try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; } - catch { } - try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; } - catch { } + try { fi.CreationTimeUtc = stat.CreationTimeUtc; } + catch { } + try { fi.LastWriteTimeUtc = stat.LastWriteTimeUtc; } + catch { } + try { fi.LastAccessTimeUtc = stat.AccessTimeUtc; } + catch { } #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body - DicConsole - .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", - xattrBuf.Length, xattr, entry, outputPath); - } - else - DicConsole - .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", - xattr, entry); + DicConsole + .WriteLine("Written {0} bytes of xattr {1} from file {2} to {3}", + xattrBuf.Length, xattr, entry, outputPath); } + else + DicConsole + .ErrorWriteLine("Cannot write xattr {0} for {1}, output exists", + xattr, entry); } } diff --git a/DiscImageChef/Commands/Ls.cs b/DiscImageChef/Commands/Ls.cs index c6ca20792..9bdb02869 100644 --- a/DiscImageChef/Commands/Ls.cs +++ b/DiscImageChef/Commands/Ls.cs @@ -261,13 +261,14 @@ namespace DiscImageChef.Commands stat.Inode, stat.Length, entry); error = fs.ListXAttr(entry, ref xattrs); - if(error == Errno.NoError) - foreach(string xattr in xattrs) - { - byte[] xattrBuf = new byte[0]; - error = fs.GetXattr(entry, xattr, ref xattrBuf); - if(error == Errno.NoError) DicConsole.WriteLine("\t\t{0}\t{1} bytes", xattr, xattrBuf.Length); - } + if(error != Errno.NoError) continue; + + foreach(string xattr in xattrs) + { + byte[] xattrBuf = new byte[0]; + error = fs.GetXattr(entry, xattr, ref xattrBuf); + if(error == Errno.NoError) DicConsole.WriteLine("\t\t{0}\t{1} bytes", xattr, xattrBuf.Length); + } } else DicConsole.WriteLine("{0}", entry); } diff --git a/DiscImageChef/Commands/MediaInfo.cs b/DiscImageChef/Commands/MediaInfo.cs index ba43317a4..641574b45 100644 --- a/DiscImageChef/Commands/MediaInfo.cs +++ b/DiscImageChef/Commands/MediaInfo.cs @@ -1369,13 +1369,12 @@ namespace DiscImageChef.Commands { DataFile.WriteTo("Media-Info command", outputPrefix, "_mediaserialnumber.bin", "SCSI READ MEDIA SERIAL NUMBER", cmdBuf); - if(cmdBuf.Length >= 4) - { - DicConsole.Write("Media Serial Number: "); - for(int i = 4; i < cmdBuf.Length; i++) DicConsole.Write("{0:X2}", cmdBuf[i]); + if(cmdBuf.Length < 4) return; - DicConsole.WriteLine(); - } + DicConsole.Write("Media Serial Number: "); + for(int i = 4; i < cmdBuf.Length; i++) DicConsole.Write("{0:X2}", cmdBuf[i]); + + DicConsole.WriteLine(); } } }