Ejemplo n.º 1
0
static int probe_superblocks(blkid_probe pr)
{
    struct stat st;
    int rc;

    if (fstat(blkid_probe_get_fd(pr), &st))
        return -1;

    blkid_probe_enable_partitions(pr, 1);

    if (!S_ISCHR(st.st_mode) &&
            blkid_probe_get_size(pr) <= 1024 * 1440 &&
            blkid_probe_is_wholedisk(pr)) {
        /*
         * check if the small disk is partitioned, if yes then
         * don't probe for filesystems.
         */
        blkid_probe_enable_superblocks(pr, 0);

        rc = blkid_do_fullprobe(pr);
        if (rc < 0)
            return rc;        /* -1 = error, 1 = nothing, 0 = success */

        if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
            return 0;        /* partition table detected */
    }

    blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
    blkid_probe_enable_superblocks(pr, 1);

    return blkid_do_safeprobe(pr);
}
Ejemplo n.º 2
0
static int last_lba(blkid_probe pr, uint64_t *lba)
{
	uint64_t sz = blkid_probe_get_size(pr);
	unsigned int ssz = blkid_probe_get_sectorsize(pr);

	if (sz < ssz)
		return -1;

	*lba = (sz / ssz) - 1ULL;
	return 0;
}
Ejemplo n.º 3
0
u_int64_t zuluCryptGetVolumeSize( const char * device )
{
	stringList_t stl = StringListVoid ;

	StringListIterator it  ;
	StringListIterator end ;

	string_t xt ;

	const char * e ;

	u_int64_t r = 0 ;

	blkid_probe blkid = blkid_new_probe_from_filename( device ) ;

	if( blkid == NULL ){
		return 0 ;
	}

	e = NULL ;
	blkid_do_probe( blkid ) ;
	blkid_probe_lookup_value( blkid,"TYPE",&e,NULL ) ;

	if( StringsAreNotEqual( e,"btrfs" ) ){
		r = blkid_probe_get_size( blkid ) ;
		blkid_free_probe( blkid ) ;
		return r ;
	}else{
		/*
		 * we got a btrfs volume,this device could be one among a bunch of devices that makes the btfs volume.
		 * iterate through all known devices and add their sizes to this device if they are a part of the same
		 * btrfs volume.
		 */
		e = NULL ;

		if( blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) == 0 ){
			xt = String( e ) ;
		}else{
			xt = StringVoid ;
		}

		blkid_free_probe( blkid ) ;

		if( xt == StringVoid ){
			return 0 ;
		}else{
			/*
			 * zuluCryptVolumeList() is defined in this source file
			 */
			stl = zuluCryptVolumeList() ;
			zuluCryptSecurityGainElevatedPrivileges() ;

			StringListGetIterators( stl,&it,&end ) ;

			while( it != end ){
				blkid = blkid_new_probe_from_filename( StringContent( *it ) ) ;
				it++ ;
				if( blkid != NULL ){
					blkid_do_probe( blkid ) ;
					e = NULL ;
					if( blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) == 0 ){
						if( StringEqual( xt,e ) ){
							r += blkid_probe_get_size( blkid ) ;
						}
					}
					blkid_free_probe( blkid ) ;
				}
			}
			StringDelete( &xt ) ;
			StringListDelete( &stl ) ;
			return r ;
		}
	}
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    int i, nparts;
    char *devname;
    blkid_probe pr;
    blkid_partlist ls;
    blkid_parttable root_tab;

    if (argc < 2) {
        fprintf(stderr, "usage: %s <device|file>  "
                "-- prints partitions\n",
                program_invocation_short_name);
        return EXIT_FAILURE;
    }

    devname = argv[1];
    pr = blkid_new_probe_from_filename(devname);
    if (!pr)
        err(EXIT_FAILURE, "%s: faild to create a new libblkid probe",
            devname);
    /* Binary interface */
    ls = blkid_probe_get_partitions(pr);
    if (!ls)
        errx(EXIT_FAILURE, "%s: failed to read partitions\n", devname);

    /*
     * Print info about the primary (root) partition table
     */
    root_tab = blkid_partlist_get_table(ls);
    if (!root_tab)
        errx(EXIT_FAILURE, "%s: does not contains any "
             "known partition table\n", devname);

    printf("size: %jd, sector size: %u, PT: %s, offset: %jd\n---\n",
           blkid_probe_get_size(pr),
           blkid_probe_get_sectorsize(pr),
           blkid_parttable_get_type(root_tab),
           blkid_parttable_get_offset(root_tab));

    /*
     * List partitions
     */
    nparts = blkid_partlist_numof_partitions(ls);
    if (!nparts)
        goto done;

    for (i = 0; i < nparts; i++) {
        const char *p;
        blkid_partition par = blkid_partlist_get_partition(ls, i);
        blkid_parttable tab = blkid_partition_get_table(par);

        printf("#%d: %10llu %10llu  0x%x",
               blkid_partition_get_partno(par),
               (unsigned long long) blkid_partition_get_start(par),
               (unsigned long long) blkid_partition_get_size(par),
               blkid_partition_get_type(par));

        if (root_tab != tab)
            /* subpartition (BSD, Minix, ...) */
            printf(" (%s)", blkid_parttable_get_type(tab));

        p = blkid_partition_get_name(par);
        if (p)
            printf(" name='%s'", p);
        p = blkid_partition_get_uuid(par);
        if (p)
            printf(" uuid='%s'", p);
        p = blkid_partition_get_type_string(par);
        if (p)
            printf(" type='%s'", p);

        putc('\n', stdout);
    }

done:
    blkid_free_probe(pr);
    return EXIT_SUCCESS;
}
Ejemplo n.º 5
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;
}