예제 #1
0
static void
sgi_write_table(void)
{
	sgilabel->csum = 0;
	sgilabel->csum = SGI_SSWAP32(two_s_complement_32bit_sum(
			(unsigned int*)sgilabel, sizeof(*sgilabel)));
	assert(two_s_complement_32bit_sum(
		(unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);

	if (lseek(fd, 0, SEEK_SET) < 0)
		fdisk_fatal(unable_to_seek);
	if (write(fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE)
		fdisk_fatal(unable_to_write);
	if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) {
		/*
		 * keep this habit of first writing the "sgilabel".
		 * I never tested whether it works without (AN 981002).
		 */
		sgiinfo *info = fill_sgiinfo();
		int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start);
		if (lseek(fd, infostartblock*SECTOR_SIZE, SEEK_SET) < 0)
			fdisk_fatal(unable_to_seek);
		if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE)
			fdisk_fatal(unable_to_write);
		free(info);
	}
}
예제 #2
0
static int
check_sgi_label(void)
{
	if (sizeof(sgi_partition) > 512) {
		/* According to MIPS Computer Systems, Inc the label
		 * must not contain more than 512 bytes */
		BUG_bad_sgi_partition_size();
	}

	if (sgilabel->magic != SGI_LABEL_MAGIC
	 && sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED
	) {
		current_label_type = label_dos;
		return 0;
	}

	sgi_other_endian = (sgilabel->magic == SGI_LABEL_MAGIC_SWAPPED);
	/*
	 * test for correct checksum
	 */
	if (two_s_complement_32bit_sum((unsigned int*)sgilabel,
				sizeof(*sgilabel))) {
		printf("Detected sgi disklabel with wrong checksum\n");
	}
	update_units();
	current_label_type = label_sgi;
	partitions = 16;
	sgi_volumes = 15;
	return 1;
}
예제 #3
0
static int
sgi_probe_label(struct fdisk_context *cxt) {
	if (sizeof(sgilabel) > 512) {
		fprintf(stderr,
			_("According to MIPS Computer Systems, Inc the "
			  "Label must not contain more than 512 bytes\n"));
		exit(1);
	}

	if (sgilabel->magic != SGI_LABEL_MAGIC &&
	    sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED) {
		other_endian = 0;
		return 0;
	}

	other_endian = (sgilabel->magic == SGI_LABEL_MAGIC_SWAPPED);
	/*
	 * test for correct checksum
	 */
	if (two_s_complement_32bit_sum((unsigned int*)sgilabel,
				       sizeof(*sgilabel))) {
		fprintf(stderr,
			_("Detected sgi disklabel with wrong checksum.\n"));
	}
	cxt->disklabel = FDISK_DISKLABEL_SGI;
	partitions= 16;
	volumes = 15;
	return 1;
}
예제 #4
0
static void
sgi_write_table(void)
{
	sgilabel->csum = 0;
	sgilabel->csum = SGI_SSWAP32(two_s_complement_32bit_sum(
			(unsigned int*)sgilabel, sizeof(*sgilabel)));
	assert(two_s_complement_32bit_sum(
		(unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);

	write_sector(0, sgilabel);
	if (is_prefixed_with((char*)sgilabel->directory[0].vol_file_name, "sgilabel")) {
		/*
		 * keep this habit of first writing the "sgilabel".
		 * I never tested whether it works without (AN 981002).
		 */
		sgiinfo *info = fill_sgiinfo();
		int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start);
		write_sector(infostartblock, info);
		free(info);
	}
}
예제 #5
0
static int sgi_write_disklabel(struct fdisk_context *cxt)
{
	sgiinfo *info = NULL;

	sgilabel->csum = 0;
	sgilabel->csum = SSWAP32(two_s_complement_32bit_sum(
		(unsigned int*)sgilabel,
		sizeof(*sgilabel)));
	assert(two_s_complement_32bit_sum(
		(unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);
	if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
		goto err;
	if (write(cxt->dev_fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE)
		goto err;
	if (!strncmp((char *) sgilabel->directory[0].vol_file_name, "sgilabel", 8)) {
		/*
		 * keep this habit of first writing the "sgilabel".
		 * I never tested whether it works without (AN 981002).
		 */
		int infostartblock
			= SSWAP32(sgilabel->directory[0].vol_file_start);

		if (lseek(cxt->dev_fd, (off_t) infostartblock *
						SECTOR_SIZE, SEEK_SET) < 0)
			goto err;

		info = fill_sgiinfo();
		if (!info)
			goto err;

		if (write(cxt->dev_fd, info, SECTOR_SIZE) != SECTOR_SIZE)
			goto err;
	}

	free(info);
	return 0;
err:
	free(info);
	return -errno;
}