Documentation
¶
Overview ¶
Package driveutil provides comprehensive Windows drive management utilities including drive enumeration, metadata extraction, monitoring, and utility functions.
This package is Windows-specific and uses the Windows API to interact with drives. It supports both fixed and removable drives, providing detailed information about each drive including serial numbers, labels, and types.
Key features:
- Drive detection and enumeration
- Volume serial number extraction
- Drive monitoring with callback support
- Drive existence checking
- Comprehensive drive metadata (label, type, serial)
The DriveStore type provides stateful drive monitoring, tracking drives by their unique combination of drive letter and serial number to detect insertions and removals.
Example usage:
// List all drives
drives := driveutil.ListDrives()
for _, drive := range drives {
fmt.Printf("Drive: %s, Label: %s, Serial: %08X\n",
drive.Letter, drive.Label, drive.Serial)
}
// Monitor for new drives
store := make(driveutil.DriveStore)
store.DetectDrives(func(drive string, serial uint32) {
fmt.Printf("New drive detected: %s (Serial: %08X)\n", drive, serial)
})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetVolumeSerialNumber ¶
GetVolumeSerialNumber returns the serial number for a given drive root.
Types ¶
type DriveInfo ¶
type DriveInfo struct {
Letter string
Label string
Serial uint32
Type uint32 // windows.DRIVE_FIXED, DRIVE_REMOVABLE, etc.
}
DriveInfo represents information about a drive.
func ListDrives ¶
func ListDrives() []DriveInfo
ListDrives returns a slice of DriveInfo for all present fixed/removable drives.
type DriveStore ¶
DriveStore keeps track of currently detected drives by their unique ID.
func (DriveStore) DetectDrives ¶
func (store DriveStore) DetectDrives(onNewDrive func(drive string, serial uint32))
DetectDrives enumerates all logical drives, checks their type, and gets their serial number. Calls the provided callback for each new drive detected.
func (DriveStore) MonitorDrives ¶
func (store DriveStore) MonitorDrives(onNewDrive func(drive string, serial uint32), interval time.Duration)
MonitorDrives calls DetectDrives in a loop with a sleep interval.