Anonymous avatar Anonymous committed d85e297

Update fdisk to use common functions. Update common functions to respect fdisk expected behaviour - the second time when we query the sector, the user can specify size with +. (fdisk@sv.gnu.org/fdisk--main--0--patch-38)
fdisk@sv.gnu.org/fdisk--main--0--patch-38
Keywords:

Comments (0)

Files changed (6)

 		command.c	\
 		command.h	\
 		fdisk.c  	\
+		common.c	\
+		common.h	\
 		strlist.c	\
 		strlist.h	\
 		ui.c		\
 
 #include "common.h"
 
-#define SMALLBUF 128
+#define SMALLBUF 256
 
 /* Here we store the struct with interface functions */
 static UICalls *uiquery;
 	return 1;
 }
 
+/* This function gets sector. The prev option specifies
+   the previous selected sector, used if the user 
+   wants to specify a size, not a position */
 static int
 get_sector (const char* prompt, PedDevice* dev, PedSector* value,
-			 PedGeometry** range,  int custom)
+            PedGeometry** range, PedSector prev, int custom)
 {
 	char*	def_str;
 	char*	input = NULL;
+	char*	buf;
 	int	valid;
 	
 	if (!custom) {
 			*range = NULL;
 		return 0;
 	}
-
-	valid = ped_unit_parse (input, dev, value, range);
-
-	ped_free (input);
+	/* TODO: Improve... */
+	if (prev >= 0 && input[0] == '+') {
+		PedGeometry *geom;
+		PedSector sector, start, end;
+		/* If the string starts with +, interpret as size */
+		buf = calloc(128,sizeof(char));
+		valid = sscanf(input, "+%127s", buf);
+		free(input);
+		if (!valid) {
+			free(buf);
+			return 0;
+		}
+		valid = ped_unit_parse(buf, dev, &sector, &geom);
+		free(buf);
+		if (!valid) return 0;
+		/* Recalculate the sector and the range */
+		start = geom->start + prev - 1;
+		end = geom->end + prev - 1;
+		sector += prev - 1;
+		/* Check if they are outside the disk */
+		if (start >= dev->length) return 0;
+		if (sector >= dev->length) sector = dev->length - 1;
+		if (end >= dev->length) end = dev->length - 1;
+		valid = ped_geometry_init(geom, dev,
+		                          start, end - start + 1);
+		if (valid) {
+			if (range) *range = geom;
+			*value = sector;
+		}
+		
+	} else {
+		valid = ped_unit_parse (input, dev, value, range);
+		ped_free (input);
+	}
 	return valid;
 }
 
         if (!_partition_warn_busy (part))
                 goto error;
 	if (!type) {
+		type = ped_file_system_type_get ("ext2");
         	if (!get_fs_type (_("File system"), &type, 1))
 	                goto error;
 	}
                         goto error;
         }
 
-                
-        /*peek_word = command_line_peek_word ();*/
+            
         if (part_type == PED_PARTITION_EXTENDED) {
-            /*|| (peek_word && isdigit (peek_word[0]))) {*/
-                fs_type = NULL;
+		if (opts & UI_MAKEPARTFS) {
+                	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                        	_("An extended partition cannot hold a file system."));
+                	return 0;
+        	}
+		else
+                	fs_type = NULL;
         } else if (!fs_type) {
                 if (!get_fs_type (_("File system type"), &fs_type, 0))
                         goto error;
         }
 
-        /*if (peek_word)
-                ped_free (peek_word);*/
 
 
 
                                          PED_DISK_TYPE_PARTITION_NAME)) 
                 uiquery->getstring(_("Partition name"), &part_name, NULL, NULL, 1); 
 
-        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, -1,
+	                 opts & UI_CUSTOM_VALUES))
                 goto error;
-        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, start, 
+	                 opts & UI_CUSTOM_VALUES))
                 goto error;
         
         /* processing starts here */
                 if (!get_fs_type (_("File system type"), &fs_type, 1))
                         return 0;
         }
-	if (!perform_mkpart(disk,start,end,part_type,fs_type,&part,opts))
+	if (!perform_mkpart(disk,start,end,part_type,fs_type,&part,opts | UI_MAKEPARTFS))
 		return 0;
 	if (!perform_mkfs(disk,part,fs_type,opts & ~UI_WARN_COMMIT))
 		return 0;
                 goto error;
 
         /* get new target */
-        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, -1, 
+	                 opts & UI_CUSTOM_VALUES))
                 goto error_close_fs;
         if (opts & UI_CUSTOM_VALUES)
 		end = start + old_geom.length - 1;
-        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, start, 
+	                 opts & UI_CUSTOM_VALUES))
                 goto error_close_fs;
 
         /* set / test on "disk" */
 	if (uiquery->need_commit)
 		if (!perform_commit(disk,UI_DEFAULT))
 			goto error;
-        if (!get_sector (_("Start"), disk->dev, &start, NULL, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("Start"), disk->dev, &start, NULL, -1, 
+	                 opts & UI_CUSTOM_VALUES))
                 goto error;
-        if (!get_sector (_("End"), disk->dev, &end, NULL, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("End"), disk->dev, &end, NULL, start, 
+	                 opts & UI_CUSTOM_VALUES))
                 goto error;
 
         fuzz = PED_MAX (PED_MIN ((end - start) / 10, MEGABYTE_SECTORS(disk->dev)),
                         goto error;
         }
 
-        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, -1,
+	                 opts & UI_CUSTOM_VALUES))
                 goto error;
-        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, start, 
+	                 opts & UI_CUSTOM_VALUES))
                 goto error;
 
 	/* FIXME: Decide when exactly we need to "fuzzify" */
 #define UI_RESIZE_INEXACT UI_FUNCTION_SPECIFIC_2 /* Exact resize */
 /* Specific for perform_set: */
 #define UI_FLAG_TOGGLE UI_FUNCTION_SPECIFIC_1	/* perform_set must toggle flags */
+/* Specific for perform_mkfs */
+#define UI_MAKEPARTFS UI_FUNCTION_SPECIFIC_1
 
 /* Setting of UICalls */
 extern void set_uicalls(UICalls *);
 */
 
 #include "../config.h"
+#include "common.h"
 #include "command.h"
 #include "ui.h"
 
 static char* mkpart_fs_type_msg;
 static char* resize_fs_type_msg;
 
-static PedTimer* timer;
+//static PedTimer* timer;
 static TimerContext timer_context;
 static FdiskCommand* fdisk_main_menu_commands[256] = {NULL};
 static FdiskCommand* fdisk_ex_menu_commands[256] = {NULL};
 
 /* 0 = Disk was not altered.
    1 = Disk was altered. */
-static int need_commit = 0;
+//static int need_commit = 0;
+
+/* UI Calls structure */
+static UICalls uiquery;
 
 /* 0 = Sectors are the default unit.
    1 = Cylinders are the default unit (Default).*/
 
 static void _done (PedDevice* dev);
 
+/* Timer handler and other UI functions */ 
 static void
 _timer_handler (PedTimer* timer, void* context)
 {
 	}
 }
 
+/* We might as well get rid of these  two */
+
+static int
+getstring (const char* prompt, char** value, const StrList* words,
+	   const StrList* locwords, int multi_word)
+{
+	char*		def_str = NULL;
+	char*		input;
+	StrList*	valid = NULL;
+	/* TODO: Add a function that does just this to strlist.c */
+	valid = str_list_join (str_list_duplicate(words),
+	                       str_list_duplicate(locwords));
+
+	if (*value) def_str = strdup(*value);
+	input = fdisk_command_line_get_word (prompt, def_str,
+				             valid, multi_word);
+	str_list_destroy(valid);
+	if (def_str) free(def_str);
+	*value = input;
+	return 1;
+}
+
+static int
+getbool (const char* prompt, int* value)
+{
+	*value = command_line_prompt_boolean_question (prompt);
+	return 1;
+}
+/* We don't need this one
+static int
+(*getint) (const char* prompt, int* value) = fdisk_command_line_get_integer; 
+*/
+
+#if 0
 static int
 _partition_warn_busy (PedPartition* part)
 {
 	ped_constraint_destroy (b);
 	return result;
 }
