+/**
+ * g_unix_mount_guess_should_display:
+ * @mount_entry: a #GUnixMountEntry
+ *
+ * Guesses whether a Unix mount should be displayed in the UI.
+ *
+ * Returns: %TRUE if @mount_entry is deemed to be displayable.
+ */
+gboolean
+g_unix_mount_guess_should_display (GUnixMountEntry *mount_entry)
+{
+ const char *mount_path;
+ const gchar *user_name;
+ gsize user_name_len;
+
+ /* Never display internal mountpoints */
+ if (g_unix_mount_is_system_internal (mount_entry))
+ return FALSE;
+
+ /* Only display things in /media (which are generally user mountable)
+ and home dir (fuse stuff) and /run/media/$USER */
+ mount_path = mount_entry->mount_path;
+ if (mount_path != NULL)
+ {
+ gboolean is_in_runtime_dir = FALSE;
+ /* Hide mounts within a dot path, suppose it was a purpose to hide this mount */
+ if (g_strstr_len (mount_path, -1, "/.") != NULL)
+ return FALSE;
+
+ /* Check /run/media/$USER/ */
+ user_name = g_get_user_name ();
+ user_name_len = strlen (user_name);
+ if (strncmp (mount_path, "/run/media/", sizeof ("/run/media/") - 1) == 0 &&
+ strncmp (mount_path + sizeof ("/run/media/") - 1, user_name, user_name_len) == 0 &&
+ mount_path[sizeof ("/run/media/") - 1 + user_name_len] == '/')
+ is_in_runtime_dir = TRUE;
+
+ if (is_in_runtime_dir || g_str_has_prefix (mount_path, "/media/"))
+ {
+ char *path;
+ /* Avoid displaying mounts that are not accessible to the user.
+ *
+ * See http://bugzilla.gnome.org/show_bug.cgi?id=526320 for why we
+ * want to avoid g_access() for mount points which can potentially
+ * block or fail stat()'ing, such as network mounts.
+ */
+ path = g_path_get_dirname (mount_path);
+ if (g_str_has_prefix (path, "/media/"))
+ {
+ if (g_access (path, R_OK|X_OK) != 0)
+ {
+ g_free (path);
+ return FALSE;
+ }
+ }
+ g_free (path);
+
+ if (mount_entry->device_path && mount_entry->device_path[0] == '/')
+ {
+ struct stat st;
+ if (g_stat (mount_entry->device_path, &st) == 0 &&
+ S_ISBLK(st.st_mode) &&
+ g_access (mount_path, R_OK|X_OK) != 0)
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ if (g_str_has_prefix (mount_path, g_get_home_dir ()) &&
+ mount_path[strlen (g_get_home_dir())] == G_DIR_SEPARATOR)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ * g_unix_mount_point_guess_can_eject:
+ * @mount_point: a #GUnixMountPoint
+ *
+ * Guesses whether a Unix mount point can be ejected.
+ *
+ * Returns: %TRUE if @mount_point is deemed to be ejectable.
+ */