]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: FS id and parent ID could be zero
authorKarel Zak <kzak@redhat.com>
Thu, 20 Feb 2014 15:59:11 +0000 (16:59 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 23 Apr 2014 09:54:10 +0000 (11:54 +0200)
It seems that linux 3.14 is able to produce things like:

  19 0 8:3 / / rw,relatime - ext4 /dev/sda3 rw,data=ordered
     ^

Reported-by: Mantas Mikulėnas <grawity@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab.c
misc-utils/findmnt.c

index 80b225e3fea6cf2990e655fa5dd11913da9d0ab0..b023504adf1fbca5747852658b4b95eb1cfd8217 100644 (file)
@@ -47,6 +47,8 @@
 #include "strutils.h"
 #include "loopdev.h"
 
+static int is_mountinfo(struct libmnt_table *tb);
+
 /**
  * mnt_new_table:
  *
@@ -491,7 +493,7 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
        assert(tb);
        assert(root);
 
-       if (!tb || !root)
+       if (!tb || !root || !is_mountinfo(tb))
                return -EINVAL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup root fs"));
@@ -501,8 +503,6 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
        mnt_reset_iter(&itr, MNT_ITER_FORWARD);
        while(mnt_table_next_fs(tb, &itr, &fs) == 0) {
                int id = mnt_fs_get_parent_id(fs);
-               if (!id)
-                       break;          /* @tab is not a mountinfo file? */
 
                if (!*root || id < root_id) {
                        *root = fs;
@@ -510,7 +510,7 @@ int mnt_table_get_root_fs(struct libmnt_table *tb, struct libmnt_fs **root)
                }
        }
 
-       return root_id ? 0 : -EINVAL;
+       return *root ? 0 : -EINVAL;
 }
 
 /**
@@ -531,15 +531,13 @@ 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;
 
-       if (!tb || !itr || !parent)
+       if (!tb || !itr || !parent || !is_mountinfo(tb))
                return -EINVAL;
 
        DBG(TAB, mnt_debug_h(tb, "lookup next child of '%s'",
                                mnt_fs_get_target(parent)));
 
        parent_id = mnt_fs_get_id(parent);
-       if (!parent_id)
-               return -EINVAL;
 
        /* get ID of the previously returned child */
        if (itr->head && itr->p != itr->head) {
@@ -570,7 +568,7 @@ int mnt_table_next_child_fs(struct libmnt_table *tb, struct libmnt_iter *itr,
                }
        }
 
-       if (!chld_id)
+       if (!*chld)
                return 1;       /* end of iterator */
 
        /* set the iterator to the @chld for the next call */
index 91cc9350e088e51955ce3309093ef9919ceb5599..f269246fcbae235f64e4d6349e9cd18f0b6b6d23 100644 (file)
@@ -821,8 +821,9 @@ static int tab_is_tree(struct libmnt_table *tb)
        if (!itr)
                return 0;
 
-       if (mnt_table_next_fs(tb, itr, &fs) == 0)
-               rc = mnt_fs_get_id(fs) > 0 && mnt_fs_get_parent_id(fs) > 0;
+       rc = (mnt_table_next_fs(tb, itr, &fs) == 0 &&
+             mnt_fs_is_kernel(fs) &&
+             mnt_fs_get_root(fs));
 
        mnt_free_iter(itr);
        return rc;