How to programmatically retrieve storage disk information in Linux? (C # MONO)

I need to programmatically get all the drives for storage on a Linux system with the following fields:

  • Way
  • File system (FAT32, NTFS, etc.)
  • Containing physical disk

It should support all common types of storage: hard drives, Disk-On-Keys, CdRom, Dvd, etc.

How to do this from C # to work well with MONO?

+3
source share
1 answer

. /dev/disk/by -path. /dev. , gudev - . glib-sharp, , gtk-sharp2 ( ). , :

GLib.GType.Init();
gudev.GUdevClient a=new gudev.GUdevClient(null);            
gudev.GUdevDevice dev=a.QueryByDeviceFile("/dev/disk/by-path/--some-file--");
Console.WriteLine (dev.GetProperty("ID_FS_TYPE")); //will output the file system, eg. ntfs
Console.WrtieLine(dev.GetProperty("ID_FS_LABEL")); //will output the label of the disk

, . "Mono.Posix" Mono.Unix.UnixSymbolicLinkInfo, . :

Mono.Unix.UnixSymbolicLinkInfo sym=new Mono.Unix.UnixSymbolicLinkInfo("/dev/disk/by-path/--some-file--");
Console.WriteLine(sym.ContentsPath); //Will output something like ../../sda1

../.. /dev /etc/mtab. :

/dev/file mountpoint stuff-you-don't-care-about

. /n . - , , .

+3

Source: https://habr.com/ru/post/1737807/


All Articles