Anonymous avatar Anonymous committed eefc7cd

remove all file system stuff, some fixes, prepare for release 1.3.0a

Comments (0)

Files changed (8)

+1.3.0a (Sun Sep 18 2011)
+========================
+  * remove file system stuff so code compile with parted 3.0
+
 1.2.5 (3 May 2011)
 =================
   * Bug fix: add m4/intlmacosx.m4 
 # 2.59 is needed by GNULib modules
 AC_PREREQ([2.59])
-AC_INIT(fdisk, 1.2.5, [bug-fdisk@gnu.org])
+AC_INIT(fdisk, [1.3.0a], [bug-fdisk@gnu.org])
 AC_CONFIG_AUX_DIR(autotools)
 
 AM_INIT_AUTOMAKE
 	                        pos.end.sector,c->dev,NULL,&opts))
 		return 0;
 
-	PedFileSystemType *fs_type = ped_file_system_type_get("ext2");
-	if (!perform_mkpart(c->disk,&pos,type,bsd_disklabel ? fs_type : NULL,part,opts)) {
+	if (!perform_mkpart(c->disk,&pos,type, part,opts)) {
 		if (!*part) {
 			do {
 				temp = ped_disk_next_partition(c->disk,temp);
 	ped_device_end_external_access(c->disk->dev);
 	return 1;
 }
+
 static int
 do_resize (Context *c, PedPartition **part) {
 	static MenuItem part_position[] = {
 	const char resize_keys[] = { 'r', 'c', ESC, '\0' };
 	int key;
 	PedConstraint *constraint = NULL;
-	PedFileSystem *fs = NULL;
 	PedSector first,last;
 	PartPos pos;
 	UIOpts opts = UI_WARN_COMMIT | UI_SNAP_TO_START;
-	if (!((*part)->type & PED_PARTITION_EXTENDED)) {
-		if ((*part)->fs_type && (*part)->fs_type->ops->resize) {
-			menu_title(_("What do you want to do?"));
-			key = do_menu(resize_menu, 11, MENU_BUTTON | MENU_TITLE,resize_keys, NULL);
+
+	if(!warn_fs_support())
+		return 0;
+
+	if (!((*part)->type & PED_PARTITION_EXTENDED)) 
+		{
+			if ((*part)->fs_type) 
+				{
+					menu_title(_("What do you want to do?"));
+					key = do_menu(resize_menu, 11, MENU_BUTTON | MENU_TITLE,resize_keys, NULL);
+				}
+			else 
+				{
+					key = 0;
+					getbool(_("Can't resize the partition. Alter the size? (For experts only)"),&key);
+					key = (key ? 'c' : ESC);
+				}
+			if (key == ESC)
+				return 0;
+			if (key == 'r') 
+				{
+					XASSERT(*part, return 0);
+					XASSERT((*part)->disk, return 0);
+					XASSERT((*part)->disk->dev, return 0);
+
+					constraint = ped_device_get_optimal_aligned_constraint((*part)->disk->dev);
+				} 
+			else 
+				{
+					opts |= UI_NO_FS_RESIZE;
+				}
 		}
-		else {
-			key = 0;
-			getbool(_("Can't resize the partition. Alter the size? (For experts only)"),&key);
-			key = (key ? 'c' : ESC);
-		}
-		if (key == ESC)
-			return 0;
-		if (key == 'r') {
-			fs = ped_file_system_open(&(*part)->geom);
-			if (!fs) {
-				warning_waitkey(_("Could not open the filesystem for resizing"));
-				return 0;
-			}
-			constraint = ped_file_system_get_resize_constraint(fs);
-			if (!constraint || constraint->min_size == constraint->max_size) {
-				warning_waitkey(_("We can't resize this filesystem type"));
-				ped_file_system_close (fs);
-				if (constraint) ped_constraint_destroy(constraint);
-				return 0;
-			}
-			ped_file_system_close (fs);
-		} else {
-			opts |= UI_NO_FS_RESIZE;
-		}
-	}
 
 	pos.start.sector = (*part)->geom.start;
 	pos.end.sector = (*part)->geom.end;
 	return 1;
 }
 
+#if 0
 static int
 do_move (Context *c, PedPartition **part) {
 	/* Combine this with new partition? */
 	notice_waitkey(N_("The filesystem was created successfully."));
 	return 1;
 }
+#endif
 
 static int
 do_check (Context *c, PedPartition **part) {
 	return 1;
 }
 
+#if 0
 static int
 do_copy(Context *c, PedPartition **part) {
 	if (!perform_cp(c->disk,*part, UI_WARN_COMMIT)) {
 	notice_waitkey(N_("Partition copied successfully"));
 	return 1;
 }
+#endif
 
 static int
 do_delete(Context *c, PedPartition **part) {
 			//redraw = 1;
 			key = 0;
 			break;
-		case 'f':
-			do_mkfs(c,part);
-			//redraw = 1;
-			key = 0;
-			break;
 		case 'c':
 			do_check(c,part);
 			//redraw = 1;
 			//redraw = 1;
 			key = 0;
 			break;
-		case 'y':
-			do_copy(c,part);
-			//redraw = 1;
-			key = 0;
-			break;
 		case 'r':
 			do_resize(c,part);
 			//redraw = 1;
 			//redraw = 1;
 			key = 0;
 			break;
-		case 'o':
-			do_move(c,part);
-			//redraw = 1;
-			key = 0;
-			break;
 		case 'x':
 			do_maximize(c,part);
 			//redraw = 1;
 StrList *fs_type_mkfs;
 StrList *flag_name_list;
 
+
+static int ask_boolean_question(const char* _prompt);
+int warn_fs_support(void)
+{
+	/* Notify  the user that the file systems 
+		 are no longer supported.  Let decide 
+		 whether to continue or not */
+
+	return ask_boolean_question("File systems  are no longer supported  by the GNU fdisk.\n"
+								              "This operation will not consider your data, and it could be lost.\n"
+															"Do you want to continue?");
+}
+
 int
 init_flag_str ()
 {
 int
 init_fs_type_str ()
 {
+	return 0;
+#if 0
 	PedFileSystemType*	walk;
 
 	fs_type_list = NULL;
 	}
 
 	return 1;
+#endif
 }
 
 int
 	PedGeometry * new;
 
 	constraint = _get_aligned_device_constraint(geometry->dev);
+
 	if (keep_inside) {
 		constraint = constraint_intersect_and_destroy(
 				constraint,
 
 	new = ped_constraint_solve_nearest(constraint, geometry);
 	ped_constraint_destroy(constraint);
+
 	return new;
 }
 
 static int
 snap (PedSector* sector, PedSector new_sector, PedGeometry* range)
 {
-        PED_ASSERT (ped_geometry_test_sector_inside (range, *sector), return 0);
+        XASSERT (ped_geometry_test_sector_inside (range, *sector), return 0);
         if (!ped_geometry_test_sector_inside (range, new_sector))
                 return 0;
         *sector = new_sector;
         PedSector new_sect;
         EMoves move;
 
-        PED_ASSERT (what == SECT_START || what == SECT_END, return 0);
+        XASSERT (what == SECT_START || what == SECT_END, return 0);
 
         if (!(*allow & (MOVE_UP | MOVE_DOWN))) {
                 *dist = 0;
                                                  && what == SECT_END) )
                         move = MOVE_UP;
                 else
-                        PED_ASSERT (0, return 0);
+                        XASSERT (0, return 0);
         } else if (*allow & MOVE_UP)
                 move = MOVE_UP;
         else if (*allow & MOVE_DOWN)
         end_want = prefer_snap (end, SECT_END, end_range, &end_allow,
                                 end_part, &end_dist );
 
-        PED_ASSERT (start_dist >= 0 && end_dist >= 0, return);
+        XASSERT (start_dist >= 0 && end_dist >= 0, return);
 
         /* If start and end are on adjacent partitions,    */
         /* and if they would prefer crossing, then refrain */
                         start_want = prefer_snap (start, SECT_START,
                                                   start_range, &start_allow,
                                                   start_part, &start_dist );
-                        PED_ASSERT (start_dist >= 0, return);
+                        XASSERT (start_dist >= 0, return);
                 } else {
                         end_allow &= ~MOVE_DOWN;
                         end_want = prefer_snap (end, SECT_END,
                                                 end_range, &end_allow,
                                                 end_part, &end_dist );
-                        PED_ASSERT (end_dist >= 0, return);
+                        XASSERT (end_dist >= 0, return);
                 }
         }
 
         end = ( end_want == MOVE_DOWN ? end_part->geom.start - 1 :
               ( end_want == MOVE_UP ? end_part->geom.end :
                 end ) );
-        PED_ASSERT (ped_geometry_test_sector_inside(start_range,start), return);
-        PED_ASSERT (ped_geometry_test_sector_inside (end_range, end), return);
-        PED_ASSERT (start <= end,
+        XASSERT (ped_geometry_test_sector_inside(start_range,start), return);
+        XASSERT (ped_geometry_test_sector_inside (end_range, end), return);
+        XASSERT (start <= end,
                     PED_DEBUG (0, "start = %d, end = %d\n", start, end));
         ped_geometry_set (new_geom, start, end - start + 1);
 }
 	PedPartition*	part;
 	int		num;
 	char		buf[SMALLBUF];
-	if (!disk)
-		return 0;
+	
+	XASSERT(disk != NULL, return 0);
+
+	/* Christian 
+	 * error when partition table is empty 
+	 */
+
+	if(ped_disk_get_last_partition_num(disk) < 1)
+		{
+			ped_exception_throw(PED_EXCEPTION_ERROR,
+													PED_EXCEPTION_CANCEL,
+													_("The partition table is empty."));
+			return 0;
+		}
+
 	if (!uiquery->getpart) {
 		snprintf(buf,SMALLBUF,_("%s number (1-%d)"),
 		         prompt,ped_disk_get_last_partition_num (disk));
 		if (!uiquery->getdisktype(prompt, &disk_type)) return 0;
 	}
 	*value = disk_type;
-	PED_ASSERT (*value != NULL, return 0);
+	XASSERT (*value != NULL, return 0);
 	return 1;
 }
 
 }
 
 /* Looks for the first suitable free space for a new partition */
-int place_part_start(PedDisk *disk, PartPos *pos, PedPartitionType type) {
+int place_part_start(PedDisk *disk, PartPos *pos, PedPartitionType type) 
+{
 	PedGeometry *aligned;
 	PedPartition *part = NULL;
 	type = (type & PED_PARTITION_LOGICAL) | PED_PARTITION_FREESPACE;
+
 	for (part = ped_disk_next_partition(disk, NULL);
-	     part; part = ped_disk_next_partition(disk,part)) {
-		if (part->type == type) {
-			aligned = _get_aligned_geometry(&part->geom, 1);
+	     part; part = ped_disk_next_partition(disk,part)) 
+		{
+			if (part->type == type ) 
+				{
+					/* Christian: avoid sigsegv! */
+					if((aligned = _get_aligned_geometry(&part->geom, 1)) == NULL)
+						continue;
 
-			pos->start.sector = aligned->start;
-			pos->start.range = ped_geometry_new (disk->dev,
-				 		aligned->start, 1);
-			ped_geometry_destroy(aligned);
-			return 1;
+					pos->start.sector = aligned->start;
+					pos->start.range = ped_geometry_new (disk->dev,
+								aligned->start, 1);
+					ped_geometry_destroy(aligned);
+					return 1;
+				}
 		}
-	}
 	return 0;
 }
 
 	PedPartition *part = ped_disk_get_partition_by_sector(disk,
 							pos->start.sector);
 	if (part->type & PED_PARTITION_FREESPACE) {
-		aligned = _get_aligned_geometry(&part->geom, 1);
+			if((aligned = _get_aligned_geometry(&part->geom, 1)) == NULL)
+				return 0;
 
 		pos->end.sector = aligned->end;
 		pos->end.range = ped_geometry_new (disk->dev,
 }
 
 
-/* Do not confuse this with query_part_position, this queries the user for
-   start and end of the partition and is called from the functions in here */
 static int
-get_position(PartPos* pos, PedDisk *disk, GSOpts opts)
+get_start_position(PartPos* pos, PedDisk *disk, GSOpts opts)
 {
   char *start;
+
+  if (ped_unit_get_default() == PED_UNIT_CYLINDER) 
+		start = _("First cylinder");
+  else if (ped_unit_get_default() == PED_UNIT_SECTOR) 
+		start = _("First sector");
+  else 
+    start = _("Start");
+  
+  if (!get_sector (start, disk->dev, &(pos->start), -1LL, opts))
+    return 0;
+
+	return 1;
+}
+
+static int
+get_end_position(PartPos* pos, PedDisk *disk, GSOpts opts)
+{
   char *end;
   if (ped_unit_get_default() == PED_UNIT_CYLINDER) 
     { 
-      start = _("First cylinder");
       end = 
 	(compat_mode == 0) ? 
 	    _("Last cilynder or +size or +sizeMB or +sizeKB or +size%")
     }
   else if (ped_unit_get_default() == PED_UNIT_SECTOR) 
     {
-      start = _("First sector");
       end = 
 	(compat_mode == 0) ?
 	  _("Last sector or +size or +sizeMB or +sizeKB or +size%")
 	: _("Last sector or +size or +sizeMB or +sizeKB");
     }
   else {
-    start = _("Start");
     end = _("End or +size");
   }
   
-  if (!get_sector (start, disk->dev, &(pos->start), -1LL, opts))
-    return 0;
-
   /* If we are creating a new partition and want to look where to
      place its end ... */
   if (opts & PLACE_END_NEWPART)
 }
 
 
+/* Do not confuse this with query_part_position, this queries the user for
+   start and end of the partition and is called from the functions in here */
+static int
+get_position(PartPos* pos, PedDisk *disk, GSOpts opts)
+{
+	if(!get_start_position(pos, disk, opts) || !get_end_position(pos, disk, opts))
+		return 0;
+	return 1;
+}
+
 static int
 ask_boolean_question(const char* prompt) {
 	int answer = 0;
 
 /* Check partition consistency */
 int
-perform_check (PedDisk* disk, PedPartition* part)
+perform_check (PedDisk * disk, PedPartition * part)
 {
-        PedFileSystem*  fs;
-	if (!part) {
-		if (!get_partition (_("Partition"),disk, &part))
-			return 0;
-	}
-        if (!_partition_warn_busy (part))
-                return 0;
+  if (!part)
+    {
+      if (!get_partition (_("Partition"), disk, &part))
+	return 0;
+    }
+  if (!_partition_warn_busy (part))
+    return 0;
 
-        if (!ped_disk_check (disk))
-                return 0;
+  if (!ped_disk_check (disk))
+    return 0;
 
-        fs = ped_file_system_open (&part->geom);
-        if (!fs)
-                return 0;
-        if (!ped_file_system_check (fs, uiquery->timer)) {
-		ped_file_system_close (fs);
-		return 0;
-	}
-
-        ped_file_system_close (fs);
-        return 1;
-}
-
-/* Copy a partition.
-   The parameters specify the destination partition.
-   The source partition is get using a callback function prompt.
-   Writes partition table to disk */
-/* If warn is set to 1, warns the user TODO: get rid of warn */
-int
-perform_cp (PedDisk* dst_disk, PedPartition* dst, UIOpts opts)
-{
-        PedDisk*                src_disk = NULL;
-        PedPartition*           src = NULL;
-        PedFileSystem*          src_fs;
-        PedFileSystem*          dst_fs;
-        PedFileSystemType*      dst_fs_type;
-
-	if (!dst_disk)
-                goto error;
-
-	if (opts & UI_WARN_COMMIT)
-		if (!ask_boolean_question
-		(_("WARNING: This writes all data to disk automatically, continue?")))
-			return 0;
-	/* It doesn't hurt to commit at that point, right? */
-	if (uiquery->need_commit && !perform_commit(dst_disk,UI_DEFAULT)) goto error;
-
-
-        src_disk = dst_disk;
-	if (!get_disk (_("Source device"), &src_disk))
-		goto error_destroy_disk;
-
-
-        if (!get_partition (_("Source partition"),src_disk, &src))
-                goto error_destroy_disk;
-        if (src->type == PED_PARTITION_EXTENDED) {
-                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-                        _("Can't copy an extended partition."));
-                goto error_destroy_disk;
-        }
-        if (!_partition_warn_busy (src))
-                goto error_destroy_disk;
-	if (!dst) {
-		if (!get_partition (_("Destination partition"),dst_disk, &dst))
-			goto error_destroy_disk;
-	}
-        if (!_partition_warn_busy (dst))
-                goto error_destroy_disk;
-
-/* do the copy */
-        src_fs = ped_file_system_open (&src->geom);
-        if (!src_fs)
-                goto error_destroy_disk;
-	/* At this point we do something worth commiting. If we fail, the caller should clean the mess */
-	uiquery->need_commit = 1;
-        dst_fs = ped_file_system_copy (src_fs, &dst->geom, uiquery->timer);
-        if (!dst_fs)
-                goto error_close_src_fs;
-        dst_fs_type = dst_fs->type;     /* may be different to src_fs->type */
-        ped_file_system_close (src_fs);
-        ped_file_system_close (dst_fs);
-
-/* update the partition table, close disks */
-        if (!ped_partition_set_system (dst, dst_fs_type))
-                goto error_destroy_disk;
-        if (!ped_disk_commit (dst_disk)) {
-		//if (uiquery->need_commit) uiquery->need_commit = -1;
-                goto error_destroy_disk;
-	}
-	uiquery->need_commit = 0;
-        if (src_disk != dst_disk)
-                ped_disk_destroy (src_disk);
-        /*ped_disk_destroy (dst_disk);*/
-        return 1;
-
-error_close_src_fs:
-        ped_file_system_close (src_fs);
-error_destroy_disk:
-        if (src_disk && src_disk != dst_disk)
-                ped_disk_destroy (src_disk);
-        /*ped_disk_destroy (dst_disk);*/
-error:
-        return 0;
+  return 1;
 }
 
 /* Create a new partition table. Takes dev and disk as parameters,
         return 0;
 }
 
+#if 0
 /* Create a filesystem. Takes filesystem type as an optional parameter */
 /* If warn is set to 1, warns the user TODO: get rid of warn */
 int
 
 
 }
+#endif
 
 /* The parameter custom is 1, then the user is asked about the start and end sector *
  * If the parameter newpart is not NULL, it is set to the newly created partition */
 /* NOTE: On some occassions it changes the *newpart to NULL! */
 int
-perform_mkpart (PedDisk* disk, PartPos *pos, PedPartitionType part_type,
-	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts)
+perform_mkpart (PedDisk* disk, PartPos *pos, PedPartitionType part_type, PedPartition **newpart, UIOpts opts)
 {
         PedPartition*            part;
         PedConstraint*           user_constraint;
         PedConstraint*           dev_constraint;
         PedConstraint*           final_constraint;
-	PedConstraint*		 fs_constraint;
        /* char*                    peek_word;*/
         char*                    part_name = NULL;
         char                     *start_usr = NULL, *end_usr = NULL;
                         goto error;
         }
 
-
+/*
         if (part_type == PED_PARTITION_EXTENDED) {
 		if (opts & UI_MAKEPARTFS) {
                 	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
                 if (!get_fs_type (_("File system type"), &fs_type, 0))
                         goto error;
         }
-
-
-
+*/
 
         if (ped_disk_type_check_feature (disk->type,
                                          PED_DISK_TYPE_PARTITION_NAME))
 
 
 	if ((opts & UI_CUSTOM_VALUES) &&
-			pos->start.sector == 0LL && pos->end.sector == 0LL) {
-		place_part_start(disk,pos,part_type);
-		if (!get_position(pos, disk, GET_SECT | PLACE_END_NEWPART))
-			goto error;
-	}
-	else {
-		if (!get_position(pos, disk, opts & UI_CUSTOM_VALUES))
-			goto error;
-	}
+			pos->start.sector == 0LL && pos->end.sector == 0LL) 
+		{
+			place_part_start(disk,pos,part_type);
+			
+			if(!get_position(pos, disk, GET_SECT | PLACE_END_NEWPART))
+				goto error;
+		}
+	else 
+		{
+			if (!get_position(pos, disk, opts & UI_CUSTOM_VALUES))
+				goto error;
+		}
 
         /* processing starts here */
-        part = ped_partition_new (disk, part_type, fs_type,
-	                          pos->start.sector, pos->end.sector);
-        if (!part)
-                goto error;
+        if((part = ped_partition_new (disk, 
+					     												part_type, 
+							    										ped_file_system_type_get("ext2"),
+									    								pos->start.sector, 
+											    						pos->end.sector)) == NULL)
+					goto error;
 
 	/* Check if the partition occupying the space before the place we
 	   are trying to put this one, requires a metadata sectors after it,
         /* create constraints */
         user_constraint = constraint_from_start_end (disk->dev,
                         pos->start.range, pos->end.range);
-        PED_ASSERT (user_constraint != NULL, return 0);
+        XASSERT (user_constraint != NULL, return 0);
 
         dev_constraint = _get_aligned_device_constraint(disk->dev);
-        PED_ASSERT (dev_constraint != NULL, return 0);
+        XASSERT (dev_constraint != NULL, return 0);
 
         final_constraint = ped_constraint_intersect (user_constraint,
                         dev_constraint);
 		ped_exception_leave_all();
 	}
 
-	/* We check whether we can create this filesystem here */
-	if (fs_type)
-		fs_constraint = ped_file_system_get_create_constraint(fs_type,disk->dev);
-	else
-		fs_constraint = NULL;
-	if (fs_constraint) {
-		if (!ped_constraint_is_solution(fs_constraint,&(part->geom))) {
-			const char *error = NULL;
-			if (part->geom.length < fs_constraint->min_size) {
-				error = _("The size of the partition is too small for %s filesystem");
-			}
-			else if (part->geom.length > fs_constraint->max_size) {
-				error = _("The size of the partition is too big for %s filesystem");
-			}
-			/* FIXME: WHAT THE?.. */
-			/* OK, I got it, but I will leave it here for a while */
-			//else {
-			//	error = _("You can't use this partition for %s filesystem");
-			//}
-			if (error)
-				switch (ped_exception_throw (
-					PED_EXCEPTION_WARNING,
-					PED_EXCEPTION_IGNORE_CANCEL,
-					error, fs_type->name)) {
-					case PED_EXCEPTION_IGNORE:
-						/* User doesn't care */
-						break;
-					case PED_EXCEPTION_CANCEL:
-					case PED_EXCEPTION_UNHANDLED:
-					default:
-						ped_constraint_destroy(fs_constraint);
-						goto error_remove_part;
-				}
-		}
-		ped_constraint_destroy(fs_constraint);
-	}
-
         /* set minor attributes */
         if (part_name)
-                PED_ASSERT (ped_partition_set_name (part, part_name), return 0);
-        if (!ped_partition_set_system (part, fs_type))
-                goto error;
+                XASSERT (ped_partition_set_name (part, part_name), return 0);
         if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
                 ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
 
                 PED_FREE (start_sol);
         if (end_sol != NULL)
                 PED_FREE (end_sol);
+
 	if (newpart) *newpart = part;
         return 1;
 
         return 0;
 }
 
+#if 0
 int
 perform_mkpartfs (PedDisk* disk, PartPos *pos, PedPartitionType part_type,
 	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts)
 
 
 }
