Example #1
0
static int
check_partition_consistency (const PedDevice* dev,
	       		     const PC98RawPartition* raw_part)
{
	if (raw_part->ipl_sect >= dev->hw_geom.sectors
	   || raw_part->sector >= dev->hw_geom.sectors
	   || raw_part->end_sector >= dev->hw_geom.sectors
	   || raw_part->ipl_head >= dev->hw_geom.heads
	   || raw_part->head >= dev->hw_geom.heads
	   || raw_part->end_head >= dev->hw_geom.heads
	   || PED_LE16_TO_CPU(raw_part->ipl_cyl) >= dev->hw_geom.cylinders
	   || PED_LE16_TO_CPU(raw_part->cyl) >= dev->hw_geom.cylinders
	   || PED_LE16_TO_CPU(raw_part->end_cyl) >= dev->hw_geom.cylinders
	   || PED_LE16_TO_CPU(raw_part->cyl)
	   	> PED_LE16_TO_CPU(raw_part->end_cyl)
#if 0
	   || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->ipl_cyl),
			     raw_part->ipl_head, raw_part->ipl_sect)
	   || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->cyl),
			     raw_part->head, raw_part->sector)
	   || !chs_to_sector(dev, PED_LE16_TO_CPU(raw_part->end_cyl),
			     raw_part->end_head, raw_part->end_sector)
#endif
	   || PED_LE16_TO_CPU(raw_part->end_cyl)
	  		< PED_LE16_TO_CPU(raw_part->cyl))
		return 0;

	return 1;
}
Example #2
0
File: pc98.c Project: Excito/parted
static PedSector _GL_ATTRIBUTE_PURE
legacy_end (const PedDisk* disk, const PC98RawPartition* raw_part)
{
	PED_ASSERT (disk != NULL);
	PED_ASSERT (raw_part != NULL);

	if (raw_part->end_head == 0 && raw_part->end_sector == 0) {
		return chs_to_sector (disk->dev,
				      PED_LE16_TO_CPU(raw_part->end_cyl),
				      disk->dev->hw_geom.heads - 1,
				      disk->dev->hw_geom.sectors - 1);
	} else {
		return chs_to_sector (disk->dev,
				      PED_LE16_TO_CPU(raw_part->end_cyl),
				      raw_part->end_head,
				      raw_part->end_sector);
	}
}
Example #3
0
File: pc98.c Project: Excito/parted
static PedSector _GL_ATTRIBUTE_PURE
legacy_start (const PedDisk* disk, const PC98RawPartition* raw_part)
{
	PED_ASSERT (disk != NULL);
	PED_ASSERT (raw_part != NULL);

	return chs_to_sector (disk->dev, PED_LE16_TO_CPU(raw_part->cyl),
			      raw_part->head, raw_part->sector);
}
Example #4
0
File: pc98.c Project: Excito/parted
static int
read_table (PedDisk* disk)
{
	int			i;
	PC98RawTable		table;
	PedConstraint*		constraint_any;

	PED_ASSERT (disk != NULL);
	PED_ASSERT (disk->dev != NULL);

	constraint_any = ped_constraint_any (disk->dev);

	if (!ped_device_read (disk->dev, (void*) &table, 0, 2))
		goto error;

	if (!pc98_check_magic(&table)) {
		if (ped_exception_throw (
			PED_EXCEPTION_ERROR, PED_EXCEPTION_IGNORE_CANCEL,
			_("Invalid partition table on %s."),
			disk->dev->path))
			goto error;
	}

	for (i = 0; i < MAX_PART_COUNT; i++) {
		PC98RawPartition*	raw_part;
		PedPartition*		part;
		PC98PartitionData*	pc98_data;
		PedSector		part_start;
		PedSector		part_end;

		raw_part = &table.partitions [i];

		if (is_unused_partition(raw_part))
			continue;

		part_start = legacy_start (disk, raw_part);
		part_end   = legacy_end (disk, raw_part);

		part = ped_partition_new (disk, PED_PARTITION_NORMAL,
                                          NULL, part_start, part_end);
		if (!part)
			goto error;
		pc98_data = part->disk_specific;
		PED_ASSERT (pc98_data != NULL);

		pc98_data->system = (raw_part->mid << 8) | raw_part->sid;
		pc98_data->boot = GET_BIT(raw_part->mid, 7);
		pc98_data->hidden = !GET_BIT(raw_part->sid, 7);

		ped_partition_set_name (part, raw_part->name);

		pc98_data->ipl_sector = chs_to_sector (
			disk->dev,
			PED_LE16_TO_CPU(raw_part->ipl_cyl),
			raw_part->ipl_head,
			raw_part->ipl_sect);

		/* hack */
		if (pc98_data->ipl_sector == part->geom.start)
			pc98_data->ipl_sector = 0;

		part->num = i + 1;

		if (!ped_disk_add_partition (disk, part, constraint_any))
			goto error;

		if (part->geom.start != part_start
		    || part->geom.end != part_end) {
			ped_exception_throw (
				PED_EXCEPTION_NO_FEATURE,
				PED_EXCEPTION_CANCEL,
				_("Partition %d isn't aligned to cylinder "
				  "boundaries.  This is still unsupported."),
				part->num);
			goto error;
		}

		part->fs_type = ped_file_system_probe (&part->geom);
	}

	ped_constraint_destroy (constraint_any);
	return 1;

error:
	ped_disk_delete_all (disk);
	ped_constraint_destroy (constraint_any);
	return 0;
}