How to get serial number from Mac hard disks?

后端 未结 7 798
遇见更好的自我
遇见更好的自我 2020-12-01 10:10

Is there an easy way to get the serial number of all the hard disks in a Mac using an API?

Basically, I\'m looking for a unique identifier for the hard disk with whi

7条回答
  •  难免孤独
    2020-12-01 10:32

    I think it's better to get the Volume UUID (which appears in the Disk Utility, for example.) UUID can be obtained using the Disk Arbitration framework, which is slightly higher-level than IOKit and easier to use. Create DADiskRef using DADiskCreateFromBSDName, and use DADiskCopyDescription to get the info dictionary, and look up the key kDADiskDescriptionMediaUUIDKey. Info on the mount point etc. can be obtained by statfs.

    That said, it might be easier just to invoke the command-line utility diskutil with the option -plist to get the info in the plist format.

    The sample code FSMegaInfo might also be instructive how to get much more info about a disk.

提交回复
热议问题