+#endif
 
 /* FIXME: This function seems to be problematic, deal with it appropriately in the ui */
 int
-perform_move (PedDisk *disk,  PedPartition* part, PartPos *pos, UIOpts opts)
+perform_move (PedDisk * disk, PedPartition * part, PartPos * pos, UIOpts opts)
 {
 
-        PedFileSystem*  fs;
-        PedFileSystem*  fs_copy;
-        PedConstraint*  constraint;
-        PedGeometry     old_geom, new_geom;
+  PedConstraint *constraint;
+  PedGeometry old_geom, new_geom;
 
+	constraint = NULL;
 
-        if (!disk)
-                goto error;
+	XASSERT(disk != NULL, goto error);
 
-	if (opts & UI_WARN_COMMIT) {
-		if (!ask_boolean_question
-		(_("WARNING: This writes all data to disk automatically, continue?")))
-			return 0;
-	}
-	/* So the best we can do here is to commit */
-	if (uiquery->need_commit)
-		if (!perform_commit(disk,UI_DEFAULT))
-			goto error;
-	if (!part)
-        	if (!get_partition (_("Partition"), disk, &part))
-                	goto error;
-        if (!_partition_warn_busy (part))
-                goto error;
-        if (part->type == PED_PARTITION_EXTENDED) {
-                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-                        _("Can't move an extended partition."));
-                goto error;
-        }
-        old_geom = part->geom;
-        fs = ped_file_system_open (&old_geom);
-        if (!fs)
-                goto error;
+	/* so if disk is empty we exit function */
+  if (!part && !get_partition (_("Partition"), disk, &part))
+		goto error;
 
-        /* get new target */
-	if ((opts & UI_CUSTOM_VALUES) &&
-			pos->start.sector == 0LL && pos->end.sector == 0LL) {
-		place_part_start(disk,pos,part->type);
-		if (!get_position(pos, disk, GET_SECT | PLACE_END_NEWPART))
-			goto error_close_fs;
-	}
-	else {
-		if (!get_position(pos, disk, opts & UI_CUSTOM_VALUES))
-			goto error_close_fs;
-	}
+	if(!warn_fs_support())
+		goto error;
 
+  if (opts & UI_WARN_COMMIT)
+    {
+			if (!ask_boolean_question (_("WARNING: This writes all data to disk automatically, continue?")))
+				return 0;
+    }
 
-        /* set / test on "disk" */
-        if (!ped_geometry_init (&new_geom, disk->dev, pos->start.sector,
-                                pos->end.sector - pos->start.sector + 1LL))
-                goto error_close_fs;
-        snap_to_boundaries (&new_geom, NULL, disk,
-                            pos->start.range, pos->end.range);
+  /* So the best we can do here is to commit */
+  if (uiquery->need_commit && !perform_commit (disk, UI_DEFAULT))
+		goto error;
 
-        constraint = constraint_intersect_and_destroy (
-                        ped_file_system_get_copy_constraint (fs, disk->dev),
-                        constraint_from_start_end (disk->dev, pos->start.range,
-                                                   pos->end.range));
-	/* So here we do something worth commiting and dangerous. UI *must*
-	   do something if we fail and need_commit is true... */
-	uiquery->need_commit = 1;
-        if (!ped_disk_set_partition_geom (disk, part, constraint,
-                                          new_geom.start, new_geom.end))
-                goto error_destroy_constraint;
-        ped_constraint_destroy (constraint);
-        if (ped_geometry_test_overlap (&old_geom, &part->geom)) {
-                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-                        _("Can't move a partition onto itself.  Try using resize, perhaps?"));
-                goto error_close_fs;
-        }
+  if (!_partition_warn_busy (part))
+    goto error;
 
-        /* do the move */
-        fs_copy = ped_file_system_copy (fs, &part->geom, uiquery->timer);
-        if (!fs_copy) {
-		#if 0
+  if (part->type == PED_PARTITION_EXTENDED)
+    {
+      ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+			   _("Can't move an extended partition."));
+      goto error;
+    }
+
+  old_geom = part->geom;
+
+  /* get new target */
+	
+	if(pos->start.sector == 0LL)
+		place_part_start (disk, pos, part->type);
+
+	/* Christian we are moving, do not 
+		 let the user select partition end */
+
+	/* if(!get_position (pos, disk, GET_SECT | PLACE_END_NEWPART)) */
+	if(!get_start_position (pos, disk, GET_SECT))
+		goto error;
+
+	pos->end.sector = pos->start.sector + old_geom.length;
+
+	if((pos->end.range = ped_geometry_new(disk->dev, pos->end.sector, 1)) == NULL)
+		goto error;
+
+  /* set / test on "disk" */
+  if (!ped_geometry_init (&new_geom, disk->dev, pos->start.sector,
+			  pos->end.sector - pos->start.sector + 1LL))
+    goto error;
+  snap_to_boundaries (&new_geom, NULL, disk,
+		      pos->start.range, pos->end.range);
+
+  constraint =
+    constraint_intersect_and_destroy (ped_constraint_duplicate(ped_constraint_any(disk->dev)),
+																			constraint_from_start_end (disk->dev,
+																																 pos->start.range,
+																																 pos->end.range));
+
+  /* So here we do something worth commiting and dangerous. UI *must*
+     do something if we fail and need_commit is true... */
+  uiquery->need_commit = 1;
+
+  if (!ped_disk_set_partition_geom (disk, 
+																		part, 
+																		constraint,
+																		new_geom.start, 
+																		new_geom.end))
+    goto error;
+
+  ped_constraint_destroy (constraint);
+	constraint = NULL;
+
+	/* move from 32-128 to 16-112 ?? */
+#if 0
+  if (ped_geometry_test_overlap (&old_geom, &part->geom))
+    {
+      ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+			   _
+			   ("Can't move a partition onto itself.  Try using resize, perhaps?"));
+      goto error;
+    }
+#endif
+
+  if (!ped_disk_commit (disk))
+    {
+      //if (uiquery->need_commit) uiquery->need_commit = -1;
+      goto error;
+    }
+
+  uiquery->need_commit = 0;
+  
+	if (pos->start.range != NULL)
+    ped_geometry_destroy (pos->start.range);
+  
+	if (pos->end.range != NULL)
+    ped_geometry_destroy (pos->end.range);
+  
+	return 1;
+
+error:
+
+	if(constraint)
 		ped_constraint_destroy (constraint);
-		constraint = ped_constraint_any(disk->dev);
-		ped_disk_set_partition_geom(disk,part,constraint,
-		                            old_geom.start,old_geom.end);
-		#endif
-		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-			_("Couldn't run the partition copy"));
-                goto error_close_fs;
-	}
-        ped_file_system_close (fs_copy);
-        ped_file_system_close (fs);
-        if (!ped_disk_commit (disk)) {
-		//if (uiquery->need_commit) uiquery->need_commit = -1;
-                goto error;
-	}
-	uiquery->need_commit = 0;
-        if (pos->start.range != NULL)
-                ped_geometry_destroy (pos->start.range);
-        if (pos->end.range != NULL)
-                ped_geometry_destroy (pos->end.range);
-        return 1;
 
-error_destroy_constraint:
-        ped_constraint_destroy (constraint);
-error_close_fs:
-        ped_file_system_close (fs);
-error:
-        if (pos->start.range != NULL)
-                ped_geometry_destroy (pos->start.range);
-        if (pos->end.range != NULL)
-                ped_geometry_destroy (pos->end.range);
-        return 0;
+  if (pos->start.range != NULL)
+    ped_geometry_destroy (pos->start.range);
+
+  if (pos->end.range != NULL)
+    ped_geometry_destroy (pos->end.range);
+  
+	return 0;
 }
 
 int
         PedGeometry             probe_end_region;
 
 
-        if (!disk)
-                goto error;
+				XASSERT(disk != NULL, goto error);
+
 	if (opts & UI_WARN_COMMIT)
 		if (!ask_boolean_question
 		(_("WARNING: This writes all data to disk automatically, continue?")))
 
 
 int
-perform_resize (PedDisk *disk, PedPartition *part, PartPos *pos, UIOpts opts)
+perform_resize (PedDisk * disk, PedPartition * part, PartPos * pos, UIOpts opts)
 {
+	PedConstraint disk_constraint;
+	PedAlignment *align_start;
+	PedAlignment *align_end;
+	PedGeometry range_start;
+	PedGeometry range_end;
 
-        PedFileSystem           *fs;
-        PedConstraint           *constraint;
-        PedGeometry             new_geom;
+	int ret;
 
+	align_start = NULL;
+	align_end = NULL;
+	ret = 0;
 
-        if (!disk)
-                goto error;
+	XASSERT(disk != NULL, goto lb_out);
 
-	if (!part)
-        	if (!get_partition (_("Partition"), disk, &part))
-                	goto error;
+  if (!warn_fs_support ())
+		goto lb_out;
 
-	if (!(part->type == PED_PARTITION_EXTENDED || (opts & UI_NO_FS_RESIZE)))  {
-		if (opts & UI_WARN_COMMIT && !ask_boolean_question
-		(_("WARNING: This writes all data to disk automatically, continue?")))
-			return 0;
-		if (uiquery->need_commit)
-			if (!perform_commit(disk,UI_DEFAULT))
-				goto error;
-	}
+  if (!part && !get_partition (_("Partition"), disk, &part))
+		goto lb_out;
 
-        if (part->type != PED_PARTITION_EXTENDED) {
-                if (!_partition_warn_busy (part))
-                        goto error;
-        }
+  if (!(part->type == PED_PARTITION_EXTENDED || (opts & UI_NO_FS_RESIZE)))
+    {
+      if (opts & UI_WARN_COMMIT 
+					&& !ask_boolean_question (_("WARNING: This writes all data to disk automatically, continue?")))
+				goto lb_out;
+      
+			if (uiquery->need_commit && !perform_commit (disk, UI_DEFAULT))
+				goto lb_out;
+    }
+	else if(part->type != PED_PARTITION_EXTENDED && !_partition_warn_busy (part))
+		goto lb_out;
+  
+	if (!get_position (pos, disk, opts & UI_CUSTOM_VALUES))
+    goto lb_out;
 
- 	if (!get_position(pos, disk,opts & UI_CUSTOM_VALUES))
-		goto error;
+	/* STEP 0: get alignment constraint from disk */
 
-	/* FIXME: This is most likely not needed */
-	//if (!(opts & UI_CUSTOM_VALUES) && (opts & UI_NO_FS_RESIZE)) {
-	if (opts & UI_RESIZE_INEXACT) {
-		if (part->geom.start != pos->start.sector)
-			fuzzify(pos->start.range,disk->dev,NULL, 127, 127);
-		if (part->geom.end != pos->end.sector)
-			fuzzify(pos->end.range,disk->dev,NULL, 127, 127);
-	}
-	//}
-	if (!ped_geometry_init (&new_geom, disk->dev, pos->start.sector,
-	                        pos->end.sector - pos->start.sector + 1LL))
-                goto error;
-        snap_to_boundaries (&new_geom, &part->geom, disk,
-                            pos->start.range, pos->end.range);
-	/* If the partition is extended or we have UI_NO_FS_RESIZE,
-	   don't try to resize the fs... FIXME? */
-        if (part->type == PED_PARTITION_EXTENDED || (opts & UI_NO_FS_RESIZE)) {
-		/* I really hope this part isn't dangerous */
-                constraint = constraint_from_start_end (disk->dev,
-                                pos->start.range, pos->end.range);
-                if (!ped_disk_set_partition_geom (disk, part, constraint,
-                                                  new_geom.start, new_geom.end))
-                        goto error_destroy_constraint;
-		if (part->type == PED_PARTITION_EXTENDED)
-                	ped_partition_set_system (part, NULL);
+	/* Get the alignment needed for partition boundaries on this disk. 
+		 The returned alignment describes the alignment for the start sector of the partition, 
+		 for all disklabel types which require alignment, except Sun disklabels, 
+		 the end sector must be aligned too. */
 
-		uiquery->need_commit = 1;
-        } else {
-		fs = ped_file_system_open (&part->geom);
-		if (!fs)
-			goto error;
-		constraint = constraint_intersect_and_destroy (
-				ped_file_system_get_resize_constraint (fs),
-				constraint_from_start_end (disk->dev,
-					pos->start.range, pos->end.range));
-		/* We will play with the geometry */
-		uiquery->need_commit = 1;
-                if (!ped_disk_set_partition_geom (disk, part, constraint,
-                                                  new_geom.start, new_geom.end))
-                        goto error_close_fs;
-                if (!ped_file_system_resize (fs, &part->geom, uiquery->timer))
-                        goto error_close_fs;
-                /* may have changed... eg fat16 -> fat32 */
-                ped_partition_set_system (part, fs->type);
-                ped_file_system_close (fs);
+	align_start = ped_disk_get_partition_alignment(disk);
+	align_end = ped_alignment_duplicate(align_start);
 
-		ped_disk_commit (disk);
-		uiquery->need_commit = 0;
-        }
+	/* To get the end sector alignment decrease the PedAlignment offset by 1. */
+	if(align_end->offset > 0)
+		align_end->offset--;
 
-        ped_constraint_destroy (constraint);
-        if (pos->start.range != NULL)
-                ped_geometry_destroy (pos->start.range);
-        if (pos->end.range != NULL)
-                ped_geometry_destroy (pos->end.range);
-        return 1;
+	if(ped_geometry_init(&range_start, disk->dev, pos->start.range->start - align_start->grain_size, align_start->grain_size * 2) == 0
+		 || ped_geometry_init(&range_end, disk->dev, pos->end.range->start - align_end->grain_size, align_end->grain_size * 2) == 0)
+		goto lb_out;
 
-error_close_fs:
-        ped_file_system_close (fs);
-error_destroy_constraint:
-        ped_constraint_destroy (constraint);
-error:
-        if (pos->start.range != NULL)
-                ped_geometry_destroy (pos->start.range);
-        if (pos->end.range != NULL)
-                ped_geometry_destroy (pos->end.range);
-        return 0;
+
+	/* STEP 1: get constraint */
+
+	if(ped_constraint_init(&disk_constraint,
+												 align_start, 
+												 align_end, 
+												 &range_start,
+												 &range_end,
+												 range_end.start - range_start.end, /* min size */
+												 range_end.end - range_start.start /* max size */) == 0)
+		goto lb_out;
+
+
+
+	if(ped_disk_set_partition_geom(disk, 
+																 part,
+																 &disk_constraint,
+																 pos->start.sector,
+																 pos->end.sector) == 0)
+		goto lb_out;
+	
+	ped_disk_commit (disk);
+  uiquery->need_commit = 0;
+	ret = 1;
+
+lb_out:
+
+	if(align_start)
+		ped_alignment_destroy(align_start);
+
+	if(align_end)
+		ped_alignment_destroy(align_end);
+
+	if(!ret)
+		{
+			if (pos->start.range != NULL)
+				ped_geometry_destroy (pos->start.range);
+			
+			if (pos->end.range != NULL)
+				ped_geometry_destroy (pos->end.range);
+		}
+
+  return ret;
 }
 
 int
 }
 
 
-static void
-_print_flag (int *i, const char *name) {
-	printf(*i == 0 ? "%s" : ",%s", name);
-	(*i)++;
-}
-
-
 void
 print_partition_types() {
 	PedFileSystemType *walk;
 	for (walk = ped_file_system_type_get_next(NULL); walk; walk = ped_file_system_type_get_next(walk)) {
-		int i = 0;
 		printf ("%-15s",walk->name);
-		if (walk->ops->open) _print_flag(&i,_("open"));
-		if (walk->ops->create) _print_flag(&i,_("create"));
-		if (walk->ops->check) _print_flag(&i,_("check"));
-		if (walk->ops->copy) _print_flag(&i,_("copy"));
-		if (walk->ops->resize) _print_flag(&i,_("resize"));
-		printf("\n");
 	}
 	exit(0);
 }
 /* Specific for perform_mkfs */
 #define UI_MAKEPARTFS UI_FUNCTION_SPECIFIC_1
 
+extern int warn_fs_support(void);
+#define XASSERT(_condition, _code)                                           \
+do {                                                                         \
+	if(!(_condition))                                                          \
+		{                                                                        \
+			ped_exception_throw(PED_EXCEPTION_ERROR,                               \
+													PED_EXCEPTION_CANCEL,                              \
+													"GNU Fdisk error: %s:%d assertion `%s' failed.",   \
+													__FILE__, __LINE__, #_condition);                  \
+			_code;                                                                 \
+		}                                                                        \
+} while(0)
+
 /* Setting of UICalls */
 extern void set_uicalls(UICalls *);
 
  * not needed
  */
 extern int perform_check (PedDisk*, PedPartition*);
-/* The parameters are the *destination* disk and partition */
-extern int perform_cp (PedDisk*, PedPartition*, UIOpts);
 extern int perform_mklabel (PedDevice*, PedDisk**, const PedDiskType*);
 
+#if 0
 extern int perform_mkfs (PedDisk*, PedPartition*,
                          const PedFileSystemType*, UIOpts);
+#endif
+
 /* NOTE: The PartPos structs *are* modified when calling these function */
-extern int perform_mkpart (PedDisk*, PartPos* pos,
-                      PedPartitionType,	const PedFileSystemType*,
-                      PedPartition **newpart, UIOpts);
-
+extern int perform_mkpart (PedDisk* disk, PartPos *pos, 
+													 PedPartitionType part_type, 
+													 PedPartition **newpart, UIOpts opts);
+#if 0
 extern int perform_mkpartfs (PedDisk*, PartPos* pos,
                         PedPartitionType, const PedFileSystemType*,
                         PedPartition **newpart, UIOpts);
+#endif
 
-extern int perform_move (PedDisk*, PedPartition*, PartPos* pos,
-                    UIOpts);
+extern int perform_move (PedDisk * disk, PedPartition * part, PartPos * pos, UIOpts opts);
 extern int perform_name (PedDisk*, PedPartition*, char*);
 extern int perform_rescue (PedDisk*, PedSector start, PedSector end, UIOpts);
 extern int perform_resize (PedDisk*, PedPartition*, PartPos* pos,
 //static char* state_msg =	N_("STATE is one of: on, off\n");
 // static char* device_msg =	N_("DEVICE is usually /dev/hda or /dev/sda\n");
 // static char* name_msg =		N_("NAME is any word you want\n");
-static char* resize_msg_start = N_("The partition must have one of the "
-				   "following FS-TYPEs: ");
+//static char* resize_msg_start = N_("The partition must have one of the "
+//				   "following FS-TYPEs: ");
 
 static char* label_type_msg;
 static char* flag_msg;
 	return perform_mklabel(dev,disk,type);
 }
 #endif
+
+#if 0
 static int
 do_mkfs (PedDisk** disk)
 {
 
 	return perform_mkfs(*disk,NULL,NULL,UI_WARN_COMMIT);
 }
+#endif
 
 static int
-do_mkpart (PedDisk **disk)
+do_mkpart (PedDisk ** disk)
 {
-	PartPos			 pos;
-	PedPartitionType	 part_type = 0;
-	const PedFileSystemType	*fs_type = ped_file_system_type_get ("ext2");
-	char*			 peek_word;
-	UIOpts			 opts = UI_CUSTOM_VALUES;
-
-
-
-
-	if (!get_part_type (_("Partition type"), *disk,
-					       &part_type))
-		return 0;
-
-	peek_word = fdisk_command_line_peek_word ();
-	if (part_type == PED_PARTITION_EXTENDED
-	    || (peek_word && isdigit (peek_word[0]))) {
-		fs_type = NULL;
-	}
-	/* gfdisk should ask for filesystem, lfdisk should not */
-	else if (!compat_mode) {
-		if (!get_fs_type (_("File system type"),
-					       &fs_type, 0))
-			return 0;
-	}
-	if (peek_word)
-		PED_FREE (peek_word);
-
-
-	pos.start.sector = 0LL;
-	pos.end.sector = 0LL;
-	pos.start.range = NULL;
-	pos.end.range = NULL;
-
-	/*
-	 * Christian <mail.kristian@yahoo.it> bug-fixed:
-	 *
-	 * (gdb) c
-	 * Continuing.
-	 * Partition type
-	 *   e   extended
-	 *   p   primary partition (1-4)
-	 * e
-	 * 
-	 * Program received signal SIGSEGV, Segmentation fault.
-	 * 0x0804bb3f in do_mkpart (disk=0xbf8c4150) at fdisk.c:673
-	 * 673             if (!fdisk_compatibility_mode && fs_type->ops->create &&
-	 */
-
-	/* if (!fdisk_compatibility_mode && fs_typ->ops->create && */
-
-	if (!compat_mode && fs_type && fs_type->ops->create &&
-	    part_type != PED_PARTITION_EXTENDED &&
-	    command_line_prompt_boolean_question(
-		_("Do you want to create the filesystem on the partition?")))
-	{
-	  return perform_mkpartfs (*disk, &pos, part_type, fs_type,
-				   NULL, opts | UI_WARN_COMMIT);
-	}
-	else
-	{
-	  return perform_mkpart (*disk, &pos, part_type, fs_type,
-				 NULL, opts);
-	}
+  PartPos pos;
+  PedPartitionType part_type = 0;
+  UIOpts opts = UI_CUSTOM_VALUES;
+
+  if (!get_part_type (_("Partition type"), *disk, &part_type))
+    return 0;
+
+  pos.start.sector = 0LL;
+  pos.end.sector = 0LL;
+  pos.start.range = NULL;
+  pos.end.range = NULL;
+
+  return perform_mkpart (*disk, &pos, part_type, NULL, opts);
 }
 
 #if 0
 }
 #endif
 
-static int
-do_move (PedDisk** disk)
-{
-	PartPos pos;
-	/* TODO: Make default position more friendly */
-	pos.start.sector = 0LL;
-	pos.end.sector = 0LL;
-	pos.start.range = NULL;
-	pos.end.range = NULL;
-	if(!perform_move (*disk, NULL, &pos, UI_CUSTOM_VALUES|UI_WARN_COMMIT)) {
-		ped_exception_throw(PED_EXCEPTION_ERROR,
-		                    PED_EXCEPTION_CANCEL,
-		         _("Partition move failed"));
-		if (uiquery.need_commit)
-				_disk_reread(disk);
-		return 0;
-	}
-	return 1;
-}
 // unused
 #if 0
 static int
 }
 
 static int
-do_resize (PedDisk** disk)
+do_resize (PedDisk ** disk)
 {
-	Option query_opts[] = {
-		{ 's', _("don't move the beginning of the partition") },
-		{ 'b', _("place it at the beginning of the free space before it") },
-		{ 'e', _("place it at the end") },
-		{ 'c', _("select custom start and end") },
-		{ '\0', NULL }
-
-	};
-	PartPos pos;
-	PedPartition *part = NULL, *temp;
-	PedSector first,last;
-	PedConstraint *constraint = NULL;
-	PedPartitionType desired;
-	UIOpts ui_opts = UI_WARN_COMMIT | UI_SNAP_TO_START;
-
-	if (!get_partition (_("Partition"), *disk, &part))
-                	return 0;
-
-	/* TODO: Almost shared between fdisk and cfdisk, move to common */
-	if (part->fs_type) {
-		if (!part->fs_type->ops->resize) {
-			ped_exception_throw(PED_EXCEPTION_ERROR,
-			                    PED_EXCEPTION_CANCEL,
-			                    _("You can't resize this filesystem type."));
-			return 0;
-		}
-		else {
-			PedFileSystem *fs = ped_file_system_open(&part->geom);
-			constraint = ped_file_system_get_resize_constraint(fs);
-			if (!constraint || constraint->min_size == constraint->max_size)
-			{
-				ped_exception_throw(PED_EXCEPTION_ERROR,
-				                    PED_EXCEPTION_CANCEL,
-				       _("We can't resize this filesystem type"));
-				if (constraint) ped_constraint_destroy(constraint);
-				if (fs) ped_file_system_close (fs);
-				return 0;
-			}
-			if (fs) ped_file_system_close (fs);
-		}
-	}
-	else if (part->type != PED_PARTITION_EXTENDED) {
-		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-		                    _("No filesystem detected on the partition."));
-		return 0;
-	}
-	pos.start.sector = part->geom.start;
-	pos.end.sector = part->geom.end;
-
-	desired = PED_PARTITION_FREESPACE |
-	                           (part->type & PED_PARTITION_LOGICAL);
-
-	temp = part_list_prev(part,PED_PARTITION_METADATA);
-
-	if (temp && (temp->type & desired))
-		first = temp->geom.start;
-	else
-		first = part->geom.start;
-
-	temp = part_list_next(part,PED_PARTITION_METADATA);
-
-	if (temp && (temp->type & desired))
-		last = temp->geom.end;
-	else
-		last = part->geom.end;
-
-	if(!query_part_position(_("Place for the resized partition"),
-	                        query_opts,&pos,first,last,(*disk)->dev,
-	                        constraint,&ui_opts)) {
-		if (constraint) ped_constraint_destroy (constraint);
-		return 0;
-	}
-	if (!perform_resize (*disk, part, &pos, ui_opts)) {
-		ped_exception_throw(PED_EXCEPTION_ERROR,
-		                    PED_EXCEPTION_CANCEL,
-		         _("Resize of the partition failed"));
-		if (!(ui_opts & UI_NO_FS_RESIZE) && uiquery.need_commit)
-				_disk_reread(disk);
-		return 0;
-	}
-	return 1;
-#if 0
-	PedPartition		*part = NULL;
-	PedFileSystem		*fs;
-	PedConstraint		*constraint;
-	PedSector		start, end;
-	PedGeometry             *range_start = NULL, *range_end = NULL;
-	PedGeometry		new_geom;
-
-	if (!*disk)
-		goto error;
-
-	if (!command_line_prompt_boolean_question
-	(_("WARNING: resize writes all data to disk automatically, continue")))
-	        return 1;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-	if (part->type != PED_PARTITION_EXTENDED) {
-		if (!_partition_warn_busy (part))
-			goto error;
-	}
-
-	start = part->geom.start;
-	end = part->geom.end;
-	if (!fdisk_command_line_get_sector (_("Start?"), (*disk)->dev, &start, &range_start))
-		goto error;
-	if (!fdisk_command_line_get_sector (_("End?"), (*disk)->dev, &end, &range_end))
-		goto error;
-
-	if (!ped_geometry_init (&new_geom, (*disk)->dev, start, end - start + 1))
-		goto error;
-	snap_to_boundaries (&new_geom, &part->geom, *disk,
-			    range_start, range_end);
-
-	if (part->type == PED_PARTITION_EXTENDED) {
-		constraint = constraint_from_start_end ((*disk)->dev,
-				range_start, range_end);
-		if (!ped_disk_set_partition_geom (*disk, part, constraint,
-						  new_geom.start, new_geom.end))
-			goto error_destroy_constraint;
-		ped_partition_set_system (part, NULL);
-	} else {
-		fs = ped_file_system_open (&part->geom);
-		if (!fs)
-			goto error;
-		constraint = constraint_intersect_and_destroy (
-				ped_file_system_get_resize_constraint (fs),
-				constraint_from_start_end (
-					(*disk)->dev, range_start, range_end));
-		if (!ped_disk_set_partition_geom (*disk, part, constraint,
-						  new_geom.start, new_geom.end))
-			goto error_close_fs;
-		if (!ped_file_system_resize (fs, &part->geom, timer))
-			goto error_close_fs;
-		/* may have changed... eg fat16 -> fat32 */
-		ped_partition_set_system (part, fs->type);
-		ped_file_system_close (fs);
-	}
-
-	ped_constraint_destroy (constraint);
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 1;
-
-error_close_fs:
-	ped_file_system_close (fs);
-error_destroy_constraint:
-	ped_constraint_destroy (constraint);
-error:
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 0;
-#endif
+  Option query_opts[] = {
+    {'s', _("don't move the beginning of the partition")},
+    {'b', _("place it at the beginning of the free space before it")},
+    {'e', _("place it at the end")},
+    {'c', _("select custom start and end")},
+    {'\0', NULL}
+  };
+
+  PartPos pos;
+  PedPartition *part = NULL, *temp;
+  PedSector first, last;
+  PedPartitionType desired;
+  UIOpts ui_opts = UI_WARN_COMMIT | UI_SNAP_TO_START;
+
+  if (!get_partition (_("Partition"), *disk, &part))
+    return 0;
+
+  /* get constraint from device */
+  
+  pos.start.sector = part->geom.start;
+  pos.end.sector = part->geom.end;
+
+  desired = PED_PARTITION_FREESPACE | (part->type & PED_PARTITION_LOGICAL);
+
+  temp = part_list_prev (part, PED_PARTITION_METADATA);
+
+  if (temp && (temp->type & desired))
+    first = temp->geom.start;
+  else
+    first = part->geom.start;
+
+  temp = part_list_next (part, PED_PARTITION_METADATA);
+
+  if (temp && (temp->type & desired))
+    last = temp->geom.end;
+  else
+    last = part->geom.end;
+
+  if (!query_part_position (_("Place for the resized partition"),
+			    query_opts, &pos, first, last, (*disk)->dev, NULL, &ui_opts))
+    {
+      return 0;
+    }
+
+  if (!perform_resize (*disk, part, &pos, ui_opts))
+    {
+      ped_exception_throw (PED_EXCEPTION_ERROR,
+                           PED_EXCEPTION_CANCEL,
+                           _("Resize of the partition failed"));
+      
+      if (!(ui_opts & UI_NO_FS_RESIZE) && uiquery.need_commit)
+        _disk_reread (disk);
+
+      return 0;
+    }
+
+  return 1;
 }
 
 static int
 	return perform_rm (*disk, NULL);
 }
 
+static int
+do_move (PedDisk** disk)
+{
+  PartPos pos;
+  
+  XASSERT(disk && *disk, return 0);
+
+  /* TODO: Make default position more friendly */
+  pos.start.sector = 0LL;
+  pos.end.sector = 0LL;
+  pos.start.range = NULL;
+  pos.end.range = NULL;
+
+  if(!perform_move (*disk, NULL, &pos, UI_WARN_COMMIT)) 
+    {
+      ped_exception_throw(PED_EXCEPTION_ERROR,
+                          PED_EXCEPTION_CANCEL,
+                          _("Partition move failed"));
+      if (uiquery.need_commit)
+        _disk_reread(disk);
+      return 0;
+    }
+  return 1;
+}
+
 #if 0
 static int
 do_select (PedDisk** disk)
 
 
 static int
