12.0.2 • Published 24 days ago

drivelist v12.0.2

Weekly downloads
14,629
License
Apache-2.0
Repository
github
Last release
24 days ago

drivelist

List all connected drives in your computer, in all major operating systems.

Current Release License Downloads Travis CI status AppVeyor status Dependency status Gitter Chat

Notice that this module does not require admin privileges to get the drives in any supported operating system.

Supports:

  • Windows.
  • GNU/Linux distributions that include util-linux and udev.
  • Mac OS X.

The drivelist core consists of a set of scripts built with technologies that are available by default on the target operating systems (like Bash, VBScript, etc). Each of these scripts attempts to get information about the available drives (and metadata related to them), using any methods the target platform provides, like a combination of diskutil, /proc/mounts, etc. You can find these scripts in the scripts/ directory.

The scripts are then expected to print to stdout all the drive information they have gathered in a predefined way, based on the YAML language. The scripts are expected to output a set of blocks (separated by blank lines), each representing a drive with a set of key/value pairs. The exact keys that we expect are constantly changing while we keep improving this module, but you can see what the currently expected keys are by running the platform script that corresponds to your operating system.

This is how the raw output looks on my MacBook Pro at the time of this writing:

$ ./scripts/darwin.sh
enumerator: diskutil
busType: UNKNOWN
busVersion: "0.0"
device: /dev/disk0
raw: /dev/rdisk0
description: "APPLE SSD TS128E"
error: null
size: 121332826112
blockSize: null
logicalBlockSize: null
mountpoints: []
isReadOnly: False
isSystem: True
isVirtual: null
isRemovable: null
isCard: null
isSCSI: null
isUSB: null
isUAS: null

enumerator: diskutil
busType: UNKNOWN
busVersion: "0.0"
device: /dev/disk2
raw: /dev/rdisk2
description: "SD Card Reader"
error: null
size: 31104958464
blockSize: null
logicalBlockSize: null
mountpoints:
  - path: "/Volumes/Patchwork"
isReadOnly: False
isSystem: False
isVirtual: null
isRemovable: null
isCard: null
isSCSI: null
isUSB: null
isUAS: null

Because of the simplicity of this module's design, supporting a new operating system simply means adding a new script to scripts/ that gathers drive data and outputs something similar to the above example. The challenge with this is that we must ensure all the platform scripts print consistent output.

When the user executes drivelist.list(), the module checks the operating system of the client, and executes the corresponding drive scanning script as a child process. It then parses the YAML output of the script as an array of objects, and returns that to the user.

Examples (the output will vary depending on your machine):

const drivelist = require('drivelist');

drivelist.list((error, drives) => {
  if (error) {
    throw error;
  }

  console.log(drives);
});

Mac OS X:

[{
  enumerator: 'diskutil',
  busType: 'UNKNOWN',
  busVersion: '0.0',
  device: '/dev/disk0',
  raw: '/dev/rdisk0',
  description: 'APPLE SSD TS128E',
  error: null,
  size: 121332826112,
  blockSize: null,
  logicalBlockSize: null,
  mountpoints: [],
  isReadOnly: false,
  isSystem: true,
  isVirtual: null,
  isRemovable: null,
  isCard: null,
  isSCSI: null,
  isUSB: null,
  isUAS: null
}, {
  enumerator: 'diskutil',
  busType: 'UNKNOWN',
  busVersion: '0.0',
  device: '/dev/disk1',
  raw: '/dev/rdisk1',
  description: 'APPLE SSD TS128E',
  error: null,
  size: 120473067520,
  blockSize: null,
  logicalBlockSize: null,
  mountpoints: [
    { path: '/' },
    { path: '/private/var/vm' }
  ],
  isReadOnly: false,
  isSystem: true,
  isVirtual: null,
  isRemovable: null,
  isCard: null,
  isSCSI: null,
  isUSB: null,
  isUAS: null
}, {
  enumerator: 'diskutil',
  busType: 'UNKNOWN',
  busVersion: '0.0',
  device: '/dev/disk2',
  raw: '/dev/rdisk2',
  description: 'SD Card Reader',
  error: null,
  size: 31104958464,
  blockSize: null,
  logicalBlockSize: null,
  mountpoints: [
    { path: '/Volumes/Patchwork' }
  ],
  isReadOnly: false,
  isSystem: false,
  isVirtual: null,
  isRemovable: null,
  isCard: null,
  isSCSI: null,
  isUSB: null,
  isUAS: null
}]

GNU/Linux

[{
  enumerator: 'lsblk',
  busType: 'UNKNOWN',
  busVersion: '0.0',
  device: '/dev/sdb',
  raw: '/dev/sdb',
  description: 'Storage Device',
  error: null,
  size: 31914983424,
  blockSize: null,
  logicalBlockSize: null,
  mountpoints: [{
    path: '/media/jonas/Etcher 1.2.0'
  }],
  isReadOnly: false,
  isSystem: false,
  isVirtual: null,
  isRemovable: null,
  isCard: null,
  isSCSI: null,
  isUSB: null,
  isUAS: null
}, {
  enumerator: 'lsblk',
  busType: 'UNKNOWN',
  busVersion: '0.0',
  device: '/dev/sda',
  raw: '/dev/sda',
  description: 'Samsung SSD 850',
  error: null,
  size: 120034123776,
  blockSize: null,
  logicalBlockSize: null,
  mountpoints: [{
    path: '/'
  }, {
    path: '/boot/efi'
  }],
  isReadOnly: false,
  isSystem: true,
  isVirtual: null,
  isRemovable: null,
  isCard: null,
  isSCSI: null,
  isUSB: null,
  isUAS: null
}]

Windows

[{
  enumerator: 'SCSI',
  busType: 'SATA',
  busVersion: '2.0',
  device: '\\\\?\\scsi#disk&ven_wdc&prod_wd1600bevs-07rst#4&5a60d67&0&000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}',
  raw: '\\\\.\\PhysicalDrive0',
  description: 'WDC WD1600BEVS-07RST0',
  error: null,
  size: 160041885696,
  blockSize: 512,
  logicalBlockSize: 512,
  mountpoints: [{
    path: 'D:\\'
  }],
  isReadOnly: false,
  isSystem: true,
  isVirtual: false,
  isRemovable: false,
  isCard: false,
  isSCSI: true,
  isUSB: false,
  isUAS: false
}, {
  enumerator: 'SD',
  busType: 'SD',
  busVersion: '2.0',
  device: '\\\\?\\sd#disk&generic&sc16g&8.0#5&c518b2e&0&c3964099&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}',
  raw: '\\\\.\\PhysicalDrive4',
  description: 'Generic SC16G SD Card',
  error: null,
  size: 15931539456,
  blockSize: 4096,
  logicalBlockSize: 512,
  mountpoints: [{
    path: 'G:\\'
  }, {
    path: 'H:\\'
  }],
  isReadOnly: false,
  isSystem: false,
  isVirtual: false,
  isRemovable: true,
  isCard: true,
  isSCSI: true,
  isUSB: false,
  isUAS: false
}, {
  enumerator: 'SCSI',
  busType: 'USB',
  busVersion: '2.0',
  device: '\\\\?\\scsi#disk&ven_usb3.0&prod_#000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}',
  raw: '\\\\.\\PhysicalDrive2',
  description: 'USB3.0  SCSI Disk Device',
  error: null,
  size: 500107862016,
  blockSize: 4096,
  logicalBlockSize: 512,
  mountpoints: [{
    path: 'E:\\'
  }],
  isReadOnly: false,
  isSystem: false,
  isVirtual: false,
  isRemovable: true,
  isCard: false,
  isSCSI: true,
  isUSB: false,
  isUAS: true
}, {
  enumerator: 'SCSI',
  busType: 'SATA',
  busVersion: '2.0',
  device: '\\\\?\\scsi#disk&ven_samsung&prod_ssd_850_evo_m.2#4&5a60d67&0&020000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}',
  raw: '\\\\.\\PhysicalDrive1',
  description: 'Samsung SSD 850 EVO M.2 120GB',
  error: null,
  size: 120034123776,
  blockSize: 512,
  logicalBlockSize: 512,
  mountpoints: [{
    path: 'C:\\'
  }],
  isReadOnly: false,
  isSystem: true,
  isVirtual: false,
  isRemovable: false,
  isCard: false,
  isSCSI: true,
  isUSB: false,
  isUAS: false
}, {
  enumerator: 'USBSTOR',
  busType: 'USB',
  busVersion: '2.0',
  device: '\\\\?\\usbstor#disk&ven_disk&prod_name&rev_ax10#0012345667888&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}',
  raw: '\\\\.\\PhysicalDrive3',
  description: 'Disk Name USB Device',
  error: null,
  size: 1000204886016,
  blockSize: 512,
  logicalBlockSize: 512,
  mountpoints: [{
    path: 'F:\\'
  }],
  isReadOnly: false,
  isSystem: false,
  isVirtual: false,
  isRemovable: true,
  isCard: false,
  isSCSI: false,
  isUSB: true,
  isUAS: false
}]

Installation

