I have a path to a partition. How can I retrieve UUID of that partition programatically without using terminal commands? An example will be more helpful.
-
This might help you.(http://stackoverflow.com/questions/329925/extracting-mac-addresses-from-uuids) – iammilind Jul 04 '11 at 05:28
-
3@iammilind : That's MAC, a 48 bit network address. This seems to be Apple Mac OSX. – MSalters Jul 04 '11 at 09:39
-
Your question says **partition** but it's tagged with **volume**. The UUID of a partition is different from the UUID of the "volume" that is in that partition. For example, using the answer of @user57368 : `$ diskutil info /Volumes/Mulch | grep UUID` ` Volume UUID: E1EAC65D-47A2-3AB3-BCE5-BA25FD2C6A30` ` Disk / Partition UUID: E24032E3-DC36-470E-86B9-C9664026F8EC` – FutureNerd Oct 18 '15 at 20:55
3 Answers
$ diskutil info / | grep UUID
Running this from C is left as an exercise for the reader.
If you want a partition other than the root, you can specify the mount point or device name (eg. disk0s2) in place of /
.

- 5,675
- 28
- 39
-
Thank you for the terminal command. Can u tell me how(is there a way) to do that only using c or c++ without using terminal commands. – surendran Jul 15 '11 at 07:35
You can use the Disk Arbitration framework (Apple reference). There is also a good summary at this blog by Chris Suter.
You can get the UUID by using the kDADiskDescriptionMediaUUIDKey. Aaron Burghardt described it well in this mailing list thread. Here is a quote from that link:
Once you have the DADisk, use DADiskCopyDescription to get a dictionary of properties, in which you will find the UUID with the key kDADiskDescriptionMediaUUIDKey (see DADisk.h for other keys that may be of interest). Note, a DADisk is a wrapper around an IOMedia object and the description dictionary corresponds directly to the properties in the IOMedia object. Also, CFShow() is useful for printing the description dictionary to the console.

- 3,485
- 2
- 21
- 25
I think the easiest is to use polkit
Download the DiskWatcher.h and .m from http://polkit.googlecode.com/svn/trunk/FileSystem/DiskWatcher.h http://polkit.googlecode.com/svn/trunk/FileSystem/DiskWatcher.m
Add it to your project (It has no ARC so add -fno-objc-arc flag if you use ARC)
Add DiskArbiratation framework You can use
+ (NSString*) diskIdentifierForPath:(NSString*)path;
NSString *UUID1 = [DiskWatcher diskIdentifierForPath:@"/Volumes/Backup900GB"];

- 21,461
- 5
- 90
- 86