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/libblkid/src/probe.c
int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo* id,
                          uint64_t* offset, const struct blkid_idmag** res)
{
    const struct blkid_idmag* mag = NULL;
    uint64_t off = 0;

    if (id)
        mag = &id->magics[0];
    if (res)
        *res = NULL;

    /* try to detect by magic string */
    while (mag && mag->magic)
    {
        unsigned char* buf;

        off = (mag->kboff + (mag->sboff >> 10)) << 10;
        buf = blkid_probe_get_buffer(pr, off, 1024);

        if (!buf && errno)
            return -errno;

        if (buf && !memcmp(mag->magic, buf + (mag->sboff & 0x3ff), mag->len))
        {

            DBG(LOWPROBE, ul_debug("\tmagic sboff=%u, kboff=%ld", mag->sboff,
                                   mag->kboff));
            if (offset)
                *offset = off + (mag->sboff & 0x3ff);
            if (res)
                *res = mag;
            return BLKID_PROBE_OK;
        }
        mag++;
    }

    if (id && id->magics[0].magic)
        /* magic string(s) defined, but not found */
        return BLKID_PROBE_NONE;

    return BLKID_PROBE_OK;
}
/*
 * Check for matching magic value.
 * Returns BLKID_PROBE_OK if found, BLKID_PROBE_NONE if not found
 * or no magic present, or negative value on error.
 */
Check for matching magic value.
Returns BLKID_PROBE_OK if found, BLKID_PROBE_NONE if not found
or no magic present, or negative value on error.
Check for matching magic value . Returns BLKID_PROBE_OK if found BLKID_PROBE_NONE if not found or no magic present or negative value on error .
int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo* id,
                          uint64_t* offset, const struct blkid_idmag** res)
{
    const struct blkid_idmag* mag = NULL;
    uint64_t off = 0;
    if (id)
        mag = &id->magics[0];
    if (res)
        *res = NULL;
    while (mag && mag->magic)
    {
        unsigned char* buf;
        off = (mag->kboff + (mag->sboff >> 10)) << 10;
        buf = blkid_probe_get_buffer(pr, off, 1024);
        if (!buf && errno)
            return -errno;
        if (buf && !memcmp(mag->magic, buf + (mag->sboff & 0x3ff), mag->len))
        {
            DBG(LOWPROBE, ul_debug("\tmagic sboff=%u, kboff=%ld", mag->sboff,
                                   mag->kboff));
            if (offset)
                *offset = off + (mag->sboff & 0x3ff);
            if (res)
                *res = mag;
            return BLKID_PROBE_OK;
        }
        mag++;
    }
    if (id && id->magics[0].magic)
        return BLKID_PROBE_NONE;
    return BLKID_PROBE_OK;
}
int blkid_probe_get_idmag ( blkid_probe pr , const struct blkid_idinfo * id , uint64_t * offset , const struct blkid_idmag * * res ) { const struct blkid_idmag * mag = NULL ; uint64_t off = 0 ; if ( id ) mag = & id -> magics [ 0 ] ; if ( res ) * res = NULL ; while ( mag && mag -> magic ) { unsigned char * buf ; off = ( mag -> kboff + ( mag -> sboff >> 10 ) ) << 10 ; buf = blkid_probe_get_buffer ( pr , off , 1024 ) ; if ( ! buf && errno ) return - errno ; if ( buf && ! memcmp ( mag -> magic , buf + ( mag -> sboff & 0x3ff ) , mag -> len ) ) { DBG ( LOWPROBE , ul_debug ( " \t " , mag -> sboff , mag -> kboff ) ) ; if ( offset ) * offset = off + ( mag -> sboff & 0x3ff ) ; if ( res ) * res = mag ; return BLKID_PROBE_OK ; } mag ++ ; } if ( id && id -> magics [ 0 ] . magic ) return BLKID_PROBE_NONE ; return BLKID_PROBE_OK ; }
Check for matching magic value.
Check for matching magic value .
/* try to detect by magic string */ /* magic string(s) defined, but not found */