-do_copy(PedDisk** disk)
-{
-	if (!perform_cp (*disk, NULL, UI_WARN_COMMIT)) {
-		ped_exception_throw(PED_EXCEPTION_ERROR,
-		                    PED_EXCEPTION_CANCEL,
-		         _("Partition copy failed"));
-		if (uiquery.need_commit)
-				_disk_reread(disk);
-		return 0;
-	}
-	return 1;
-}
-
-
-
-static int
 do_ex_menu (PedDisk** disk) {
 	int status,old_menu;
         old_menu = in_menu;
 	label_type_msg = str_list_convert (list);
 	str_list_destroy (list);
 
-/* mkfs - file system types */
-	list = str_list_create (_(fs_type_msg_start), NULL);
-
-	first = 1;
-	for (fs_type = ped_file_system_type_get_next (NULL);
-	     fs_type; fs_type = ped_file_system_type_get_next (fs_type)) {
-		if (fs_type->ops->create == NULL)
-			continue;
-
-		if (first)
-			first = 0;
-		else
-			str_list_append (list, ", ");
-		str_list_append (list, fs_type->name);
-	}
-	str_list_append (list, "\n");
-
-	mkfs_fs_type_msg = str_list_convert (list);
-	str_list_destroy (list);
-
 /* mkpart - file system types */
 	list = str_list_create (_(fs_type_msg_start), NULL);
 
 
 	mkpart_fs_type_msg = str_list_convert (list);
 	str_list_destroy (list);
-
-/* resize - file system types */
-	list = str_list_create (_(resize_msg_start), NULL);
-
-	first = 1;
-	for (fs_type = ped_file_system_type_get_next (NULL);
-	     fs_type; fs_type = ped_file_system_type_get_next (fs_type)) {
-		if (fs_type->ops->resize == NULL)
-			continue;
-
-		if (first)
-			first = 0;
-		else
-			str_list_append (list, ", ");
-		str_list_append (list, fs_type->name);
-	}
-	str_list_append (list, "\n");
-
-	resize_fs_type_msg = str_list_convert (list);
-	str_list_destroy (list);
 }
 
 static void
 
 
   if (!compat_mode)
-  {
-
-	fdisk_command_register (
-		fdisk_ex_menu_commands,
-			fdisk_command_create (
-				str_list_create_unique ("v", _("v"), NULL),
-				do_move,
-				str_list_create (_(" v   move a partition"), NULL),
-				str_list_create (_(number_msg), _(start_end_msg), NULL),
-			1)
-		);
-
-	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
-		str_list_create_unique ("c", _("c"), NULL),
-		do_rescue,
-		str_list_create (
-_(" c   rescue a lost partition"),
-NULL),
-		str_list_create (_(start_end_msg), NULL), 1));
-
-	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
-		str_list_create_unique ("z", _("z"), NULL),
-		do_resize,
-		str_list_create (
-_(" z   resize a partition and its file system"),
-NULL), NULL, 1));
-
-	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
-		str_list_create_unique ("h", _("h"), NULL),
-		do_check,
-		str_list_create (
-_(" h   check the consistency of a partition"),
-NULL), NULL, 1));
-
-	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
-		str_list_create_unique ("o", _("o"), NULL),
-		do_copy,
-		str_list_create (
-_(" o   copy the partition over another partition"),
-NULL), NULL, 1));
-
-	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
-		str_list_create_unique ("k", _("k"), NULL),
-		do_mkfs,
-		str_list_create (
-_(" k   creates a filesystem on a partition"),
-NULL), NULL, 1));
-
-
-  }
+    {
+	    fdisk_command_register (fdisk_ex_menu_commands,
+                              fdisk_command_create (str_list_create_unique ("v", _("v"), NULL),
+                                                    do_move,
+                                                    str_list_create (_(" v   move a partition"), NULL),
+                                                    str_list_create (_(number_msg), _(start_end_msg), NULL),
+                                                    1));
+
+      fdisk_command_register (fdisk_ex_menu_commands, 
+                              fdisk_command_create (str_list_create_unique ("c", _("c"), NULL),
+                                                    do_rescue,
+                                                    str_list_create (_(" c   rescue a lost partition"), NULL),
+                                                    str_list_create (_(start_end_msg), NULL), 1));
+
+      fdisk_command_register (fdisk_ex_menu_commands, 
+                              fdisk_command_create (str_list_create_unique ("z", _("z"), NULL),
+                                                    do_resize,
+                                                    str_list_create (_(" z   resize a partition"),
+                                                                     NULL), NULL, 1));
+
+      fdisk_command_register (fdisk_ex_menu_commands, 
+                              fdisk_command_create (str_list_create_unique ("h", _("h"), NULL),
+                                                    do_check,
+                                                    str_list_create (_(" h   check the consistency of a partition"), NULL), 
+                                                    NULL, 
+                                                    1));
+    }
+
   if (compat_mode)
 	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
 		str_list_create_unique ("b", _("b"), NULL),
 #endif /* !ENABLE_NLS */
 
 #include "strlist.h"
+#include "common.h"
 
 #define MIN(a,b)	( (a<b)?  a : b )
 
 	int		search_result;
 	int		line_break;
 
-	PED_ASSERT (line_length - indent > 10, return);
+	XASSERT (line_length - indent > 10, return);
 
 	spaces = get_spaces (indent);
 	line_left = line_length - offset;
 # include "config.h"
 #endif
 
+#include "common.h"
 #include "command.h"
 #include "strlist.h"
 #include "ui.h"
 static StrList*		on_list;
 static StrList*		off_list;
 static StrList*		on_off_list;
-static StrList*		fs_type_list;
-static StrList*		disk_type_list;
+static StrList*		ui_fs_type_list;
+static StrList*		ui_disk_type_list;
 
 /* Declare readline_state */
 static struct {
   char*	prompt = strdup (head);
 
   if (def && possibilities)
-    PED_ASSERT (str_list_match_any (possibilities, def), return NULL);
+    XASSERT (str_list_match_any (possibilities, def), return NULL);
 
   if (possibilities &&
       prompt_possibilities &&
   return prompt;
 }
 
+/* use same function from common.c */
+#if 0
+
 static int
 _can_create_primary (const PedDisk* disk)
 {
   return 0;
 }
 
+
 static int
 _can_create_extended (const PedDisk* disk)
 {
   return 1;
 }
 
+
 static int
 _can_create_logical (const PedDisk* disk)
 {
   return ped_disk_extended_partition (disk) != 0;
 }
 
+#endif
+
 static int
 init_ex_opt_str ()
 {
 }
 
 static int
-init_fs_type_str ()
+ui_init_fs_type_str ()
 {
   PedFileSystemType* walk;
 
-  fs_type_list = NULL;
+  ui_fs_type_list = NULL;
 
   for (walk = ped_file_system_type_get_next (NULL); walk;
        walk = ped_file_system_type_get_next (walk))
     {
-      fs_type_list = str_list_insert (fs_type_list, walk->name);
-      if (!fs_type_list)
+      ui_fs_type_list = str_list_insert (ui_fs_type_list, walk->name);
+      if (!ui_fs_type_list)
 	return 0;
     }
   return 1;
 }
 
 static int
-init_disk_type_str ()
+ui_init_disk_type_str ()
 {
   PedDiskType* walk;
 
-  disk_type_list = NULL;
+  ui_disk_type_list = NULL;
+
 
   for (walk = ped_disk_type_get_next (NULL); walk;
        walk = ped_disk_type_get_next (walk))
     {
-      disk_type_list = str_list_insert (disk_type_list, walk->name);
-      if (!disk_type_list)
+      ui_disk_type_list = str_list_insert (ui_disk_type_list, walk->name);
+      if (!ui_disk_type_list)
 	return 0;
     }
   return 1;
 	char*		result;
 	StrList*	next;
 
-	PED_ASSERT (command_line != NULL, return NULL);
+	XASSERT (command_line != NULL, return NULL);
 
 	result = str_list_convert_node (command_line);
 	next = command_line->next;
 	}
 	*value = ped_disk_type_get (disk_type_name);
 	free (disk_type_name);
-	PED_ASSERT (*value != NULL, return 0);
+	XASSERT (*value != NULL, return 0);
 	return 1;
 }
 #endif
   
   if (!init_ex_opt_str ()
       || !init_state_str ()
-      || !init_fs_type_str ()
-      || !init_disk_type_str ())
+      || !ui_init_fs_type_str ()
+      || !ui_init_disk_type_str ())
     return 0;
   ped_exception_set_handler (exception_handler);
 
   ped_exception_set_handler (NULL);
   done_ex_opt_str ();
   done_state_str ();
-  str_list_destroy (fs_type_list);
-  str_list_destroy (disk_type_list);
+  str_list_destroy (ui_fs_type_list);
+  str_list_destroy (ui_disk_type_list);
 }
 
 int
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.