示例#1
0
int get_device_info(int fd, struct device_info *info)
{
    blkid_probe probe;
    struct stat stat;
    int ret;

    *info = device_info_clueless;

    ret = fstat(fd, &stat);
    if (ret < 0) {
	perror("fstat on target failed");
	return -1;
    }

    if (S_ISREG(stat.st_mode)) {
	/* there is nothing more to discover for an image file */
	info->type = TYPE_FILE;
	info->partition = 0;
	info->size = stat.st_size;
	return 0;
    }

    if (!S_ISBLK(stat.st_mode)) {
	/* neither regular file nor block device? not usable */
	info->type = TYPE_BAD;
	return 0;
    }

    probe = blkid_new_probe();
    if (!probe) {
	return -1;
    }

    if (blkid_probe_set_device(probe, fd, 0, 0)) {
	blkid_free_probe(probe);
	return -1;
    }

    get_block_device_size(info, fd);
    get_block_geometry(info, fd);
    info->sector_size = blkid_probe_get_sectorsize(probe);

    /* use udev information if available, fall back to blkid probing */
    if (udev_fill_info(info, &stat))
	blkid_fill_info(info, probe);

    blkid_free_probe(probe);
    return 0;
}
示例#2
0
int get_device_info(int fd, struct device_info *info)
{
    struct stat stat;
    int ret;

    *info = device_info_clueless;

    ret = fstat(fd, &stat);
    if (ret < 0) {
	perror("fstat on target failed");
	return -1;
    }

    if (S_ISREG(stat.st_mode)) {
	/* there is nothing more to discover for an image file */
	info->type = TYPE_FILE;
	info->partition = 0;
	info->size = stat.st_size;
	return 0;
    }

    if (!S_ISBLK(stat.st_mode)) {
	/* neither regular file nor block device? not usable */
	info->type = TYPE_BAD;
	return 0;
    }

    get_block_device_size(info, fd);
    get_block_geometry(info, fd);
    get_sector_size(info, fd);

    /* use udev information if available */
    udev_fill_info(info, &stat);

    return 0;
}