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/context_loopdev.c
static int __attribute__((nonnull))
is_mounted_same_loopfile(struct libmnt_context* cxt, const char* target,
                         const char* backing_file, uint64_t offset)
{
    struct libmnt_table* tb;
    struct libmnt_iter itr;
    struct libmnt_fs* fs;
    struct libmnt_cache* cache;
    const char* bf;
    int rc = 0;
    struct libmnt_ns* ns_old;

    assert(cxt);
    assert(cxt->fs);
    assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));

    if (mnt_context_get_mtab(cxt, &tb))
        return 0;

    ns_old = mnt_context_switch_target_ns(cxt);
    if (!ns_old)
        return -MNT_ERR_NAMESPACE;

    DBG(LOOP,
        ul_debugobj(cxt, "checking if %s mounted on %s", backing_file, target));

    cache = mnt_context_get_cache(cxt);
    mnt_reset_iter(&itr, MNT_ITER_BACKWARD);

    bf = cache ? mnt_resolve_path(backing_file, cache) : backing_file;

    /* Search for a mountpoint node in mtab, proceed if any of these have the
     * loop option set or the device is a loop device
     */
    while (rc == 0 && mnt_table_next_fs(tb, &itr, &fs) == 0)
    {
        const char* src = mnt_fs_get_source(fs);
        const char* opts = mnt_fs_get_user_options(fs);
        char* val;
        size_t len;

        if (!src || !mnt_fs_match_target(fs, target, cache))
            continue;

        rc = 0;

        if (strncmp(src, "/dev/loop", 9) == 0)
        {
            rc = loopdev_is_used((char*)src, bf, offset, 0, LOOPDEV_FL_OFFSET);
        }
        else if (opts && (cxt->user_mountflags & MNT_MS_LOOP) &&
                 mnt_optstr_get_option(opts, "loop", &val, &len) == 0 && val)
        {

            val = strndup(val, len);
            rc = loopdev_is_used((char*)val, bf, offset, 0, LOOPDEV_FL_OFFSET);
            free(val);
        }
    }
    if (rc)
        DBG(LOOP, ul_debugobj(cxt, "%s already mounted", backing_file));

    if (!mnt_context_switch_ns(cxt, ns_old))
        return -MNT_ERR_NAMESPACE;
    return rc;
}
/* Check if there already exists a mounted loop device on the mountpoint node
 * with the same parameters.
 */
Check if there already exists a mounted loop device on the mountpoint node
with the same parameters.
Check if there already exists a mounted loop device on the mountpoint node with the same parameters .
static int __attribute__((nonnull))
is_mounted_same_loopfile(struct libmnt_context* cxt, const char* target,
                         const char* backing_file, uint64_t offset)
{
    struct libmnt_table* tb;
    struct libmnt_iter itr;
    struct libmnt_fs* fs;
    struct libmnt_cache* cache;
    const char* bf;
    int rc = 0;
    struct libmnt_ns* ns_old;
    assert(cxt);
    assert(cxt->fs);
    assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
    if (mnt_context_get_mtab(cxt, &tb))
        return 0;
    ns_old = mnt_context_switch_target_ns(cxt);
    if (!ns_old)
        return -MNT_ERR_NAMESPACE;
    DBG(LOOP,
        ul_debugobj(cxt, "checking if %s mounted on %s", backing_file, target));
    cache = mnt_context_get_cache(cxt);
    mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
    bf = cache ? mnt_resolve_path(backing_file, cache) : backing_file;
    while (rc == 0 && mnt_table_next_fs(tb, &itr, &fs) == 0)
    {
        const char* src = mnt_fs_get_source(fs);
        const char* opts = mnt_fs_get_user_options(fs);
        char* val;
        size_t len;
        if (!src || !mnt_fs_match_target(fs, target, cache))
            continue;
        rc = 0;
        if (strncmp(src, "/dev/loop", 9) == 0)
        {
            rc = loopdev_is_used((char*)src, bf, offset, 0, LOOPDEV_FL_OFFSET);
        }
        else if (opts && (cxt->user_mountflags & MNT_MS_LOOP) &&
                 mnt_optstr_get_option(opts, "loop", &val, &len) == 0 && val)
        {
            val = strndup(val, len);
            rc = loopdev_is_used((char*)val, bf, offset, 0, LOOPDEV_FL_OFFSET);
            free(val);
        }
    }
    if (rc)
        DBG(LOOP, ul_debugobj(cxt, "%s already mounted", backing_file));
    if (!mnt_context_switch_ns(cxt, ns_old))
        return -MNT_ERR_NAMESPACE;
    return rc;
}
static int __attribute__ ( ( nonnull ) ) is_mounted_same_loopfile ( struct libmnt_context * cxt , const char * target , const char * backing_file , uint64_t offset ) { struct libmnt_table * tb ; struct libmnt_iter itr ; struct libmnt_fs * fs ; struct libmnt_cache * cache ; const char * bf ; int rc = 0 ; struct libmnt_ns * ns_old ; assert ( cxt ) ; assert ( cxt -> fs ) ; assert ( ( cxt -> flags & MNT_FL_MOUNTFLAGS_MERGED ) ) ; if ( mnt_context_get_mtab ( cxt , & tb ) ) return 0 ; ns_old = mnt_context_switch_target_ns ( cxt ) ; if ( ! ns_old ) return - MNT_ERR_NAMESPACE ; DBG ( LOOP , ul_debugobj ( cxt , " " , backing_file , target ) ) ; cache = mnt_context_get_cache ( cxt ) ; mnt_reset_iter ( & itr , MNT_ITER_BACKWARD ) ; bf = cache ? mnt_resolve_path ( backing_file , cache ) : backing_file ; while ( rc == 0 && mnt_table_next_fs ( tb , & itr , & fs ) == 0 ) { const char * src = mnt_fs_get_source ( fs ) ; const char * opts = mnt_fs_get_user_options ( fs ) ; char * val ; size_t len ; if ( ! src || ! mnt_fs_match_target ( fs , target , cache ) ) continue ; rc = 0 ; if ( strncmp ( src , " " , 9 ) == 0 ) { rc = loopdev_is_used ( ( char * ) src , bf , offset , 0 , LOOPDEV_FL_OFFSET ) ; } else if ( opts && ( cxt -> user_mountflags & MNT_MS_LOOP ) && mnt_optstr_get_option ( opts , " " , & val , & len ) == 0 && val ) { val = strndup ( val , len ) ; rc = loopdev_is_used ( ( char * ) val , bf , offset , 0 , LOOPDEV_FL_OFFSET ) ; free ( val ) ; } } if ( rc ) DBG ( LOOP , ul_debugobj ( cxt , " " , backing_file ) ) ; if ( ! mnt_context_switch_ns ( cxt , ns_old ) ) return - MNT_ERR_NAMESPACE ; return rc ; }
Check if there already exists a mounted loop device on the mountpoint node
 with the same parameters.
Check if there already exists a mounted loop device on the mountpoint node with the same parameters .
/* Search for a mountpoint node in mtab, proceed if any of these have the
     * loop option set or the device is a loop device
     */