* mnt_fs_get_id:
* @fs: /proc/self/mountinfo entry
*
- * Returns: mount ID (unique identifier of the mount) or negative number in case of error.
+ * This ID is "old" and used in mountinfo only. Since Linux v6.8 there is also unique
+ * 64-bit ID, see mnt_fs_get_uniq_id().
+ *
+ * Returns: mount ID or negative number in case of error.
*/
int mnt_fs_get_id(struct libmnt_fs *fs)
{
return fs ? fs->id : -EINVAL;
}
+/**
+ * mnt_fs_get_uniq_id:
+ * @fs: filesystem instance
+ *
+ * This ID is provided by statmount() or statx(STATX_MNT_ID_UNIQUE) since Linux
+ * kernel since v6.8.
+ *
+ * Returns: unique mount ID
+ *
+ * Since: 2.41
+ */
+uint64_t mnt_fs_get_uniq_id(struct libmnt_fs *fs)
+{
+ return fs ? fs->uniq_id : 0;
+}
+
+/**
+ * mnt_fs_set_uniq_id:
+ * @fs: filesystem instance
+ * @id: mount node ID
+ *
+ * This ID is provided by statmount() or statx(STATX_MNT_ID_UNIQUE) since Linux
+ * kernel since v6.8.
+ *
+ * Returns: 0 or negative number in case of error.
+ *
+ * Since: 2.41
+ */
+int mnt_fs_set_uniq_id(struct libmnt_fs *fs, uint64_t id)
+{
+ if (!fs)
+ return -EINVAL;
+ fs->uniq_id = id;
+ return 0;
+}
+
/**
* mnt_fs_get_parent_id:
* @fs: /proc/self/mountinfo entry
return fs ? fs->parent : -EINVAL;
}
+/**
+ * mnt_fs_get_parent_uniq_id:
+ * @fs: filesystem instance
+ *
+ * This ID is provided by statmount() since Linux kernel since v6.8.
+ *
+ * Returns: parent mount ID or 0 if not avalable
+ */
+uint64_t mnt_fs_get_parent_uniq_id(struct libmnt_fs *fs)
+{
+ return fs ? fs->uniq_parent : 0;
+}
+
/**
* mnt_fs_get_devno:
* @fs: /proc/self/mountinfo entry
fprintf(file, "id: %d\n", mnt_fs_get_id(fs));
if (mnt_fs_get_parent_id(fs))
fprintf(file, "parent: %d\n", mnt_fs_get_parent_id(fs));
+ if (mnt_fs_get_uniq_id(fs))
+ fprintf(file, "uniq-id: %" PRIu64 "\n", mnt_fs_get_uniq_id(fs));
+ if (mnt_fs_get_parent_uniq_id(fs))
+ fprintf(file, "uniq-parent: %" PRIu64 "\n", mnt_fs_get_parent_uniq_id(fs));
if (mnt_fs_get_devno(fs))
fprintf(file, "devno: %d:%d\n", major(mnt_fs_get_devno(fs)),
minor(mnt_fs_get_devno(fs)));
#include <stdio.h>
#include <mntent.h>
#include <sys/types.h>
+#include <stdint.h>
/* Make sure libc MS_* definitions are used by default. Note that MS_* flags
* may be already defined by linux/fs.h or another file -- in this case we
extern int mnt_fs_set_root(struct libmnt_fs *fs, const char *path);
extern const char *mnt_fs_get_bindsrc(struct libmnt_fs *fs);
extern int mnt_fs_set_bindsrc(struct libmnt_fs *fs, const char *src);
+
extern int mnt_fs_get_id(struct libmnt_fs *fs);
+extern uint64_t mnt_fs_get_uniq_id(struct libmnt_fs *fs);
+extern int mnt_fs_set_uniq_id(struct libmnt_fs *fs, uint64_t id);
+
extern int mnt_fs_get_parent_id(struct libmnt_fs *fs);
+extern uint64_t mnt_fs_get_parent_uniq_id(struct libmnt_fs *fs);
+
extern dev_t mnt_fs_get_devno(struct libmnt_fs *fs);
extern pid_t mnt_fs_get_tid(struct libmnt_fs *fs);
struct libmnt_optlist *optlist;
int id; /* mountinfo[1]: ID */
+ uint64_t uniq_id; /* unique node ID; statx(STATX_MNT_ID_UNIQUE); statmount->mnt_id */
int parent; /* mountinfo[2]: parent */
+ uint64_t uniq_parent; /* unique parent ID; statmount->mnt_parent_id */
dev_t devno; /* mountinfo[3]: st_dev */
char *bindsrc; /* utab, full path from fstab[1] for bind mounts */