diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt index 0a35f9541..753317eb4 100644 --- a/docs/reference/gio/gio-sections.txt +++ b/docs/reference/gio/gio-sections.txt @@ -1569,6 +1569,7 @@ g_unix_mount_point_guess_symbolic_icon g_unix_mount_point_guess_name g_unix_mount_point_guess_can_eject g_unix_mount_points_get +g_unix_mount_point_at g_unix_mounts_get g_unix_mount_at g_unix_mounts_changed_since diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index e0dc51847..3514e2e8e 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -1604,6 +1604,52 @@ g_unix_mount_points_get (guint64 *time_read) return _g_get_unix_mount_points (); } +/** + * g_unix_mount_point_at: + * @mount_path: (type filename): path for a possible unix mount point. + * @time_read: (out) (optional): guint64 to contain a timestamp. + * + * Gets a #GUnixMountPoint for a given mount path. If @time_read is set, it + * will be filled with a unix timestamp for checking if the mount points have + * changed since with g_unix_mount_points_changed_since(). + * + * If more mount points have the same mount path, the last matching mount point + * is returned. + * + * Returns: (transfer full) (nullable): a #GUnixMountPoint, or %NULL if no match + * is found. + * + * Since: 2.66 + **/ +GUnixMountPoint * +g_unix_mount_point_at (const char *mount_path, + guint64 *time_read) +{ + GList *mount_points, *l; + GUnixMountPoint *mount_point, *found; + + mount_points = g_unix_mount_points_get (time_read); + + found = NULL; + for (l = mount_points; l != NULL; l = l->next) + { + mount_point = l->data; + + if (strcmp (mount_path, mount_point->mount_path) == 0) + { + if (found != NULL) + g_unix_mount_point_free (found); + + found = mount_point; + } + else + g_unix_mount_point_free (mount_point); + } + g_list_free (mount_points); + + return found; +} + /** * g_unix_mounts_changed_since: * @time: guint64 to contain a timestamp. diff --git a/gio/gunixmounts.h b/gio/gunixmounts.h index a392d497f..72b210dc1 100644 --- a/gio/gunixmounts.h +++ b/gio/gunixmounts.h @@ -130,6 +130,9 @@ GIcon * g_unix_mount_point_guess_symbolic_icon (GUnixMountPoint *mount GLIB_AVAILABLE_IN_ALL GList * g_unix_mount_points_get (guint64 *time_read); +GLIB_AVAILABLE_IN_2_56 +GUnixMountPoint *g_unix_mount_point_at (const char *mount_path, + guint64 *time_read); GLIB_AVAILABLE_IN_ALL GList * g_unix_mounts_get (guint64 *time_read); GLIB_AVAILABLE_IN_ALL