2

I need to be able to get the partition/filesystem UUID of a partition, similar to how you can with VOL in WinDOS and ls -l /dev/disks/by-partuuid in *nix, but with C# code. What's the best way to do this?

For reference, I need to be able to get the UUID from either the current directory, or the "closest" mount upwards.

EDIT: My bad, should've said this up front: it needs to run on Mono.

Nathan Ringo
  • 973
  • 2
  • 10
  • 30
  • Then I guess WMI is out of the question... – Mike de Klerk Aug 26 '13 at 05:14
  • System.Management exists, if that's what you're referencing. – Nathan Ringo Aug 26 '13 at 05:21
  • @tikking1 I was searching in `WMI` (Windows Management Instrumentation) till you updated the post it should be supported by mono. I doubt `WMI` is supported on Linux/Mac. So the `System.Management` namespace might be there, I doubt it supports the `WMI` queries: http://stackoverflow.com/questions/1003355/the-mono-net-framework-and-wmi – Mike de Klerk Aug 26 '13 at 05:58

2 Answers2

2

You can write the code for both platforms and then decide at runtime based on Environment.OSVersion.Platform which one to use. Make sure you write the implementations in separate methods (or classes), that way the runtime won't attempt to load the pinvoked libraries for the wrong platform.

For windows you can use the GetVolumeInformation or the WMI as described in the other answer. For linux you can use the directory you mentioned in your question possibly in conjunction with pinvoking readlink or using the Mono.Posix assembly.

Jester
  • 56,577
  • 4
  • 81
  • 125
0

You may need to P/Invoke GetVolumeInformation function.

Jake Lin
  • 11,146
  • 6
  • 29
  • 40