Exemplo n.º 1
0
static int _dev_read_ahead_dev(struct device *dev, uint32_t *read_ahead)
{
	long read_ahead_long;

	if (dev->read_ahead != -1) {
		*read_ahead = (uint32_t) dev->read_ahead;
		return 1;
	}

	if (!dev_open_readonly(dev))
		return_0;

	if (ioctl(dev->fd, BLKRAGET, &read_ahead_long) < 0) {
		log_sys_error("ioctl BLKRAGET", dev_name(dev));
		if (!dev_close(dev))
			stack;
		return 0;
	}

	*read_ahead = (uint32_t) read_ahead_long;
	dev->read_ahead = read_ahead_long;

	log_very_verbose("%s: read_ahead is %u sectors",
			 dev_name(dev), *read_ahead);

	if (!dev_close(dev))
		stack;

	return 1;
}
Exemplo n.º 2
0
struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
			    struct dm_pool *mem, const char *vg_name)
{
	struct disk_list *dl;

	if (!dev_open_readonly(dev))
		return_NULL;

	dl = __read_disk(fmt, dev, mem, vg_name);

	if (!dev_close(dev))
		stack;

	return dl;
}
Exemplo n.º 3
0
Arquivo: dev-md.c Projeto: Jajcus/lvm2
/*
 * Returns -1 on error
 */
int dev_is_md(struct device *dev, uint64_t *sb)
{
    int ret = 1;
    md_minor_version_t minor;
    uint64_t size, sb_offset;

    if (!dev_get_size(dev, &size)) {
        stack;
        return -1;
    }

    if (size < MD_RESERVED_SECTORS * 2)
        return 0;

    if (!dev_open_readonly(dev)) {
        stack;
        return -1;
    }

    /* Check if it is an md component device. */
    /* Version 0.90.0 */
    sb_offset = MD_NEW_SIZE_SECTORS(size) << SECTOR_SHIFT;
    if (_dev_has_md_magic(dev, sb_offset))
        goto out;

    minor = MD_MINOR_VERSION_MIN;
    /* Version 1, try v1.0 -> v1.2 */
    do {
        sb_offset = _v1_sb_offset(size, minor);
        if (_dev_has_md_magic(dev, sb_offset))
            goto out;
    } while (++minor <= MD_MINOR_VERSION_MAX);

    ret = 0;

out:
    if (!dev_close(dev))
        stack;

    if (ret && sb)
        *sb = sb_offset;

    return ret;
}
Exemplo n.º 4
0
int dev_is_luks(struct device *dev, uint64_t *signature)
{
	char buf[LUKS_SIGNATURE_SIZE];
	int ret = -1;

	if (!dev_open_readonly(dev)) {
		stack;
		return -1;
	}

	*signature = 0;

	if (!dev_read(dev, 0, LUKS_SIGNATURE_SIZE, buf))
		goto_out;

	ret = memcmp(buf, LUKS_SIGNATURE, LUKS_SIGNATURE_SIZE) ? 0 : 1;

out:
	if (!dev_close(dev))
		stack;

	return ret;
}