简体   繁体   English

使用 OSX api 查找卷序列号

[英]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 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 ),尤其是 lpVolumeSerialNumber。

I have looked around in Disk Arbitration but found nothing but I am not limited to using that API.我在磁盘仲裁中环顾四周,但一无所获,但我不仅限于使用 API。 Any hint is much appreciated.任何提示都非常感谢。

Thanks谢谢

On macOS there is a Volume UUID but not a serial number .在 macOS 上,有一个 Volume UUID 但没有序列号

You can get the Volume UUID directly from its URL您可以直接从其 URL 获取 Volume UUID

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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