assert(tb);
assert(root);
- if (!tb || !root)
+ if (!tb || !root || !is_mountinfo(tb))
return -EINVAL;
DBG(TAB, mnt_debug_h(tb, "lookup root fs"));
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;
}
}
- return root_id ? 0 : -EINVAL;
+ return *root ? 0 : -EINVAL;
}
/**
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) {
}
}
- if (!chld_id)
+ if (!*chld)
return 1; /* end of iterator */
/* set the iterator to the @chld for the next call */
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;