Install drivelist by running:

$ npm install --save drivelist

Documentation

drivelist.list(callback)

Kind: static method of drivelist
Summary: List available drives
Access: public

ParamTypeDescription
callbackfunctioncallback (error, drives)

Example

const drivelist = require('drivelist');

drivelist.list((error, drives) => {
  if (error) {
    throw error;
  }

  drives.forEach((drive) => {
    console.log(drive);
  });
});

Tests

Run the test suite by doing:

$ npm test

Contribute

We're looking forward to support more operating systems. Please raise an issue or even better, send a PR to increase support!

Before submitting a PR, please make sure that you include tests, and that the linter runs without any warning:

$ npm run lint

Execute the following command after making any changes to the platform scripts:

npm run compile-scripts

Support

If you're having any problem, please raise an issue on GitHub.

License

The project is licensed under the Apache 2.0 license.

12.0.0

24 days ago

12.0.1

24 days ago

12.0.2

24 days ago

11.2.2

2 months ago

11.2.1

3 months ago

11.2.0

3 months ago

11.0.4

1 year ago

11.0.2

2 years ago

11.0.3

1 year ago

11.0.1

2 years ago

11.1.0

1 year ago

10.0.0

2 years ago

11.0.0

2 years ago

9.2.4

3 years ago

9.2.3

3 years ago

9.2.2

3 years ago

9.2.1

3 years ago

9.2.0

3 years ago

9.1.0

4 years ago

9.0.2

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

8.0.10

4 years ago

8.0.9

4 years ago

8.0.8

4 years ago

8.0.7

5 years ago

8.0.6

5 years ago

8.0.5

5 years ago

8.0.4

5 years ago

8.0.3

5 years ago

8.0.2

5 years ago

8.0.1

5 years ago

8.0.0

5 years ago

7.0.3

5 years ago

7.0.2

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

6.4.6

5 years ago

6.4.5

5 years ago

6.4.4

5 years ago

6.4.3

6 years ago

6.4.2

6 years ago

6.4.1

6 years ago

6.4.0

6 years ago

6.3.2

6 years ago

6.3.1

6 years ago

6.3.0

6 years ago

6.2.5

6 years ago

6.2.4

6 years ago

6.2.3

6 years ago

6.2.2

6 years ago

6.2.1

6 years ago

6.2.0

6 years ago

6.1.8

6 years ago

6.1.7

6 years ago

6.1.6

6 years ago

6.1.5

6 years ago

6.1.4

6 years ago

6.1.3

6 years ago

6.1.2

6 years ago

6.1.1

6 years ago

6.1.0

6 years ago

6.0.5

6 years ago

6.0.4

6 years ago

6.0.3

6 years ago

6.0.2

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.2.12

6 years ago

5.2.11

6 years ago

5.2.10

6 years ago

5.2.9

6 years ago

5.2.8

6 years ago

5.2.7

6 years ago

5.2.6

7 years ago

5.2.5

7 years ago

5.2.4

7 years ago

5.2.3

7 years ago

5.2.2

7 years ago

5.2.1

7 years ago

5.2.0

7 years ago

5.1.8

7 years ago

5.1.7

7 years ago

5.1.6

7 years ago

5.1.5

7 years ago

5.1.4

7 years ago

5.1.3

7 years ago

5.1.2

7 years ago

5.1.1

7 years ago

5.0.28

7 years ago

5.1.0

7 years ago

5.0.27

7 years ago

5.0.26

7 years ago

5.0.25

7 years ago

5.0.22

7 years ago

5.0.21

7 years ago

5.0.20

7 years ago

5.0.19

7 years ago

5.0.18

7 years ago

5.0.17

7 years ago

5.0.16

7 years ago

5.0.15

7 years ago

5.0.14

7 years ago

5.0.13

7 years ago

5.0.12

7 years ago

5.0.11

7 years ago

5.0.10

7 years ago

5.0.9

7 years ago

5.0.8

7 years ago

5.0.7

7 years ago

5.0.6

7 years ago

5.0.5

7 years ago

5.0.4

7 years ago

5.0.3

7 years ago

5.0.2

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.0.0

8 years ago

3.3.4

8 years ago

3.3.3

8 years ago

3.3.2

8 years ago

3.3.1

8 years ago

3.3.0

8 years ago

3.2.6

8 years ago

3.2.5

8 years ago

3.2.4

8 years ago

3.2.3

8 years ago

3.2.2

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.14

8 years ago

2.0.13

8 years ago

2.0.12

8 years ago

2.0.11

8 years ago

2.0.10

8 years ago

2.0.9

8 years ago

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago