Diff for /embedaddon/smartmontools/os_win32.cpp between versions 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2013/07/22 01:17:35 version 1.1.1.4, 2013/10/14 07:54:03
Line 76 Line 76
 // CSMI support  // CSMI support
 #include "csmisas.h"  #include "csmisas.h"
   
   // Silence -Wunused-local-typedefs warning from g++ >= 4.8
   #if __GNUC__ >= 4
   #define ATTR_UNUSED __attribute__((unused))
   #else
   #define ATTR_UNUSED /**/
   #endif
   
 // Macro to check constants at compile time using a dummy typedef  // Macro to check constants at compile time using a dummy typedef
 #define ASSERT_CONST(c, n) \  #define ASSERT_CONST(c, n) \
  typedef char assert_const_##c[((c) == (n)) ? 1 : -1]  typedef char assert_const_##c[((c) == (n)) ? 1 : -1] ATTR_UNUSED
 #define ASSERT_SIZEOF(t, n) \  #define ASSERT_SIZEOF(t, n) \
  typedef char assert_sizeof_##t[(sizeof(t) == (n)) ? 1 : -1]  typedef char assert_sizeof_##t[(sizeof(t) == (n)) ? 1 : -1] ATTR_UNUSED
   
 #ifndef _WIN64  #ifndef _WIN64
 #define SELECT_WIN_32_64(x32, x64) (x32)  #define SELECT_WIN_32_64(x32, x64) (x32)
Line 597  std::string win_smart_interface::get_os_version_str() Line 604  std::string win_smart_interface::get_os_version_str()
       return vstr;        return vstr;
   }    }
   
  if (vi.dwPlatformId > 0xff || vi.dwMajorVersion > 0xff || vi.dwMinorVersion > 0xff)  const char * w = 0;
    return vstr;  if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
   
  const char * w;    if (vi.dwMajorVersion > 6 || (vi.dwMajorVersion == 6 && vi.dwMinorVersion >= 2)) {
  switch (vi.dwPlatformId << 16 | vi.dwMajorVersion << 8 | vi.dwMinorVersion) {      // Starting with Windows 8.1 Preview, GetVersionEx() does no longer report the
    case VER_PLATFORM_WIN32_WINDOWS<<16|0x0400| 0:      // actual OS version, see:
      w = (vi.szCSDVersion[1] == 'B' ||      // http://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx
           vi.szCSDVersion[1] == 'C'     ? "95-osr2" : "95");    break;
    case VER_PLATFORM_WIN32_WINDOWS<<16|0x0400|10:      ULONGLONG major_equal = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
      w = (vi.szCSDVersion[1] == 'A'     ? "98se"    : "98");    break;      for (unsigned major = vi.dwMajorVersion; major <= 9; major++) {
    case VER_PLATFORM_WIN32_WINDOWS<<16|0x0400|90: w = "me";     break;        OSVERSIONINFOEXA vi2; memset(&vi2, 0, sizeof(vi2));
  //case VER_PLATFORM_WIN32_NT     <<16|0x0300|51: w = "nt3.51"; break;        vi2.dwOSVersionInfoSize = sizeof(vi2); vi2.dwMajorVersion = major;
    case VER_PLATFORM_WIN32_NT     <<16|0x0400| 0: w = "nt4";    break;        if (!VerifyVersionInfo(&vi2, VER_MAJORVERSION, major_equal))
    case VER_PLATFORM_WIN32_NT     <<16|0x0500| 0: w = "2000";   break;          continue;
    case VER_PLATFORM_WIN32_NT     <<16|0x0500| 1:        if (vi.dwMajorVersion < major) {
      w = (!GetSystemMetrics(87/*SM_MEDIACENTER*/) ?   "xp"          vi.dwMajorVersion = major; vi.dwMinorVersion = 0;
                                                   :   "xp-mc"); break;        }
    case VER_PLATFORM_WIN32_NT     <<16|0x0500| 2:
      w = (!GetSystemMetrics(89/*SM_SERVERR2*/)    ?   "2003"        ULONGLONG minor_equal = VerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL);
                                                   :   "2003r2"); break;        for (unsigned minor = vi.dwMinorVersion; minor <= 9; minor++) {
    case VER_PLATFORM_WIN32_NT     <<16|0x0600| 0:          memset(&vi2, 0, sizeof(vi2)); vi2.dwOSVersionInfoSize = sizeof(vi2);
      w = (vi.wProductType == VER_NT_WORKSTATION   ?   "vista"          vi2.dwMinorVersion = minor;
                                                   :   "2008" );  break;          if (!VerifyVersionInfo(&vi2, VER_MINORVERSION, minor_equal))
    case VER_PLATFORM_WIN32_NT     <<16|0x0600| 1:            continue;
      w = (vi.wProductType == VER_NT_WORKSTATION   ?   "win7"          vi.dwMinorVersion = minor;
                                                   :   "2008r2"); break;          break;
    case VER_PLATFORM_WIN32_NT     <<16|0x0600| 2:        }
      w = (vi.wProductType == VER_NT_WORKSTATION   ?   "win8"
                                                   :   "2012"); break;        break;
    default: w = 0; break;      }
     }
 
     if (vi.dwMajorVersion <= 0xf && vi.dwMinorVersion <= 0xf) {
       bool ws = (vi.wProductType <= VER_NT_WORKSTATION);
       switch (vi.dwMajorVersion << 4 | vi.dwMinorVersion) {
         case 0x50: w =       "2000";              break;
         case 0x51: w =       "xp";                break;
         case 0x52: w = (!GetSystemMetrics(89/*SM_SERVERR2*/)
                            ? "2003"  : "2003r2"); break;
         case 0x60: w = (ws ? "vista" : "2008"  ); break;
         case 0x61: w = (ws ? "win7"  : "2008r2"); break;
         case 0x62: w = (ws ? "win8"  : "2012"  ); break;
         case 0x63: w = (ws ? "win8.1": "2012r2"); break;
       }
     }
   }    }
   
   const char * w64 = "";    const char * w64 = "";