-
+#endif
 static void 
 help_on (char* topic) 
 { 
 static int
 do_check (PedDisk** disk)
 {
-	PedFileSystem*	fs;
-	PedPartition*	part = NULL;
-	int		part_num;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-	if (!_partition_warn_busy (part))
-		goto error;
-
-	if (!ped_disk_check (*disk))
-		goto error;
-
-	fs = ped_file_system_open (&part->geom);
-	if (!fs)
-		goto error;
-	if (!ped_file_system_check (fs, timer))
-		goto error_close_fs;
-	ped_file_system_close (fs);
-	return 1;
-
-error_close_fs:
-	ped_file_system_close (fs);
-error:
-	return 0;
+	return perform_check(*disk,NULL);
 }
 
 static int
 do_cp (PedDisk** disk)
 {
-	PedDisk*		src_disk;
-	PedDisk*		dst_disk;
-	PedDevice*		src_device;
-	PedPartition*		src = NULL;
-	PedPartition*		dst = NULL;
-	PedFileSystem*		src_fs;
-	PedFileSystem*		dst_fs;
-	PedFileSystemType*	dst_fs_type;
-
-	if (!command_line_prompt_boolean_question 
-	(_("WARNING: mkfs writes all data to disk automatically, continue"))) 
-		return 1;
-
-	dst_disk = ped_disk_new ((*disk)->dev);
-	if (!dst_disk)
-		goto error;
-
-	src_disk = dst_disk;
-	if (!fdisk_command_line_is_integer ()) {
-		if (!fdisk_command_line_get_disk (_("Source device?"), &src_disk))
-			goto error;
-	}
-
-	if (!fdisk_command_line_get_partition (_("Source partition number?"),
-					       src_disk, &src))
-		goto error;
-	if (src->type == PED_PARTITION_EXTENDED) {
-		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-			_("Can't copy an extended partition."));
-		goto error;
-	}
-	if (!_partition_warn_busy (src))
-		goto error;
-
-	if (!fdisk_command_line_get_partition (_("Destination partition number?"),
-					 dst_disk, &dst))
-		goto error;
-	if (!_partition_warn_busy (dst))
-		goto error;
-
-/* do the copy */
-	src_fs = ped_file_system_open (&src->geom);
-	if (!src_fs)
-		goto error;
-	dst_fs = ped_file_system_copy (src_fs, &dst->geom, 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;
-	if (!ped_disk_commit (dst_disk))
-		goto error;
-	if (src_disk != dst_disk)
-		ped_disk_destroy (src_disk);
-	return 1;
-
-error_close_src_fs:
-	ped_file_system_close (src_fs);
-error:
-	return 0;
+	return perform_cp(*disk,NULL,UI_WARN_COMMIT);
 }
 
 void 
 							destroy disk. */ 
 	const PedDiskType*	type = ped_disk_type_get ("msdos");
 
-	ped_exception_fetch_all ();
-
-	if (!(*disk)) ped_exception_catch ();
-	ped_exception_leave_all ();
-
-	if (*disk) {
-		if (!_disk_warn_busy (*disk)) {
-			ped_disk_destroy (*disk);
-			goto error;
-		}
-		ped_disk_destroy (*disk);
-	}
-
-	*disk = ped_disk_new_fresh (dev, type);
-	if (!*disk)
-		goto error;
-
-	if (!need_commit) need_commit = 1;
-	
-	return 1;
-
-error:
-	return 0;
+	return perform_mklabel(dev,disk,type);
 }
 
 static int
 
 	ped_exception_fetch_all ();
 
-	if (!(*disk)) ped_exception_catch ();
-	ped_exception_leave_all ();
-
-	if (*disk) {
-		if (!_disk_warn_busy (*disk)) {
-			ped_disk_destroy (*disk);
-			goto error;
-		}
-		ped_disk_destroy (*disk);
-	}
-
-	*disk = ped_disk_new_fresh (dev, type);
-	if (!*disk)
-		goto error;
-
-	if (!need_commit) need_commit = 1;
-	
-	return 1;
-
-error:
-	return 0;
+	return perform_mklabel(dev,disk,type);
 }
 
 static int
 
 	ped_exception_fetch_all ();
 
