Anonymous avatar Anonymous committed c39c6aa

Fix an error with a wrong free in perform_mkpart. Fix choosing partition type in fdisk (ui.c). Make the prompting for partition position to be similar to linux fdisk (get_position in common.c and _construct_prompt in ui.c). Make system types localizable. (fdisk@sv.gnu.org/fdisk--main--0--patch-42)
fdisk@sv.gnu.org/fdisk--main--0--patch-42
Keywords:

Comments (0)

Files changed (5)

 static int
 get_position(PartPos* pos, PedDisk *disk, GSOpts opts)
 {
-        if (!get_sector (_("Start"), disk->dev, &(pos->start), -1LL, opts))
+
+	char *start;
+	char *end;
+	if (ped_unit_get_default() == PED_UNIT_CYLINDER) {
+		start = _("First cylinder");
+		end = _("Last cylinder or +size or +sizeMB or +sizeKB");
+	}
+	else if (ped_unit_get_default() == PED_UNIT_SECTOR) {
+		start = _("First sector");
+		end = _("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
 
 	/* We give the sector from the first query, so that the user can
            specify size */
-        if (!get_sector (_("End"), disk->dev, &(pos->end), pos->start.sector, opts))
+        if (!get_sector (end, disk->dev, &(pos->end), pos->start.sector, opts))
                 return 0;
 
 	return 1;
 
 error_remove_part:
 	/* We need to make this NULL here, for cfdisk's usage */
-	*newpart = NULL;
+	if (newpart) *newpart = NULL;
         ped_disk_remove_partition (disk, part);
 error_destroy_all_constraints:
         ped_constraint_destroy (final_constraint);
 	/* TODO: Make default position more friendly */
 	pos.start.sector = 0LL;
 	pos.end.sector = 0LL;
+	pos.start.range = NULL;
+	pos.end.range = NULL;
 	return perform_mkpart (*disk, &pos, part_type, fs_type,
 	                       NULL, UI_CUSTOM_VALUES);
 }
 	/* TODO: Make default position more friendly */
 	pos.start.sector = 0LL;
 	pos.end.sector = 0LL;
+	pos.start.range = NULL;
+	pos.end.range = NULL;
 	return perform_mkpartfs (*disk, &pos, 0, NULL, NULL, 
 	                         UI_CUSTOM_VALUES | UI_WARN_COMMIT | 
 	                         UI_SPECIFY_PART_TYPE);
 	/* TODO: Make default position more friendly */
 	pos.start.sector = 0LL;
 	pos.end.sector = 0LL;
+	pos.start.range = NULL;
+	pos.end.range = NULL;
 	return perform_move (*disk, NULL, &pos, UI_CUSTOM_VALUES);
 }
 
 {
 	if (cylinder_unit) {
 		printf ("%s\n", _("Changing display/entry units to sectors"));
-		PedUnit unit = ped_unit_get_by_name ("s");
-		ped_unit_set_default (unit);
+		/*  PedUnit unit = ped_unit_get_by_name ("s");
+		 *  ped_unit_set_default (unit);
+		 */
+		ped_unit_set_default(PED_UNIT_SECTOR);
 		cylinder_unit = 0;
 		return 1;
 	} else {
 		printf ("%s\n", _("Changing display/entry units to cylinders"));
-		PedUnit unit = ped_unit_get_by_name ("cyl");
-		ped_unit_set_default (unit);
+		/*  PedUnit unit = ped_unit_get_by_name ("cyl");
+		 *  ped_unit_set_default (unit);
+		 */
+		ped_unit_set_default(PED_UNIT_CYLINDER);
 		cylinder_unit = 1;
 		return 1;
 	}
 	_init_messages ();
 	_init_main_menu_commands ();
 
+	/* The default units are cylinders */
+	ped_unit_set_default(PED_UNIT_CYLINDER);
+
 	/* TODO: Make _init_messages init these, remove messages from ui.c */
 	init_flag_str();
 	init_fs_type_str();
 
 #ifndef SYS_TYPES_H_INCLUDED
 #define SYS_TYPES_H_INCLUDED
-#include <parted/parted.h>
+
 
 
 #ifndef HACKS_H_INCLUDED
 };
 #endif
 
+#define N_(String) String
+
 
 /* The system types for msdos  partition tables
  * Needed for lfdisk and some interface improvements
  */
 struct systypes msdos_systypes[] = {
 	/* TODO: I don't like some of the strings, change them */
-	{ 0x00, "Empty" }, /* "Empty" */
-	{ 0x01, "FAT12" }, 
-	{ 0x02, "XENIX root" }, 
-	{ 0x03, "XENIX usr" }, 
-	{ 0x04, "Small FAT16" }, 
-	{ 0x05, "Extended" }, /* "Extended" */
-	{ 0x06, "FAT16" }, 
-	{ 0x07, "HPFS/NTFS" }, 
-	{ 0x08, "AIX" }, 
-	{ 0x09, "AIX bootable" }, 
-	{ 0x0a, "OS/2 boot mgr" }, 
-	{ 0x0b, "FAT32" }, 
-	{ 0x0c, "FAT32 LBA" }, 
-	{ 0x0e, "FAT16 LBA" }, 
-	{ 0x0f, "Extended LBA" }, 
-	{ 0x10, "OPUS" }, 
-	{ 0x11, "Hidden FAT12" }, 
-	{ 0x12, "Compaq diag" }, 
-	{ 0x14, "Hidd Sm FAT16" }, 
-	{ 0x16, "Hidd FAT16" }, 
-	{ 0x17, "Hidd HPFS/NTFS" }, 
-	{ 0x18, "AST SmartSleep" }, 
-	{ 0x1b, "Hidd FAT32" }, 
-	{ 0x1c, "Hidd FAT32 LBA" }, 
-	{ 0x1e, "Hidd FAT16 LBA" }, 
-	{ 0x24, "NEC DOS" }, 
-	{ 0x39, "Plan 9" }, 
-	{ 0x3c, "PMagic recovery" }, 
-	{ 0x40, "Venix 80286" }, 
-	{ 0x41, "PPC PReP Boot" }, 
-	{ 0x42, "SFS" }, 
-	{ 0x4d, "QNX4.x" }, 
-	{ 0x4e, "QNX4.x 2nd part" }, 
-	{ 0x4f, "QNX4.x 3rd part" }, 
-	{ 0x50, "OnTrack DM" }, 
-	{ 0x51, "OnTrackDM6 Aux1" }, 
-	{ 0x52, "CP/M" }, 
-	{ 0x53, "OnTrackDM6 Aux3" }, 
-	{ 0x54, "OnTrack DM6" }, 
-	{ 0x55, "EZ Drive" }, 
-	{ 0x56, "Golden Bow" }, 
-	{ 0x5c, "Priam Edisk" }, 
-	{ 0x61, "SpeedStor" }, 
-	{ 0x63, "GNU HURD/SysV" }, 
-	{ 0x64, "Netware 286" }, 
-	{ 0x65, "Netware 386" }, 
-	{ 0x70, "DiskSec MltBoot" }, 
-	{ 0x75, "PC/IX" }, 
-	{ 0x80, "Minix <1.4a" }, 
-	{ 0x81, "Minix >1.4b" }, 
-	{ 0x82, "Linux swap" }, /* FIXME: Or solaris */
-	{ 0x83, "Linux" }, 
-	{ 0x84, "OS/2 hidden C:" }, 
-	{ 0x85, "Linux extended" }, 
-	{ 0x86, "NTFS volume set" },
-	{ 0x87, "NTFS volume set" }, 
-	{ 0x88, "Linux plaintext" }, 
-	{ 0x8e, "Linux LVM" }, 
-	{ 0x93, "Amoeba" }, 
+	{ 0x00, N_("Empty") }, /* "Empty") */
+	{ 0x01, N_("FAT12") }, 
+	{ 0x02, N_("XENIX root") }, 
+	{ 0x03, N_("XENIX usr") }, 
+	{ 0x04, N_("Small FAT16") }, 
+	{ 0x05, N_("Extended") }, /* "Extended") */
+	{ 0x06, N_("FAT16") }, 
+	{ 0x07, N_("HPFS/NTFS") }, 
+	{ 0x08, N_("AIX") }, 
+	{ 0x09, N_("AIX bootable") }, 
+	{ 0x0a, N_("OS/2 boot mgr") }, 
+	{ 0x0b, N_("FAT32") }, 
+	{ 0x0c, N_("FAT32 LBA") }, 
+	{ 0x0e, N_("FAT16 LBA") }, 
+	{ 0x0f, N_("Extended LBA") }, 
+	{ 0x10, N_("OPUS") }, 
+	{ 0x11, N_("Hidden FAT12") }, 
+	{ 0x12, N_("Compaq diag") }, 
+	{ 0x14, N_("Hidd Sm FAT16") }, 
+	{ 0x16, N_("Hidd FAT16") }, 
+	{ 0x17, N_("Hidd HPFS/NTFS") }, 
+	{ 0x18, N_("AST SmartSleep") }, 
+	{ 0x1b, N_("Hidd FAT32") }, 
+	{ 0x1c, N_("Hidd FAT32 LBA") }, 
+	{ 0x1e, N_("Hidd FAT16 LBA") }, 
+	{ 0x24, N_("NEC DOS") }, 
+	{ 0x39, N_("Plan 9") }, 
+	{ 0x3c, N_("PMagic recovery") }, 
+	{ 0x40, N_("Venix 80286") }, 
+	{ 0x41, N_("PPC PReP Boot") }, 
+	{ 0x42, N_("SFS") }, 
+	{ 0x4d, N_("QNX4.x") }, 
+	{ 0x4e, N_("QNX4.x 2nd part") }, 
+	{ 0x4f, N_("QNX4.x 3rd part") }, 
+	{ 0x50, N_("OnTrack DM") }, 
+	{ 0x51, N_("OnTrackDM6 Aux1") }, 
+	{ 0x52, N_("CP/M") }, 
+	{ 0x53, N_("OnTrackDM6 Aux3") }, 
+	{ 0x54, N_("OnTrack DM6") }, 
+	{ 0x55, N_("EZ Drive") }, 
+	{ 0x56, N_("Golden Bow") }, 
+	{ 0x5c, N_("Priam Edisk") }, 
+	{ 0x61, N_("SpeedStor") }, 
+	{ 0x63, N_("GNU HURD/SysV") }, 
+	{ 0x64, N_("Netware 286") }, 
+	{ 0x65, N_("Netware 386") }, 
+	{ 0x70, N_("DiskSec MltBoot") }, 
+	{ 0x75, N_("PC/IX") }, 
+	{ 0x80, N_("Minix <1.4a") }, 
+	{ 0x81, N_("Minix >1.4b") }, 
+	{ 0x82, N_("Linux swap") }, /* FIXME: Or solaris */
+	{ 0x83, N_("Linux") }, 
+	{ 0x84, N_("OS/2 hidden C:") }, 
+	{ 0x85, N_("Linux extended") }, 
+	{ 0x86, N_("NTFS volume set") },
+	{ 0x87, N_("NTFS volume set") }, 
+	{ 0x88, N_("Linux plaintext") }, 
+	{ 0x8e, N_("Linux LVM") }, 
+	{ 0x93, N_("Amoeba") }, 
 	/*This guys created a seperate partition for badblocks?! */
-	{ 0x94, "Amoeba BBT" },  
-	{ 0x9f, "BSD/OS" }, 
-	{ 0xa0, "Thinkpad hib" }, 
-	{ 0xa5, "FreeBSD" }, 
-	{ 0xa6, "OpenBSD" }, 
-	{ 0xa7, "NeXTSTEP" }, 
-	{ 0xa8, "Darwin UFS" }, 
-	{ 0xa9, "NetBSD" }, 
-	{ 0xab, "Darwin boot" }, 
-	{ 0xb7, "BSDI fs" }, 
-	{ 0xb8, "BSDI swap" }, 
+	{ 0x94, N_("Amoeba BBT") },  
+	{ 0x9f, N_("BSD/OS") }, 
+	{ 0xa0, N_("Thinkpad hib") }, 
+	{ 0xa5, N_("FreeBSD") }, 
+	{ 0xa6, N_("OpenBSD") }, 
+	{ 0xa7, N_("NeXTSTEP") }, 
+	{ 0xa8, N_("Darwin UFS") }, 
+	{ 0xa9, N_("NetBSD") }, 
+	{ 0xab, N_("Darwin boot") }, 
+	{ 0xb7, N_("BSDI fs") }, 
+	{ 0xb8, N_("BSDI swap") }, 
 	/* Beware of the hidden wizard */
-	{ 0xbb, "Boot Wizard Hid" },
-	{ 0xbe, "Solaris boot" }, 
-	{ 0xbf, "Solaris" }, 
-	{ 0xc1, "DRDOS/2 FAT12" }, 
-	{ 0xc4, "DRDOS/2 smFAT16" }, 
-	{ 0xc6, "DRDOS/2 FAT16" }, 
+	{ 0xbb, N_("Boot Wizard Hid") },
+	{ 0xbe, N_("Solaris boot") }, 
+	{ 0xbf, N_("Solaris") }, 
+	{ 0xc1, N_("DRDOS/2 FAT12") }, 
+	{ 0xc4, N_("DRDOS/2 smFAT16") }, 
+	{ 0xc6, N_("DRDOS/2 FAT16") }, 
 	/* Reminds me of Rush - 2112 */
-	{ 0xc7, "Syrinx" },  
-	{ 0xda, "Non-FS data" },
-	{ 0xdb, "CP/M / CTOS" }, 
-	{ 0xde, "Dell Utility" }, 
+	{ 0xc7, N_("Syrinx") },  
+	{ 0xda, N_("Non-FS data") },
+	{ 0xdb, N_("CP/M / CTOS") }, 
+	{ 0xde, N_("Dell Utility") }, 
 	/* Should 0x20 be DontBootIt then? */
-	{ 0xdf, "BootIt" },  
-	{ 0xe1, "DOS access" }, 
-	{ 0xe3, "DOS R/O" }, 
+	{ 0xdf, N_("BootIt") },  
+	{ 0xe1, N_("DOS access") }, 
+	{ 0xe3, N_("DOS R/O") }, 
 	/*I sense some strange déjà vu */
-	{ 0xe4, "SpeedStor" },  
-	{ 0xeb, "BeOS fs" }, 
-	{ 0xee, "EFI GPT" }, 
-	{ 0xef, "EFI FAT" }, 
-	{ 0xf0, "Lnx/PA-RISC bt" }, 
-	{ 0xf1, "SpeedStor" }, 
-	{ 0xf2, "DOS secondary" }, 
+	{ 0xe4, N_("SpeedStor") },  
+	{ 0xeb, N_("BeOS fs") }, 
+	{ 0xee, N_("EFI GPT") }, 
+	{ 0xef, N_("EFI FAT") }, 
+	{ 0xf0, N_("Lnx/PA-RISC bt") }, 
+	{ 0xf1, N_("SpeedStor") }, 
+	{ 0xf2, N_("DOS secondary") }, 
 	/* Are these guys trying for a Guinness record or something? */
-	{ 0xf4, "SpeedStor" },  
-	{ 0xfd, "Lnx RAID auto" }, 
-	{ 0xfe, "LANstep" }, 
-	{ 0xff, "XENIX BBT" },
+	{ 0xf4, N_("SpeedStor") },  
+	{ 0xfd, N_("Lnx RAID auto") }, 
+	{ 0xfe, N_("LANstep") }, 
+	{ 0xff, N_("XENIX BBT") },
 	{ 0, NULL }
 };
 
 		}
 		prompt = realloc_and_cat (prompt, ": ");
 	} else if (def) {
-		if (strlen (prompt))
+		size_t len = strlen (prompt);
+		if (len && prompt[len-1] != '\n')
 			prompt = realloc_and_cat (prompt, "  ");
-		prompt = realloc_and_cat (prompt, "[");
+		prompt = realloc_and_cat (prompt, "(default ");
 		prompt = realloc_and_cat (prompt, def);
-		prompt = realloc_and_cat (prompt, "]: ");
+		prompt = realloc_and_cat (prompt, "): ");
 	} else {
 		size_t len = strlen (prompt);
 		if (len && prompt[--len] != '\n') {
                                   PedPartitionType *type)
 {
 	Option opts[4];
-	int i = 0;
+	int i = 0, temp;
 	if (_can_create_extended (disk)) {
 		opts[i].option = 'e';
 		opts[i].description = _("extended");
 		i++;
 	}
 	if (_can_create_logical (disk)) {
+		temp = PED_PARTITION_LOGICAL;
 		opts[i].option = 'l';
 		opts[i].description = _("logical (5 or over)");
 		i++;
 		i++; 
 	}
 	opts[i].option = 0;
-
-	*type = fdisk_command_line_get_option(prompt, opts);
+	if (i == 0)
+		return 0;
+	else if (i == 1)
+		temp = opts[0].option;
+	else
+		temp = fdisk_command_line_get_option(prompt, opts);
+	if (temp == 'e')
+		*type = PED_PARTITION_EXTENDED;
+	else if (temp == 'l')
+		*type = PED_PARTITION_LOGICAL;
+	else if (temp == 'p')
+		*type = PED_PARTITION_NORMAL;
+	else
+		return 0;
 	return 1;
 }
 #if 0

tests/check_common.c

 #define run_pos_test(part,constraint,desired_opts,poss_ok,posg,strings) \
 	pos.start.sector = 2000LL; \
 	pos.end.sector = 21999LL; \
+	pos.start.range = NULL; \
+	pos.end.range = NULL; \
 	opts = UI_DEFAULT; \
 	pos_gets = 0; string_gets = 0; \
 	fail_unless(query_part_position("", NULL, &pos,  \
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.