Beispiel #1
0
static void
partinfo(int fd, char *device)
{
	int i;
	int	slice;
	major_t maj;
	minor_t min;
	struct stat64 statbuf;
	struct vtoc vtdata;
	struct dk_gpt *efi;

	i = stat64(device, &statbuf);
	if (i < 0)
		exit(DRERR);
	maj = major(statbuf.st_rdev);
	min = minor(statbuf.st_rdev);

	if ((slice = readvtoc(fd, device, &vtdata)) >= 0) {

		(void) printf("%s\t%0lx\t%0lx\t%ld\t%ld\t%x\t%x\n",
			device, maj, min,
			vtdata.v_part[slice].p_start,
			vtdata.v_part[slice].p_size,
			vtdata.v_part[slice].p_flag,
			vtdata.v_part[slice].p_tag);
	} else if ((slice == VT_ENOTSUP) &&
	    (slice = efi_alloc_and_read(fd, &efi)) >= 0) {
		(void) printf("%s\t%lx\t%lx\t%lld\t%lld\t%hx\t%hx\n",
			device, maj, min,
			efi->efi_parts[slice].p_start,
			efi->efi_parts[slice].p_size,
			efi->efi_parts[slice].p_flag,
			efi->efi_parts[slice].p_tag);
	} else {
		exit(DRERR);
	}
}
Beispiel #2
0
static void
devinfo(struct dk_geom *geom, int fd, char *device)
{
	int i;
	unsigned int nopartitions, sectorcyl, bytes;
	struct vtoc vtdata;
/*
 *	unsigned int version = 0;
 *	unsigned int driveid = 0;
 */

	nopartitions = 0;
	sectorcyl = 0;
	bytes = 0;

	if (readvtoc(fd, device, &vtdata) < 0)
		exit(DRERR);
	sectorcyl = geom->dkg_nhead  *  geom->dkg_nsect;
	bytes = vtdata.v_sectorsz;
/*
 *	these are not supported by Sun.
 *
 *	driveid = osect0->newsect0.pdinfo.driveid;
 *	version = osect0->newsect0.pdinfo.version;
 */
	for (i = 0; i < V_NUMPAR; i++)	{
		if (vtdata.v_part[i].p_size != 0x00)
			nopartitions++;
	}
/*
 *	(void) printf("%s	%0x	%0x	%d	%d	%d\n",
 *		device, version, driveid, sectorcyl, bytes, nopartitions);
 */
	(void) printf("%s	%0x	%0x	%d	%d	%d\n",
		device, 0, 0, sectorcyl, bytes, nopartitions);
}
Beispiel #3
0
/*
 * prtvtoc(): Read and print a VTOC.
 */
static int
prtvtoc(char *devname)
{
    int		fd;
    int		idx;
    freemap_t	*freemap;
    struct stat	sb;
    struct extvtoc	vtoc;
    int		geo;
    struct dk_geom	geom;
    char		*name;
    int		newvtoc = 0;
    struct dk_gpt	*efi;

    name = getfullrawname(devname);
    if (name == NULL)
        return (warn(devname,
                     "internal administrative call (getfullrawname) failed"));
    if (strcmp(name, "") == 0)
        name = devname;
    if ((fd = open(name, O_NONBLOCK|O_RDONLY)) < 0)
        return (warn(name, strerror(errno)));
    if (fstat(fd, &sb) < 0)
        return (warn(name, strerror(errno)));
    if ((sb.st_mode & S_IFMT) != S_IFCHR)
        return (warn(name, "Not a raw device"));

    geo = (readgeom(fd, name, &geom) == 0);
    if (geo) {
        if ((idx = readvtoc(fd, name, &vtoc)) == VT_ENOTSUP) {
            idx = (readefi(fd, name, &efi) == 0);
            newvtoc = 1;
        } else
            idx = (idx == 0);
    }
    (void) close(fd);
    if ((!geo) || (!idx))
        return (-1);
    if (!newvtoc)
        freemap = findfree(&geom, &vtoc);
    else
        freemap = findfree64(efi);
    if (fflag) {
        if (!newvtoc)
            putfree(&vtoc, freemap);
        else
            putfree64(efi, freemap);
    } else {
        if (!newvtoc)
            puttable(&geom, &vtoc, freemap, devname,
                     getmntpt(major(sb.st_rdev),
                              noparttn(minor(sb.st_rdev))));
        else
            puttable64(efi, freemap, devname,
                       getmntpt(major(sb.st_rdev),
                                noparttn(minor(sb.st_rdev))));
    }
    if (newvtoc)
        efi_free(efi);
    return (0);
}