Find volume serial number using OSX apis

289 Views Asked by At

I am looking for a way to get the volume serial number (https://en.wikipedia.org/wiki/Volume_serial_number) for volumes which represent USB drive partitions on OSX, similar to what this function does on Windows (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa), in particular the lpVolumeSerialNumber.

I have looked around in Disk Arbitration but found nothing but I am not limited to using that API. Any hint is much appreciated.

Thanks

1

There are 1 best solutions below

1
vadian On

On macOS there is a Volume UUID but not a serial number.

You can get the Volume UUID directly from its URL

let url = URL(fileURLWithPath: "/Volumes/MyDisk")
let uuidString = try? url.resourceValues(forKeys: [.volumeUUIDStringKey]).volumeUUIDString