openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/libmount/src/tab.c
int mnt_table_get_root_fs(struct libmnt_table* tb, struct libmnt_fs** root)
{
    struct libmnt_iter itr;
    struct libmnt_fs* fs;
    int root_id = 0;

    if (!tb || !root || !is_mountinfo(tb))
        return -EINVAL;

    DBG(TAB, ul_debugobj(tb, "lookup root fs"));

    *root = NULL;

    /* get smallest possible ID from the table */
    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 (!*root || id < root_id)
        {
            *root = fs;
            root_id = id;
        }
    }

    /* go to the root node by "parent_id -> id" relation */
    while (*root)
    {
        struct libmnt_fs* x = get_parent_fs(tb, *root);
        if (!x || x == *root)
            break;
        DBG(TAB, ul_debugobj(tb, " messy mountinfo, walk to %s",
                             mnt_fs_get_target(x)));
        *root = x;
    }

    return *root ? 0 : -EINVAL;
}
/**
 * mnt_table_get_root_fs:
 * @tb: mountinfo file (/proc/self/mountinfo)
 * @root: returns pointer to the root filesystem (/)
 *
 * The function uses the parent ID from the mountinfo file to determine the
 * root filesystem (the filesystem with the smallest ID with parent ID missing
 * in the table). The function is designed mostly for applications where it is
 * necessary to sort mountpoints by IDs to get the tree of the mountpoints
 * (e.g. findmnt default output).
 *
 * If you're not sure, then use
 *
 *	mnt_table_find_target(tb, "/", MNT_ITER_BACKWARD);
 *
 * this is more robust and usable for arbitrary tab files (including fstab).
 *
 * Returns: 0 on success or negative number in case of error.
 */
@tb: mountinfo file (/proc/self/mountinfo)
@root: returns pointer to the root filesystem (/)

The function uses the parent ID from the mountinfo file to determine the
root filesystem (the filesystem with the smallest ID with parent ID missing
in the table). The function is designed mostly for applications where it is
necessary to sort mountpoints by IDs to get the tree of the mountpoints
.

If you're not sure, then use



this is more robust and usable for arbitrary tab files (including fstab).

0 on success or negative number in case of error.
@tb : mountinfo file ( / proc / self / mountinfo ) @root : returns pointer to the root filesystem ( / ) The function uses the parent ID from the mountinfo file to determine the root filesystem ( the filesystem with the smallest ID with parent ID missing in the table ) . The function is designed mostly for applications where it is necessary to sort mountpoints by IDs to get the tree of the mountpoints . If you ' re not sure then use this is more robust and usable for arbitrary tab files ( including fstab ) . 0 on success or negative number in case of error .
int mnt_table_get_root_fs(struct libmnt_table* tb, struct libmnt_fs** root)
{
    struct libmnt_iter itr;
    struct libmnt_fs* fs;
    int root_id = 0;
    if (!tb || !root || !is_mountinfo(tb))
        return -EINVAL;
    DBG(TAB, ul_debugobj(tb, "lookup root fs"));
    *root = NULL;
    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 (!*root || id < root_id)
        {
            *root = fs;
            root_id = id;
        }
    }
    while (*root)
    {
        struct libmnt_fs* x = get_parent_fs(tb, *root);
        if (!x || x == *root)
            break;
        DBG(TAB, ul_debugobj(tb, " messy mountinfo, walk to %s",
                             mnt_fs_get_target(x)));
        *root = x;
    }
    return *root ? 0 : -EINVAL;
}
int mnt_table_get_root_fs ( struct libmnt_table * tb , struct libmnt_fs * * root ) { struct libmnt_iter itr ; struct libmnt_fs * fs ; int root_id = 0 ; if ( ! tb || ! root || ! is_mountinfo ( tb ) ) return - EINVAL ; DBG ( TAB , ul_debugobj ( tb , " " ) ) ; * root = NULL ; 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 ( ! * root || id < root_id ) { * root = fs ; root_id = id ; } } while ( * root ) { struct libmnt_fs * x = get_parent_fs ( tb , * root ) ; if ( ! x || x == * root ) break ; DBG ( TAB , ul_debugobj ( tb , " " , mnt_fs_get_target ( x ) ) ) ; * root = x ; } return * root ? 0 : - EINVAL ; }
mnt_table_get_root_fs:
 @tb: mountinfo file (/proc/self/mountinfo)
 @root: returns pointer to the root filesystem (/)
mnt_table_get_root_fs : @tb : mountinfo file ( / proc / self / mountinfo ) @root : returns pointer to the root filesystem ( / )
/* get smallest possible ID from the table */ /* go to the root node by "parent_id -> id" relation */