def device(dev, stats=False, config=False, internals=False, superblock=False):
    result = {}

    if not _sysfs_attr(_bcpath(dev), None, 'error', '{0} is not a bcache fo any kind'.format(dev)):
        return False
    elif _bcsys(dev, 'set'):
        # ---------------- It's the cache itself ----------------
        result['uuid'] = uuid()
        base_attr = ['block_size', 'bucket_size', 'cache_available_percent', 'cache_replacement_policy', 'congested']

        # ---------------- Parse through both the blockdev & the FS ----------------
        result.update(_sysfs_parse(_bcpath(dev), base_attr, stats, config, internals))
        result.update(_sysfs_parse(_fspath(), base_attr, stats, config, internals))

        result.update(result.pop('base'))
    else:
        # ---------------- It's a backing device ----------------
        back_uuid = uuid(dev)
        if back_uuid is not None:
            result['cache'] = back_uuid

        try:
            result['dev'] = os.path.basename(_bcsys(dev, 'dev'))
        except:  # pylint: disable=bare-except
            pass
        result['bdev'] = _bdev(dev)

        base_attr = ['cache_mode', 'running', 'state', 'writeback_running']
        base_path = _bcpath(dev)

        result.update(_sysfs_parse(base_path, base_attr, stats, config, internals))
        result.update(result.pop('base'))

        # ---------------- Modifications ----------------
        state = [result['state']]
        if result.pop('running'):
            state.append('running')
        else:
            state.append('stopped')
        if 'writeback_running' in result:
            if result.pop('writeback_running'):
                state.append('writeback_running')
            else:
                state.append('writeback_stopped')
        result['state'] = state

    # ---------------- Statistics ----------------
    if 'stats' in result:
        replre = r'(stats|cache)_'
        statres = result['stats']
        for attr in result['stats'].keys():
            if '/' not in attr:
                key = re.sub(replre, '', attr)
                statres[key] = statres.pop(attr)
            else:
                stat, key = attr.split('/', 1)
                stat = re.sub(replre, '', stat)
                key = re.sub(replre, '', key)
                if stat not in statres:
                    statres[stat] = {}
                statres[stat][key] = statres.pop(attr)
        result['stats'] = statres

    # ---------------- Internals ----------------
    if internals:
        interres = result.pop('inter_ro', {})
        interres.update(result.pop('inter_rw', {}))
        if len(interres):
            for key in interres.keys():
                if key.startswith('internal'):
                    nkey = re.sub(r'internal[s/]*', '', key)
                    interres[nkey] = interres.pop(key)
                    key = nkey
                if key.startswith(('btree', 'writeback')):
                    mkey, skey = re.split(r'_', key, maxsplit=1)
                    if mkey not in interres:
                        interres[mkey] = {}
                    interres[mkey][skey] = interres.pop(key)
            result['internals'] = interres

    # ---------------- Config ----------------
    if config:
        configres = result['config']
        for key in configres.keys():
            if key.startswith('writeback'):
                mkey, skey = re.split(r'_', key, maxsplit=1)
                if mkey not in configres:
                    configres[mkey] = {}
                configres[mkey][skey] = configres.pop(key)
        result['config'] = configres

    # ---------------- Superblock ----------------
    if superblock:
        result['superblock'] = super_(dev)

    return result
Check the state of a single bcache device
dataset/ETHPy150Open saltstack/salt/salt/modules/bcache.py/device