Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import DiskArbitration
  2.  
  3. func volumeUUIDForPath(path: String) -> String?
  4. {
  5. var retval: String?
  6.  
  7. if let session = DASessionCreate(kCFAllocatorDefault)
  8. {
  9. let fsStats = UnsafeMutablePointer<statfs>.alloc(1)
  10. defer { fsStats.destroy(1) }
  11. if statfs((path as NSString).UTF8String, fsStats) == 0
  12. {
  13. let deviceName = withUnsafePointer(&fsStats.memory.f_mntfromname,
  14. {
  15. (ptr) -> String? in
  16. let int8Ptr = unsafeBitCast(ptr, UnsafePointer<Int8>.self)
  17. return String.fromCString(int8Ptr)
  18. })
  19.  
  20. if let device = deviceName,
  21. disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, device),
  22. description = DADiskCopyDescription(disk)
  23. {
  24. let myDict = description as NSDictionary
  25. let uuid = myDict[kDADiskDescriptionVolumeUUIDKey as String /* "DAVolumeUUIDD" */] as! CFUUID
  26. retval = CFUUIDCreateString(kCFAllocatorDefault, uuid) as String
  27. }
  28. else { retval = "" }
  29. }
  30. }
  31.  
  32. return retval
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement