예제 #1
0
파일: constraint.c 프로젝트: Excito/parted
/**
 * Return a constraint that only the given region will satisfy.
 */
PedConstraint*
ped_constraint_exact (const PedGeometry* geom)
{
	PedAlignment	start_align;
	PedAlignment	end_align;
	PedGeometry	start_sector;
	PedGeometry	end_sector;
	int ok;

	/* With grain size of 0, it always succeeds.  */
	ok = ped_alignment_init (&start_align, geom->start, 0);
	assert (ok);
	ok = ped_alignment_init (&end_align, geom->end, 0);
	assert (ok);

	ok = ped_geometry_init (&start_sector, geom->dev, geom->start, 1);
	if (!ok)
	  return NULL;
	ok = ped_geometry_init (&end_sector, geom->dev, geom->end, 1);
	if (!ok)
	  return NULL;

	return ped_constraint_new (&start_align, &end_align,
				   &start_sector, &end_sector, 1,
				   geom->dev->length);
}
예제 #2
0
static PedConstraint *reiserfs_get_resize_constraint(const PedFileSystem *
						     fs)
{
	PedDevice *dev;
	PedSector min_size;
	PedGeometry full_disk;
	reiserfs_fs_t *fs_info;
	PedAlignment start_align;
	PedGeometry start_sector;

	PED_ASSERT(fs != NULL);

	fs_info = fs->type_specific;
	dev = fs->geom->dev;

	if (!ped_alignment_init(&start_align, fs->geom->start, 0))
		return NULL;
	if (!ped_geometry_init(&full_disk, dev, 0, dev->length - 1))
		return NULL;
	if (!ped_geometry_init(&start_sector, dev, fs->geom->start, 1))
		return NULL;

	/*
	   Minsize for reiserfs is area occupied by data blocks and
	   metadata blocks minus free space blocks and minus bitmap
	   blocks which describes free space blocks.
	 */
	min_size = reiserfs_fs_min_size(fs_info) *
	    (reiserfs_fs_block_size(fs_info) / PED_SECTOR_SIZE_DEFAULT);

	return ped_constraint_new(&start_align, ped_alignment_any,
				  &start_sector, &full_disk, min_size,
				  dev->length);
}
예제 #3
0
파일: dasd.c 프로젝트: bcl/parted
static PedConstraint*
_primary_constraint (PedDisk* disk)
{
	PedAlignment start_align;
	PedAlignment end_align;
	PedGeometry	max_geom;
	PedSector sector_size;
	LinuxSpecific* arch_specific;
	DasdDiskSpecific* disk_specific;
	PedSector start;

	PDEBUG;

	arch_specific = LINUX_SPECIFIC (disk->dev);
	disk_specific = disk->disk_specific;
	sector_size = arch_specific->real_sector_size / disk->dev->sector_size;

	if (!ped_alignment_init (&start_align, 0,
							 disk->dev->hw_geom.sectors * sector_size))
		return NULL;
	if (!ped_alignment_init (&end_align, -1,
						     disk->dev->hw_geom.sectors * sector_size))
		return NULL;

	start = (FIRST_USABLE_TRK * (long long) disk->dev->hw_geom.sectors
			    * (long long) arch_specific->real_sector_size
			    / (long long) disk->dev->sector_size);

	if (!ped_geometry_init (&max_geom, disk->dev, start, disk->dev->length))
		return NULL;

	return ped_constraint_new(&start_align, &end_align, &max_geom,
							  &max_geom, 1, disk->dev->length);
}
예제 #4
0
/**
 * Return a constraint that only the given region will satisfy.
 */
PedConstraint*
ped_constraint_exact (const PedGeometry* geom)
{
	PedAlignment	start_align;
	PedAlignment	end_align;
	PedGeometry	start_sector;
	PedGeometry	end_sector;

	ped_alignment_init (&start_align, geom->start, 0);
	ped_alignment_init (&end_align, geom->end, 0);
	ped_geometry_init (&start_sector, geom->dev, geom->start, 1);
	ped_geometry_init (&end_sector, geom->dev, geom->end, 1);

	return ped_constraint_new (&start_align, &end_align,
				   &start_sector, &end_sector, 1,
				   geom->dev->length);
}
예제 #5
0
파일: dvh.c 프로젝트: Distrotech/parted
static PedConstraint*
_get_primary_constraint (PedDisk* disk)
{
        PedGeometry     max_geom;
	if (!ped_geometry_init (&max_geom, disk->dev, 1, disk->dev->length - 1))
		return NULL;
        return ped_constraint_new_from_max (&max_geom);
}
예제 #6
0
static PedConstraint*
_get_constraint (const PedDevice* dev)
{
	PedGeometry	max;

	ped_geometry_init (&max, dev, 1, dev->length - 1);
	return ped_constraint_new_from_max (&max);
}
예제 #7
0
파일: dvh.c 프로젝트: Distrotech/parted
/* The constraint for the volume header partition is different, because it must
 * contain the first sector of the disk.
 */
static PedConstraint*
_get_extended_constraint (PedDisk* disk)
{
        PedGeometry     min_geom;
	if (!ped_geometry_init (&min_geom, disk->dev, 0, 1))
		return NULL;
        return ped_constraint_new_from_min (&min_geom);
}
예제 #8
0
/**
 * Return a constraint that requires a region to entirely contain \p min.
 *
 * \return \c NULL on failure.
 */
PedConstraint*
ped_constraint_new_from_min (const PedGeometry* min)
{
	PedGeometry	full_dev;

	PED_ASSERT (min != NULL);

	ped_geometry_init (&full_dev, min->dev, 0, min->dev->length);
	return ped_constraint_new_from_min_max (min, &full_dev);
}
예제 #9
0
/**
 * Find the largest region that satisfies a constraint.
 *
 * There might be more than one solution.  This function makes no
 * guarantees about which solution it will choose in this case.
 */
PedGeometry*
ped_constraint_solve_max (const PedConstraint* constraint)
{
	PedDevice*	dev;
	PedGeometry	full_dev;

	if (!constraint)
		return NULL;
	dev = constraint->start_range->dev;
	ped_geometry_init (&full_dev, dev, 0, dev->length - 1);
	return ped_constraint_solve_nearest (constraint, &full_dev);
}
예제 #10
0
/**
 * Return a constraint that requires a region to be entirely contained inside
 * \p max, and to entirely contain \p min.
 *
 * \return \c NULL on failure.
 */
PedConstraint*
ped_constraint_new_from_min_max (
	const PedGeometry* min,
	const PedGeometry* max)
{
	PedGeometry	start_range;
	PedGeometry	end_range;

	PED_ASSERT (min != NULL);
	PED_ASSERT (max != NULL);
	PED_ASSERT (ped_geometry_test_inside (max, min));

	ped_geometry_init (&start_range, min->dev, max->start,
			   min->start - max->start + 1);
	ped_geometry_init (&end_range, min->dev, min->end,
			   max->end - min->end + 1);

	return ped_constraint_new (
			ped_alignment_any, ped_alignment_any,
			&start_range, &end_range,
			min->length, max->length);
}
예제 #11
0
static PedConstraint *reiserfs_get_create_constraint(const PedDevice *dev)
{
	PedGeometry full_dev;
	PedSector min_blks = (SUPER_OFFSET_IN_BYTES / DEFAULT_BLOCK_SIZE)
			     + 2 + DEFAULT_JOURNAL_SIZE + 1 + 100 + 1;

	if (!ped_geometry_init(&full_dev, dev, 0, dev->length - 1))
		return NULL;

	return ped_constraint_new(ped_alignment_any, ped_alignment_any,
				  &full_dev, &full_dev,
				  min_blks * (DEFAULT_BLOCK_SIZE / 512),
				  dev->length);
}
예제 #12
0
파일: hfs.c 프로젝트: Excito/parted
PedConstraint *
hfsplus_get_resize_constraint (const PedFileSystem *fs)
{
	PedDevice*	dev = fs->geom->dev;
	PedAlignment	start_align;
	PedGeometry	start_sector;
	PedGeometry	full_dev;
	PedSector	min_size;

	if (!ped_alignment_init (&start_align, fs->geom->start, 0))
		return NULL;
	if (!ped_geometry_init (&start_sector, dev, fs->geom->start, 1))
		return NULL;
	if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
		return NULL;

	min_size = hfsplus_get_min_size (fs);
	if (!min_size) return NULL;

	return ped_constraint_new (&start_align, ped_alignment_any,
				   &start_sector, &full_dev, min_size,
				   fs->geom->length);
}
예제 #13
0
파일: hfs.c 프로젝트: Excito/parted
PedConstraint *
hfs_get_resize_constraint (const PedFileSystem *fs)
{
	PedDevice*	dev = fs->geom->dev;
	PedAlignment	start_align;
	PedGeometry	start_sector;
	PedGeometry	full_dev;
	PedSector	min_size;

	if (!ped_alignment_init (&start_align, fs->geom->start, 0))
		return NULL;
	if (!ped_geometry_init (&start_sector, dev, fs->geom->start, 1))
		return NULL;
	if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
		return NULL;
	/* 2 = last two sectors (alternate MDB and unused sector) */
	min_size = hfs_get_empty_end(fs) + 2;
	if (min_size == 2) return NULL;

	return ped_constraint_new (&start_align, ped_alignment_any,
				   &start_sector, &full_dev, min_size,
				   fs->geom->length);
}
예제 #14
0
static PedConstraint *reiserfs_get_copy_constraint(const PedFileSystem *fs,
						   const PedDevice *dev)
{
	PedGeometry full_dev;

	PED_ASSERT(fs != NULL);
	PED_ASSERT(dev != NULL);

	if (!ped_geometry_init(&full_dev, dev, 0, dev->length - 1))
		return NULL;

	return ped_constraint_new(ped_alignment_any, ped_alignment_any,
				  &full_dev, &full_dev,
				  reiserfs_fs_bitmap_used(fs->type_specific),
				  dev->length);
}
예제 #15
0
/**
 * Return a constraint that any region on the given device will satisfy.
 */
PedConstraint*
ped_constraint_any (const PedDevice* dev)
{
	PedGeometry	full_dev;

	if (!ped_geometry_init (&full_dev, dev, 0, dev->length))
		return NULL;

	return ped_constraint_new (
			ped_alignment_any,
		       	ped_alignment_any,
			&full_dev,
			&full_dev,
		       	1,
			dev->length);
}
예제 #16
0
파일: rdb.c 프로젝트: inteos/WBSAirback
static PedConstraint*
_amiga_get_constraint (const PedDisk *disk)
{
	PedDevice *dev = disk->dev;
	PedAlignment start_align, end_align;
	PedGeometry max_geom;
	PedSector cyl_size = dev->hw_geom.sectors * dev->hw_geom.heads;

	if (!ped_alignment_init(&start_align, 0, cyl_size))
		return NULL;
	if (!ped_alignment_init(&end_align, -1, cyl_size))
		return NULL;
	if (!ped_geometry_init(&max_geom, dev, MAX_RDB_BLOCK + 1,
			       dev->length - MAX_RDB_BLOCK - 1))
		return NULL;

	return ped_constraint_new (&start_align, &end_align,
		&max_geom, &max_geom, 1, dev->length);
}
예제 #17
0
파일: pc98.c 프로젝트: Excito/parted
static PedConstraint*
_primary_constraint (PedDisk* disk)
{
	PedDevice*	dev = disk->dev;
	PedAlignment	start_align;
	PedAlignment	end_align;
	PedGeometry	max_geom;
	PedSector	cylinder_size;

	cylinder_size = dev->hw_geom.sectors * dev->hw_geom.heads;

	if (!ped_alignment_init (&start_align, 0, cylinder_size))
		return NULL;
	if (!ped_alignment_init (&end_align, -1, cylinder_size))
		return NULL;
	if (!ped_geometry_init (&max_geom, dev, cylinder_size,
			       	dev->length - cylinder_size))
		return NULL;

	return ped_constraint_new (&start_align, &end_align, &max_geom,
				   &max_geom, 1, dev->length);
}
예제 #18
0
/*
 * Given a constraint and a start ("half of the solution"), find the
 * range of all possible ends, such that all (start, end) are solutions
 * to constraint (subject to additional alignment requirements).
 */
static PedGeometry*
_constraint_get_end_range (const PedConstraint* constraint, PedSector start)
{
	PedDevice*	dev = constraint->end_range->dev;
	PedSector	first_min_max_end;
	PedSector	last_min_max_end;
	PedGeometry	end_min_max_range;

	if (start + constraint->min_size - 1 > dev->length - 1)
		return NULL;

	first_min_max_end = start + constraint->min_size - 1;
	last_min_max_end = start + constraint->max_size - 1;
	if (last_min_max_end > dev->length - 1)
		last_min_max_end = dev->length - 1;

	ped_geometry_init (&end_min_max_range, dev,
			   first_min_max_end,
			   last_min_max_end - first_min_max_end + 1);

	return ped_geometry_intersect (&end_min_max_range,
		       		       constraint->end_range);
}
예제 #19
0
/*
 * Return the region within which the start must lie
 * in order to satisfy a constriant.  It takes into account
 * constraint->start_range, constraint->min_size and constraint->max_size.
 * All sectors in this range that also satisfy alignment requirements have
 * an end, such that the (start, end) satisfy the constraint.
 */
static PedGeometry*
_constraint_get_canonical_start_range (const PedConstraint* constraint)
{
	PedSector	first_end_soln;
	PedSector	last_end_soln;
	PedSector	min_start;
	PedSector	max_start;
	PedGeometry	start_min_max_range;

	if (constraint->min_size > constraint->max_size)
		return NULL;

	first_end_soln = ped_alignment_align_down (
			constraint->end_align, constraint->end_range,
			constraint->end_range->start);
	last_end_soln = ped_alignment_align_up (
			constraint->end_align, constraint->end_range,
			constraint->end_range->end);
	if (first_end_soln == -1 || last_end_soln == -1
	    || first_end_soln > last_end_soln
	    || last_end_soln < constraint->min_size)
		return NULL;

	min_start = first_end_soln - constraint->max_size + 1;
	if (min_start < 0)
		min_start = 0;
	max_start = last_end_soln - constraint->min_size + 1;
	if (max_start < 0)
		return NULL;

	ped_geometry_init (
		&start_min_max_range, constraint->start_range->dev,
		min_start, max_start - min_start + 1);

	return ped_geometry_intersect (&start_min_max_range,
				       constraint->start_range);
}
예제 #20
0
int
main (int argc, char **argv)
{
	set_program_name (argv[0]);

	PedSector start = 0, len = 0;
	PedGeometry geom, new_geom;
	PedDevice *dev;
	PedFileSystem *fs;
	PedTimer *g_timer = NULL;

	if (argc != 2 && argc != 4) {
		fprintf(stderr, "usage: %s <device>\n"
				"       %s <device> <start> <length>\n",
				argv[0], argv[0]);
		return 1;
	}

	dev = ped_device_get(argv[1]);
	if (!dev) {
		fprintf(stderr, "cannot create device %s\n", argv[1]);
		return 1;
	}

	if (!ped_device_open(dev)) {
		fprintf(stderr, "cannot open device %s\n", argv[1]);
		return 1;
	}

	if (!ped_geometry_init(&geom, dev, 0, dev->length)) {
		fprintf(stderr, "cannot initialize geometry\n");
		return 1;
	}

	if (argc > 2) {
		start = strtoll(argv[2], NULL, 0);
		len = strtoll(argv[3], NULL, 0);
	} else {
		start = 0;
		len = dev->length;
	}

	if (!ped_geometry_init(&new_geom, dev, start, len)) {
		fprintf(stderr, "cannot initialize new geometry\n");
		return 1;
	}

	fs = ped_file_system_open(&geom);
	if (!fs) {
		fprintf(stderr, "cannot read fs\n");
		return 1;
	}

	if (!ped_file_system_resize(fs, &new_geom, g_timer)) {
		fprintf(stderr, "cannot resize filesystem\n");
		return 1;
	}

	ped_file_system_close(fs);
	return 0;
}