Line 636  std::string win_smart_interface::get_os_version_str() Line 658  std::string win_smart_interface::get_os_version_str()
 #endif  #endif
   
   if (!w)    if (!w)
    snprintf(vptr, vlen, "-%s%lu.%lu%s",    snprintf(vptr, vlen, "-%s%u.%u%s",
      (vi.dwPlatformId==VER_PLATFORM_WIN32_NT ? "nt" : "9x"),      (vi.dwPlatformId==VER_PLATFORM_WIN32_NT ? "nt" : "??"),
      vi.dwMajorVersion, vi.dwMinorVersion, w64);      (unsigned)vi.dwMajorVersion, (unsigned)vi.dwMinorVersion, w64);
   else if (vi.wServicePackMinor)    else if (vi.wServicePackMinor)
     snprintf(vptr, vlen, "-%s%s-sp%u.%u", w, w64, vi.wServicePackMajor, vi.wServicePackMinor);      snprintf(vptr, vlen, "-%s%s-sp%u.%u", w, w64, vi.wServicePackMajor, vi.wServicePackMinor);
   else if (vi.wServicePackMajor)    else if (vi.wServicePackMajor)
Line 1101  static int smart_get_version(HANDLE hdevice, GETVERSIO Line 1123  static int smart_get_version(HANDLE hdevice, GETVERSIO
   if (!DeviceIoControl(hdevice, SMART_GET_VERSION,    if (!DeviceIoControl(hdevice, SMART_GET_VERSION,
     NULL, 0, &vers, sizeof(vers), &num_out, NULL)) {      NULL, 0, &vers, sizeof(vers), &num_out, NULL)) {
     if (ata_debugmode)      if (ata_debugmode)
      pout("  SMART_GET_VERSION failed, Error=%ld\n", GetLastError());      pout("  SMART_GET_VERSION failed, Error=%u\n", (unsigned)GetLastError());
     errno = ENOSYS;      errno = ENOSYS;
     return -1;      return -1;
   }    }
   assert(num_out == sizeof(GETVERSIONINPARAMS));    assert(num_out == sizeof(GETVERSIONINPARAMS));
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
    pout("  SMART_GET_VERSION suceeded, bytes returned: %lu\n"    pout("  SMART_GET_VERSION suceeded, bytes returned: %u\n"
         "    Vers = %d.%d, Caps = 0x%lx, DeviceMap = 0x%02x\n",         "    Vers = %d.%d, Caps = 0x%x, DeviceMap = 0x%02x\n",
      num_out, vers.bVersion, vers.bRevision,      (unsigned)num_out, vers.bVersion, vers.bRevision,
      vers.fCapabilities, vers.bIDEDeviceMap);      (unsigned)vers.fCapabilities, vers.bIDEDeviceMap);
     if (vers_ex.wIdentifier == SMART_VENDOR_3WARE)      if (vers_ex.wIdentifier == SMART_VENDOR_3WARE)
      pout("    Identifier = %04x(3WARE), ControllerId=%u, DeviceMapEx = 0x%08lx\n",      pout("    Identifier = %04x(3WARE), ControllerId=%u, DeviceMapEx = 0x%08x\n",
      vers_ex.wIdentifier, vers_ex.wControllerId, vers_ex.dwDeviceMapEx);      vers_ex.wIdentifier, vers_ex.wControllerId, (unsigned)vers_ex.dwDeviceMapEx);
   }    }
   
   if (ata_version_ex)    if (ata_version_ex)
Line 1202  static int smart_ioctl(HANDLE hdevice, IDEREGS * regs, Line 1224  static int smart_ioctl(HANDLE hdevice, IDEREGS * regs,
   }    }
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
    pout("  %s suceeded, bytes returned: %lu (buffer %lu)\n", name,    pout("  %s suceeded, bytes returned: %u (buffer %u)\n", name,
      num_out, outpar->cBufferSize);      (unsigned)num_out, (unsigned)outpar->cBufferSize);
     print_ide_regs_io(regs, (regs->bFeaturesReg == ATA_SMART_STATUS ?      print_ide_regs_io(regs, (regs->bFeaturesReg == ATA_SMART_STATUS ?
       (const IDEREGS *)(outpar->bBuffer) : NULL));        (const IDEREGS *)(outpar->bBuffer) : NULL));
   }    }
Line 1279  static int ide_pass_through_ioctl(HANDLE hdevice, IDER Line 1301  static int ide_pass_through_ioctl(HANDLE hdevice, IDER
     if (   num_out != size      if (   num_out != size
         || (buf->DataBuffer[0] == magic && !nonempty(buf->DataBuffer+1, datasize-1))) {          || (buf->DataBuffer[0] == magic && !nonempty(buf->DataBuffer+1, datasize-1))) {
       if (ata_debugmode) {        if (ata_debugmode) {
        pout("  IOCTL_IDE_PASS_THROUGH output data missing (%lu, %lu)\n",        pout("  IOCTL_IDE_PASS_THROUGH output data missing (%u, %u)\n",
          num_out, buf->DataBufferSize);          (unsigned)num_out, (unsigned)buf->DataBufferSize);
         print_ide_regs_io(regs, &buf->IdeReg);          print_ide_regs_io(regs, &buf->IdeReg);
       }        }
       VirtualFree(buf, 0, MEM_RELEASE);        VirtualFree(buf, 0, MEM_RELEASE);
Line 1291  static int ide_pass_through_ioctl(HANDLE hdevice, IDER Line 1313  static int ide_pass_through_ioctl(HANDLE hdevice, IDER
   }    }
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
    pout("  IOCTL_IDE_PASS_THROUGH suceeded, bytes returned: %lu (buffer %lu)\n",    pout("  IOCTL_IDE_PASS_THROUGH suceeded, bytes returned: %u (buffer %u)\n",
      num_out, buf->DataBufferSize);      (unsigned)num_out, (unsigned)buf->DataBufferSize);
     print_ide_regs_io(regs, &buf->IdeReg);      print_ide_regs_io(regs, &buf->IdeReg);
   }    }
   *regs = buf->IdeReg;    *regs = buf->IdeReg;
Line 1398  static int ata_pass_through_ioctl(HANDLE hdevice, IDER Line 1420  static int ata_pass_through_ioctl(HANDLE hdevice, IDER
     if (   num_out != size      if (   num_out != size
         || (ab.ucDataBuf[0] == magic && !nonempty(ab.ucDataBuf+1, datasize-1))) {          || (ab.ucDataBuf[0] == magic && !nonempty(ab.ucDataBuf+1, datasize-1))) {
       if (ata_debugmode) {        if (ata_debugmode) {
        pout("  IOCTL_ATA_PASS_THROUGH output data missing (%lu)\n", num_out);        pout("  IOCTL_ATA_PASS_THROUGH output data missing (%u)\n", (unsigned)num_out);
         print_ide_regs_io(regs, ctfregs);          print_ide_regs_io(regs, ctfregs);
       }        }
       errno = EIO;        errno = EIO;
Line 1408  static int ata_pass_through_ioctl(HANDLE hdevice, IDER Line 1430  static int ata_pass_through_ioctl(HANDLE hdevice, IDER
   }    }
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
    pout("  IOCTL_ATA_PASS_THROUGH suceeded, bytes returned: %lu\n", num_out);    pout("  IOCTL_ATA_PASS_THROUGH suceeded, bytes returned: %u\n", (unsigned)num_out);
     print_ide_regs_io(regs, ctfregs);      print_ide_regs_io(regs, ctfregs);
   }    }
   *regs = *ctfregs;    *regs = *ctfregs;
Line 1521  static int ata_via_scsi_miniport_smart_ioctl(HANDLE hd Line 1543  static int ata_via_scsi_miniport_smart_ioctl(HANDLE hd
   // Check result    // Check result
   if (sb.srbc.ReturnCode) {    if (sb.srbc.ReturnCode) {
     if (ata_debugmode) {      if (ata_debugmode) {
      pout("  IOCTL_SCSI_MINIPORT_%s failed, ReturnCode=0x%08lx\n", name, sb.srbc.ReturnCode);      pout("  IOCTL_SCSI_MINIPORT_%s failed, ReturnCode=0x%08x\n", name, (unsigned)sb.srbc.ReturnCode);
       print_ide_regs_io(regs, NULL);        print_ide_regs_io(regs, NULL);
     }      }
     errno = EIO;      errno = EIO;
Line 1539  static int ata_via_scsi_miniport_smart_ioctl(HANDLE hd Line 1561  static int ata_via_scsi_miniport_smart_ioctl(HANDLE hd
   }    }
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
    pout("  IOCTL_SCSI_MINIPORT_%s suceeded, bytes returned: %lu (buffer %lu)\n", name,    pout("  IOCTL_SCSI_MINIPORT_%s suceeded, bytes returned: %u (buffer %u)\n", name,
      num_out, sb.params.out.cBufferSize);      (unsigned)num_out, (unsigned)sb.params.out.cBufferSize);
     print_ide_regs_io(regs, (code == IOCTL_SCSI_MINIPORT_RETURN_STATUS ?      print_ide_regs_io(regs, (code == IOCTL_SCSI_MINIPORT_RETURN_STATUS ?
                              (const IDEREGS *)(sb.params.out.bBuffer) : 0));                               (const IDEREGS *)(sb.params.out.bBuffer) : 0));
   }    }
Line 1595  static int ata_via_3ware_miniport_ioctl(HANDLE hdevice Line 1617  static int ata_via_3ware_miniport_ioctl(HANDLE hdevice
   
   if (sb.srbc.ReturnCode) {    if (sb.srbc.ReturnCode) {
     if (ata_debugmode) {      if (ata_debugmode) {
      pout("  ATA via IOCTL_SCSI_MINIPORT failed, ReturnCode=0x%08lx\n", sb.srbc.ReturnCode);      pout("  ATA via IOCTL_SCSI_MINIPORT failed, ReturnCode=0x%08x\n", (unsigned)sb.srbc.ReturnCode);
       print_ide_regs_io(regs, NULL);        print_ide_regs_io(regs, NULL);
     }      }
     errno = EIO;      errno = EIO;
Line 1607  static int ata_via_3ware_miniport_ioctl(HANDLE hdevice Line 1629  static int ata_via_3ware_miniport_ioctl(HANDLE hdevice
     memcpy(data, sb.buffer, datasize);      memcpy(data, sb.buffer, datasize);
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
    pout("  ATA via IOCTL_SCSI_MINIPORT suceeded, bytes returned: %lu\n", num_out);    pout("  ATA via IOCTL_SCSI_MINIPORT suceeded, bytes returned: %u\n", (unsigned)num_out);
     print_ide_regs_io(regs, &sb.regs);      print_ide_regs_io(regs, &sb.regs);
   }    }
   *regs = sb.regs;    *regs = sb.regs;
Line 1643  static int update_3ware_devicemap_ioctl(HANDLE hdevice Line 1665  static int update_3ware_devicemap_ioctl(HANDLE hdevice
   }    }
   if (srbc.ReturnCode) {    if (srbc.ReturnCode) {
     if (ata_debugmode)      if (ata_debugmode)
      pout("  UPDATE DEVICEMAP via IOCTL_SCSI_MINIPORT failed, ReturnCode=0x%08lx\n", srbc.ReturnCode);      pout("  UPDATE DEVICEMAP via IOCTL_SCSI_MINIPORT failed, ReturnCode=0x%08x\n", (unsigned)srbc.ReturnCode);
     errno = EIO;      errno = EIO;
     return -1;      return -1;
   }    }
Line 1932  static int storage_query_property_ioctl(HANDLE hdevice Line 1954  static int storage_query_property_ioctl(HANDLE hdevice
   if (!DeviceIoControl(hdevice, IOCTL_STORAGE_QUERY_PROPERTY,    if (!DeviceIoControl(hdevice, IOCTL_STORAGE_QUERY_PROPERTY,
     &query, sizeof(query), data, sizeof(*data), &num_out, NULL)) {      &query, sizeof(query), data, sizeof(*data), &num_out, NULL)) {
     if (ata_debugmode > 1 || scsi_debugmode > 1)      if (ata_debugmode > 1 || scsi_debugmode > 1)
      pout("  IOCTL_STORAGE_QUERY_PROPERTY failed, Error=%ld\n", GetLastError());      pout("  IOCTL_STORAGE_QUERY_PROPERTY failed, Error=%u\n", (unsigned)GetLastError());
     errno = ENOSYS;      errno = ENOSYS;
     return -1;      return -1;
   }    }
Line 1970  static int storage_predict_failure_ioctl(HANDLE hdevic Line 1992  static int storage_predict_failure_ioctl(HANDLE hdevic
   if (!DeviceIoControl(hdevice, IOCTL_STORAGE_PREDICT_FAILURE,    if (!DeviceIoControl(hdevice, IOCTL_STORAGE_PREDICT_FAILURE,
     0, 0, &pred, sizeof(pred), &num_out, NULL)) {      0, 0, &pred, sizeof(pred), &num_out, NULL)) {
     if (ata_debugmode > 1)      if (ata_debugmode > 1)
      pout("  IOCTL_STORAGE_PREDICT_FAILURE failed, Error=%ld\n", GetLastError());      pout("  IOCTL_STORAGE_PREDICT_FAILURE failed, Error=%u\n", (unsigned)GetLastError());
     errno = ENOSYS;      errno = ENOSYS;
     return -1;      return -1;
   }    }
   
   if (ata_debugmode > 1) {    if (ata_debugmode > 1) {
     pout("  IOCTL_STORAGE_PREDICT_FAILURE returns:\n"      pout("  IOCTL_STORAGE_PREDICT_FAILURE returns:\n"
         "    PredictFailure: 0x%08lx\n"         "    PredictFailure: 0x%08x\n"
          "    VendorSpecific: 0x%02x,0x%02x,0x%02x,...,0x%02x\n",           "    VendorSpecific: 0x%02x,0x%02x,0x%02x,...,0x%02x\n",
         pred.PredictFailure,         (unsigned)pred.PredictFailure,
          pred.VendorSpecific[0], pred.VendorSpecific[1], pred.VendorSpecific[2],           pred.VendorSpecific[0], pred.VendorSpecific[1], pred.VendorSpecific[2],
          pred.VendorSpecific[sizeof(pred.VendorSpecific)-1]           pred.VendorSpecific[sizeof(pred.VendorSpecific)-1]
     );      );
Line 3151  bool win_csmi_device::csmi_ioctl(unsigned code, IOCTL_ Line 3173  bool win_csmi_device::csmi_ioctl(unsigned code, IOCTL_
   // Check result    // Check result
   if (csmi_buffer->ReturnCode) {    if (csmi_buffer->ReturnCode) {
     if (scsi_debugmode) {      if (scsi_debugmode) {
      pout("  IOCTL_SCSI_MINIPORT(CC_CSMI_%u) failed, ReturnCode=%lu\n",      pout("  IOCTL_SCSI_MINIPORT(CC_CSMI_%u) failed, ReturnCode=%u\n",
        code, csmi_buffer->ReturnCode);        code, (unsigned)csmi_buffer->ReturnCode);
     }      }
    return set_err(EIO, "CSMI(%u) failed with ReturnCode=%lu", code, csmi_buffer->ReturnCode);    return set_err(EIO, "CSMI(%u) failed with ReturnCode=%u", code, (unsigned)csmi_buffer->ReturnCode);
   }    }
   
   if (scsi_debugmode > 1)    if (scsi_debugmode > 1)
    pout("  IOCTL_SCSI_MINIPORT(CC_CSMI_%u) succeeded, bytes returned: %lu\n", code, num_out);    pout("  IOCTL_SCSI_MINIPORT(CC_CSMI_%u) succeeded, bytes returned: %u\n", code, (unsigned)num_out);
   
   return true;    return true;
 }  }
Line 3233  bool win_scsi_device::open(int pd_num, int ld_num, int Line 3255  bool win_scsi_device::open(int pd_num, int ld_num, int
            FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,             FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
            OPEN_EXISTING, 0, 0);             OPEN_EXISTING, 0, 0);
   if (h == INVALID_HANDLE_VALUE) {    if (h == INVALID_HANDLE_VALUE) {
    set_err(ENODEV, "%s: Open failed, Error=%ld", b, GetLastError());    set_err(ENODEV, "%s: Open failed, Error=%u", b, (unsigned)GetLastError());
     return false;      return false;
   }    }
   set_fh(h);    set_fh(h);

Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>