Example #1
0
static int sun_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsigned long flag)
{
	struct sun_disklabel *sunlabel;
	struct sun_info *p;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_label(cxt, SUN));

	if (i >= cxt->label->nparts_max)
		return -EINVAL;

	sunlabel = self_disklabel(cxt);
	p = &sunlabel->vtoc.infos[i];

	switch (flag) {
	case SUN_FLAG_UNMNT:
		p->flags ^= cpu_to_be16(SUN_FLAG_UNMNT);
		fdisk_label_set_changed(cxt->label, 1);
		break;
	case SUN_FLAG_RONLY:
		p->flags ^= cpu_to_be16(SUN_FLAG_RONLY);
		fdisk_label_set_changed(cxt->label, 1);
		break;
	default:
		return 1;
	}

	return 0;
}
Example #2
0
int fdisk_sgi_set_bootfile(struct fdisk_context *cxt)
{
	int rc = 0;
	size_t sz;
	char *name = NULL;
	struct sgi_disklabel *sgilabel = self_disklabel(cxt);

	fdisk_info(cxt, _("The current boot file is: %s"), sgilabel->boot_file);

	rc = fdisk_ask_string(cxt, _("Enter of the new boot file"), &name);
	if (rc == 0)
		rc = sgi_check_bootfile(cxt, name);
	if (rc) {
		if (rc == 1)
			fdisk_info(cxt, _("Boot file unchanged"));
		goto done;
	}

	memset(sgilabel->boot_file, 0, sizeof(sgilabel->boot_file));
	sz = strlen(name);

	assert(sz <= sizeof(sgilabel->boot_file));	/* see sgi_check_bootfile() */

	memcpy(sgilabel->boot_file, name, sz);

	fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
			_("Bootfile is changed to \"%s\"."), name);
done:
	free(name);
	return rc;
}
Example #3
0
static int sgi_set_partition(struct fdisk_context *cxt, size_t i,
			     unsigned int start, unsigned int length, int sys)
{
	struct sgi_disklabel *sgilabel;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_disklabel(cxt, SGI));

	sgilabel = self_disklabel(cxt);
	sgilabel->partitions[i].type = cpu_to_be32(sys);
	sgilabel->partitions[i].num_blocks = cpu_to_be32(length);
	sgilabel->partitions[i].first_block = cpu_to_be32(start);

	fdisk_label_set_changed(cxt->label, 1);

	if (sgi_gaps(cxt) < 0)	/* rebuild freelist */
		fdisk_warnx(cxt, _("Partition overlap on the disk."));
	if (length) {
		struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sys);
		fdisk_info_new_partition(cxt, i + 1, start, start + length, t);
	}

	return 0;
}
Example #4
0
static int sun_delete_partition(struct fdisk_context *cxt,
		size_t partnum)
{
	struct sun_disklabel *sunlabel;
	struct sun_partition *part;
	struct sun_info *info;
	unsigned int nsec;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_label(cxt, SUN));

	sunlabel = self_disklabel(cxt);
	part = &sunlabel->partitions[partnum];
	info = &sunlabel->vtoc.infos[partnum];

	if (partnum == 2 &&
	    be16_to_cpu(info->id) == SUN_TAG_WHOLEDISK &&
	    !part->start_cylinder &&
	    (nsec = be32_to_cpu(part->num_sectors))
	    == cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders)
		fdisk_info(cxt, _("If you want to maintain SunOS/Solaris compatibility, "
			 "consider leaving this "
			 "partition as Whole disk (5), starting at 0, with %u "
			 "sectors"), nsec);
	info->id = cpu_to_be16(SUN_TAG_UNASSIGNED);
	part->num_sectors = 0;
	cxt->label->nparts_cur = count_used_partitions(cxt);
	fdisk_label_set_changed(cxt->label, 1);
	return 0;
}
Example #5
0
static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name)
{
	size_t sz;
	struct sgi_disklabel *sgilabel = self_disklabel(cxt);

	sz = strlen(name);

	if (sz < 3) {
		/* "/a\n" is minimum */
		fdisk_warnx(cxt, _("Invalid Bootfile! "
			 "The bootfile must be an absolute non-zero pathname,"
			 "e.g. \"/unix\" or \"/unix.save\"."));
		return -EINVAL;

	} else if (sz > sizeof(sgilabel->boot_file)) {
		fdisk_warnx(cxt, _("Name of Bootfile too long: %zu bytes maximum."),
				sizeof(sgilabel->boot_file));
		return -EINVAL;

	} else if (*name != '/') {
		fdisk_warnx(cxt, _("Bootfile must have a fully qualified pathname."));
		return -EINVAL;
	}

	if (strncmp(name, (char *) sgilabel->boot_file,
				sizeof(sgilabel->boot_file))) {
		fdisk_warnx(cxt, _("Be aware, that the bootfile is not checked "
			"for existence. SGI's default is \"/unix\" and for "
			"backup \"/unix.save\"."));
		/* filename is correct and did change */
		return 0;
	}

	return 1;	/* filename did not change */
}
Example #6
0
static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsigned long flag)
{
	struct sgi_disklabel *sgilabel;
	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_disklabel(cxt, SGI));

	if (i >= cxt->label->nparts_max)
		return -EINVAL;

	sgilabel = self_disklabel(cxt);

	switch (flag) {
	case SGI_FLAG_BOOT:
		sgilabel->root_part_num =
			be16_to_cpu(sgilabel->root_part_num) == i ?
			0 : cpu_to_be16(i);
		fdisk_label_set_changed(cxt->label, 1);
		break;
	case SGI_FLAG_SWAP:
		sgilabel->swap_part_num =
			be16_to_cpu(sgilabel->swap_part_num) == i ?
			0 : cpu_to_be16(i);
		fdisk_label_set_changed(cxt->label, 1);
		break;
	default:
		return 1;
	}

	return 0;
}
Example #7
0
static int sun_list_disklabel(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_label(cxt, SUN));

	sunlabel = self_disklabel(cxt);

	if (fdisk_is_details(cxt)) {
		fdisk_info(cxt,
		_("Label geometry: %d rpm, %d alternate and %d physical cylinders,\n"
		  "                %d extra sects/cyl, interleave %d:1"),
		       be16_to_cpu(sunlabel->rpm),
		       be16_to_cpu(sunlabel->acyl),
		       be16_to_cpu(sunlabel->pcyl),
		       be16_to_cpu(sunlabel->apc),
		       be16_to_cpu(sunlabel->intrlv));
		fdisk_info(cxt, _("Label ID: %s"), sunlabel->label_id);
		fdisk_info(cxt, _("Volume ID: %s"),
		       *sunlabel->vtoc.volume_id ? sunlabel->vtoc.volume_id : _("<none>"));
	}

	return 0;
}
Example #8
0
static int sun_write_disklabel(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel;
	unsigned short *ush;
	unsigned short csum = 0;
	const size_t sz = sizeof(struct sun_disklabel);

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_label(cxt, SUN));

	sunlabel = self_disklabel(cxt);

	/* Maybe geometry has been modified */
	sunlabel->nhead = cpu_to_be16(cxt->geom.heads);
	sunlabel->nsect = cpu_to_be16(cxt->geom.sectors);

	if (cxt->geom.cylinders != be16_to_cpu(sunlabel->ncyl)) {
		int a = cpu_to_be16(cxt->geom.cylinders);
		int b = be16_to_cpu(sunlabel->acyl);
		sunlabel->ncyl = a - b;
	}

	ush = (unsigned short *) sunlabel;

	while(ush < (unsigned short *)(&sunlabel->csum))
		csum ^= *ush++;
	sunlabel->csum = csum;
	if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
		return -errno;
	if (write_all(cxt->dev_fd, sunlabel, sz) != 0)
		return -errno;

	return 0;
}
Example #9
0
int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt)
{
    struct bsd_disklabel *d = self_disklabel(cxt);
    uintmax_t res;

#if defined (__alpha__) || defined (__ia64__)
    if (fdisk_ask_number(cxt, DEFAULT_SECTOR_SIZE, d->d_secsize,
                         UINT32_MAX, _("bytes/sector"), &res) == 0)
        d->d_secsize = res;

    d->d_nsectors = ask_uint32(cxt, d->d_nsectors, _("sectors/track"));
    d->d_ntracks = ask_uint32(cxt, d->d_ntracks, _("tracks/cylinder"));
    d->d_ncylinders = ask_uint32(cxt, d->d_ncylinders  ,_("cylinders"));
#endif
    if (fdisk_ask_number(cxt, 1, d->d_nsectors * d->d_ntracks,
                         d->d_nsectors * d->d_ntracks,
                         _("sectors/cylinder"), &res) == 0)
        d->d_secpercyl = res;

    d->d_rpm = ask_uint16(cxt, d->d_rpm, _("rpm"));
    d->d_interleave = ask_uint16(cxt, d->d_interleave, _("interleave"));
    d->d_trackskew = ask_uint16(cxt, d->d_trackskew, _("trackskew"));
    d->d_cylskew = ask_uint16(cxt, d->d_cylskew, _("cylinderskew"));

    d->d_headswitch = ask_uint32(cxt, d->d_headswitch, _("headswitch"));
    d->d_trkseek = ask_uint32(cxt, d->d_trkseek, _("track-to-track seek"));

    d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
    return 0;
}
Example #10
0
static int bsd_write_disklabel(struct fdisk_context *cxt)
{
    off_t offset = 0;
    struct fdisk_bsd_label *l = self_label(cxt);
    struct bsd_disklabel *d = self_disklabel(cxt);


    if (l->dos_part)
        offset = dos_partition_get_start(l->dos_part) * cxt->sector_size;

    d->d_checksum = 0;
    d->d_checksum = bsd_dkcksum(d);

    /* Update label within boot block. */
    memmove(&l->bsdbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE
                          + BSD_LABELOFFSET], d, sizeof(*d));

#if defined (__alpha__) && BSD_LABELSECTOR == 0
    /* Write the checksum to the end of the first sector. */
    alpha_bootblock_checksum(l->bsdbuffer);
#endif
    if (lseek(cxt->dev_fd, offset, SEEK_SET) == -1) {
        fdisk_warn(cxt, _("seek on %s failed"), cxt->dev_path);
        return -errno;
    }
    if (write_all(cxt->dev_fd, l->bsdbuffer, sizeof(l->bsdbuffer))) {
        fdisk_warn(cxt, _("cannot write %s"), cxt->dev_path);
        return -errno;
    }
    sync_disks(cxt);

    fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
                _("Disklabel written to %s."), cxt->dev_path);
    return 0;
}
Example #11
0
static int bsd_partition_is_used(
    struct fdisk_context *cxt,
    size_t partnum)
{
    struct bsd_disklabel *d = self_disklabel(cxt);

    if (partnum >= BSD_MAXPARTITIONS)
        return 0;

    return d->d_partitions[partnum].p_size ? 1 : 0;
}
Example #12
0
int fdisk_sgi_create_info(struct fdisk_context *cxt)
{
	struct sgi_disklabel *sgilabel = self_disklabel(cxt);

	/* I keep SGI's habit to write the sgilabel to the second block */
	sgilabel->volume[0].block_num = cpu_to_be32(2);
	sgilabel->volume[0].num_bytes = cpu_to_be32(sizeof(struct sgi_info));
	strncpy((char *) sgilabel->volume[0].name, "sgilabel", 8);

	fdisk_info(cxt, _("SGI info created on second sector"));
	return 0;
}
Example #13
0
static int sun_set_parttype(
		struct fdisk_context *cxt,
		size_t i,
		struct fdisk_parttype *t)
{
	struct sun_disklabel *sunlabel;
	struct sun_partition *part;
	struct sun_info *info;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_disklabel(cxt, SUN));

	sunlabel = self_disklabel(cxt);

	if (i >= cxt->label->nparts_max || !t || t->type > UINT16_MAX)
		return -EINVAL;

	if (i == 2 && t->type != SUN_TAG_WHOLEDISK)
		fdisk_info(cxt, _("Consider leaving partition 3 as Whole disk (5),\n"
		         "as SunOS/Solaris expects it and even Linux likes it.\n"));

	part = &sunlabel->partitions[i];
	info = &sunlabel->vtoc.infos[i];

	if (t->type == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
	    int yes, rc;
	    rc = fdisk_ask_yesno(cxt,
	      _("It is highly recommended that the partition at offset 0\n"
	      "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
	      "there may destroy your partition table and bootblock.\n"
	      "Are you sure you want to tag the partition as Linux swap?"), &yes);
	    if (rc)
		    return rc;
	    if (!yes)
		    return 1;
	}

	switch (t->type) {
	case SUN_TAG_SWAP:
	case SUN_TAG_LINUX_SWAP:
		/* swaps are not mountable by default */
		info->flags |= cpu_to_be16(SUN_FLAG_UNMNT);
		break;
	default:
		/* assume other types are mountable;
		   user can change it anyway */
		info->flags &= ~cpu_to_be16(SUN_FLAG_UNMNT);
		break;
	}
	info->id = cpu_to_be16(t->type);
	return 0;
}
Example #14
0
static size_t count_used_partitions(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	size_t ct = 0, i;

	assert(sunlabel);

	for (i = 0; i < cxt->label->nparts_max; i++) {
		if (sunlabel->partitions[i].num_sectors)
			ct++;
	}
	return ct;
}
Example #15
0
static int sgi_set_partition(struct fdisk_context *cxt,
		size_t i,
		struct fdisk_partition *pa)
{
	struct sgi_disklabel *sgilabel;

	if (i >= cxt->label->nparts_max)
		return -EINVAL;

	sgilabel = self_disklabel(cxt);

	if (pa->type) {
		struct fdisk_parttype *t = pa->type;

		if (sgi_get_num_sectors(cxt, i) == 0)	/* caught already before, ... */ {
			fdisk_warnx(cxt, _("Sorry, only for non-empty partitions you can change the tag."));
			return -EINVAL;
		}

		if ((i == 10 && t->code != SGI_TYPE_ENTIRE_DISK)
		    || (i == 8 && t->code != 0))
			fdisk_info(cxt, _("Consider leaving partition 9 as volume header (0), "
					  "and partition 11 as entire volume (6), "
					  "as IRIX expects it."));

		if (cxt->script == NULL
		    && ((t->code != SGI_TYPE_ENTIRE_DISK) && (t->code != SGI_TYPE_VOLHDR))
		    && (sgi_get_start_sector(cxt, i) < 1)) {
			int yes = 0;
			fdisk_ask_yesno(cxt,
				_("It is highly recommended that the partition at offset 0 "
				  "is of type \"SGI volhdr\", the IRIX system will rely on it to "
				  "retrieve from its directory standalone tools like sash and fx. "
				  "Only the \"SGI volume\" entire disk section may violate this. "
				  "Are you sure about tagging this partition differently?"), &yes);
			if (!yes)
				return 1;
		}

		sgilabel->partitions[i].type = cpu_to_be32(t->code);
	}

	if (fdisk_partition_has_start(pa))
		sgilabel->partitions[i].first_block = cpu_to_be32(pa->start);
	if (fdisk_partition_has_size(pa))
		sgilabel->partitions[i].num_blocks = cpu_to_be32(pa->size);

	fdisk_label_set_changed(cxt->label, 1);
	return 0;
}
Example #16
0
/**
 * fdisk_sun_set_pcylcount
 * @cxt: context
 *
 * Sets number of physical cylinders. This function uses libfdisk Ask API for
 * dialog with user.
 *
 * Returns: 0 on success, <0 on error.
 */
int fdisk_sun_set_pcylcount(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	uintmax_t res;
	int rc = fdisk_ask_number(cxt, 0,			/* low */
			be16_to_cpu(sunlabel->pcyl),		/* default */
			USHRT_MAX,				/* high */
			_("Number of physical cylinders"),	/* query */
			&res);					/* result */
	if (!rc)
		return rc;
	sunlabel->pcyl = cpu_to_be16(res);
	return 0;
}
Example #17
0
/**
 * fdisk_sun_set_ilfact:
 * @cxt: context
 *
 * Sets interleave factor. This function uses libfdisk Ask API for dialog with
 * user.
 *
 * Returns: 0 on success, <0 on error.
 */
int fdisk_sun_set_ilfact(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	uintmax_t res;
	int rc = fdisk_ask_number(cxt, 1,			/* low */
			be16_to_cpu(sunlabel->intrlv),		/* default */
			32,					/* high */
			_("Interleave factor"),	/* query */
			&res);					/* result */
	if (rc)
		return rc;
	sunlabel->intrlv = cpu_to_be16(res);
	return 0;
}
Example #18
0
/**
 * fdisk_sun_set_rspeed
 * @cxt: context
 *
 * Sets rotation speed. This function uses libfdisk Ask API for dialog with
 * user.
 *
 * Returns: 0 on success, <0 on error.
 */
int fdisk_sun_set_rspeed(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	uintmax_t res;
	int rc = fdisk_ask_number(cxt, 1,			/* low */
			be16_to_cpu(sunlabel->rpm),		/* default */
			USHRT_MAX,				/* high */
			_("Rotation speed (rpm)"),		/* query */
			&res);					/* result */
	if (rc)
		return rc;
	sunlabel->rpm = cpu_to_be16(res);
	return 0;
}
Example #19
0
/*
 * Read a bsd_disklabel from sector 0 or from the starting sector of p.
 * If it has the right magic, return 0.
 */
static int bsd_readlabel(struct fdisk_context *cxt)
{
    struct fdisk_bsd_label *l;
    struct bsd_disklabel *d;
    int t;
    off_t offset = 0;

    l = self_label(cxt);
    d = self_disklabel(cxt);

    if (l->dos_part)
        /* BSD is nested within DOS partition, get the begin of the
         * partition. Note that DOS uses native sector size. */
        offset = dos_partition_get_start(l->dos_part) * cxt->sector_size;

    if (lseek(cxt->dev_fd, offset, SEEK_SET) == -1)
        return -1;
    if (read_all(cxt->dev_fd, l->bsdbuffer, sizeof(l->bsdbuffer)) < 0)
        return errno ? -errno : -1;

    /* The offset to begin of the disk label. Note that BSD uses
     * 512-byte (default) sectors. */
    memmove(d, &l->bsdbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE
                             + BSD_LABELOFFSET], sizeof(*d));

    if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC) {
        DBG(LABEL, ul_debug("not found magic"));
        return -1;
    }

    for (t = d->d_npartitions; t < BSD_MAXPARTITIONS; t++) {
        d->d_partitions[t].p_size   = 0;
        d->d_partitions[t].p_offset = 0;
        d->d_partitions[t].p_fstype = BSD_FS_UNUSED;
    }

    if (d->d_npartitions > BSD_MAXPARTITIONS)
        fdisk_warnx(cxt, ("Too many partitions (%d, maximum is %d)."),
                    d->d_npartitions, BSD_MAXPARTITIONS);

    /* let's follow in-PT geometry */
    cxt->geom.sectors = d->d_nsectors;
    cxt->geom.heads = d->d_ntracks;
    cxt->geom.cylinders = d->d_ncylinders;

    cxt->label->nparts_cur = d->d_npartitions;
    cxt->label->nparts_max = BSD_MAXPARTITIONS;
    DBG(LABEL, ul_debug("read BSD label"));
    return 0;
}
Example #20
0
/**
 * fdisk_sun_set_xcyl:
 * @cxt: context
 *
 * Sets number of extra sectors per cylinder. This function uses libfdisk Ask API
 * for dialog with user.
 *
 * Returns: 0 on success, <0 on error.
 */
