Get a list of mounted devices

Hi, ALL,
I’d like to get a list of the mounted devices on the system along with the device type.

How can I do that?

Thank you.

The gio mount -li cmd might be what you are looking for.

Hi,
Im looking for a C/C++ solution.
Or you suggesting to call exec() with this command and parse the output?

Thank you.

See the Gio.VolumeMonitor API.

@oholy ,
Thx that helped.
Is there a way to know if the drive is read-only or a networked one?

Thank you.

You can use the GMount and GVolume interfaces.

If you want to know if a volume is read-only, you can get the root and then use g_file_query_info() with access attributes.

@ebassi ,
Thx for the info.
What about network drive check? Meaning the remote one and not the current one…

Thank you.

Emmanuelle,

In addition:

The page at Gio.Volume, doesn’t explain how to create a GVolume object. Basically, I’m looking for something like:

g_volume_new()/g_volume_new_from_string( "cdrom" );

How do I do that?

Or I get the volumes out of “volume manager” and then compare the name the string I’m interested in?

Thank you.

What about network drive check? Meaning the remote one and not the current one…

g_strcmp0 (g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS), "network") == 0?

Or I get the volumes out of “volume manager” and then compare the name the string I’m interested in?

Yes, this is the way how it works.

@oholy ,
Could you please give a link to all this G_VOLUME_IDENTIFIER_KIND_ enumeration with explanation of what everyone does?

Thank you.

It is a string constant, not an enumeration. See Volume Identifiers and the various other VOLUME_IDENTIFIER_KIND_* at the bottom of gio Constants.

Hi,
From the page GIcon: GIO Reference Manual, I see that the GIcon (a pointer returned from g_volume_get_icon() is NOT an actual image/pixbuf. And the application needs to handle different cases in order to get access to the actual bitmap. However there is no access to which type it is using at the moment.

Is there a way to acquire an actual image?

Thank you.

Depending on the type of GIcon you’re getting back, you’ll have to deal with different image loading mechanisms. For instance, if you’re getting a GThemedIcon back, then you’ll have to use an icon theme loader, like GtkIconTheme; for a GFileIcon, you can get the GFile of the image; for a GBytesIcon, you can extract the image data from the instance.

@ebassi ,

And how do I know what type of GIcon I am getting?

g_volume_get_icon() just gives me a GIcon…

Thank you.

You can do it with the check type macros of GObject, like this:

icon = g_volume_get_icon() ;
if (G_IS_THEMED_ICON (icon))
  //use GtkIconTheme api
else if (G_IS_FILE_ICON (icon))
  //user GFileIcon api
else if (G_IS_BYTES_ICON (icon))
  //user GFileIcon api

@nbenitez ,
So second and third conditions both use GFileIcon?

Now I understand for the second one I can use:

GFile *file = g_file_icon_get_file( (GFileIcon *) icon );

and then use

GdkPixbuf *image gdk_pixbuf_new_from_file( file, error );

But I am not sure how to do that for the third condition (BYTES_ICON).

Is it also convertible to GFileIcon?

Thank you.

Sorry have another related question.

The page at GVolume: GIO Reference Manual shows there are 2 different icons: icon and symbolic icon.

What is the difference between them?

Thank you.

Yes was a typo in there, following code should clarify your doubt:

icon = g_volume_get_icon() ;
if (G_IS_THEMED_ICON (icon))
   GThemedIcon *ticon = G_THEMED_ICON (icon); //use GtkIconTheme api
else if (G_IS_FILE_ICON (icon))
   GFileIcon *ficon = G_FILE_ICON (icon); //use GFileIcon api
else if (G_IS_BYTES_ICON (icon))
   GBytesIcon *bicon = G_BYTES_ICON (icon);//use GBytesIcon api

Symbolic is a special icon style which offers better contrast (accesibility) see UI Icons - GNOME Human Interface Guidelines documentation