From: Karel Zak Date: Tue, 29 Nov 2022 09:13:39 +0000 (+0100) Subject: libmount: use mount ID to merge utab and mountinfo files X-Git-Tag: v2.39-rc1~222 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8cf6c5075780598fe3b30e7a7753d8323d093e22;p=thirdparty%2Futil-linux.git libmount: use mount ID to merge utab and mountinfo files Signed-off-by: Karel Zak --- diff --git a/libmount/src/hook_mount.c b/libmount/src/hook_mount.c index 299be87a88..1fd31d9473 100644 --- a/libmount/src/hook_mount.c +++ b/libmount/src/hook_mount.c @@ -254,10 +254,16 @@ static int hook_create_mount(struct libmnt_context *cxt, rc = statx(api->fd_tree, "", AT_EMPTY_PATH, STATX_MNT_ID, &st); cxt->fs->id = (int) st.stx_mnt_id; + + if (cxt->update) { + struct libmnt_fs *fs = mnt_update_get_fs(cxt->update); + if (fs) + fs->id = cxt->fs->id; + } } done: - DBG(HOOK, ul_debugobj(hs, "create FS done [rc=%d]", rc)); + DBG(HOOK, ul_debugobj(hs, "create FS done [rc=%d, id=%d]", rc, cxt->fs ? cxt->fs->id : -1)); return rc; } diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 6e3d5ef9f7..526a0078bb 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->source && !strncmp(p, "SRC=", 4)) { + if (!fs->id && !strncmp(p, "ID=", 3)) { + int rc = 0; + + end = next_s32(p + 3, &fs->id, &rc); + if (!end || rc) + return rc; + + } else if (!fs->source && !strncmp(p, "SRC=", 4)) { char *v = unmangle(p + 4, &end); if (!v) goto enomem; @@ -1171,6 +1178,7 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct struct libmnt_fs *fs; struct libmnt_iter itr; const char *optstr, *src, *target, *root, *attrs; + int id; if (!tb || !uf) return NULL; @@ -1182,6 +1190,7 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct optstr = mnt_fs_get_user_options(uf); attrs = mnt_fs_get_attributes(uf); root = mnt_fs_get_root(uf); + id = mnt_fs_get_id(uf); if (!src || !target || !root || (!attrs && !optstr)) return NULL; @@ -1194,20 +1203,23 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct if (fs->flags & MNT_FS_MERGED) continue; - if (r && strcmp(r, root) == 0 + 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)) break; } if (fs) { - DBG(TAB, ul_debugobj(tb, "found fs -- appending user optstr")); + DBG(TAB, ul_debugobj(tb, " found")); mnt_fs_append_options(fs, optstr); mnt_fs_append_attributes(fs, attrs); mnt_fs_set_bindsrc(fs, mnt_fs_get_bindsrc(uf)); fs->flags |= MNT_FS_MERGED; - DBG(TAB, ul_debugobj(tb, "found fs:")); DBG(TAB, mnt_fs_print_debug(fs, stderr)); } return fs; diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index f914df4122..f5e5d3045c 100644 --- a/libmount/src/tab_update.c +++ b/libmount/src/tab_update.c @@ -435,10 +435,15 @@ static int fprintf_utab_fs(FILE *f, struct libmnt_fs *fs) if (!fs || !f) return -EINVAL; - p = mangle(mnt_fs_get_source(fs)); - if (p) { - rc = fprintf(f, "SRC=%s ", p); - free(p); + if (mnt_fs_get_id(fs) > 0) { + rc = fprintf(f, "ID=%d ", mnt_fs_get_id(fs)); + } + if (rc >= 0) { + p = mangle(mnt_fs_get_source(fs)); + if (p) { + rc = fprintf(f, "SRC=%s ", p); + free(p); + } } if (rc >= 0) { p = mangle(mnt_fs_get_target(fs));