int fdisk_sun_set_xcyl(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	uintmax_t res;
	int rc = fdisk_ask_number(cxt, 0,			/* low */
			be16_to_cpu(sunlabel->apc),		/* default */
			cxt->geom.sectors,			/* high */
			_("Extra sectors per cylinder"),	/* query */
			&res);					/* result */
	if (rc)
		return rc;
	sunlabel->apc = cpu_to_be16(res);
	return 0;
}
Example #21
0
static struct fdisk_parttype *sun_get_parttype(
		struct fdisk_context *cxt,
		size_t n)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	struct fdisk_parttype *t;

	if (n >= cxt->label->nparts_max)
		return NULL;

	t = fdisk_label_get_parttype_from_code(cxt->label,
			be16_to_cpu(sunlabel->vtoc.infos[n].id));
	return t ? : fdisk_new_unknown_parttype(be16_to_cpu(sunlabel->vtoc.infos[n].id), NULL);
}
Example #22
0
/**
 * fdisk_sun_set_alt_cyl:
 * @cxt: context
 *
 * Sets number of alternative cylinders. This function uses libfdisk Ask API
 * for dialog with user.
 *
 * Returns: 0 on success, <0 on error.
 */
int fdisk_sun_set_alt_cyl(struct fdisk_context *cxt)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	uintmax_t res;
	int rc = fdisk_ask_number(cxt, 0,			/* low */
			be16_to_cpu(sunlabel->acyl),		/* default */
			65535,					/* high */
			_("Number of alternate cylinders"),	/* query */
			&res);					/* result */
	if (rc)
		return rc;

	sunlabel->acyl = cpu_to_be16(res);
	return 0;
}
Example #23
0
static void set_sun_partition(struct fdisk_context *cxt, size_t i,
		uint32_t start,uint32_t stop, uint16_t sysid)
{
	struct sun_disklabel *sunlabel = self_disklabel(cxt);
	struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);

	sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
	sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
	sunlabel->partitions[i].start_cylinder =
		cpu_to_be32(start / (cxt->geom.heads * cxt->geom.sectors));
	sunlabel->partitions[i].num_sectors = cpu_to_be32(stop - start);
	fdisk_label_set_changed(cxt->label, 1);

	fdisk_info_new_partition(cxt, i + 1, start, stop, t);
}
Example #24
0
static void fetch_sun(struct fdisk_context *cxt,
		      uint32_t *starts,
		      uint32_t *lens,
		      uint32_t *start,
		      uint32_t *stop)
{
	struct sun_disklabel *sunlabel;
	int continuous = 1;
	size_t i;

	assert(cxt);
	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_label(cxt, SUN));

	sunlabel = self_disklabel(cxt);

	*start = 0;
	*stop = cxt->geom.cylinders * cxt->geom.heads * cxt->geom.sectors;

	for (i = 0; i < cxt->label->nparts_max; i++) {
		struct sun_partition *part = &sunlabel->partitions[i];
		struct sun_info *info = &sunlabel->vtoc.infos[i];

		if (part->num_sectors &&
		    be16_to_cpu(info->id) != SUN_TAG_UNASSIGNED &&
		    be16_to_cpu(info->id) != SUN_TAG_WHOLEDISK) {
			starts[i] = be32_to_cpu(part->start_cylinder) *
				     cxt->geom.heads * cxt->geom.sectors;
			lens[i] = be32_to_cpu(part->num_sectors);
			if (continuous) {
				if (starts[i] == *start)
					*start += lens[i];
				else if (starts[i] + lens[i] >= *stop)
					*stop = starts[i];
				else
					continuous = 0;
				        /* There will be probably more gaps
					  than one, so lets check afterwards */
			}
		} else {
			starts[i] = 0;
			lens[i] = 0;
		}
	}
}
Example #25
0
static int sgi_list_table(struct fdisk_context *cxt)
{
	struct sgi_disklabel *sgilabel = self_disklabel(cxt);
	struct sgi_device_parameter *sgiparam = &sgilabel->devparam;
	int rc = 0;

	if (fdisk_context_display_details(cxt))
		fdisk_info(cxt, _(
			"Label geometry: %d heads, %llu sectors\n"
			"                %llu cylinders, %d physical cylinders\n"
			"                %d extra sects/cyl, interleave %d:1\n"),
			cxt->geom.heads, cxt->geom.sectors,
			cxt->geom.cylinders, be16_to_cpu(sgiparam->pcylcount),
			(int) sgiparam->sparecyl, be16_to_cpu(sgiparam->ilfact));

	fdisk_info(cxt, _("Bootfile: %s"), sgilabel->boot_file);
	return rc;
}
Example #26
0
static int bsd_delete_part(
    struct fdisk_context *cxt,
    size_t partnum)
{
    struct bsd_disklabel *d = self_disklabel(cxt);

    d->d_partitions[partnum].p_size   = 0;
    d->d_partitions[partnum].p_offset = 0;
    d->d_partitions[partnum].p_fstype = BSD_FS_UNUSED;

    if (d->d_npartitions == partnum + 1)
        while (!d->d_partitions[d->d_npartitions - 1].p_size)
            d->d_npartitions--;

    cxt->label->nparts_cur = d->d_npartitions;
    fdisk_label_set_changed(cxt->label, 1);
    return 0;
}
Example #27
0
static int sun_get_partition(struct fdisk_context *cxt, size_t n,
                             struct fdisk_partition *pa)
{
    struct sun_disklabel *sunlabel;
    struct sun_partition *part;
    uint16_t flags;
    uint32_t start, len;

    assert(cxt);
    assert(cxt->label);
    assert(fdisk_is_label(cxt, SUN));

    if (n >= cxt->label->nparts_max)
        return -EINVAL;

    sunlabel = self_disklabel(cxt);
    part = &sunlabel->partitions[n];

    pa->used = part->num_sectors ? 1 : 0;
    if (!pa->used)
        return 0;

    flags = be16_to_cpu(sunlabel->vtoc.infos[n].flags);
    start = be32_to_cpu(part->start_cylinder)
            * cxt->geom.heads * cxt->geom.sectors;
    len = be32_to_cpu(part->num_sectors);

    pa->type = sun_get_parttype(cxt, n);
    if (pa->type && pa->type->code == SUN_TAG_WHOLEDISK)
        pa->wholedisk = 1;

    if (flags & SUN_FLAG_UNMNT || flags & SUN_FLAG_RONLY) {
        if (asprintf(&pa->attrs, "%c%c",
                     flags & SUN_FLAG_UNMNT ? 'u' : ' ',
                     flags & SUN_FLAG_RONLY ? 'r' : ' ') < 0)
            return -ENOMEM;
    }

    pa->start = start;
    pa->end = start + len - (len ? 1 : 0);
    pa->size = len;

    return 0;
}
Example #28
0
static int sgi_get_disklabel_item(struct fdisk_context *cxt, struct fdisk_labelitem *item)
{
	struct sgi_disklabel *sgilabel;
	struct sgi_device_parameter *sgiparam;
	int rc = 0;

	assert(cxt);
	assert(cxt->label);
	assert(fdisk_is_label(cxt, SGI));

	sgilabel = self_disklabel(cxt);
	sgiparam = &sgilabel->devparam;

	switch (item->id) {
	case SGI_LABELITEM_PCYLCOUNT:
		item->name = _("Physical cylinders");
		item->type = 'j';
		item->data.num64 = (uint64_t) be16_to_cpu(sgiparam->pcylcount);
		break;
	case SGI_LABELITEM_SPARECYL:
		item->name = _("Extra sects/cyl");
		item->type = 'j';
		item->data.num64 = (uint64_t) sgiparam->sparecyl;
		break;
	case SGI_LABELITEM_ILFACT:
		item->name = _("Interleave");
		item->type = 'j';
		item->data.num64 = (uint64_t) be16_to_cpu(sgiparam->ilfact);
		break;
	case SGI_LABELITEM_BOOTFILE:
		item->name = _("Bootfile");
		item->type = 's';
		item->data.str = *sgilabel->boot_file ? strdup((char *) sgilabel->boot_file) : NULL;
		break;
	default:
		if (item->id < __FDISK_NLABELITEMS)
			rc = 1;	/* unssupported generic item */
		else
			rc = 2;	/* out of range */
		break;
	}

	return rc;
}
Example #29
0
static int bsd_list_disklabel(struct fdisk_context *cxt)
{
    struct bsd_disklabel *d = self_disklabel(cxt);

    assert(cxt);
    assert(cxt->label);
    assert(fdisk_is_disklabel(cxt, BSD));

    if (fdisk_context_display_details(cxt)) {
        fdisk_info(cxt, "# %s:", cxt->dev_path);

        if ((unsigned) d->d_type < BSD_DKMAXTYPES)
            fdisk_info(cxt, _("type: %s"), bsd_dktypenames[d->d_type]);
        else
            fdisk_info(cxt, _("type: %d"), d->d_type);

        fdisk_info(cxt, _("disk: %.*s"), (int) sizeof(d->d_typename), d->d_typename);
        fdisk_info(cxt, _("label: %.*s"), (int) sizeof(d->d_packname), d->d_packname);

        fdisk_info(cxt, _("flags: %s"),
                   d->d_flags & BSD_D_REMOVABLE ? _(" removable") :
                   d->d_flags & BSD_D_ECC ? _(" ecc") :
                   d->d_flags & BSD_D_BADSECT ? _(" badsect") : "");

        /* On various machines the fields of *lp are short/int/long */
        /* In order to avoid problems, we cast them all to long. */
        fdisk_info(cxt, _("bytes/sector: %ld"), (long) d->d_secsize);
        fdisk_info(cxt, _("sectors/track: %ld"), (long) d->d_nsectors);
        fdisk_info(cxt, _("tracks/cylinder: %ld"), (long) d->d_ntracks);
        fdisk_info(cxt, _("sectors/cylinder: %ld"), (long) d->d_secpercyl);
        fdisk_info(cxt, _("cylinders: %ld"), (long) d->d_ncylinders);
        fdisk_info(cxt, _("rpm: %d"), d->d_rpm);
        fdisk_info(cxt, _("interleave: %d"), d->d_interleave);
        fdisk_info(cxt, _("trackskew: %d"), d->d_trackskew);
        fdisk_info(cxt, _("cylinderskew: %d"), d->d_cylskew);
        fdisk_info(cxt, _("headswitch: %ld (milliseconds)"), (long) d->d_headswitch);
        fdisk_info(cxt, _("track-to-track seek: %ld (milliseconds)"), (long) d->d_trkseek);
    }

    fdisk_info(cxt, _("partitions: %d"), d->d_npartitions);

    return 0;
}
Example #30
0
static int bsd_set_parttype(
    struct fdisk_context *cxt,
    size_t partnum,
    struct fdisk_parttype *t)
{
    struct bsd_partition *p;
    struct bsd_disklabel *d = self_disklabel(cxt);

    if (partnum >= d->d_npartitions || !t || t->type > UINT8_MAX)
        return -EINVAL;

    p = &d->d_partitions[partnum];
    if (t->type == p->p_fstype)
        return 0;

    p->p_fstype = t->type;
    fdisk_label_set_changed(cxt->label, 1);
    return 0;
}