diff options
| author | Karel Zak <kzak@redhat.com> | 2024-06-11 11:55:39 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2025-01-08 13:57:42 +0100 |
| commit | 57ab4dc3781765a182cbb63dd04b5f25a2d88724 (patch) | |
| tree | a9f9c9c5ac7f9f264abeb1d54deeeb231933e456 /libmount/src | |
| parent | ba353afbeba6bcb7a07c447ee6832aa51eaf70ad (diff) | |
| download | util-linux-57ab4dc3781765a182cbb63dd04b5f25a2d88724.tar.gz | |
libmount: Add API to get/set unique IDs
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>
Diffstat (limited to 'libmount/src')
| -rw-r--r-- | libmount/src/fs.c | 58 | ||||
| -rw-r--r-- | libmount/src/libmount.h.in | 7 | ||||
| -rw-r--r-- | libmount/src/libmount.sym | 6 | ||||
| -rw-r--r-- | libmount/src/mountP.h | 2 |
4 files changed, 72 insertions, 1 deletions
diff --git a/libmount/src/fs.c b/libmount/src/fs.c index 5b3a5511f4..d8886dc389 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -1361,7 +1361,10 @@ 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) { @@ -1369,6 +1372,42 @@ int mnt_fs_get_id(struct libmnt_fs *fs) } /** + * 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 * @@ -1380,6 +1419,19 @@ int mnt_fs_get_parent_id(struct libmnt_fs *fs) } /** + * 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))); diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index 0a2d821996..90f6a66c0e 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -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); diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym index 2b6b12d5c3..cdd76ba328 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -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; diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index bfdf8f4514..370bcd9e74 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -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 */ |
