Difference between volume and drive

@pwithnall ,
All I needed to do is grab all volumes in a list of string.
Then later on display them in a tree like fashion with the appropriate (themed DPI aware) icon.

This task was easily achievable from the monitor, but turns out I can’t do that.

Any idea what to do and how to achieve what I’m looking for?

Basically I’m looking for an analog of tree like control that displays all available volumes (hard drives, CD/DVD, USB, floppy, network drives) with the appropriate icons and then the directory tree of the volume alone with my selected file.

I was thinking it is a very easy task, but apparently it is not…

Thank you.

Yes. This is covered in the documentation: GioUnix – 2.0: UNIX Mounts

Yes, / is not something any non-hacker would need to be listed in a file chooser. All the paths which are interesting to users are below /.

I can’t write the code for you. My best suggestion would be to find an app which already does what you want, or close to it, and read the code for that app to learn from it. You could also copy their code, if it’s close enough to what you want, as long as you retain the copyright notice and obey the code’s license.

Reading the GIO and gio-unix documentation in depth will also help you. Several of the questions you’ve asked above are covered in the documentation.

I don’t think I would have ever described this as an easy task. The mount hierarchy on Linux can easily be quite complicated, especially with the common use of bind mounts now.

@pwithnall ,

Imagine a scenario where you attach the USB stick and mount it somewhere.

I for one would be interested in 2 different ‘/’ folder, just like on Windows to separate the devices.

Or imagine you have a CD/DVD device without the disk. Many programs show it as a separate entity incluidng Files/Nautilus. And when your insert the disk and the drive is mounted - you need to see it in the tree/list/whatever as ‘/’.

Those are legitimate scenarios where one should have a visibiluity of multiple ‘/’ things

I didn’t ask you to. :wink:
I just asked for a suggestion on how to achieve what I’m looking for.
I understand *nix is NOT Windows. Those are 2 completely different beasts. But when you try to write cross-platform app, you try really hard for it to behave the same way functionally and preferably from the UI perspective as one depend on the other (not vice versa of course)…

I will try to do just that.
So GIO and gio-unix are 2 separate beasts, right? Because even the API is different (looking at GioUnixMount and GioMount)…

Thank you.

@pwithnall ,
Is there a GUnixVolume class?

Thank you.

According to Google GUnixVolume is available for Android only…

Not good. :wink:

Is there a way to go from GUnixMount to GMount? To get GVolume?

Thank you.

Maybe we’re talking cross-purposes here. You seem to be expecting there to be multiple / paths, right? That’s not the case on Linux. There is one root directory, /, and mounts (USB sticks, CDs, whatever) are mounted beneath that. USB sticks will typically be mounted at /run/media/$USER/$DISK_NAME for example.

Mounts like that should be listed by GVolumeMonitor as they are interesting. But the root directory, /, should not be, because it’s not interesting to the user. It’s always there and only contains paths which are incomprehensible to the average user, and can’t be modified by them.

Apologies if you understand all that already, but your choice of terminology is suggesting otherwise to me.

Unfortunately, working out the best way to solve a problem is 90% of the work required to write the code.

They are two separate libraries, but libgio-unix depends on libgio. GMount is an interface (defined in libgio) which is implemented by GUnixMount (defined in libgio-unix).

Yes. Its API is not public, but it is returned as an instance of the GVolume interface by the mount/volume APIs (which act as factories for it, to use the Java OOP terminology).

I don’t know where you found that but it’s not true. GUnixVolume is used on all Unix/Linux platforms.

GUnixMount implements the GMount interface, so you can cast to it: G_MOUNT (my_unix_mount). If you’re not familiar with how GObject inheritance, interfaces and casting work, please consider reading the GObject tutorial.

@pwithnall ,

My word choice is very poor :wink:
What I meant is the following:

When working in Windows machine that have floppy, one hard drive and one CD-ROM, I will see “A:” for a floppy, “C:” for a hard drive and “D:” for a CD-ROM, Of course if there is no diskette/disks in floppy/CD-ROM, trying to access them willl fail, but the device will be there.

What I’d like to see is something similar - “Floppy” for a floppy drive/“A:”, “Hard drive” for a hard drive/“C:” and “CD-ROM” for a CD-ROM/“D:”.
Of course the actual definition could be different, but you should get the idea.

This is how cross-platform development should work - you have the same design from the UI perspective, but functionality of course will be slightly different, based on the platform restrictions.

Now I understand that the regular user don’t have any business looking into /dev or /proc or any other system directory. And if the IT people have set appropriate rules of engagement - it will never happen.

Just like C:\ drive is always there and can’t be changed/assigned a new letter for the volume/disk.
Regular user shouldn’t care that the C: drive is called C: drive and it contains folder called Windows which has all the system libraries and executables - he never should see it, because its not interesting for them. However, it is there, it is displayed and we can’t do anything in regards to that.

Now on Linux, when you open “Files”/“Nautilus” and click “Other Locations” (I’m currently at work and looking at my RHEL8 GNOME), you will see “Computer”, and then clicking on it, you will get to see the whole tree. With the appopriate folder icons for links and folders with only “root” access. The other OSes have the same functionality.

Yes. 200% agree. :wink:

OK, good to know.

You mean “Java-sucks”, right. :wink:
I much prefer C++, but it suffice for this as an explanation.

This point is mute as this class/interface is not public.
But… if you go to google and type GUnixVolume you will get a lot of links to Android. Here is one: gio/gunixvolume.c - platform/external/bluetooth/glib - Git at Google.

I will need to comprehend all this. :wink:
Thank you for all this information. I clarified some things on what I expect in my software to see it should look like.
When I come home tonight I will re-read this nswer, especially the last portion and will try to write some code.

Thank you.

This has been overhauled with GNOME 47. The “Other Locations” view showed both connected local drives and network locations. “Other Locations” has been replaced in GNOME 47. There’s a new, more intuitive, Network view for network locations. And for removable/extra local drives when you connect them they show in the left sidebar. See the description and screenshot in the release notes here: GNOME Release Notes

You can still see the whole tree by typing / in the location bar.

@pwithnall ,

Below is the screenshot I see from my home laptop running GNOME on X.
No gvfs-show option is set in the fstab.

I presume that the ‘/’ on the right indicate GUnixMount.get_device_path().
The “Gentoo” on the left is what GUnixMount.guess_name() will return.

And now I can get to the drive from GUnixVolume, right?

Thank you.

You can find that out by reading the code for Nautilus. Try git grep get_device_path or git grep g_unix_mount to find the right areas of the code.

@pwithnall ,

Following code:

    GList *drives = g_volume_monitor_get_connected_drives( monitor );
    for( GList *d = drives; d != nullptr; d = d->next )
    {
        GDrive *drive = d->data;
        volumelist = g_drive_get_volumes( drive );
    }

results in the:

error: invalid conversion from ‘void*’ to ‘GDrive*’ {aka ‘_GDrive*’} [-fpermissive]
   23 |         volumelist = g_drive_get_volumes( drive );
      |                                           ^~~~~
      |                                           |
      |                                           void*

Doing g_drive_get_volumes( (GDrive *) drive ); works, but shouldn’t be necessary AFAICT, as documentation clearly states that function return list of GDrive objects…

I’m definitely missing something… :wink:

What am I missing?

This code is basically the same as in Nautilus…

Thank you.

GList is a generic data structure, so cannot have a specific pointer type for every element type it could be used with. You need the cast.

Use G_DRIVE (drive) instead of (GDrive *) drive to get runtime type checking too.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.