def _get_size_for_dev(device):
    """
    @param device: the device
    @type device: pyudev.Device
    @return: the size in logical blocks, 0 if none found
    @rtype: int
    """
    attributes = device.attributes
    try:
        sect_size = attributes.asint('size')
    except (KeyError, UnicodeDecodeError, ValueError):
        return 0
    if device['DEVTYPE'] == 'partition':
        attributes = device.parent.attributes
    try:
        logical_block_size = attributes.asint('queue/logical_block_size')
    except (KeyError, UnicodeDecodeError, ValueError):
        return 0
    return sect_size * 512 // logical_block_size