-	if (!(*disk)) ped_exception_catch ();
-	ped_exception_leave_all ();
-
-	if (*disk) {
-		if (!_disk_warn_busy (*disk)) {
-			ped_disk_destroy (*disk);
-			goto error;
-		}
-		ped_disk_destroy (*disk);
-	}
-
-	if (!fdisk_command_line_get_disk_type (_("New disk label type?"), &type))
-		goto error;
-
-	*disk = ped_disk_new_fresh (dev, type);
-	if (!*disk)
-		goto error;
-
-	if (!need_commit) need_commit = 1;
-	
-	return 1;
-
-error:
-	return 0;
+	return perform_mklabel(dev,disk,type);
 }
 
 static int
 do_mkfs (PedDisk** disk)
 {
-	PedPartition*		part = NULL;
-	const PedFileSystemType* type = ped_file_system_type_get ("ext2");
-	PedFileSystem*		fs;
 
-	if (!*disk)
-		goto error;
-
-	if (!command_line_prompt_boolean_question 
-	(_("WARNING: mkfs writes all data to disk automatically, continue"))) 
-	        return 1;
-	
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-	if (!_partition_warn_busy (part))
-		goto error;
-	if (!fdisk_command_line_get_fs_type (_("File system?"), &type))
-		goto error;
-
-	fs = ped_file_system_create (&part->geom, type, timer);
-	if (!fs)
-		goto error;
-	ped_file_system_close (fs);
-
-	if (!ped_partition_set_system (part, type))
-		goto error;
-	if (!ped_disk_commit (*disk))
-		goto error;
-	
-	return 1;
-
-error:
-	return 0;
+	return perform_mkfs(*disk,NULL,NULL,UI_WARN_COMMIT);
 }
 
 static int
 do_mkpart (PedDisk **disk)
 {
 	PedPartition* 		 part;
-	PedPartitionType	 part_type;
+	PedPartitionType	 part_type = 0;
 	const PedFileSystemType* fs_type = ped_file_system_type_get ("ext2");
-	PedSector		 start = 0, end = 0;
-	PedGeometry 		 *range_start = NULL, *range_end = NULL;
-	PedConstraint*		 constraint;
+	//PedSector		 start = 0, end = 0;
+	//PedGeometry 		 *range_start = NULL, *range_end = NULL;
+	//PedConstraint*		 constraint;
 	char*			 peek_word;
 
 	if (!fdisk_command_line_get_part_type (_("Partition type?"), *disk,
 					       &part_type))
-		goto error;
+		return 0;
 
 	peek_word = fdisk_command_line_peek_word ();
 	if (part_type == PED_PARTITION_EXTENDED
 	} else {
 		if (!fdisk_command_line_get_fs_type (_("File system type?"),
 					       &fs_type))
-			goto error;
+			return 0;
 	}
 	if (peek_word)
 		ped_free (peek_word);
-
-	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;
-	part = ped_partition_new (*disk, part_type, fs_type, start, end);
-	if (!part)
-		goto error;
-	snap_to_boundaries (&part->geom, NULL, *disk, range_start, range_end);
-	constraint = constraint_from_start_end ((*disk)->dev, range_start, range_end);
-	if (!constraint)
-		goto error_destroy_part;
-	if (!ped_disk_add_partition (*disk, part, constraint))
-		goto error_destroy_constraint;
-	ped_constraint_destroy (constraint);
-
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-
-	if (!need_commit) need_commit = 1;
-
-	return 1;
-
-error_destroy_constraint:
-	ped_constraint_destroy (constraint);
-error_destroy_part:
-	ped_partition_destroy (part);
-error:
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 0;
+	/* TODO: Specify size in fdisk's fashion */
+	return perform_mkpart (*disk, 0LL, 0LL, part_type, fs_type,
+	                       NULL, UI_CUSTOM_VALUES);
 }
 
 static int
 do_mkpartfs (PedDisk** disk)
 {
-	PedPartition*       part;
-	PedPartitionType    part_type;
-	const PedFileSystemType* fs_type = ped_file_system_type_get ("ext2");
-	PedSector           start = 0, end = 0;
-	PedGeometry         *range_start = NULL, *range_end = NULL;
-	PedConstraint*      constraint;
-	PedFileSystem*      fs;
-
-	if (!*disk)
-		goto error;
-
-	if (!command_line_prompt_boolean_question 
-	(_("WARNING: mkpartfs writes all data to disk automatically, continue"))) 
-	        return 1;
-
-	if (!fdisk_command_line_get_part_type (_("Partition type?"), *disk,
-					 &part_type))
-		goto error;
-
-	if (part_type == PED_PARTITION_EXTENDED) {
-		ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-			_("An extended partition cannot hold a file system.  "
-			  "Did you want mkpart?"));
-		goto error;
-	}
-
-	if (!fdisk_command_line_get_fs_type (_("File system type?"), &fs_type))
-		goto error;
-	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;
-	part = ped_partition_new (*disk, part_type, fs_type, start, end);
-	if (!part)
-		goto error;
-	snap_to_boundaries (&part->geom, NULL, *disk, range_start, range_end);
-	constraint = constraint_intersect_and_destroy (
-			ped_file_system_get_create_constraint (fs_type, (*disk)->dev),
-			constraint_from_start_end ((*disk)->dev, range_start, range_end));
-	if (!ped_disk_add_partition (*disk, part, constraint))
-		goto error_destroy_constraint;
-	ped_constraint_destroy (constraint);
-
-	fs = ped_file_system_create (&part->geom, fs_type, timer);
-	if (!fs) 
-		goto error;
-	ped_file_system_close (fs);
-
-	if (!ped_partition_set_system (part, fs_type))
-		goto error;
-
-	if (!ped_disk_commit (*disk))
-		goto error;
-
-	if (need_commit) need_commit = 0;
-
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 1;
-
-error_destroy_constraint:
-	ped_constraint_destroy (constraint);
-error_destroy_part:
-	ped_partition_destroy (part);
-error:
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 0;
+	return perform_mkpartfs (*disk, 0LL, 0LL, 0, NULL, NULL, 
+	                         UI_CUSTOM_VALUES | UI_WARN_COMMIT | 
+	                         UI_SPECIFY_PART_TYPE);
 }
 
 static int
 do_move (PedDisk** disk)
 {
-	PedPartition*	part = NULL;
-	PedFileSystem*	fs;
-	PedFileSystem*	fs_copy;
-	PedConstraint*	constraint;
-	PedSector	start = 0, end = 0;
-	PedGeometry     *range_start = NULL, *range_end = NULL;
-	PedGeometry	old_geom, new_geom;
-
-	if (!*disk)
-		goto error;
-
-	if (!command_line_prompt_boolean_question 
-	(_("WARNING: move writes all data to disk automatically, continue"))) 
-	        return 1;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *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;
-
-	/* get new target */
-	if (!fdisk_command_line_get_sector (_("Start?"), (*disk)->dev, &start, &range_start))
-		goto error_close_fs;
-	end = start + old_geom.length - 1;
-	if (!fdisk_command_line_get_sector (_("End?"), (*disk)->dev, &end, &range_end))
-		goto error_close_fs;
-
-	/* set / test on "disk" */
-	if (!ped_geometry_init (&new_geom, (*disk)->dev, start, end - start + 1))
-		goto error_close_fs;
-	snap_to_boundaries (&new_geom, NULL, *disk, range_start, range_end);
-
-	constraint = constraint_intersect_and_destroy (
-			ped_file_system_get_copy_constraint (fs, (*disk)->dev),
-			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_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;
-	}
-
-        /* do the move */
-	fs_copy = ped_file_system_copy (fs, &part->geom, timer);
-	if (!fs_copy)
-		goto error_close_fs;
-	ped_file_system_close (fs_copy);
-	ped_file_system_close (fs);
-	if (!ped_disk_commit (*disk))
-		goto error;
-	
-	if (need_commit) need_commit = 0;
-	
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 1;
-
-error_destroy_constraint:
-	ped_constraint_destroy (constraint);
-error_close_fs:
-	ped_file_system_close (fs);
-error:
-	if (range_start != NULL)
-		ped_geometry_destroy (range_start);
-	if (range_end != NULL)
-		ped_geometry_destroy (range_end);
-	return 0;
+	return perform_move (*disk, NULL, 0LL, 0LL, UI_CUSTOM_VALUES);
 }
 
 static int
 do_name (PedDisk** disk)
 {
-	PedPartition*	part = NULL;
-	char*		name;
-
-	if (!*disk)
-		goto error;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-
-	name = fdisk_command_line_get_word (_("Partition name?"),
-					    ped_partition_get_name (part), NULL, 0);
-	if (!name)
-		goto error;
-	if (!ped_partition_set_name (part, name))
-		goto error_free_name;
-	free (name);
-
-	if (!need_commit) need_commit = 1;
-
-	return 1;
-
-error_free_name:
-	free (name);
-error:
-	return 0;
+	return perform_name(*disk, NULL, NULL);
 }
-
+/* TODO: REMOVE */
+#if 0
 static void
 partition_print_flags (PedPartition* part)
 {
 		}
 	}
 }
+#endif
 
 /* Prints a sector out, first in compact form, and then with a percentage.
  * Eg: 32Gb (40%)
 
 	return PED_PARTITION_LOGICAL;
 }
-
+#if 0
 /* This function checks if "part" contains a file system, and returs
  * 	0 if either no file system was found, or the user declined to add it.
  * 	1 if a file system was found, and the user chose to add it.
 	return 0;
 }
 
+#endif
 static int
 do_rescue (PedDisk** disk)
 {
+	return perform_rescue(*disk, 0LL, 0LL,
+	                      UI_CUSTOM_VALUES | UI_WARN_COMMIT);
+#if 0
 	PedSector		start = 0, end = 0;
 	PedSector		fuzz;
 	PedGeometry		probe_start_region;
 
 error:
 	return 0;
+#endif
 }
 
 static int
 do_resize (PedDisk** disk)
 {
+	return (*disk, NULL, 0LL, 0LL, UI_WARN_COMMIT | UI_CUSTOM_VALUES);
+#if 0
 	PedPartition		*part = NULL;
 	PedFileSystem		*fs;
 	PedConstraint		*constraint;
 	if (range_end != NULL)
 		ped_geometry_destroy (range_end);
 	return 0;
+#endif
 }
 
 static int
 do_rm (PedDisk** disk)
 {
-	PedPartition*		part = NULL;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-	if (!_partition_warn_busy (part))
-		goto error;
-
-	ped_disk_delete_partition (*disk, part);
-
-	if (!need_commit) need_commit = 1;
-
-	return 1;
-
-error:
-	return 0;
+	return perform_rm (*disk, NULL);
 }
 
 static int
 	if (!ped_device_open (dev))
 		return 0;
 
-	if (need_commit) 
+	if (uiquery.need_commit) 
 	        if (!command_line_prompt_boolean_question 
 		(_("WARNING: changes were made to the disk, "
 		   "are you sure you want to discard them")))
 	/* Tell the user we are using the new device. */
 	fdisk_print_using_dev (dev);
 
