15 Star 2 Fork 68

src-openEuler/util-linux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-libmount-improve-mnt_table_next_child_fs.patch 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
zhangyao2022 提交于 2年前 . sync community patches
From f64ea9979a5eaddaed98bde17832f855f2f0daee Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Thu, 2 Nov 2023 10:41:03 +0100
Subject: [PATCH] libmount: improve mnt_table_next_child_fs()
The function utilizes the struct libmnt_itr to iterate through the mountinfo file
but neglects the direction specified by the iterator. This a bug. The application
must manage the direction, as, for instance, umount(8) requires the children of
the mountpoint in reverse order.
Fixes: https://github.com/util-linux/util-linux/issues/2552
Signed-off-by: Karel Zak <kzak@redhat.com>
---
libmount/src/tab.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 0d5c115..be0c13a 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -649,8 +649,8 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
* @parent: parental FS
* @chld: returns the next child filesystem
*
- * Note that filesystems are returned in the order of mounting (according to
- * IDs in /proc/self/mountinfo).
+ * Since version 2.40, the filesystems are returned in the order specified by
+ * @itr. In the old versions the derection is always MNT_ITER_FORWARD.
*
* Returns: 0 on success, negative number in case of error or 1 at the end of list.
*/
@@ -659,6 +659,7 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
{
struct libmnt_fs *fs;
int parent_id, lastchld_id = 0, chld_id = 0;
+ int direction = mnt_iter_get_direction(itr);
if (!tb || !itr || !parent || !is_mountinfo(tb))
return -EINVAL;
@@ -676,7 +677,7 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
*chld = NULL;
- mnt_reset_iter(itr, MNT_ITER_FORWARD);
+ mnt_reset_iter(itr, direction);
while(mnt_table_next_fs(tb, itr, &fs) == 0) {
int id;
@@ -690,10 +691,20 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
if (id == parent_id)
continue;
- if ((!lastchld_id || id > lastchld_id) &&
- (!*chld || id < chld_id)) {
- *chld = fs;
- chld_id = id;
+ if (direction == MNT_ITER_FORWARD) {
+ /* return in the order of mounting */
+ if ((!lastchld_id || id > lastchld_id) &&
+ (!*chld || id < chld_id)) {
+ *chld = fs;
+ chld_id = id;
+ }
+ } else {
+ /* return last child first */
+ if ((!lastchld_id || id < lastchld_id) &&
+ (!*chld || id > chld_id)) {
+ *chld = fs;
+ chld_id = id;
+ }
}
}
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/util-linux.git
git@gitee.com:src-openeuler/util-linux.git
src-openeuler
util-linux
util-linux
openEuler-22.03-LTS

搜索帮助