From: Karel Zak Date: Wed, 12 Jun 2024 11:14:18 +0000 (+0200) Subject: libmount: use unique ID in utab X-Git-Tag: v2.42-start~97^2~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b1348c73793cd87522e1ffb48d086880f7b7b22;p=thirdparty%2Futil-linux.git libmount: use unique ID in utab Signed-off-by: Karel Zak --- diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index b8ec244f7..e5db3e385 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -323,7 +323,14 @@ static int mnt_parse_utab_line(struct libmnt_fs *fs, const char *s) if (!*p) break; - if (!fs->id && !strncmp(p, "ID=", 3)) { + if (!fs->uniq_id && !strncmp(p, "UNIQID=", 7)) { + int rc = 0; + + end = next_u64(p + 7, &fs->uniq_id, &rc); + if (!end || rc) + return rc; + + } else if (!fs->id && !strncmp(p, "ID=", 3)) { int rc = 0; end = next_s32(p + 3, &fs->id, &rc); @@ -1178,6 +1185,7 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct struct libmnt_iter itr; const char *optstr, *src, *target, *root, *attrs; int id; + uint64_t uniq_id; if (!tb || !uf) return NULL; @@ -1190,6 +1198,7 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct attrs = mnt_fs_get_attributes(uf); root = mnt_fs_get_root(uf); id = mnt_fs_get_id(uf); + uniq_id = mnt_fs_get_uniq_id(uf); if (!src || !target || !root || (!attrs && !optstr)) return NULL; @@ -1202,10 +1211,16 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct if (fs->flags & MNT_FS_MERGED) continue; - if (id > 0 && mnt_fs_get_id(fs)) { + if (uniq_id > 0 && mnt_fs_get_uniq_id(fs)) { + DBG(TAB, ul_debugobj(tb, " using uniq ID")); + if (mnt_fs_get_uniq_id(fs) == uniq_id) + break; + + } else if (id > 0 && mnt_fs_get_id(fs)) { DBG(TAB, ul_debugobj(tb, " using ID")); if (mnt_fs_get_id(fs) == id) break; + } else if (r && strcmp(r, root) == 0 && mnt_fs_streq_target(fs, target) && mnt_fs_streq_srcpath(fs, src)) diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index fa07dc0d9..a256edf85 100644 --- a/libmount/src/tab_update.c +++ b/libmount/src/tab_update.c @@ -446,9 +446,11 @@ static int fprintf_utab_fs(FILE *f, struct libmnt_fs *fs) if (!fs || !f) return -EINVAL; - if (mnt_fs_get_id(fs) > 0) { + if (mnt_fs_get_id(fs) > 0) rc = fprintf(f, "ID=%d ", mnt_fs_get_id(fs)); - } + if (mnt_fs_get_uniq_id(fs) > 0) + rc = fprintf(f, "UNIQID=%" PRIu64, mnt_fs_get_uniq_id(fs)); + if (rc >= 0) { p = mangle(mnt_fs_get_source(fs)); if (p) {