-	if (need_commit) need_commit = 0;
+	if (uiquery.need_commit) uiquery.need_commit = 0;
 
 	return 1;
 }
 static int
 do_set (PedDisk** disk)
 {
-	PedPartition*		part = NULL;
-	PedPartitionFlag	flag;
-	int			state;
-
-	if (!(*disk))
-		goto error;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-	if (!fdisk_command_line_get_part_flag (_("Flag to change?"), part, &flag))
-		goto error;
-	state = ped_partition_get_flag (part, flag);
-	if (!fdisk_command_line_get_state (_("New state?"), &state))
-		goto error;
-
-	if (!ped_partition_set_flag (part, flag, state))
-       	        goto error;
-
-	if (!need_commit) need_commit = 1;
-
-	return 1;
-
-error:
-	return 0;
+	return perform_set (*disk, NULL, 0, UI_DEFAULT);
 }
 
 static int
 do_toggle_boot_flag (PedDisk** disk)
 {
-	PedPartition*		part = NULL;
-	PedPartitionFlag	flag = PED_PARTITION_BOOT;
-	int			state;
-
-	if (!(*disk))
-		goto error;
-
-	if (!fdisk_command_line_get_partition (_("Partition number?"), *disk, &part))
-		goto error;
-
-	state = ((ped_partition_get_flag (part, flag)) ? 0 : 1);
-
-	if (!ped_partition_set_flag (part, flag, state))
-		goto error;
-
-	if (!need_commit) need_commit = 1;
-
-	return 1;
-
-error:
-	return 0;
+	
+	
+	return perform_set (*disk, NULL, PED_PARTITION_BOOT, UI_FLAG_TOGGLE);
 }
 
 static int
 static int 
 do_commit (PedDisk **disk)
 {  
+	/* TODO: Move these to common! */
 	if ((*disk)->dev->boot_dirty && (*disk)->dev->type != PED_DEVICE_FILE) {
 	        ped_exception_throw (
 				     PED_EXCEPTION_WARNING,
 				       "rebooting.  Read section 4 of the Parted User "
 				       "documentation for more information."));
 	}
