Skip to contentSkip to conversation

fdisk: print the welcome message when OSF/1 disklabel is detected

PATCH In review Francesco Cosoleto 2 participants 9 messages Nov 11, 2011 – Nov 14, 2011 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 fdisk: print the welcome message when OSF/1 disklabel is detected

---
 fdisk/fdisk.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
fdisk/fdisk.c +5 -4
index 249de71..135d118 100644
@@ -3079,7 +3079,12 @@ main(int argc, char **argv) {
 	gpt_warning(disk_device);
 	get_boot(fdisk);
 
+	fprintf(stderr, _("Welcome to fdisk (%s).\n\n"
+		"Changes will remain in memory only, until you decide to write them.\n"
+		"Be careful before using the write command.\n"), PACKAGE_STRING);
+
 	if (disklabel == OSF_LABEL) {
+		putchar('\n');
 		/* OSF label, and no DOS label */
 		printf(_("Detected an OSF/1 disklabel on %s, entering "
 			 "disklabel mode.\n"),
@@ -3089,10 +3094,6 @@ main(int argc, char **argv) {
 		disklabel = DOS_LABEL;
 	}
 
-	fprintf(stderr, _("Welcome to fdisk (%s).\n\n"
-		"Changes will remain in memory only, until you decide to write them.\n"
-		"Be careful before using the write command.\n"), PACKAGE_STRING);
-
 	while (1) {
 		putchar('\n');
 		c = tolower(read_char(_("Command (m for help): ")));
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 2/5 fdisk: rename bselect, xselect functions

---
 fdisk/fdisk.c         |    9 +++++----
 fdisk/fdisk.h         |    2 +-
 fdisk/fdiskbsdlabel.c |    3 ++-
 3 files changed, 8 insertions(+), 6 deletions(-)
fdisk/fdisk.c +5 -4
index 135d118..7d1bd19 100644
@@ -2735,7 +2735,8 @@ move_begin(int i) {
 }
 
 static void
-xselect(void) {
+expert_command_prompt(void)
+{
 	char c;
 
 	while(1) {
@@ -3089,7 +3090,7 @@ main(int argc, char **argv) {
 		printf(_("Detected an OSF/1 disklabel on %s, entering "
 			 "disklabel mode.\n"),
 		       disk_device);
-		bselect();
+		bsd_command_prompt();
 		/* If we return we may want to make an empty DOS label? */
 		disklabel = DOS_LABEL;
 	}
@@ -3120,7 +3121,7 @@ main(int argc, char **argv) {
 				else
 					sgi_set_bootfile(line_ptr);
 			} else
-				bselect();
+				bsd_command_prompt();
 			break;
 		case 'c':
 			if (disklabel == DOS_LABEL)
@@ -3192,7 +3193,7 @@ main(int argc, char **argv) {
 					_("\n\tSorry, no experts menu for SGI "
 					"partition tables available.\n\n"));
 			} else
-				xselect();
+				expert_command_prompt();
 			break;
 		default:
 			unknown_command(c);
fdisk/fdisk.h +1 -1
index e289043..0bc1289 100644
@@ -107,7 +107,7 @@ enum labeltype {
 extern enum labeltype disklabel;
 
 /* prototypes for fdiskbsdlabel.c */
-extern void bselect(void);
+extern void bsd_command_prompt(void);
 extern int check_osf_label(void);
 extern int btrydev(char * dev);
 extern void xbsd_print_disklabel(int);
fdisk/fdiskbsdlabel.c +2 -1
index aa27bad..68d481c 100644
@@ -160,7 +160,8 @@ is_bsd_partition_type(int type) {
 #endif
 
 void
-bselect (void) {
+bsd_command_prompt (void)
+{
 #if !defined (__alpha__)
   int t, ss;
   struct partition *p;
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 3/5 fdisk: move command prompt code to a separate function

In reply to Francesco Cosoleto
---
 fdisk/fdisk.c |  244 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 125 insertions(+), 119 deletions(-)
fdisk/fdisk.c +125 -119
index 7d1bd19..2a0e09c 100644
@@ -2946,7 +2946,131 @@ unknown_command(int c) {
 	printf(_("%c: unknown command\n"), c);
 }
 
+static void command_prompt(void)
+{
+	int c, j;
+
+	fprintf(stderr, _("Welcome to fdisk (%s).\n\n"
+		"Changes will remain in memory only, until you decide to write them.\n"
+		"Be careful before using the write command.\n"), PACKAGE_STRING);
 
+	if (disklabel == OSF_LABEL) {
+		putchar('\n');
+		/* OSF label, and no DOS label */
+		printf(_("Detected an OSF/1 disklabel on %s, entering "
+			 "disklabel mode.\n"),
+		       disk_device);
+		bsd_command_prompt();
+		/* If we return we may want to make an empty DOS label? */
+		disklabel = DOS_LABEL;
+	}
+
+	while (1) {
+		putchar('\n');
+		c = tolower(read_char(_("Command (m for help): ")));
+		switch (c) {
+		case 'a':
+			if (disklabel == DOS_LABEL)
+				toggle_active(get_partition(1, partitions));
+			else if (disklabel == SUN_LABEL)
+				toggle_sunflags(get_partition(1, partitions),
+						SUN_FLAG_UNMNT);
+			else if (disklabel == SGI_LABEL)
+				sgi_set_bootpartition(
+					get_partition(1, partitions));
+			else
+				unknown_command(c);
+			break;
+		case 'b':
+			if (disklabel == SGI_LABEL) {
+				printf(_("\nThe current boot file is: %s\n"),
+				       sgi_get_bootfile());
+				if (read_chars(_("Please enter the name of the "
+					       "new boot file: ")) == '\n')
+					printf(_("Boot file unchanged\n"));
+				else
+					sgi_set_bootfile(line_ptr);
+			} else
+				bsd_command_prompt();
+			break;
+		case 'c':
+			if (disklabel == DOS_LABEL)
+				toggle_dos_compatibility_flag();
+			else if (disklabel == SUN_LABEL)
+				toggle_sunflags(get_partition(1, partitions),
+						SUN_FLAG_RONLY);
+			else if (disklabel == SGI_LABEL)
+				sgi_set_swappartition(
+						get_partition(1, partitions));
+			else
+				unknown_command(c);
+			break;
+		case 'd':
+			/* If sgi_label then don't use get_existing_partition,
+			   let the user select a partition, since
+			   get_existing_partition() only works for Linux-like
+			   partition tables */
+			if (disklabel != SGI_LABEL) {
+				j = get_existing_partition(1, partitions);
+			} else {
+				j = get_partition(1, partitions);
+			}
+			if (j >= 0)
+				delete_partition(j);
+			break;
+		case 'i':
+			if (disklabel == SGI_LABEL)
+				create_sgiinfo();
+			else
+				unknown_command(c);
+		case 'l':
+			list_types(get_sys_types());
+			break;
+		case 'm':
+			menu();
+			break;
+		case 'n':
+			new_partition();
+			break;
+		case 'o':
+			create_doslabel();
+			break;
+		case 'p':
+			list_table(0);
+			break;
+		case 'q':
+			close(fd);
+			printf("\n");
+			exit(0);
+		case 's':
+			create_sunlabel();
+			break;
+		case 't':
+			change_sysid();
+			break;
+		case 'u':
+			change_units();
+			break;
+		case 'v':
+			verify();
+			break;
+		case 'w':
+			write_table(); 		/* does not return */
+			break;
+		case 'x':
+			if (disklabel == SGI_LABEL) {
+				fprintf(stderr,
+					_("\n\tSorry, no experts menu for SGI "
+					"partition tables available.\n\n"));
+			} else
+				expert_command_prompt();
+			break;
+		default:
+			unknown_command(c);
+			menu();
+		}
+	}
+}
 
 int
 main(int argc, char **argv) {
@@ -3080,125 +3204,7 @@ main(int argc, char **argv) {
 	gpt_warning(disk_device);
 	get_boot(fdisk);
 
-	fprintf(stderr, _("Welcome to fdisk (%s).\n\n"
-		"Changes will remain in memory only, until you decide to write them.\n"
-		"Be careful before using the write command.\n"), PACKAGE_STRING);
+	command_prompt();
 
-	if (disklabel == OSF_LABEL) {
-		putchar('\n');
-		/* OSF label, and no DOS label */
-		printf(_("Detected an OSF/1 disklabel on %s, entering "
-			 "disklabel mode.\n"),
-		       disk_device);
-		bsd_command_prompt();
-		/* If we return we may want to make an empty DOS label? */
-		disklabel = DOS_LABEL;
-	}
-
-	while (1) {
-		putchar('\n');
-		c = tolower(read_char(_("Command (m for help): ")));
-		switch (c) {
-		case 'a':
-			if (disklabel == DOS_LABEL)
-				toggle_active(get_partition(1, partitions));
-			else if (disklabel == SUN_LABEL)
-				toggle_sunflags(get_partition(1, partitions),
-						SUN_FLAG_UNMNT);
-			else if (disklabel == SGI_LABEL)
-				sgi_set_bootpartition(
-					get_partition(1, partitions));
-			else
-				unknown_command(c);
-			break;
-		case 'b':
-			if (disklabel == SGI_LABEL) {
-				printf(_("\nThe current boot file is: %s\n"),
-				       sgi_get_bootfile());
-				if (read_chars(_("Please enter the name of the "
-					       "new boot file: ")) == '\n')
-					printf(_("Boot file unchanged\n"));
-				else
-					sgi_set_bootfile(line_ptr);
-			} else
-				bsd_command_prompt();
-			break;
-		case 'c':
-			if (disklabel == DOS_LABEL)
-				toggle_dos_compatibility_flag();
-			else if (disklabel == SUN_LABEL)
-				toggle_sunflags(get_partition(1, partitions),
-						SUN_FLAG_RONLY);
-			else if (disklabel == SGI_LABEL)
-				sgi_set_swappartition(
-						get_partition(1, partitions));
-			else
-				unknown_command(c);
-			break;
-		case 'd':
-        		/* If sgi_label then don't use get_existing_partition,
-			   let the user select a partition, since
-			   get_existing_partition() only works for Linux-like
-			   partition tables */
-			if (disklabel != SGI_LABEL) {
-                		j = get_existing_partition(1, partitions);
-        		} else {
-                		j = get_partition(1, partitions);
-        		}
-			if (j >= 0)
-				delete_partition(j);
-			break;
-		case 'i':
-			if (disklabel == SGI_LABEL)
-				create_sgiinfo();
-			else
-				unknown_command(c);
-		case 'l':
-			list_types(get_sys_types());
-			break;
-		case 'm':
-			menu();
-			break;
-		case 'n':
-			new_partition();
-			break;
-		case 'o':
-			create_doslabel();
-			break;
-		case 'p':
-			list_table(0);
-			break;
-		case 'q':
-			close(fd);
-			printf("\n");
-			exit(0);
-		case 's':
-			create_sunlabel();
-			break;
-		case 't':
-			change_sysid();
-			break;
-		case 'u':
-			change_units();
-			break;
-		case 'v':
-			verify();
-			break;
-		case 'w':
-			write_table(); 		/* does not return */
-			break;
-		case 'x':
-			if (disklabel == SGI_LABEL) {
-				fprintf(stderr,
-					_("\n\tSorry, no experts menu for SGI "
-					"partition tables available.\n\n"));
-			} else
-				expert_command_prompt();
-			break;
-		default:
-			unknown_command(c);
-			menu();
-		}
-	}
 	return 0;
 }
Signature · 1 line
1.7.3.4
#3 lore raw

PATCH 4/5 fdisk: rewrite print menu system

In reply to Francesco Cosoleto

DOS and SGI label menus are unchanged, SUN label menu is only an alphabetic order fix. BSD label command descriptions changed slightly to use a common form.

---
 fdisk/fdisk.c         |  205 ++++++++++++++++---------------------------------
 fdisk/fdisk.h         |   20 ++++--
 fdisk/fdiskbsdlabel.c |   23 +-----
 3 files changed, 81 insertions(+), 167 deletions(-)
fdisk/fdisk.c +66 -139
index 2a0e09c..934d458 100644
@@ -77,6 +77,60 @@ static void delete_partition(int i);
 				s |= (sector >> 2) & 0xc0;	\
 			}
 
+/* menu list description */
+
+struct menulist_descr {
+	char command;				/* command key */
+	char *description;			/* command description */
+	enum labeltype label[2];		/* disklabel types associated with main and expert menu */
+};
+
+static const struct menulist_descr menulist[] = {
+	{'a', N_("toggle a bootable flag"), {DOS_LABEL, 0}},
+	{'a', N_("toggle a read only flag"), {SUN_LABEL, 0}},
+	{'a', N_("select bootable partition"), {SGI_LABEL, 0}},
+	{'a', N_("change number of alternate cylinders"), {0, SUN_LABEL}},
+	{'b', N_("edit bsd disklabel"), {DOS_LABEL | SUN_LABEL, 0}},
+	{'b', N_("edit bootfile entry"), {SGI_LABEL, 0}},
+	{'b', N_("move beginning of data in a partition"), {0, DOS_LABEL}},
+	{'c', N_("toggle the dos compatibility flag"), {DOS_LABEL, 0}},
+	{'c', N_("toggle the mountable flag"), {SUN_LABEL, 0}},
+	{'c', N_("select sgi swap partition"), {SGI_LABEL, 0}},
+	{'c', N_("change number of cylinders"), {0, DOS_LABEL | SUN_LABEL}},
+	{'d', N_("delete a partition"), {DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL, 0}},
+	{'d', N_("print the raw data in the partition table"), {0, ANY_LABEL}},
+	{'e', N_("change number of extra sectors per cylinder"), {0, SUN_LABEL}},
+	{'e', N_("list extended partitions"), {0, DOS_LABEL}},
+	{'e', N_("edit drive data"), {OSF_LABEL, 0}},
+	{'f', N_("fix partition order"), {0, DOS_LABEL}},
+	{'g', N_("create an IRIX (SGI) partition table"), {0, DOS_LABEL | SGI_LABEL}},
+	{'h', N_("change number of heads"), {0, DOS_LABEL | SUN_LABEL}},
+	{'i', N_("change interleave factor"), {0, SUN_LABEL}},
+	{'i', N_("change the disk identifier"), {0, DOS_LABEL}},
+	{'i', N_("install bootstrap"), {OSF_LABEL, 0}},
+	{'l', N_("list known partition types"), {DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL, 0}},
+	{'m', N_("print this menu"), {ANY_LABEL, ANY_LABEL}},
+	{'n', N_("add a new partition"), {DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL, 0}},
+	{'o', N_("create a new empty DOS partition table"), {~OSF_LABEL, 0}},
+	{'o', N_("change rotation speed (rpm)"), {0, SUN_LABEL}},
+	{'p', N_("print the partition table"), {DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL, DOS_LABEL | SUN_LABEL}},
+	{'q', N_("quit without saving changes"), {ANY_LABEL, ANY_LABEL}},
+	{'r', N_("return to main menu"), {OSF_LABEL, DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL}},
+	{'s', N_("create a new empty Sun disklabel"), {~OSF_LABEL, 0}},
+	{'s', N_("change number of sectors/track"), {0, DOS_LABEL | SUN_LABEL}},
+	{'s', N_("show complete disklabel"), {OSF_LABEL, 0}},
+	{'t', N_("change a partition's system id"), {DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL, 0}},
+	{'u', N_("change display/entry units"), {DOS_LABEL | SUN_LABEL | SGI_LABEL | OSF_LABEL, 0}},
+	{'v', N_("verify the partition table"), {DOS_LABEL | SUN_LABEL | SGI_LABEL, DOS_LABEL | SUN_LABEL | SGI_LABEL}},
+	{'w', N_("write table to disk and exit"), {DOS_LABEL | SUN_LABEL | SGI_LABEL, DOS_LABEL | SUN_LABEL | SGI_LABEL}},
+	{'w', N_("write disklabel to disk"), {OSF_LABEL, 0}},
+	{'x', N_("extra functionality (experts only)"), {DOS_LABEL | SUN_LABEL, 0}},
+#if !defined (__alpha__)
+	{'x', N_("link BSD partition to non-BSD partition"), {OSF_LABEL, 0}},
+#endif
+	{'y', N_("change number of physical cylinders"), {0, SUN_LABEL}},
+};
+
 /* A valid partition table sector ends in 0x55 0xaa */
 static unsigned int
 part_table_flag(unsigned char *b) {
@@ -374,143 +428,16 @@ is_dos_partition(int t) {
 		t == 0xc1 || t == 0xc4 || t == 0xc6);
 }
 
-static void
-menu(void) {
-	if (disklabel == SUN_LABEL) {
-	   puts(_("Command action"));
-	   puts(_("   a   toggle a read only flag"));		/* sun */
-	   puts(_("   b   edit bsd disklabel"));
-	   puts(_("   c   toggle the mountable flag"));		/* sun */
-	   puts(_("   d   delete a partition"));
-	   puts(_("   l   list known partition types"));
-	   puts(_("   m   print this menu"));
-	   puts(_("   n   add a new partition"));
-	   puts(_("   o   create a new empty DOS partition table"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   s   create a new empty Sun disklabel"));	/* sun */
-	   puts(_("   t   change a partition's system id"));
-	   puts(_("   u   change display/entry units"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	   puts(_("   x   extra functionality (experts only)"));
-	}
-	else if (disklabel == SGI_LABEL) {
-	   puts(_("Command action"));
-	   puts(_("   a   select bootable partition"));    /* sgi flavour */
-	   puts(_("   b   edit bootfile entry"));          /* sgi */
-	   puts(_("   c   select sgi swap partition"));    /* sgi flavour */
-	   puts(_("   d   delete a partition"));
-	   puts(_("   l   list known partition types"));
-	   puts(_("   m   print this menu"));
-	   puts(_("   n   add a new partition"));
-	   puts(_("   o   create a new empty DOS partition table"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   s   create a new empty Sun disklabel"));	/* sun */
-	   puts(_("   t   change a partition's system id"));
-	   puts(_("   u   change display/entry units"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	}
-	else if (disklabel == AIX_LABEL || disklabel == MAC_LABEL) {
-	   puts(_("Command action"));
-	   puts(_("   m   print this menu"));
-	   puts(_("   o   create a new empty DOS partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   s   create a new empty Sun disklabel"));	/* sun */
-	}
-	else {
-	   puts(_("Command action"));
-	   puts(_("   a   toggle a bootable flag"));
-	   puts(_("   b   edit bsd disklabel"));
-	   puts(_("   c   toggle the dos compatibility flag"));
-	   puts(_("   d   delete a partition"));
-	   puts(_("   l   list known partition types"));
-	   puts(_("   m   print this menu"));
-	   puts(_("   n   add a new partition"));
-	   puts(_("   o   create a new empty DOS partition table"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   s   create a new empty Sun disklabel"));	/* sun */
-	   puts(_("   t   change a partition's system id"));
-	   puts(_("   u   change display/entry units"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	   puts(_("   x   extra functionality (experts only)"));
-	}
-}
+void print_menu(enum menutype menu)
+{
+	size_t i;
 
-static void
-xmenu(void) {
-	if (disklabel == SUN_LABEL) {
-	   puts(_("Command action"));
-	   puts(_("   a   change number of alternate cylinders"));      /*sun*/
-	   puts(_("   c   change number of cylinders"));
-	   puts(_("   d   print the raw data in the partition table"));
-	   puts(_("   e   change number of extra sectors per cylinder"));/*sun*/
-	   puts(_("   h   change number of heads"));
-	   puts(_("   i   change interleave factor"));			/*sun*/
-	   puts(_("   o   change rotation speed (rpm)"));		/*sun*/
-	   puts(_("   m   print this menu"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   r   return to main menu"));
-	   puts(_("   s   change number of sectors/track"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	   puts(_("   y   change number of physical cylinders"));	/*sun*/
-	}
-	else if (disklabel == SGI_LABEL) {
-	   puts(_("Command action"));
-	   puts(_("   b   move beginning of data in a partition")); /* !sun */
-	   puts(_("   c   change number of cylinders"));
-	   puts(_("   d   print the raw data in the partition table"));
-	   puts(_("   e   list extended partitions"));		/* !sun */
-	   puts(_("   g   create an IRIX (SGI) partition table"));/* sgi */
-	   puts(_("   h   change number of heads"));
-	   puts(_("   m   print this menu"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   r   return to main menu"));
-	   puts(_("   s   change number of sectors/track"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	}
-	else if (disklabel == AIX_LABEL || disklabel == MAC_LABEL) {
-	   puts(_("Command action"));
-	   puts(_("   b   move beginning of data in a partition")); /* !sun */
-	   puts(_("   c   change number of cylinders"));
-	   puts(_("   d   print the raw data in the partition table"));
-	   puts(_("   e   list extended partitions"));		/* !sun */
-	   puts(_("   g   create an IRIX (SGI) partition table"));/* sgi */
-	   puts(_("   h   change number of heads"));
-	   puts(_("   m   print this menu"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   r   return to main menu"));
-	   puts(_("   s   change number of sectors/track"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	}
-	else {
-	   puts(_("Command action"));
-	   puts(_("   b   move beginning of data in a partition")); /* !sun */
-	   puts(_("   c   change number of cylinders"));
-	   puts(_("   d   print the raw data in the partition table"));
-	   puts(_("   e   list extended partitions"));		/* !sun */
-	   puts(_("   f   fix partition order"));		/* !sun, !aix, !sgi */
-	   puts(_("   g   create an IRIX (SGI) partition table"));/* sgi */
-	   puts(_("   h   change number of heads"));
-	   puts(_("   i   change the disk identifier")); /* dos only */
-	   puts(_("   m   print this menu"));
-	   puts(_("   p   print the partition table"));
-	   puts(_("   q   quit without saving changes"));
-	   puts(_("   r   return to main menu"));
-	   puts(_("   s   change number of sectors/track"));
-	   puts(_("   v   verify the partition table"));
-	   puts(_("   w   write table to disk and exit"));
-	}
+	puts(_("Command action"));
+
+	for (i = 0; i < ARRAY_SIZE(menulist); i++)
+		if ((menu != BSD_MENU && menulist[i].label[menu] & disklabel)
+		    || (menu == BSD_MENU && menulist[i].label[MAIN_MENU] & OSF_LABEL))
+			printf("   %c   %s\n", menulist[i].command, menulist[i].description);
 }
 
 static int
@@ -2825,7 +2752,7 @@ expert_command_prompt(void)
 				sun_set_pcylcount();
 			break;
 		default:
-			xmenu();
+			print_menu(EXPERT_MENU);
 		}
 	}
 }
@@ -3027,7 +2954,7 @@ static void command_prompt(void)
 			list_types(get_sys_types());
 			break;
 		case 'm':
-			menu();
+			print_menu(MAIN_MENU);
 			break;
 		case 'n':
 			new_partition();
@@ -3067,7 +2994,7 @@ static void command_prompt(void)
 			break;
 		default:
 			unknown_command(c);
-			menu();
+			print_menu(MAIN_MENU);
 		}
 	}
 }
fdisk/fdisk.h +14 -6
index 0bc1289..2d80096 100644
@@ -45,6 +45,12 @@ struct partition {
 	unsigned char size4[4];         /* nr of sectors in partition */
 } PACKED;
 
+enum menutype {
+	MAIN_MENU,
+	EXPERT_MENU,
+	BSD_MENU
+};
+
 enum failure {ioctl_error,
 	unable_to_open, unable_to_read, unable_to_seek,
 	unable_to_write};
@@ -75,6 +81,7 @@ extern struct partition *get_part_table(int);
 extern int valid_part_table_flag(unsigned char *b);
 extern unsigned int read_int(unsigned int low, unsigned int dflt,
 			     unsigned int high, unsigned int base, char *mesg);
+extern void print_menu(enum menutype);
 extern void print_partition_size(int num, unsigned long long start, unsigned long long stop, int sysid);
 
 extern unsigned char *MBRbuffer;
@@ -96,12 +103,13 @@ extern unsigned long long get_start_sect(struct partition *p);
 extern unsigned long long get_nr_sects(struct partition *p);
 
 enum labeltype {
-	DOS_LABEL,
-	SUN_LABEL,
-	SGI_LABEL,
-	AIX_LABEL,
-	OSF_LABEL,
-	MAC_LABEL
+	DOS_LABEL = 1,
+	SUN_LABEL = 2,
+	SGI_LABEL = 4,
+	AIX_LABEL = 8,
+	OSF_LABEL = 16,
+	MAC_LABEL = 32,
+	ANY_LABEL = -1
 };
 
 extern enum labeltype disklabel;
fdisk/fdiskbsdlabel.c +1 -22
index 68d481c..1bebca2 100644
@@ -123,27 +123,6 @@ btrydev (char * dev) {
 	return 0;
 }
 
-static void
-bmenu (void) {
-  puts (_("Command action"));
-  puts (_("   d   delete a BSD partition"));
-  puts (_("   e   edit drive data"));
-  puts (_("   i   install bootstrap"));
-  puts (_("   l   list known filesystem types"));
-  puts (_("   m   print this menu"));
-  puts (_("   n   add a new BSD partition"));
-  puts (_("   p   print BSD partition table"));
-  puts (_("   q   quit without saving changes"));
-  puts (_("   r   return to main menu"));
-  puts (_("   s   show complete disklabel"));
-  puts (_("   t   change a partition's filesystem id"));
-  puts (_("   u   change units (cylinders/sectors)"));
-  puts (_("   w   write disklabel to disk"));
-#if !defined (__alpha__)
-  puts (_("   x   link BSD partition to non-BSD partition"));
-#endif
-}
-
 #if !defined (__alpha__)
 static int
 hidden(int type) {
@@ -243,7 +222,7 @@ bsd_command_prompt (void)
 	break;
 #endif
       default:
-	bmenu ();
+	print_menu(BSD_MENU);
 	break;
     }
   }
Signature · 1 line
1.7.3.4
#6 lore raw

PATCH 5/5 fdisk: enable expert menu with SGI label

In reply to Francesco Cosoleto

This allows the creation of a new label if the disk already has an existing SGI disklabel without working around this problem such as creating a DOS disklabel or overwriting with zero the partition table (problem reported in 'Gentoo Linux/MIPS Handbook').

---
 fdisk/fdisk.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)
fdisk/fdisk.c +3 -8
index 934d458..9ca3f2b 100644
@@ -103,7 +103,7 @@ static const struct menulist_descr menulist[] = {
 	{'e', N_("list extended partitions"), {0, DOS_LABEL}},
 	{'e', N_("edit drive data"), {OSF_LABEL, 0}},
 	{'f', N_("fix partition order"), {0, DOS_LABEL}},
-	{'g', N_("create an IRIX (SGI) partition table"), {0, DOS_LABEL | SGI_LABEL}},
+	{'g', N_("create an IRIX (SGI) partition table"), {0, ANY_LABEL}},
 	{'h', N_("change number of heads"), {0, DOS_LABEL | SUN_LABEL}},
 	{'i', N_("change interleave factor"), {0, SUN_LABEL}},
 	{'i', N_("change the disk identifier"), {0, DOS_LABEL}},
@@ -124,7 +124,7 @@ static const struct menulist_descr menulist[] = {
 	{'v', N_("verify the partition table"), {DOS_LABEL | SUN_LABEL | SGI_LABEL, DOS_LABEL | SUN_LABEL | SGI_LABEL}},
 	{'w', N_("write table to disk and exit"), {DOS_LABEL | SUN_LABEL | SGI_LABEL, DOS_LABEL | SUN_LABEL | SGI_LABEL}},
 	{'w', N_("write disklabel to disk"), {OSF_LABEL, 0}},
-	{'x', N_("extra functionality (experts only)"), {DOS_LABEL | SUN_LABEL, 0}},
+	{'x', N_("extra functionality (experts only)"), {DOS_LABEL | SUN_LABEL | SGI_LABEL, 0}},
 #if !defined (__alpha__)
 	{'x', N_("link BSD partition to non-BSD partition"), {OSF_LABEL, 0}},
 #endif
@@ -2985,12 +2985,7 @@ static void command_prompt(void)
 			write_table(); 		/* does not return */
 			break;
 		case 'x':
-			if (disklabel == SGI_LABEL) {
-				fprintf(stderr,
-					_("\n\tSorry, no experts menu for SGI "
-					"partition tables available.\n\n"));
-			} else
-				expert_command_prompt();
+			expert_command_prompt();
 			break;
 		default:
 			unknown_command(c);
Signature · 1 line
1.7.3.4
maintainer
#4 lore raw

Re: [PATCH 4/5] fdisk: rewrite print menu system

In reply to Francesco Cosoleto

fdisk/fdisk.c is_dos_partition(int t) { · line 439

Quoted 3 lines · Francesco Cosoleto
fdisk/fdisk.c +3 -0
+	for (i = 0; i < ARRAY_SIZE(menulist); i++)
+		if ((menu != BSD_MENU && menulist[i].label[menu] & disklabel)
+		    || (menu == BSD_MENU && menulist[i].label[MAIN_MENU] & OSF_LABEL))

Why we need BSD_MENU and this if()? Why we cannot use print_menu(MAIN_MENU) in BSD code?

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw

Re: [PATCH 4/5] fdisk: rewrite print menu system

2011/11/11 Karel Zak <[email protected]>:

Quoted 2 lines

 Why we need BSD_MENU and this if()? Why we cannot use print_menu(MAIN_MENU) in BSD code?

Changed.

I assume "edit bsd disklabel" capability in SUN label mode is a mistake.

Francesco

fdisk/fdisk.c +7 -4
index 934d458..b83cd1f 100644
@@ -90,7 +90,7 @@ static const struct menulist_descr menulist[] = {
 	{'a', N_("toggle a read only flag"), {SUN_LABEL, 0}},
 	{'a', N_("select bootable partition"), {SGI_LABEL, 0}},
 	{'a', N_("change number of alternate cylinders"), {0, SUN_LABEL}},
-	{'b', N_("edit bsd disklabel"), {DOS_LABEL | SUN_LABEL, 0}},
+	{'b', N_("edit bsd disklabel"), {DOS_LABEL, 0}},
 	{'b', N_("edit bootfile entry"), {SGI_LABEL, 0}},
 	{'b', N_("move beginning of data in a partition"), {0, DOS_LABEL}},
 	{'c', N_("toggle the dos compatibility flag"), {DOS_LABEL, 0}},
@@ -435,8 +435,7 @@ void print_menu(enum menutype menu)
 	puts(_("Command action"));
 
 	for (i = 0; i < ARRAY_SIZE(menulist); i++)
-		if ((menu != BSD_MENU && menulist[i].label[menu] & disklabel)
-		    || (menu == BSD_MENU && menulist[i].label[MAIN_MENU] & OSF_LABEL))
+		if (menulist[i].label[menu] & disklabel)
 			printf("   %c   %s\n", menulist[i].command, menulist[i].description);
 }
 
@@ -2917,8 +2916,12 @@ static void command_prompt(void)
 					printf(_("Boot file unchanged\n"));
 				else
 					sgi_set_bootfile(line_ptr);
-			} else
+			} else if (disklabel == DOS_LABEL) {
+				disklabel = OSF_LABEL;
 				bsd_command_prompt();
+				disklabel = DOS_LABEL;
+			} else
+				unknown_command(c);
 			break;
 		case 'c':
 			if (disklabel == DOS_LABEL)
fdisk/fdisk.h +0 -1
index 2d80096..81ff5a2 100644
@@ -48,7 +48,6 @@ struct partition {
 enum menutype {
 	MAIN_MENU,
 	EXPERT_MENU,
-	BSD_MENU
 };
 
 enum failure {ioctl_error,
fdisk/fdiskbsdlabel.c +1 -1
index 1bebca2..9dfc95a 100644
@@ -222,7 +222,7 @@ bsd_command_prompt (void)
 	break;
 #endif
       default:
-	print_menu(BSD_MENU);
+	print_menu(MAIN_MENU);
 	break;
     }
   }

From 01c9da56c02c60bb37c4882585187382be8edf50 Mon Sep 17 00:00:00 2001
From: Francesco Cosoleto <[email protected]>
Date: Wed, 9 Nov 2011 19:04:12 +0100
Subject: [PATCH] fdisk: rewrite print menu system

DOS and SGI label menus are unchanged. BSD label command descriptions change slightly to use a common form.

This also removes an useless menu entry in SUN label menu to edit bsd disklabel.

---
 fdisk/fdisk.c         |  210 ++++++++++++++++--------------------------------
 fdisk/fdisk.h         |   19 +++--
 fdisk/fdiskbsdlabel.c |   23 +-----
 3 files changed, 84 insertions(+), 168 deletions(-)
fdisk/fdisk.c +70 -140

248 lines not on this page · raw message

fdisk/fdisk.h +13 -6
index 0bc1289..81ff5a2 100644
@@ -45,6 +45,11 @@ struct partition {
 	unsigned char size4[4];         /* nr of sectors in partition */
 } PACKED;
 
+enum menutype {
+	MAIN_MENU,
+	EXPERT_MENU,
+};
+
 enum failure {ioctl_error,
 	unable_to_open, unable_to_read, unable_to_seek,
 	unable_to_write};
@@ -75,6 +80,7 @@ extern struct partition *get_part_table(int);
 extern int valid_part_table_flag(unsigned char *b);
 extern unsigned int read_int(unsigned int low, unsigned int dflt,
 			     unsigned int high, unsigned int base, char *mesg);
+extern void print_menu(enum menutype);
 extern void print_partition_size(int num, unsigned long long start, unsigned long long stop, int sysid);
 
 extern unsigned char *MBRbuffer;
@@ -96,12 +102,13 @@ extern unsigned long long get_start_sect(struct partition *p);
 extern unsigned long long get_nr_sects(struct partition *p);
 
 enum labeltype {
-	DOS_LABEL,
-	SUN_LABEL,
-	SGI_LABEL,
-	AIX_LABEL,
-	OSF_LABEL,
-	MAC_LABEL
+	DOS_LABEL = 1,
+	SUN_LABEL = 2,
+	SGI_LABEL = 4,
+	AIX_LABEL = 8,
+	OSF_LABEL = 16,
+	MAC_LABEL = 32,
+	ANY_LABEL = -1
 };
 
 extern enum labeltype disklabel;
fdisk/fdiskbsdlabel.c +1 -22
index 68d481c..9dfc95a 100644
@@ -123,27 +123,6 @@ btrydev (char * dev) {
 	return 0;
 }
 
-static void
-bmenu (void) {
-  puts (_("Command action"));
-  puts (_("   d   delete a BSD partition"));
-  puts (_("   e   edit drive data"));
-  puts (_("   i   install bootstrap"));
-  puts (_("   l   list known filesystem types"));
-  puts (_("   m   print this menu"));
-  puts (_("   n   add a new BSD partition"));
-  puts (_("   p   print BSD partition table"));
-  puts (_("   q   quit without saving changes"));
-  puts (_("   r   return to main menu"));
-  puts (_("   s   show complete disklabel"));
-  puts (_("   t   change a partition's filesystem id"));
-  puts (_("   u   change units (cylinders/sectors)"));
-  puts (_("   w   write disklabel to disk"));
-#if !defined (__alpha__)
-  puts (_("   x   link BSD partition to non-BSD partition"));
-#endif
-}
-
 #if !defined (__alpha__)
 static int
 hidden(int type) {
@@ -243,7 +222,7 @@ bsd_command_prompt (void)
 	break;
 #endif
       default:
-	bmenu ();
+	print_menu(MAIN_MENU);
 	break;
     }
   }
Signature · 1 line
1.7.3.4
maintainer
#7 lore raw
In reply to Francesco Cosoleto
Quoted 2 lines · Francesco Cosoleto
 fdisk/fdisk.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Applied (all patches), thanks.

fdisk/fdisk.c main(int argc, char **argv) { · line 3085

Quoted 7 lines
fdisk/fdisk.c +4 -0
 	gpt_warning(disk_device);
 	get_boot(fdisk);
 
+	fprintf(stderr, _("Welcome to fdisk (%s).\n\n"
+		"Changes will remain in memory only, until you decide to write them.\n"
+		"Be careful before using the write command.\n"), PACKAGE_STRING);
+

I have moved this message before gpt_warning() and get_boot(). The get_boot() produces very often warnings (for example on disk with no PT) and I think that the welcome message should be printed as very first message in the interactive mode.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#8 lore raw

2011/11/14 Karel Zak <[email protected]>:

Quoted 2 lines
Quoted 2 lines

+ =A0 =A0 fprintf(stderr, _("Welcome to fdisk (%s).\n\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 "Changes will remain in memory only, until you=

decide to write them.\n"

Quoted 1 line
Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 "Be careful before using the write command.\n"=

), PACKAGE_STRING);

Quoted 6 lines
Quoted 1 line

+

=A0I have moved this message before gpt_warning() and get_boot(). The =A0get_boot() produces very often warnings (for example on disk with no =A0PT) and I think that the welcome message should be printed as very =A0first message in the interactive mode.

There are some side effects. The third part of the message needs more visibility, and there is a variable number of newlines. It's possible split the string up to fix this.

Francesco