0001-libmount-FS-id-and-parent-ID-could-be-zero.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 6c373810f5b1d32824371e9dff6ee5a006388f98 Mon Sep 17 00:00:00 2001
  2. From: Karel Zak <kzak@redhat.com>
  3. Date: Thu, 20 Feb 2014 16:59:11 +0100
  4. Subject: [PATCH] libmount: FS id and parent ID could be zero
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Content-Type: text/plain; charset=UTF-8
  9. Content-Transfer-Encoding: 8bit
  10. It seems that linux 3.14 is able to produce things like:
  11. 19 0 8:3 / / rw,relatime - ext4 /dev/sda3 rw,data=ordered
  12. ^
  13. Reported-by: Mantas Mikulėnas <grawity@gmail.com>
  14. Signed-off-by: Karel Zak <kzak@redhat.com>
  15. ---
  16. libmount/src/tab.c | 12 ++++--------
  17. misc-utils/findmnt.c | 5 +++--
  18. 2 files changed, 7 insertions(+), 10 deletions(-)
  19. diff --git a/libmount/src/tab.c b/libmount/src/tab.c
  20. index 4c2f8a4..332312b 100644
  21. --- a/libmount/src/tab.c
  22. +++ b/libmount/src/tab.c
  23. @@ -505,7 +505,7 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
  24. assert(tb);
  25. assert(root);
  26. - if (!tb || !root)
  27. + if (!tb || !root || !is_mountinfo(tb))
  28. return -EINVAL;
  29. DBG(TAB, mnt_debug_h(tb, "lookup root fs"));
  30. @@ -515,8 +515,6 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
  31. mnt_reset_iter(&itr, MNT_ITER_FORWARD);
  32. while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
  33. int id = mnt_fs_get_parent_id(fs);
  34. - if (!id)
  35. - break; /* @tab is not a mountinfo file? */
  36. if (!*root || id < root_id) {
  37. *root = fs;
  38. @@ -524,7 +522,7 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
  39. }
  40. }
  41. - return root_id ? 0 : -EINVAL;
  42. + return *root ? 0 : -EINVAL;
  43. }
  44. /**
  45. @@ -545,15 +543,13 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
  46. struct libmnt_fs *fs;
  47. int parent_id, lastchld_id = 0, chld_id = 0;
  48. - if (!tb || !itr || !parent)
  49. + if (!tb || !itr || !parent || !is_mountinfo(tb))
  50. return -EINVAL;
  51. DBG(TAB, mnt_debug_h(tb, "lookup next child of '%s'",
  52. mnt_fs_get_target(parent)));
  53. parent_id = mnt_fs_get_id(parent);
  54. - if (!parent_id)
  55. - return -EINVAL;
  56. /* get ID of the previously returned child */
  57. if (itr->head && itr->p != itr->head) {
  58. @@ -584,7 +580,7 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
  59. }
  60. }
  61. - if (!chld_id)
  62. + if (!*chld)
  63. return 1; /* end of iterator */
  64. /* set the iterator to the @chld for the next call */
  65. diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
  66. index fb21174..988cd73 100644
  67. --- a/misc-utils/findmnt.c
  68. +++ b/misc-utils/findmnt.c
  69. @@ -822,8 +822,9 @@ static int tab_is_tree(struct libmnt_table *tb)
  70. if (!itr)
  71. return 0;
  72. - if (mnt_table_next_fs(tb, itr, &fs) == 0)
  73. - rc = mnt_fs_get_id(fs) > 0 && mnt_fs_get_parent_id(fs) > 0;
  74. + rc = (mnt_table_next_fs(tb, itr, &fs) == 0 &&
  75. + mnt_fs_is_kernel(fs) &&
  76. + mnt_fs_get_root(fs));
  77. mnt_free_iter(itr);
  78. return rc;
  79. --
  80. 1.9.1