Anonymous avatar Anonymous committed aa259dd

Implement menu scrolling. Begin implementing functionality. (fdisk@sv.gnu.org/fdisk--main--0--patch-10)
fdisk@sv.gnu.org/fdisk--main--0--patch-10
Keywords:

Comments (0)

Files changed (3)

 	MENU_LIST = 2,   /* Unimplemented */
 	MENU_ANYKEY = 4,
 	MENU_BUTTON = 8,
-	MENU_LEAVE_WARNING = 16 /* Don't clear the warning line */
+	MENU_LEAVE_WARNING = 16, /* Don't clear the warning line */
+	MENU_NOHIGHLIGHT = 32 /* Do not highlight the selected element in the menu */
 };
 
 typedef enum _MenuOptions MenuOptions;
 #define SMALLBUF 128
 
 
-
+/* struct for a menu item. I got the idea from Linux cfdisk. Every action is bound to a key. */
 struct MenuItem {
 	char key;
-	char *name;
-	char *desc; 
+	const char *name;
+	const char *desc; 
 };
 
 
 /* TODO: Improve this. */
 void
 display_message (const char *msg) {
-	int y = 0, x = 0, i,n = strlen(msg);
+	int y = INFOSIZE+1, x = 0, i,n = strlen(msg);
+	move(y++,0); clrtoeol();
+	mvaddch(y,0,' ');//' 'buf[0] = ' ';
+	for (x = 1; x < COLS-1; x++) {
+		mvaddch(y,x,'-'); //buf[i] = '-';
+        }
+	mvaddch(y++,x,' ');
+	x = 0;
 	move(y,x);
 	clrtoeol();
 	for (i = 0; i < n; i++) {
 	
 			/* Write the button. Highlight if is selected. */
 			
-			if (i == selected) attron(A_STANDOUT);
+			if (i == selected && !(opts & MENU_NOHIGHLIGHT)) attron(A_STANDOUT);
 			/*else if (strchr(keys,tolower(items[i].key))) attron(A_DIM);*/
 	
 			mvaddstr(y,x,buf);
 	
-			if (i == selected) attroff(A_STANDOUT);
+			if (i == selected && !(opts & MENU_NOHIGHLIGHT)) attroff(A_STANDOUT);
 			/*else if (strchr(keys,tolower(items[i].key))) attroff(A_BOLD);*/
 			
 			if (x + 2*item_size + 2*MENUDIV < COLS) {
 	for (count = 0; items[count].name; count++);
 	if (selected >= count)
 		selected = 0;
+	i = 0;
 	while (!strchr(keys,tolower(items[selected].key))) {
 		selected = (selected + 1) % count;
+		if (i++ > count) {
+			selected = 0;
+			break;
+		}
 	}
 	while (!key) {
 		if (redraw) {
 }
 
 /* String list choice */
+/* The last two parameters specify the number of the selected element and the first element displayed 
+   last time */
 static void
-strlist_draw (const char *prompt, const StrList *strlist, const StrList* selected) {
-	char buf[SMALLBUF]; /* FIXME: Not needed */
+strlist_draw (const char *prompt, const StrList *strlist, const StrList* selected, int selnum, int *start) {
+	/*char buf[SMALLBUF]; *//* FIXME: Not needed */
 	char *temp;
-	int n,x,y = INFOSIZE;
+	int n,x,y = INFOSIZE,i;
 	const StrList *current;
-
+	n = LINES-MENUSIZE-3;
+	if (selnum - *start < 0)
+		*start = selnum;
+	else if (selnum - *start >= n - INFOSIZE - 4)
+		*start = selnum - n + INFOSIZE + 5;
 	move(y++,0); clrtoeol();
 	move(y,0); clrtoeol(); mvaddstr(y++,5,prompt);
 	/* FIXME: Using buf here not needed. This appears another time in source. */
 	//mvaddstr(y++,0,buf);
 	move(y++,0); clrtoeol();
 	
-	n = COLS-LINES-MENUSIZE;
-	
-	for (current = strlist; current && y < n; current = current->next, y++) {
+	for (current = strlist, i = 0; current && y < n; current = current->next, i++) {
+		if (i < *start)
+			continue;
 		if (current == selected)
 			attron(A_STANDOUT);
 		move(y,0); clrtoeol();
 		if (temp) free(temp);
 		if (current == selected)
 			attroff(A_STANDOUT);
+		y++;
 	} 
 }
-
-void plist_draw (PedDisk *cdisk, PedPartition *selected);
+static void show_info();
+void plist_draw (PedDisk *cdisk, PedPartition *selected, int selnum, int *start);
 
 static const StrList*
 do_strlist (const char *prompt, const StrList *strlist) {
 	const StrList *selected = strlist, *temp;
-	int redraw = 1, key = 0, done = 0;
+	int redraw = 1, key = 0, done = 0, start = 0, selnum = 0;
 	while (!done) {
 		if (redraw) {
-			strlist_draw(prompt, strlist, selected);
+			strlist_draw(prompt, strlist, selected,selnum,&start);
 			clear_menu();
 			redraw = 0;
 		}
 						print_warning(_("No more choices"),0);
 					else {
 						selected = selected->next;
+						selnum++;
 						redraw = 1;
 					}
 				}
 							print_warning(_("Bug in the program. "
 							                "The programmer is an idiot."),0);
 						else {
+							selnum--;
 							selected = temp;
 							redraw = 1;
 						}
 		else 
 			print_warning(_("Invalid key"),0);
 	}
-	if (disk) plist_draw(disk,NULL);
+	if (disk) { 
+		show_info();
+		/* FIXME: This won't always print what we need, but who cares? */
+		start = 0;
+		plist_draw(disk,NULL,0,&start);
+	}
 	return selected;
 }
 
 		}
 		refresh();
 	}
-	if (*value) free (*value);
+	if (*value) ped_free (*value);
 	n = strlen(buf);
 	*value = (char *)calloc(n,sizeof(char));
 	strncpy(*value,buf,n);
 			selected = do_strlist(prompt,locwords);
 		else
 			selected = do_strlist(prompt,words);
-		if (*value) free(*value);
+		if (*value) ped_free(*value);
 		*value = str_list_convert_node(selected);
 		return (*value != NULL);
 	}
 	init_disk_type_str ();
 }
 
+static void
+notice_waitkey(const char *warning) {
+	static struct MenuItem waitkey[] = {
+		{ 'k', "", N_("Press any key to continue") },
+		{ 0, NULL, NULL }
+	};
+	if (warning)
+		waitkey[0].name = warning;
+	do_menu(waitkey,COLS-MENUDIV*2,MENU_ANYKEY | MENU_NOHIGHLIGHT,"k",0);
+}
+
+static void
+warning_waitkey(const char *warning) {
+	putchar(BELL);
+	notice_waitkey(warning);
+}
+
+
+/* Here we define our menu operations */
+static int
+action_new (PedPartition **part) {
+	static struct MenuItem part_position[] = {
+		{ 'b', N_("Begining"), N_("Create the partition at the begining of the free space") },
+		{ 'e', N_("End"), N_("Create the partition at the end of the free space") },
+		{ 'c', N_("Custom"), N_("Select custom start and end position of the partition") },
+		{ ESC, N_("Cancel"), N_("Do not create a partition") },
+		{ 0, NULL, NULL }
+	};
+	static struct MenuItem part_type[] = {
+		{ 'p', N_("Primary"), N_("Create primary partition") },
+		{ 'e', N_("Extended"), N_("Create extended partition") },
+		{ ESC, N_("Cancel"), N_("Do not create a partition") },
+		{ 0, NULL, NULL }
+	};
+	const char pos_keys[] = {'b', 'e', 'c', ESC, '\0'};
+	const char type_keys[] = {'p', 'e', ESC, '\0'};
+	char *temp,*def_str;
+	PedPartitionType type;
+	PedSector start, end, length, def_len;
+	int key,success = 1,done;
+	if((*part)->type & PED_PARTITION_LOGICAL)
+		type = PED_PARTITION_LOGICAL;
+	else if ((*part)->type & PED_PARTITION_FREESPACE) {
+		if(!can_create_primary(disk)) {
+			warning_waitkey(N_("Cannot create more primary partitions"));
+			return 0;
+		}
+		else if (can_create_extended(disk)) {
+			menu_title(_("Type of partition you want to create"));
+			key = do_menu(part_type, 8, MENU_BUTTON | MENU_TITLE, type_keys, 0);
+			if (key == ESC)	return 1;
+			else if (key == 'p') type = PED_PARTITION_NORMAL;
+			else if (key == 'e') type = PED_PARTITION_EXTENDED;
+		}
+		else type = PED_PARTITION_NORMAL;
+	} else {
+		warning_waitkey(N_("Report a bug in the function menu_new and win a cookie."));
+		return 0;
+	}	
+	menu_title(_("Where do you want to put the partition"));
+	key = do_menu(part_position, 8, MENU_BUTTON | MENU_TITLE, pos_keys, 0);
+	if (key == ESC)
+		return 0;
+	else {
+		start = (*part)->geom.start;
+		end = (*part)->geom.end;
+		if (key == 'c') {
+			success = do_mkpart (disk, start, end, type, NULL, part, UI_CUSTOM_VALUES, &uiquery);
+		} else {
+			length = (*part)->geom.length;
+			def_len = length;
+			done = 0;
+			while (!done) {
+				def_str = ped_unit_format(dev,length);
+				if (def_str) temp = strdup(def_str);
+				if (!read_char(_("Size"), &temp)) {
+					if (temp) ped_free(temp);
+					if (def_str) ped_free(def_str);
+					return 0;
+				}
+				done = 1;
+				/* Get the new size only if the user modified it */
+				if(strcmp(temp,def_str)) {
+					if (!ped_unit_parse(temp,dev,&length,NULL)) {
+						warning_waitkey(N_("This is an invalid partition size"));
+						done = 0;
+					}
+					else if (length > def_len) {
+						length = def_len;
+					}
+				}
+				if (temp) ped_free(temp);
+				if (def_str) ped_free(def_str);
+			}
+			if (key == 'b') {
+				success = do_mkpart(disk, start, start+length-1, type, NULL, part, UI_DEFAULT,&uiquery);
+			}
+			else if (key == 'e') {
+				success = do_mkpart(disk, end-length, end, type, NULL, part, UI_DEFAULT, &uiquery);
+			}
+		}
+	}
+	if (!success)
+		warning_waitkey(N_("Can't create partition."));
+	return success;
+	
+}
+
+static int
+action_mkfs (PedPartition **part) {
+	if (!do_mkfs (disk, *part, NULL, UI_WARN_COMMIT, &uiquery)) {
+		warning_waitkey(N_("Partition not formatted successfully"));
+		return 0;
+	}
+	notice_waitkey(N_("Partition formatted successfully."));
+	return 1;
+}
+
+static int
+action_check (PedPartition **part) {
+	if (!do_check(disk,*part, &uiquery)) {
+		warning_waitkey(N_("The consistency check failed."));
+		return 0;
+	}
+	notice_waitkey(N_("The consistency of the partition seems to be OK."));
+	return 1;
+}
+
+static int
+action_commit () {
+	if (!do_commit(disk,&uiquery)) {
+		warning_waitkey(N_("Commit failed."));
+		return 0;
+	} 
+	notice_waitkey(N_("Partition table successfully written."));
+	return 1;
+}
+
+static int
+action_units () {
+	static struct MenuItem units[] = {
+		{ '1' , N_("Sectors"), N_("Show the sizes in sectors") },
+		{ '2' , N_("Bytes"), N_("Show the sizes in bytes") },
+		{ '3' , N_("Kilobytes"), N_("Use 1000 bytes as unit size") },
+		{ '4' , N_("Megabytes"), N_("Use 1000000 bytes as unit size") },
+		{ '5' , N_("Gigabytes"), N_("Use 1000000000 bytes as unit size") },
+		{ '6' , N_("Terabytes"), N_("Use 1000000000000 bytes as unit size") },
+		{ '7', N_("Percents"), N_("Show the sizes in percents") },
+		{ '8', N_("Compact"), N_("Show the size in most appropriate units") },
+		{ '9' , N_("Kibibytes"), N_("Use 1024 bytes as unit size") },
+		{ 'a' , N_("Mebibytes"), N_("Use 1048576 bytes as unit size") },
+		{ 'b' , N_("Gibibytes"), N_("Use 1073741824 bytes as unit size") },
+		{ 'c', N_("Tebibytes"), N_("Use 1099511627776 bytes as unit size") },
+		{ 'd', N_("Cylinders"), N_("Show the sizes in cylinders") },
+		{ 'e', N_("CHS"), N_("Show the sizes in CHS units") },
+		{ 0, NULL, NULL }
+	};
+	int key;
+	//menu_title(_("Choose the display unit type"));
+	key = do_menu(units, 9, MENU_BUTTON, "1234567890abcde", 1);
+	switch (key) {
+		case '1': ped_unit_set_default(PED_UNIT_SECTOR); return 1;
+		case '2': ped_unit_set_default(PED_UNIT_BYTE); return 1;
+		case '3': ped_unit_set_default(PED_UNIT_KILOBYTE); return 1;
+		case '4': ped_unit_set_default(PED_UNIT_MEGABYTE); return 1;
+		case '5': ped_unit_set_default(PED_UNIT_GIGABYTE); return 1;
+		case '6': ped_unit_set_default(PED_UNIT_TERABYTE); return 1;
+		case '7': ped_unit_set_default(PED_UNIT_PERCENT); return 1;
+		case '8': ped_unit_set_default(PED_UNIT_COMPACT); return 1;
+		case '9': ped_unit_set_default(PED_UNIT_KIBIBYTE); return 1;
+		case 'a': ped_unit_set_default(PED_UNIT_MEBIBYTE); return 1;
+		case 'b': ped_unit_set_default(PED_UNIT_GIBIBYTE); return 1;
+		case 'c': ped_unit_set_default(PED_UNIT_TEBIBYTE); return 1;
+		case 'd': ped_unit_set_default(PED_UNIT_CYLINDER); return 1;
+		case 'e': ped_unit_set_default(PED_UNIT_CHS); return 1;
+		
+	}
+}
 
 /* Define column positions. The first three will be fixed. */
 #define col_name 3
 #define col_fs 35
 
 /* Partition list drawing function */
-/* TODO: Make scrollable */
 void
-plist_draw (PedDisk *cdisk, PedPartition *selected) {
+plist_draw (PedDisk *cdisk, PedPartition *selected, int selnum, int *start) {
 	PedPartition *part;
 	const char* temp;
 	char buf[SMALLBUF];
 	int col_label = ((float)53/(80-col_fs))*(COLS-col_fs);
 	int col_size = ((float)66/(80-col_fs))*(COLS-col_fs);
 	int n,i,x,y = INFOSIZE;
-	
+	n = LINES-3-MENUSIZE;
+	if (selnum - *start < 0)
+		*start = selnum;
+	else if (selnum - *start >= n - INFOSIZE - 4)
+		*start = selnum - n + INFOSIZE + 5;
 	move(y++,0); clrtoeol();
 	/* Display header */
 	move(y,0); clrtoeol();
-	mvaddstr(y,col_name,N_("Number"));
-	mvaddstr(y,col_flags,N_("Flags"));
-	mvaddstr(y,col_type,N_("Part Type"));
-	mvaddstr(y,col_fs,N_("Filesystem"));
-	mvaddstr(y,col_label,N_("Label"));
+	mvaddstr(y,col_name,_("Number"));
+	mvaddstr(y,col_flags,_("Flags"));
+	mvaddstr(y,col_type,_("Part Type"));
+	mvaddstr(y,col_fs,_("Filesystem"));
+	mvaddstr(y,col_label,_("Label"));
 	/* We want size to be right aligned */
-	temp = N_("Size");
+	temp = _("Size");
 	x = COLS-strlen(temp)-2;
 	x = MAX(x,col_size);
 	mvaddstr(y++,x,temp);
 	if (i < SMALLBUF) buf[i] = '\0';
 	mvaddstr(y++,0,buf);
 
-	n = LINES-2-MENUSIZE;
-	for (part = ped_disk_next_partition (cdisk, NULL); part && y < n;
+	n = LINES-3-MENUSIZE;
+	for (part = ped_disk_next_partition (cdisk, NULL), i=0; part && y < n;
 	     part = ped_disk_next_partition (cdisk, part)) {
 		if (part->type & PED_PARTITION_METADATA) continue; /* We skip METADATA partitions */
+		i++;
+		if (i < *start) continue;
 		int free = part->type & PED_PARTITION_FREESPACE;
-
 		if (part == selected) attron(A_STANDOUT);
-
-		snprintf(buf, SMALLBUF, "%*d%*s", col_name+4,part->num, col_flags-col_name-4, "");
+		if (!free)
+			snprintf(buf, SMALLBUF, "%*d%*s", col_name+4,part->num, col_flags-col_name-4, "");
+		else
+			snprintf(buf, SMALLBUF, "%*s", col_flags, "");
 		mvaddstr(y,0,buf);
 		/* ped_partition_get_flag(part, PED_PARTITION_BOOT) throws an exception when ran on a
-		   free space */
+		   free space. */
 		snprintf(buf, SMALLBUF, "%-*s", col_type-col_flags,
-		         (!free && ped_partition_get_flag(part, PED_PARTITION_BOOT) ? N_("Bootable") : ""));
+		         (!free && ped_partition_is_flag_available(part, PED_PARTITION_BOOT) && 
+		         ped_partition_get_flag(part, PED_PARTITION_BOOT) ? N_("Bootable") : ""));
 		mvaddstr(y,col_flags,buf);
 
 		if (part->type & PED_PARTITION_EXTENDED)
-			temp = N_("Extended");
+			temp = _("Extended");
 		else if (part->type & PED_PARTITION_LOGICAL)
-			temp = N_("Logical");
+			temp = _("Logical");
 		else if (free) {
-			temp = N_("None"); /* FIXME: Make this like Linux cfdisk */
+			temp = (can_create_extended(disk) ? _("Pri/Ext") : _("Primary"));
 		}
-		else temp = N_("Primary");
+		else temp = _("Primary");
 
 		snprintf(buf, SMALLBUF, "%-*s", col_fs-col_type, temp);
 		mvaddstr(y,col_type,buf);
 
 static int
 do_plist (PedDisk *cdisk) {
-	int key = 0, i, redraw = 1;
+	int key = 0, i, redraw = 1, selnum = 0, start = 0;
 	const char* keys;
 	PedPartition *selected = NULL;
 	PedPartition *temp,*memp;
 	} while (selected && selected->type & PED_PARTITION_METADATA);
 	while (!key) {
 		if(redraw) {
-			plist_draw(cdisk,selected);
+			show_info();
+			plist_draw(cdisk,selected, selnum, &start);
 			redraw = 0;
 		}
 		if (selected->type & PED_PARTITION_EXTENDED)
 			temp = disk_get_prev_nmd_partition(cdisk,selected);
 			if (temp) {
 				selected = temp;
+				selnum--;
 				redraw = 1;
 			}
 			
 			}
 			key = 0;
 		}
-		if (key == DOWN_KEY) {
+		else if (key == DOWN_KEY) {
 			temp = ped_disk_next_partition(cdisk,selected);
 			while (temp && temp->type & PED_PARTITION_METADATA)
 				temp = ped_disk_next_partition(cdisk,temp);
 			if (temp) { 
+				selnum++;
 				selected = temp;
 				redraw = 1;
 			}
 			}
 			key = 0;
 		}
-		if (key == ESC || key == 'q') {
+		else if (key == ESC || key == 'q') {
 			if (uiquery.need_commit) {
 				key = 0;
 				getbool(N_("Partition table has changed, are you sure you want to quit?"),
 				getbool(N_("Are you sure you want to quit?"), &key);
 			}
 		}
-		if (key == 'n') {
+		else if (key == 'n') {
+			action_new(&selected);
+			redraw = 1;
+			key = 0;
+		}
+		else if (key == 'w') {
+			action_commit();
+			redraw = 1;
+			key = 0;
+		}
+		else if (key == 'f') {
+			action_mkfs(&selected);
+			redraw = 1;
+			key = 0;
+		}
+		else if (key == 'c') {
+			action_check(&selected);
+			redraw = 1;
+			key = 0;
+		}
+		else if (key == 'u') {
+			action_units();
+			redraw = 1;
+			key = 0;
+		}
+		else {
+			print_warning("Unimplemented",0);	 /* TODO */
+			key = 0;
 		}
 		refresh();
 	}
 
 
 
-
+/* This prints the information at the top */
 static void
 show_info() {
 	int y;
 		{ 'q', N_("Quit"), N_("Quit program") },
 		{ 0, NULL, NULL }
 	};
+	/* If we can't find the device automatically. FIXME: This is not tested. */
 	if (!dev) {
 		menu_title(_("Cannot find a device automatically"));
 		if ('c' == do_menu(custom_part, 8, MENU_BUTTON | MENU_TITLE, "cq", 0)) {
 	}
 	ped_exception_fetch_all ();
 	disk = ped_disk_new(dev);
-	
+	/* If there is no disk label on the disk, ask the user to create one */
 	if (!disk) {
 		ped_exception_catch();
 		ped_exception_leave_all();
 		ped_exception_leave_all();
 	}
 	ped_unit_set_default(PED_UNIT_MEGABYTE);
-
+	/* Initialize the info variables */
 	snprintf(buf,SMALLBUF,_("%s, %s"),
 		ped_unit_format_custom_byte (dev, dev->length * dev->sector_size-1, PED_UNIT_BYTE),
 		ped_unit_format_custom_byte (dev, dev->length * dev->sector_size-1, PED_UNIT_MEGABYTE));
 	init_calls();
 	init_disk();
 	int test = 0;
-	/*char *value;
-	read_char(_("What is your age"),&value);
-	uiquery.getbool(value,&test);
-	free(value);*/
+
 	show_info();
 	do_plist(disk);
-	plist_draw(disk,NULL);
 	endwin();
 }
 int
 #  include <libintl.h>
 #  include <locale.h>
 #  define _(String) dgettext (PACKAGE, String)
+#  define P_(String) dgettext ("parted", String)
 #else
 #  define _(String) (String)
 #endif /* ENABLE_NLS */
 }
 
 
-static int
+int
 _can_create_primary (const PedDisk* disk)
 {
 	int	i;
 	return 0;
 }
 
-static int
+int
 _can_create_extended (const PedDisk* disk)
 {
 	if (!_can_create_primary (disk))
 	return 1;
 }
 
-static int
+int
 _can_create_logical (const PedDisk* disk)
 {
 	if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED))
 {
 	char*	def_str;
 	char*	input = NULL;
-	int	valid,n;
+	int	valid;
 	/* FIXME: Check this more thoroughfully */
 
-	if (!custom && *value) {
+	if (!custom) {
 		if (range) {
 			*range = ped_geometry_new(dev,*value,1);
 			return *range != NULL;
 	}
 
 	def_str = ped_unit_format (dev, *value);
-	if (*value) {
-		n = strlen(def_str);
-		input = (char *) calloc(n,sizeof(char));
-		strncpy(input,def_str,n);
-	}
-	if (custom || !input) {
-		uiquery->getstring(prompt,&input,NULL,NULL,1);
-	}
+	//if (*value) 
+	input = strdup(def_str);
+	uiquery->getstring(prompt,&input,NULL,NULL,1);
+	
 
 	/* def_str might have rounded *value a little bit.  If the user picked
 	 * the default, make sure the selected sector is identical to the
 		if (range) {
 			*range = ped_geometry_new (dev, *value, 1);
 			ped_free (def_str);
+			ped_free (input);
 			return *range != NULL;
 		}
-
 		ped_free (def_str);
+		ped_free(input);
 		return 1;
 	}
 
 
 	valid = ped_unit_parse (input, dev, value, range);
 
-	free (input);
+	ped_free (input);
 	return valid;
 }
 
 		if (part_type && part_type != PED_PARTITION_NORMAL)
 			goto error;
                 part_type = PED_PARTITION_NORMAL;
-        } else if (!part_type) {
+        } else if (opts & UI_SPECIFY_PART_TYPE) {
                 if (!get_part_type (_("Partition type"), disk, &part_type, uiquery))
                         goto error;
         }
             /*|| (peek_word && isdigit (peek_word[0]))) {*/
                 fs_type = NULL;
         } else if (!fs_type) {
-                if (!get_fs_type (_("File system type?"), &fs_type, uiquery))
+                if (!get_fs_type (_("File system type"), &fs_type, uiquery))
                         goto error;
         }
         /*if (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, uiquery))
+        if (!get_sector (_("Start"), disk->dev, &start, &range_start, opts & UI_CUSTOM_VALUES, uiquery))
                 goto error;
-        if (!get_sector (_("End?"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES, uiquery))
+        if (!get_sector (_("End"), disk->dev, &end, &range_end, opts & UI_CUSTOM_VALUES, uiquery))
                 goto error;
         
         /* processing starts here */
                         end_usr   = ped_unit_format (disk->dev, end);
                         start_sol = ped_unit_format (disk->dev, part->geom.start);
                         end_sol   = ped_unit_format (disk->dev, part->geom.end);
-
+			if (opts & UI_CUSTOM_VALUES)
                         switch (ped_exception_throw (
                                 PED_EXCEPTION_WARNING,
                                 PED_EXCEPTION_YES_NO,
         return 0;
 }
 
+int
+do_commit (PedDisk* disk, UICalls* uiquery)
+{
+	if (ped_disk_commit(disk)) {
+		uiquery->need_commit = 0;
+		return 1;
+	}
+	else return 0;
+}
 enum _UIOpts {
 	UI_DEFAULT = 0,
 	UI_WARN_COMMIT = 1,	/* Warn the user if the operation commits the data to the disk */
-	UI_CUSTOM_VALUES = 2 	/* Allow the user to adjust start/end on resize, etc */
+	UI_CUSTOM_VALUES = 2, 	/* Allow the user to adjust start/end on resize, etc */
+	UI_SPECIFY_PART_TYPE = 4 /* Allow the user to specify the partition type */
 };
 
+extern int _can_create_primary (const PedDisk*);
+extern int _can_create_extended (const PedDisk*);
+extern int _can_create_logical (const PedDisk*);
+
+#define can_create_primary(disk) _can_create_primary(disk)
+#define can_create_extended(disk) _can_create_extended(disk)
+#define can_create_logical(disk) _can_create_logical(disk)
+
 extern int do_check (PedDisk*, PedPartition*, UICalls *);
 extern int do_cp (PedDisk*, PedPartition*, int warn, UICalls *);
 extern int do_mklabel (PedDevice*, PedDisk**, const PedDiskType*, UICalls *);
 extern int do_rescue (PedDisk*, PedSector start, PedSector end, UIOpts, UICalls *);
 extern int do_resize (PedDisk*, PedPartition*, PedSector start, PedSector end, UIOpts, UICalls*);
 extern int do_rm (PedDisk*, PedPartition*, UICalls*);
+extern int do_commit (PedDisk*, UICalls*);
+
 #endif
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.