コード例 #1
0
static void blkid_probe_to_tags(blkid_probe pr, blkid_dev dev)
{
	const char *data;
	const char *name;
	int nvals, n;
	size_t len;

	nvals = blkid_probe_numof_values(pr);

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len) != 0)
			continue;
		if (strncmp(name, "PART_ENTRY_", 11) == 0) {
			if (strcmp(name, "PART_ENTRY_UUID") == 0)
				blkid_set_tag(dev, "PARTUUID", data, len);
			else if (strcmp(name, "PART_ENTRY_NAME") == 0)
				blkid_set_tag(dev, "PARTLABEL", data, len);

		} else if (!strstr(name, "_ID")) {
			/* superblock UUID, LABEL, ...
			 * but not {SYSTEM,APPLICATION,..._ID} */
			blkid_set_tag(dev, name, data, len);
		}
	}
}
コード例 #2
0
ファイル: verify.c プロジェクト: AtariTeenageRiot/LUKS
static void blkid_probe_to_tags(blkid_probe pr, blkid_dev dev)
{
	const char *data;
	const char *name;
	int nvals, n;
	size_t len;

	nvals = blkid_probe_numof_values(pr);

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len) == 0)
			blkid_set_tag(dev, name, data, len);
	}
}
コード例 #3
0
static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool test)
{
    const char *root_partition;
    int64_t offset = 0;
    bool noraid = false;
    _cleanup_close_ int fd = -1;
    blkid_probe pr;
    const char *data;
    const char *name;
    int nvals;
    int i;
    int err = 0;
    bool is_gpt = false;

    static const struct option options[] = {
        { "offset", optional_argument, NULL, 'o' },
        { "noraid", no_argument, NULL, 'R' },
        {}
    };

    for (;;) {
        int option;

        option = getopt_long(argc, argv, "oR", options, NULL);
        if (option == -1)
            break;

        switch (option) {
        case 'o':
            offset = strtoull(optarg, NULL, 0);
            break;
        case 'R':
            noraid = true;
            break;
        }
    }

    pr = blkid_new_probe();
    if (!pr)
        return EXIT_FAILURE;

    blkid_probe_set_superblocks_flags(pr,
                                      BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
                                      BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
                                      BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);

    if (noraid)
        blkid_probe_filter_superblocks_usage(pr, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);

    fd = open(udev_device_get_devnode(dev), O_RDONLY|O_CLOEXEC);
    if (fd < 0) {
        fprintf(stderr, "error: %s: %m\n", udev_device_get_devnode(dev));
        goto out;
    }

    err = blkid_probe_set_device(pr, fd, offset, 0);
    if (err < 0)
        goto out;

    log_debug("probe %s %sraid offset=%llu",
              udev_device_get_devnode(dev),
              noraid ? "no" : "", (unsigned long long) offset);

    err = probe_superblocks(pr);
    if (err < 0)
        goto out;

    /* If we are a partition then our parent passed on the root
     * partition UUID to us */
    root_partition = udev_device_get_property_value(dev, "ID_PART_GPT_AUTO_ROOT_UUID");

    nvals = blkid_probe_numof_values(pr);
    for (i = 0; i < nvals; i++) {
        if (blkid_probe_get_value(pr, i, &name, &data, NULL))
            continue;

        print_property(dev, test, name, data);

        /* Is this a disk with GPT partition table? */
        if (streq(name, "PTTYPE") && streq(data, "gpt"))
            is_gpt = true;

        /* Is this a partition that matches the root partition
         * property we inherited from our parent? */
        if (root_partition && streq(name, "PART_ENTRY_UUID") && streq(data, root_partition))
            udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT", "1");
    }

    if (is_gpt)
        find_gpt_root(dev, pr, test);

    blkid_free_probe(pr);
out:
    if (err < 0)
        return EXIT_FAILURE;

    return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: blkid.c プロジェクト: tcdog001/autelan
static int lowprobe_device(blkid_probe pr, const char *devname,
			int chain, char *show[], int output,
			blkid_loff_t offset, blkid_loff_t size)
{
	const char *data;
	const char *name;
	int nvals = 0, n, num = 1;
	size_t len;
	int fd;
	int rc = 0;
	static int first = 1;

	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
		return 2;
	}
	if (blkid_probe_set_device(pr, fd, offset, size))
		goto done;

	if (chain & LOWPROBE_TOPOLOGY)
		rc = lowprobe_topology(pr);
	if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS))
		rc = lowprobe_superblocks(pr);
	if (rc < 0)
		goto done;

	nvals = blkid_probe_numof_values(pr);

	if (nvals && !first && output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))
		/* add extra line between output from devices */
		fputc('\n', stdout);

	if (output & OUTPUT_DEVICE_ONLY) {
		printf("%s\n", devname);
		goto done;
	}

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len))
			continue;
		if (show[0] && !has_item(show, name))
			continue;
		len = strnlen((char *) data, len);
		print_value(output, num++, devname, (char *) data, name, len);
	}

	if (first)
		first = 0;
	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY |
					OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
		printf("\n");
done:
	if (rc == -2) {
		if (output & OUTPUT_UDEV_LIST)
			print_udev_ambivalent(pr);
		else
			fprintf(stderr,
				"%s: ambivalent result (probably more "
				"filesystems on the device, use wipefs(8) "
				"to see more details)\n",
				devname);
	}
	close(fd);
	return !nvals ? 2 : 0;
}
コード例 #5
0
ファイル: udev-builtin-blkid.c プロジェクト: Nikoli/eudev
static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool test)
{
        int64_t offset = 0;
        bool noraid = false;
        int fd = -1;
        blkid_probe pr;
        const char *data;
        const char *name;
        int nvals;
        int i;
        size_t len;
        int err = 0;

        static const struct option options[] = {
                { "offset", optional_argument, NULL, 'o' },
                { "noraid", no_argument, NULL, 'R' },
                {}
        };

        for (;;) {
                int option;

                option = getopt_long(argc, argv, "oR", options, NULL);
                if (option == -1)
                        break;

                switch (option) {
                case 'o':
                        offset = strtoull(optarg, NULL, 0);
                        break;
                case 'R':
                        noraid = true;
                        break;
                }
        }

        pr = blkid_new_probe();
        if (!pr)
                return EXIT_FAILURE;

        blkid_probe_set_superblocks_flags(pr,
                BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
                BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
                BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);

        if (noraid)
                blkid_probe_filter_superblocks_usage(pr, BLKID_FLTR_NOTIN, BLKID_USAGE_RAID);

        fd = open(udev_device_get_devnode(dev), O_RDONLY|O_CLOEXEC);
        if (fd < 0) {
                fprintf(stderr, "error: %s: %m\n", udev_device_get_devnode(dev));
                goto out;
        }

        err = blkid_probe_set_device(pr, fd, offset, 0);
        if (err < 0)
                goto out;

        log_debug("probe %s %sraid offset=%llu\n",
                  udev_device_get_devnode(dev),
                  noraid ? "no" : "", (unsigned long long) offset);

        err = probe_superblocks(pr);
        if (err < 0)
                goto out;

        nvals = blkid_probe_numof_values(pr);
        for (i = 0; i < nvals; i++) {
                if (blkid_probe_get_value(pr, i, &name, &data, &len))
                        continue;
                len = strnlen((char *) data, len);
                print_property(dev, test, name, (char *) data);
        }

        blkid_free_probe(pr);
out:
        if (fd > 0)
                close(fd);
        if (err < 0)
                return EXIT_FAILURE;
        return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: blkid.c プロジェクト: mluscon/util-linux
static int lowprobe_device(blkid_probe pr, const char *devname,
			int chain, char *show[], int output,
			blkid_loff_t offset, blkid_loff_t size)
{
	const char *data;
	const char *name;
	int nvals = 0, n, num = 1;
	size_t len;
	int fd;
	int rc = 0;
	static int first = 1;

	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "error: %s: %m\n", devname);
		return 2;
	}
	if (blkid_probe_set_device(pr, fd, offset, size))
		goto done;

	if (chain & LOWPROBE_TOPOLOGY)
		rc = lowprobe_topology(pr);
	if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS))
		rc = lowprobe_superblocks(pr);
	if (rc < 0)
		goto done;

	if (!rc)
		nvals = blkid_probe_numof_values(pr);

	if (nvals &&
	    !(chain & LOWPROBE_TOPOLOGY) &&
	    !(output & OUTPUT_UDEV_LIST) &&
	    !blkid_probe_has_value(pr, "TYPE") &&
	    !blkid_probe_has_value(pr, "PTTYPE"))
		/*
		 * Ignore probing result if there is not any filesystem or
		 * partition table on the device and udev output is not
		 * requested.
		 *
		 * The udev db stores information about partitions, so
		 * PART_ENTRY_* values are alway important.
		 */
		nvals = 0;

	if (nvals && !first && output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))
		/* add extra line between output from devices */
		fputc('\n', stdout);

	if (nvals && (output & OUTPUT_DEVICE_ONLY)) {
		printf("%s\n", devname);
		goto done;
	}

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len))
			continue;
		if (show[0] && !has_item(show, name))
			continue;
		len = strnlen((char *) data, len);
		print_value(output, num++, devname, (char *) data, name, len);
	}

	if (first)
		first = 0;
	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY |
					OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
		printf("\n");
done:
	if (rc == -2) {
		if (output & OUTPUT_UDEV_LIST)
			print_udev_ambivalent(pr);
		else
			fprintf(stderr,
				"%s: ambivalent result (probably more "
				"filesystems on the device, use wipefs(8) "
				"to see more details)\n",
				devname);
	}
	close(fd);

	if (rc == -2)
		return 8;	/* ambivalent probing result */
	if (!nvals)
		return 2;	/* nothing detected */

	return 0;		/* sucess */
}
コード例 #7
0
ファイル: topology.c プロジェクト: 0xAX/util-linux
int main(int argc, char *argv[])
{
	int rc;
	char *devname;
	blkid_probe pr;
	blkid_topology tp;

	if (argc < 2) {
		fprintf(stderr, "usage: %s <device>  "
				"-- prints topology details about the device\n",
				program_invocation_short_name);
		return EXIT_FAILURE;
	}

	devname = argv[1];
	pr = blkid_new_probe_from_filename(devname);
	if (!pr)
		err(EXIT_FAILURE, "%s: failed to create a new libblkid probe",
				devname);
	/*
	 * Binary interface
	 */
	tp = blkid_probe_get_topology(pr);
	if (tp) {
		printf("----- binary interface:\n");
		printf("\talignment offset     : %lu\n",
				blkid_topology_get_alignment_offset(tp));
		printf("\tminimum io size      : %lu\n",
				blkid_topology_get_minimum_io_size(tp));
		printf("\toptimal io size      : %lu\n",
				blkid_topology_get_optimal_io_size(tp));
		printf("\tlogical sector size  : %lu\n",
				blkid_topology_get_logical_sector_size(tp));
		printf("\tphysical sector size : %lu\n",
				blkid_topology_get_physical_sector_size(tp));
	}

	/*
	 * NAME=value interface
	 */

	/* enable topology probing */
	blkid_probe_enable_topology(pr, TRUE);

	/* disable superblocks probing (enabled by default) */
	blkid_probe_enable_superblocks(pr, FALSE);

	rc = blkid_do_fullprobe(pr);
	if (rc == -1)
		errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname);
	else if (rc == 1)
		warnx("%s: missing topology information", devname);
	else {
		int i, nvals = blkid_probe_numof_values(pr);

		printf("----- NAME=value interface (values: %d):\n", nvals);

		for (i = 0; i < nvals; i++) {
			const char *name, *data;

			blkid_probe_get_value(pr, i, &name, &data, NULL);
			printf("\t%s = %s\n", name, data);
		}
	}

	blkid_free_probe(pr);
	return EXIT_SUCCESS;
}
コード例 #8
0
static int lowprobe_device(blkid_probe pr, const char *devname,	char *show[],
			int output, blkid_loff_t offset, blkid_loff_t size)
{
	const char *data;
	const char *name;
	int nvals = 0, n, num = 1;
	size_t len;
	int fd;
	int rc = 0;
	struct stat st;

	fd = open(devname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "error: %s: %s\n", devname, strerror(errno));
		return 2;
	}
	if (blkid_probe_set_device(pr, fd, offset, size))
		goto done;

	if (fstat(fd, &st))
		goto done;
	/*
	 * partitions probing
	 */
	blkid_probe_enable_superblocks(pr, 0);	/* enabled by default ;-( */

	blkid_probe_enable_partitions(pr, 1);
	rc = blkid_do_fullprobe(pr);
	blkid_probe_enable_partitions(pr, 0);

	if (rc < 0)
		goto done;	/* -1 = error, 1 = nothing, 0 = succes */

	/*
	 * Don't probe for FS/RAIDs on small devices
	 */
	if (rc || S_ISCHR(st.st_mode) ||
	    blkid_probe_get_size(pr) > 1024 * 1440) {
		/*
		 * filesystems/RAIDs probing
		 */
		blkid_probe_enable_superblocks(pr, 1);

		rc = blkid_do_safeprobe(pr);
		if (rc < 0)
			goto done;
	}

	nvals = blkid_probe_numof_values(pr);

	if (output & OUTPUT_DEVICE_ONLY) {
		printf("%s\n", devname);
		goto done;
	}

	for (n = 0; n < nvals; n++) {
		if (blkid_probe_get_value(pr, n, &name, &data, &len))
			continue;
		if (show[0] && !has_item(show, name))
			continue;
		len = strnlen((char *) data, len);
		print_value(output, num++, devname, (char *) data, name, len);
	}

	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST)))
		printf("\n");
done:
	if (rc == -2) {
		if (output & OUTPUT_UDEV_LIST)
			print_udev_ambivalent(pr);
		else
			fprintf(stderr,
				"%s: ambivalent result (probably more "
				"filesystems on the device, use wipefs(8) "
				"to see more details)\n",
				devname);
	}
	close(fd);
	return !nvals ? 2 : 0;
}