1

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

user1573546
  • 523
  • 5
  • 13

1 Answers1

0

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
vadian
  • 274,689
  • 30
  • 353
  • 361
  • Thanks for the quick answer. I am already using the volumeUUID in my code but I am running into occasional issues with certain SD-Card readers that return the same volumeUUID for multiple cards in the reader. That's why I wanted to try accessing the volume serial number which obviously is in the file system. – user1573546 Nov 08 '19 at 21:09