omerbyrk / gousbdrivedetector

Detecting USB Storage Drives in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detecting USB Storage Drives in Go

GoDoc

Simple API to detect USB Storage device for Go. Works OS X, Linux and (with some issues, see note below) on Windows.

Usage

Check the example folder.

Issues with some USB flash drives on Windows

On Windows, we use the following command to detect removable media on the system:

wmic logicaldisk where drivetype=2 get deviceid

This checks for a special bit descriptor on the flash drive which indicates that the USB flash drive is a removable device. This should work as expected on most new flash drives. On some older drives, this bit may not be set leading to drives getting recognized as a local disk instead of a removable drive, which can lead to a false negative.

Credits

The code was inspired by USB Drive Detector, which is written for Java.

About

Detecting USB Storage Drives in Go

License:MIT License


Languages

Language:Go 100.0%