extern int mnt_guess_system_root(dev_t devno, struct libmnt_cache *cache, char **path)
__ul_attribute__((nonnull(3)));
+extern int mnt_id_from_path(const char *path, uint64_t *uniq_id, int *id);
+
/* cache.c */
extern struct libmnt_cache *mnt_new_cache(void)
__ul_attribute__((warn_unused_result));
extern int mnt_tmptgt_unshare(int *old_ns_fd);
extern int mnt_tmptgt_cleanup(int old_ns_fd);
+extern int mnt_id_from_fd(int fd, uint64_t *uniq_id, int *id);
+
/* tab.c */
extern int is_mountinfo(struct libmnt_table *tb);
extern int mnt_table_set_parser_fltrcb( struct libmnt_table *tb,
return 0;
}
+static int get_mnt_id( int fd, const char *path,
+ uint64_t *uniq_id, int *id)
+{
+#if defined(HAVE_STATX) && defined(HAVE_STRUCT_STATX) && defined(HAVE_STRUCT_STATX_STX_MNT_ID)
+ int rc;
+ struct statx sx = { 0 };
+ int flags = AT_STATX_DONT_SYNC | AT_NO_AUTOMOUNT;
+
+ if (!path || !*path)
+ flags |= AT_EMPTY_PATH;
+
+ if (id) {
+ rc = statx(fd, path ? path : "", flags,
+ STATX_MNT_ID, &sx);
+ if (rc)
+ return rc;
+ *id = sx.stx_mnt_id;
+ }
+ if (uniq_id) {
+ errno = 0;
+ rc = statx(fd, path ? path : "", flags,
+ STATX_MNT_ID_UNIQUE, &sx);
+
+ if (rc && errno == EINVAL)
+ return -ENOSYS; /* *_ID_UNIQUE unsupported? */
+ if (rc)
+ return rc;
+ *uniq_id = sx.stx_mnt_id;
+ }
+ return 0;
+#else
+ return -ENOSYS;
+#endif
+}
+
+int mnt_id_from_fd(int fd, uint64_t *uniq_id, int *id)
+{
+ return get_mnt_id(fd, NULL, uniq_id, id);
+}
+
+/**
+ * mnt_id_from_path:
+ * @path: mountpoint
+ * @uniq_id: returns STATX_MNT_ID_UNIQUE
+ * @id: returns STATX_MNT_ID
+ *
+ * Converts @path to ID.
+ *
+ * Returns: 0 on success, <0 on error
+ *
+ * Since: 2.41
+ */
+int mnt_id_from_path(const char *path, uint64_t *uniq_id, int *id)
+{
+ return get_mnt_id(-1, path, uniq_id, id);
+}
+
/**
* mnt_mangle:
* @str: string