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.
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.