Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External media connected via USB #6

Open
vasyl-shumskyi opened this issue Nov 27, 2017 · 2 comments
Open

External media connected via USB #6

vasyl-shumskyi opened this issue Nov 27, 2017 · 2 comments

Comments

@vasyl-shumskyi
Copy link

vasyl-shumskyi commented Nov 27, 2017

Is it possible to detect external media connected via USB and process such disks or flash drives separately?

Like so:

{ parts:
   [ { free: 496592740352,
       size: 539028877312,
       place: 'X:',
       letter: 'X:',
       usb: true,
       label: 'My Flash' } ]

Thanks!

@int0h
Copy link
Owner

int0h commented Nov 27, 2017

For now I can say that it's much harder to implement than labels for parts. Furthermore I need to provide the same functionality for unix based system (and mac-OS) because I'm trying to maintain the project fully cross-platform. Additionally it's harder to test properly (I need to test it on a few platforms with a few device types (flashdrive, external hdd storage etc.)).

I would say I cannot see for now any way of detecting type of a storage without huge overhead (in times both code and performance).

As for me It could be a good idea for the separate project. Let's say media-info which could take a place in terms hdd-space (cross-platform string like: X:, /dev/sda2, etc.) and returns something ilke this:

{
    type: 'flashdrive',
    interface: 'usb',
    filesystem: 'ntfs'
    ...
}

or

{
    type: 'ssd',
    interface: 'SCSI',
    filesystem: 'ext4'
    ...
}

Speaking about your case, I suggest you don't need support of unix based system (surely I can be wrong) thus It'd be much easier for you to implement that logic for the only one platform. https://ardamis.com/2012/08/21/getting-a-list-of-logical-and-physical-drives-from-the-command-line/ here's the article about wmic util (which output is used in hdd-space internally), I hope that will help you.

It's not a final decision and we can discuss it further.

@vasyl-shumskyi
Copy link
Author

vasyl-shumskyi commented Nov 27, 2017

Unfortunately, I do need USB-detection cross-platform :-]

Earlier i've handled all 3 platforms via and @sindresorhus/df and one of wmic npms. Until discovered you nice cross-platform module. So switched to it.

https://www.npmjs.com/package/@sindresorhus/df (linux, darwin)

My first thoughts was to track on *nix platforms via mount-points somehow

 if (process.platform == 'linux')
                return  
                        disk.place.startsWith('/media') || 
                        disk.place.startsWith('/mnt') || 
                        disk.place.startsWith('/mount')

But I'm not pretty sure how to handle this on win32, since place will be just another letter. So declined this solution.

Since I need to find a way to detect USB flash storages mostly and use appropriate icon for them, I thought it would be fine to use same hdd-icon for removable and internal hard drives. But its not always will be quite true to track as flash storage anything with a size < 64G, since there can be smaller partitions on Linux.

Cross-platform drivelist seems to detect flash-storages via system: true/false but its not showing free/used space:
https://www.npmjs.com/package/drivelist

So I believe there should be the way to detect connected interface somehow

Related issues:
Detect a drive type
balena-io-modules/drivelist#64
Removable drive
balena-io-modules/drivelist#18

Thanks for you help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants