sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.7k stars 306 forks source link

[Docs] diskLayout[0].interfaceType available on macOS? #922

Closed pat-encoura closed 1 month ago

pat-encoura commented 2 months ago

Apologies, this is more of a documentation question than anything but I wasn't sure how to file it. In the docs, it says diskLayout[0].interfaceType is only available on Linux and Windows, however, this field is correctly populated on my M1 macOS device. I'm wondering if this is safe to use and the docs should be updated, or if I should truly not depend on this for Mac devices.

For context, I'm trying to detect when mass storage USB devices are attached to Windows and Mac machines. Using the usb module's type field does not seem to be reliable (my USB stick's type is reported as Microphone).

Thank you!

sebhildebrandt commented 2 months ago

@pat-encoura … actually you can rely on the ìnterfaceType in Mac OS … I will correct the docs accordingly. Thank you for discovering this issue.

Concerning usb type (detected microphone issue: … which OS?

pat-encoura commented 2 months ago

@sebhildebrandt Great, thank you!

re: the usb method, my (old) SanDisk USB thumb drive is not reported on Windows, but it is on macOS:

  {
    "id": 1,
    "bus": null,
    "deviceId": null,
    "name": "Cruzer Micro",
    "type": "Microphone",
    "removable": true,
    "vendor": "SanDisk",
    "manufacturer": "SanDisk",
    "maxPower": null,
    "serialNumber": "[removed]"
  }

However both operating systems correctly report it via diskLayout().

On macOS:

  {
    "device": "disk4",
    "type": "USB",
    "name": "Cruzer Micro",
    "vendor": "",
    "size": 4025810432,
    "bytesPerSector": null,
    "totalCylinders": null,
    "totalHeads": null,
    "totalSectors": null,
    "totalTracks": null,
    "tracksPerCylinder": null,
    "sectorsPerTrack": null,
    "firmwareRevision": "",
    "serialNum": "[removed]",
    "interfaceType": "USB",
    "smartStatus": "not supported",
    "temperature": null
  }

On Windows:

  {
    "device": "\\\\:\\PHYSICALDRIVE1",
    "type": "HD",
    "name": "SanDisk Cruzer Micro USB Device",
    "vendor": "SanDisk","
    "size": 4022161920,
    "bytesPerSector": 512,
    "totalCylinders": 489,
    "totalHeads": 255,
    "totalSectors": 7855785,
    "totalTracks": 124695,
    "tracksPerCylinder": 255,
    "sectorsPerTrack": 63,
    "firmwareRevision": "8.01",
    "serialNum": "[removed]",
    "interfaceType": "USB",
    "smartStatus": "Ok"
    "temperature": null
  }
sebhildebrandt commented 1 month ago

Hi @pat-encoura ...

  1. docs are updated
  2. concerning USB detection on macOS: your disk drive should now have the correct type (no longer microphone)
  3. concerning USB detection on Windows: can you run the following command (in PowerShel) first WITHOUT the USB drive attached, then again with attached USB drive?:
Get-CimInstance CIM_LogicalDevice | where { $_.Description -match "USB"} | select Name,CreationClassName,DeviceId,Manufacturer | fl

Thank you in advance

pat-encoura commented 1 month ago

Thanks, verified the USB type on macOS is now Storage.

re: #3, here are the results

Without USB drive attached:

Name              : USB Input Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_03EB&PID_8B0D&MI_01\6&3277F58&0&0001
Manufacturer      : (Standard system devices)

Name              : USB Input Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_03EB&PID_8B0D&MI_00\6&3277F58&0&0000
Manufacturer      : (Standard system devices)

Name              : Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)
CreationClassName : Win32_PnPEntity
DeviceId          : PCI\VEN_8086&DEV_9D2F&SUBSYS_201F1043&REV_21\3&11583659&0&A0
Manufacturer      : Generic USB xHCI Host Controller

Name              : USB Composite Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_064E&PID_9700\HF1019-T838-SN03-REV0101
Manufacturer      : (Standard USB Host Controller)

Name              : USB2.0 UVC HD Webcam
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_064E&PID_9700&MI_00\6&102A07AD&0&0000
Manufacturer      : Microsoft

Name              : USB Composite Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_03EB&PID_8B0D\5&3478949&0&7
Manufacturer      : (Standard USB Host Controller)

Name              : USB Root Hub (USB 3.0)
CreationClassName : Win32_PnPEntity
DeviceId          : USB\ROOT_HUB30\4&152DA58&0&0
Manufacturer      : (Standard USB HUBs)

Name              : Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)
CreationClassName : Win32_USBController
DeviceId          : PCI\VEN_8086&DEV_9D2F&SUBSYS_201F1043&REV_21\3&11583659&0&A0
Manufacturer      : Generic USB xHCI Host Controller

Name              : USB Composite Device
CreationClassName : Win32_USBHub
DeviceId          : USB\VID_064E&PID_9700\HF1019-T838-SN03-REV0101
Manufacturer      :

Name              : USB Composite Device
CreationClassName : Win32_USBHub
DeviceId          : USB\VID_03EB&PID_8B0D\5&3478949&0&7
Manufacturer      :

Name              : USB Root Hub (USB 3.0)
CreationClassName : Win32_USBHub
DeviceId          : USB\ROOT_HUB30\4&152DA58&0&0
Manufacturer      :

With USB drive attached:

Name              : USB Mass Storage Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_0781&PID_5151\077531169C0256D9
Manufacturer      : Compatible USB storage device

Name              : USB Input Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_03EB&PID_8B0D&MI_01\6&3277F58&0&0001
Manufacturer      : (Standard system devices)

Name              : USB Input Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_03EB&PID_8B0D&MI_00\6&3277F58&0&0000
Manufacturer      : (Standard system devices)

Name              : Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)
CreationClassName : Win32_PnPEntity
DeviceId          : PCI\VEN_8086&DEV_9D2F&SUBSYS_201F1043&REV_21\3&11583659&0&A0
Manufacturer      : Generic USB xHCI Host Controller

Name              : USB Composite Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_064E&PID_9700\HF1019-T838-SN03-REV0101
Manufacturer      : (Standard USB Host Controller)

Name              : USB2.0 UVC HD Webcam
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_064E&PID_9700&MI_00\6&102A07AD&0&0000
Manufacturer      : Microsoft

Name              : USB Composite Device
CreationClassName : Win32_PnPEntity
DeviceId          : USB\VID_03EB&PID_8B0D\5&3478949&0&7
Manufacturer      : (Standard USB Host Controller)

Name              : USB Root Hub (USB 3.0)
CreationClassName : Win32_PnPEntity
DeviceId          : USB\ROOT_HUB30\4&152DA58&0&0
Manufacturer      : (Standard USB HUBs)

Name              : Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)
CreationClassName : Win32_USBController
DeviceId          : PCI\VEN_8086&DEV_9D2F&SUBSYS_201F1043&REV_21\3&11583659&0&A0
Manufacturer      : Generic USB xHCI Host Controller

Name              : USB Mass Storage Device
CreationClassName : Win32_USBHub
DeviceId          : USB\VID_0781&PID_5151\077531169C0256D9
Manufacturer      :

Name              : USB Composite Device
CreationClassName : Win32_USBHub
DeviceId          : USB\VID_064E&PID_9700\HF1019-T838-SN03-REV0101
Manufacturer      :

Name              : USB Composite Device
CreationClassName : Win32_USBHub
DeviceId          : USB\VID_03EB&PID_8B0D\5&3478949&0&7
Manufacturer      :

Name              : USB Root Hub (USB 3.0)
CreationClassName : Win32_USBHub
DeviceId          : USB\ROOT_HUB30\4&152DA58&0&0
Manufacturer      :
sebhildebrandt commented 1 month ago

Thank you @pat-encoura ... I will try to mock this input to see what happens ;-)

sebhildebrandt commented 1 month ago

Hi again @pat-encoura ... I mocked your data and it turns out, that I see your USB drive correctly:

Without your drive:

[
  {
    bus: null,
    deviceId: 'PCI\\VEN_8086&DEV_9D2F&SUBSYS_201F1043&REV_21\\3&11583659&0&A0',
    id: 7,
    name: 'Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)',
    type: 'Controller',
    removable: null,
    vendor: null,
    manufacturer: 'Generic USB xHCI Host Controller',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'USB\\VID_064E&PID_9700\\HF1019-T838-SN03-REV0101',
    id: 8,
    name: 'USB Composite Device',
    type: 'Hub',
    removable: null,
    vendor: null,
    manufacturer: '',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'USB\\VID_03EB&PID_8B0D\\5&3478949&0&7',
    id: 9,
    name: 'USB Composite Device',
    type: 'Hub',
    removable: null,
    vendor: null,
    manufacturer: '',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'USB\\ROOT_HUB30\\4&152DA58&0&0',
    id: 10,
    name: 'USB Root Hub (USB 3.0)',
    type: 'Hub',
    removable: null,
    vendor: null,
    manufacturer: '',
    maxPower: null,
    serialNumber: null
  }
]

Without drive connected:

[
  {
    bus: null,
    deviceId: 'USB\\VID_0781&PID_5151\\077531169C0256D9',
    id: 0,
    name: 'USB Mass Storage Device',
    type: 'Storage',
    removable: null,
    vendor: null,
    manufacturer: 'Compatible USB storage device',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'PCI\\VEN_8086&DEV_9D2F&SUBSYS_201F1043&REV_21\\3&11583659&0&A0',
    id: 8,
    name: 'Intel(R) USB 3.0 eXtensible Host Controller - 1.0 (Microsoft)',
    type: 'Controller',
    removable: null,
    vendor: null,
    manufacturer: 'Generic USB xHCI Host Controller',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'USB\\VID_064E&PID_9700\\HF1019-T838-SN03-REV0101',
    id: 10,
    name: 'USB Composite Device',
    type: 'Hub',
    removable: null,
    vendor: null,
    manufacturer: '',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'USB\\VID_03EB&PID_8B0D\\5&3478949&0&7',
    id: 11,
    name: 'USB Composite Device',
    type: 'Hub',
    removable: null,
    vendor: null,
    manufacturer: '',
    maxPower: null,
    serialNumber: null
  },
  {
    bus: null,
    deviceId: 'USB\\ROOT_HUB30\\4&152DA58&0&0',
    id: 12,
    name: 'USB Root Hub (USB 3.0)',
    type: 'Hub',
    removable: null,
    vendor: null,
    manufacturer: '',
    maxPower: null,
    serialNumber: null
  }
]

See first entry ...

I had an unrelated issue (adding duplicate entries to the usb array. This is fixed.

Can you pull the latest code from master and test it again:

git clone https://github.com/sebhildebrandt/systeminformation.git
cd systeminformation
npm run test

Now just press u to get results for the usb() function (with and without your USB drive

Thank you for testing it once again.

sebhildebrandt commented 1 month ago

@pat-encoura I released version 5.23.3 with the small changes that I made ... can you test this again?

pat-encoura commented 1 month ago

@sebhildebrandt Great, just tried on 5.23.3, and si.usb() is now returning the USB drive on Windows:

  {
    "bus": null,
    "deviceId": "USB\\VID_0781&PID_5151\\077531169C0256D9",
    "id": 1,
    "name": "USB Mass Storage Device",
    "type": "Storage",
    "removable": null,
    "vendor": null,
    "manufacturer": "Compatible USB storage device",
    "maxPower": null,
    "serialNumber": null
  }

Thanks for your help on this, love this library!

sebhildebrandt commented 1 month ago

@pat-encoura Thank you for testing it again! So now I can close this issue ;-)