]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: Add API to get/set unique IDs
authorKarel Zak <kzak@redhat.com>
Tue, 11 Jun 2024 09:55:39 +0000 (11:55 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jan 2025 12:57:42 +0000 (13:57 +0100)
Since the Linux kernel version 6.8, there are two types of IDs
available: the "old" ID used in /proc/self/mountinfo, and a new 64-bit
unique ID that is never recycled. This new ID is provided by the
statx(STATX_MNT_ID_UNIQUE) and statmount() syscalls.

Note that this patch only adds the API for retrieving these unique
IDs, but the backing code has not been implemented yet.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/docs/libmount-sections.txt
libmount/src/fs.c
libmount/src/libmount.h.in
libmount/src/libmount.sym
libmount/src/mountP.h

index 0b4adb5950e786b69a7df422ba383e88a47118c4..a8a503144c0a070dca934562462f0cf8a4e24889 100644 (file)
@@ -229,10 +229,12 @@ mnt_fs_get_freq
 mnt_fs_get_fs_options
 mnt_fs_get_fstype
 mnt_fs_get_id
+mnt_fs_get_uniq_id
 mnt_fs_get_option
 mnt_fs_get_optional_fields
 mnt_fs_get_options
 mnt_fs_get_parent_id
+mnt_fs_get_parent_uniq_id
 mnt_fs_get_passno
 mnt_fs_get_priority
 mnt_fs_get_propagation
@@ -273,6 +275,7 @@ mnt_fs_set_priority
 mnt_fs_set_root
 mnt_fs_set_source
 mnt_fs_set_target
+mnt_fs_set_uniq_id
 mnt_fs_set_userdata
 mnt_fs_strdup_options
 mnt_fs_streq_srcpath
index 5b3a5511f424f7d563446ef56f4001d9022ca2ca..d8886dc389751bb3d003b1c98cd294e7b7778b50 100644 (file)
@@ -1361,13 +1361,52 @@ int mnt_fs_set_bindsrc(struct libmnt_fs *fs, const char *src)
  * 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
@@ -1379,6 +1418,19 @@ int mnt_fs_get_parent_id(struct libmnt_fs *fs)
        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
@@ -1714,6 +1766,10 @@ int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file)
                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)));
index 0a2d821996efd175af25d98cd1abe39d9e630674..90f6a66c0eb9c069e0e5543e1e9563643b52eabc 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 #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
@@ -530,8 +531,14 @@ extern const char *mnt_fs_get_root(struct libmnt_fs *fs);
 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);
 
index 2b6b12d5c3b774efe15334030e419be75bee59f8..cdd76ba3283e376164595ff4c7c85b87205d963b 100644 (file)
@@ -381,3 +381,9 @@ MOUNT_2_40 {
        mnt_unref_lock;
        mnt_monitor_veil_kernel;
 } MOUNT_2_39;
+
+MOUNT_2_41 {
+       mnt_fs_get_uniq_id;
+       mnt_fs_get_parent_uniq_id;
+       mnt_fs_set_uniq_id;
+} MOUNT_2_40;
index bfdf8f451422b9bc53c30729905fada7c605ed19..370bcd9e74472e17e0cfcdf711ecd1710f7075b0 100644 (file)
@@ -201,7 +201,9 @@ struct libmnt_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 */