+	/* TODO: dev->type is deprecated, use is_blockdevice instead */
 	if ((*disk)->dev->type != PED_DEVICE_FILE && !fdisk_opt_script_mode) {
 	        ped_exception_throw (
 				     PED_EXCEPTION_INFORMATION, PED_EXCEPTION_OK,
 	printf (_("\nWriting all changes to %s.\n"), _((*disk)->dev->path));
 	if (!ped_disk_commit (*disk))
 	        goto error;
-  
+
+	/* FIXME: This is not needed */
 	if (!ped_disk_commit_to_os (*disk))
                 goto error;
   
 #endif /* ENABLE_NLS */
 }
 
+/* initialise UI calls structure */
+static void
+_init_uicalls()
+{
+	//uiquery = malloc(sizeof(UICalls));
+	/* TODO: Get rid of getstring and getint functions */
+	uiquery.getstring = getstring;
+	uiquery.getint = fdisk_command_line_get_integer;
+	uiquery.getbool = getbool;
+	uiquery.getdev = NULL;
+	uiquery.getpart = NULL;
+	uiquery.getdisktype = NULL;
+	uiquery.getfstype = NULL;
+	/* TODO: Will we use this? */
+	uiquery.getpartpos = NULL;
+	uiquery.need_commit = 0;
+	uiquery.timer = ped_timer_new (_timer_handler, &timer_context);
+	set_uicalls(&uiquery);
+}
+
 static void
 _version ()
 {
 	_init_messages ();
 	_init_main_menu_commands ();
 	
+	
 	if (!_parse_options (argc_ptr, argv_ptr))
 		goto error_done_commands;
 	dev = _choose_device (argc_ptr, argv_ptr);
 	if (!dev)
 		goto error_done_commands;
 
-	timer = ped_timer_new (_timer_handler, &timer_context);
-	if (!timer)
+	_init_uicalls();
+
+	if (!uiquery.timer)
 		goto error_done_commands;
 	timer_context.last_update = 0;
 
 {
 	ped_device_close (dev);
 
-	ped_timer_destroy (timer);
+	/* TODO: _done_uicalls? */
+	ped_timer_destroy (uiquery.timer);
 	_done_commands ();
 	_done_messages ();
 	fdisk_done_ui();
 #include "hacks.h"
 #include "sys_types.h"
 
-#define MSDOS_HACK 1
-#define MAC_HACK 1
-#define SUN_HACK 1
-#define BSD_HACK 1
-#define DVH_HACK 0
-#define GPT_HACK 0 /* No, thank you */
-#define PC98_HACK 0
-#define AMIGA_HACK 0
 
 /* FIXME: As the file is needed for lfdisk, calling it "hacks" might
  * not be the greatest idea
 	
 }
 /* Needed for lfdisk */
-#if 0
 void
 set_disk_specific_system_type (PedPartition *part, unsigned char type) {
 	/* TODO: I have no idea how we actually should do this */
 	}
 	else
 	#endif
+	#if SUN_HACK
+	if (!strcmp(part->disk->type->name,"sun")) {
+		SunPartitionData *pd = (SunPartitionData *)part->disk_specific;
+		pd->type = type;
+	}
+	else
+	#endif
 	#if BSD_HACK
 	if (!strcmp(part->disk->type->name,"bsd")) {
 		BSDPartitionData *pd = (BSDPartitionData *)part->disk_specific;
 	#endif
 	return;
 }
-#endif
 #define HACKS_H_INCLUDED
 #include <parted/parted.h>
 
+#define MSDOS_HACK 1
+#define MAC_HACK 1
+#define SUN_HACK 1
+#define BSD_HACK 1
+#define DVH_HACK 0
+#define GPT_HACK 0 /* No, thank you */
+#define PC98_HACK 0
+#define AMIGA_HACK 0
+
+
 extern int is_blockdev(const char *file);
 extern const char* get_disk_specific_system_name (PedPartition*);
 extern unsigned int get_disk_specific_system_type (PedPartition *part, int *size);
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.