简体   繁体   中英

Find volume serial number using OSX apis

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://docs.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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM