Anonymous avatar Anonymous committed 8cbae49

Rename more functions and improve checks. Make checking of resize on mac partition table work. (fdisk@sv.gnu.org/fdisk--main--0--patch-34)
fdisk@sv.gnu.org/fdisk--main--0--patch-34
Keywords:

Comments (0)

Files changed (5)

 
 /* Here we define our menu operations */
 static int
-action_new (PedPartition **part) {
+do_new (PedPartition **part) {
 	PedPartition *temp = disk_get_prev_nmd_partition (disk,*part);
 	static MenuItem part_position[] = {
 		{ 's', N_("Begining"), N_("Create the partition at the begining of the free space") },
 }
 
 static int
-action_resize (PedPartition **part) {
+do_resize (PedPartition **part) {
 	static MenuItem part_position[] = {
 		{ 's', N_("Fixed start"), N_("Don't move the beginning of the partition") },
 		/* FIXME: Wording. */
 }
 
 static int
-action_move (PedPartition **part) {
+do_move (PedPartition **part) {
 	/* Combine this with new partition? */
 	static MenuItem part_position[] = {
 		{ 's', N_("Begining"), N_("Move the partition to the begining of the free space") },
 }
 
 static int
-action_mkfs (PedPartition **part) {
+do_mkfs (PedPartition **part) {
 	char buf[SMALLBUF];
 	const PedFileSystemType *type = NULL;
 	int go;
 }
 
 static int
-action_check (PedPartition **part) {
+do_check (PedPartition **part) {
 	if (!perform_check(disk,*part)) {
 		warning_waitkey(N_("The consistency check failed."));
 		return 0;
 }
 
 static int
-action_rescue(PedPartition **part) {
+do_rescue(PedPartition **part) {
 	static MenuItem rescue_menu[] = {
 		{ 'g', N_("Continue"), N_("Proceed with the rescue") },
 		{ 'c', N_("Custom"), N_("Select custom area to look for partitions (for experts only)") },
 }
 
 static int
-action_copy(PedPartition **part) {
+do_copy(PedPartition **part) {
 	if (!perform_cp(disk,*part, UI_WARN_COMMIT)) {
 		if (uiquery.need_commit) _disk_reread(part);
 		warning_waitkey(N_("Partition not copied successfully"));
 }
 
 static int
-action_delete(PedPartition **part) {
+do_delete(PedPartition **part) {
 	int go = 1;
 	PedPartition *temp;
+	/* Don't delete the first partition on a mac partition table */
+	if (!strcmp(disk->type->name,"mac") && (*part)->num == 1) {
+		warning_waitkey(N_("You should not delete this partition."));
+		return 0;
+	}
 	/* Remember either the previous partition so we can select the free space */
 	temp = disk_get_prev_nmd_partition(disk, *part);
 	if (temp && temp->type & PED_PARTITION_FREESPACE)
 }
 
 static int
-action_maximize(PedPartition **part) {
+do_maximize(PedPartition **part) {
 	if (!perform_maximize(disk,*part)) {
 		warning_waitkey(N_("Couldn't maximize this partition"));
 		return 0;
 }
 
 static int
-action_minimize(PedPartition **part) {
+do_minimize(PedPartition **part) {
 	PedPartition *temp;
 	temp = disk_get_prev_nmd_partition(disk, *part);
 	if (temp && temp->type & PED_PARTITION_FREESPACE)
 }
 
 static int
-action_commit () {
+do_commit () {
 	if (!perform_commit(disk,UI_WARN_COMMIT)) {
 		warning_waitkey(N_("Commit failed."));
 		return 0;
 }
 
 static int
-action_units () {
+do_units () {
 	static MenuItem units[] = {
 		{ '1' , N_("Sectors"), N_("Show the sizes in sectors") },
 		{ '2' , N_("Bytes"), N_("Show the sizes in bytes") },
 /* I'm not quite sure we should let the user do this... */
 /* Actually, I'm still not quite sure if it does what it says to do :) */
 static int
-action_type (PedPartition **part) {
+do_type (PedPartition **part) {
 	static MenuItem type_menu[] = {
 		{ 'a', N_("Auto"), N_("Try to automatically set the correct type") },
 		{ 'c', N_("Custom"), N_("Select a custom filesystem type (for experts only)") },
 }
 
 static int
-action_name (PedPartition **part) {
+do_name (PedPartition **part) {
 	if (!ped_disk_type_check_feature(disk->type,PED_DISK_TYPE_PARTITION_NAME)) {
 		warning_waitkey(N_("The partition label doesn't support partition names"));
 		return 0;
 }
 
 static int
-action_flag (PedPartition **part) {
+do_flag (PedPartition **part) {
 	PedPartitionFlag selected = PED_PARTITION_BOOT;
 	/* This is not quite sexy */
 	/* FIXME FIXME FIXME Make this *sane* */
 }
 
 static int
-action_help () {
+do_help () {
 	StrList *message = _message_display_strlist(help,NULL,TAB_TO_INDENT);
 	do_strlist(_("cfdisk help"),message,1);
 	str_list_destroy(message);
 }
 
 static int
-action_pinfo (PedPartition **part) {
+do_pinfo (PedPartition **part) {
 	StrList *info = NULL;
 	char buf[SMALLBUF];
 	const char *temp;
 			}
 			break;
 		case 'n':
-			action_new(part);
+			do_new(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'w':
-			action_commit();
+			do_commit();
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'f':
-			action_mkfs(part);
+			do_mkfs(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'c':
-			action_check(part);
+			do_check(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'u':
-			action_units();
+			do_units();
 			//redraw = 1;
 			key = 0;
 			break;
 		case 's':
-			action_rescue(part);
+			do_rescue(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'y':
-			action_copy(part);
+			do_copy(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'r':
-			action_resize(part);
+			do_resize(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'd':
-			action_delete(part);
+			do_delete(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'o':
-			action_move(part);
+			do_move(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'x':
-			action_maximize(part);
+			do_maximize(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'z':
-			action_minimize(part);
+			do_minimize(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 'b':
-			action_flag(part);
+			do_flag(part);
 			//redraw = 1;
 			key = 0;
 			break;
 		case 't':
-			action_type(part);
+			do_type(part);
 			//redraw = 0; //??
 			key = 0;
 			break;
 		case 'h':
-			action_help();
+			do_help();
 			//redraw = 0;
 			key = 0;
 			break;
 		case 'm':
-			action_name(part);
+			do_name(part);
 			//redraw = 0;
 			key = 0;
 			break;
 		case 'i':
-			action_pinfo(part);
+			do_pinfo(part);
 			//redraw = 0;
 			key = 0;
 			break;
 	#if MSDOS_HACK
 	if (!strcmp(part->disk->type->name,"msdos")) {
 		int i;
-		DosPartitionData *pdata = (DosPartitionData *) part->disk_specific;
+		DosPartitionData *pd = (DosPartitionData *)part->disk_specific;
 		for (i = 0; msdos_systypes[i].name; i++) {
-			if(msdos_systypes[i].type == pdata->system) {
+			if(msdos_systypes[i].type == pd->system) {
 				return msdos_systypes[i].name;
 			}
 		}
 	#endif
 	#if MAC_HACK
 	if (!strcmp(part->disk->type->name,"mac")) {
-		MacPartitionData *pdata = (MacPartitionData *) part->disk_specific;
-		const char* type = pdata->system_name;
+		MacPartitionData *pd = (MacPartitionData *)part->disk_specific;
+		const char* type = pd->system_name;
 		if (strncmp(type,"Apple_",6))
 			return NULL;
 		else {
 /* I'm lazy to write */
 #define return_system_type(ltype,stype,type_var) \
 	if (!strcmp(part->disk->type->name,(ltype))) { \
-		stype *pdata = (stype *) part->disk_specific; \
+		stype *pd = (stype *) part->disk_specific; \
 		if (size) \
-			*size = sizeof(pdata->type_var); \
-		return pdata->type_var; \
+			*size = sizeof(pd->type_var); \
+		return pd->type_var; \
 	}
 unsigned int
 get_disk_specific_system_type (PedPartition *part, int *size) {
 	}
 	
 }
+/* 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 */
+	#if MSDOS_HACK
+	if (!strcmp(part->disk->type->name,"msdos")) {
+		DosPartitionData *pd = (DosPartitionData *)part->disk_specific;
+		pd->system = type;
+	}
+	else
+	#endif
+	#if BSD_HACK
+	if (!strcmp(part->disk->type->name,"bsd")) {
+		BSDPartitionData *pd = (BSDPartitionData *)part->disk_specific;
+		pd->type = type;
+	}
+	else
+	#endif
+	return;
+}
+#endif

tests/check_common.c

 END_TEST
 
 
-/* TODO: This fails on dvh and mac.  Figure out why. */
 /* Here we test (*only*) the size changing with perform_resize */
 START_TEST (test_chsize_msdos) {
 	change_size("msdos", UI_NO_FS_RESIZE);
 }
 END_TEST
 
+/* FIXME: This test fails! */
 START_TEST (test_chsize_dvh) {
 	change_size("dvh", UI_NO_FS_RESIZE);
 	test_exception();
 }
 END_TEST
 
-START_TEST (test_chsize_loop) {
-	change_size("gpt", UI_NO_FS_RESIZE);
-	test_exception();
+START_TEST (test_partpos) {
+	PedGeometry geom;
+	PedGeometry where;
+	PedSector start,end;
+	ped_geometry_init(&where,dev,2000LL,20000LL);
+	ped_geometry_init(&geom,dev,2000LL,20000LL);
+	fail_unless(perform_mklabel(dev,&disk,ped_disk_type_get("msdos")),
+	            "We could create the label for partpos test");
+	/* fail_unless(_mkpart(0, where.start, where.end, PED_PARTITION_NORMAL,
+	 *                   fs_type, NULL, perform_mkpart),
+	 *           "Failed to create partpos test partition")
+	 */
+	uiquery.getpartpos = getpartpos;
+	/* A: We test without constraint */
+
+	/* B: We test with some constraint */
+	/* C: We test with constraint of a partition with unmovable start */
+
+	
 }
 END_TEST
 
-
-
 Suite *common_suite(void)
 {
 	Suite *s = suite_create("Common functions");
 	tcase_add_test(tc_chsize, test_chsize_amiga);
 	tcase_add_test(tc_chsize, test_chsize_gpt);
 	//tcase_add_test(tc_chsize, test_chsize_dvh);
-	tcase_add_test(tc_chsize, test_chsize_loop);
-	//tcase_add_test(tc_chsize, test_chsize_mac);
+	tcase_add_test(tc_chsize, test_chsize_mac);
 	return s;
 }
 

tests/functions.c

    should use the second string, if it is 2, we should change it to 1, and
    if 0, we should use the first. I know it's ugly, but it works. */
 char string[2][BUFSIZE+1];
+int string_gets;
 int getstring (const char* prompt, char** value, const StrList* str_list, 
                const StrList* loc_str_list, int multi_word)
 {
+	/* We count how much times this function is called */
+	string_gets++;
+	/* We check whether the first or the second string should be 
+	   used if there is a "queue" of two strings. */
 	char *s;
 	if (string[0][BUFSIZE] == 1) {
 		s = string[1];
 	return 1;
 }
 
+int part_pos;
+int pos_gets;
+int getpartpos (const char* prompt, const void* context,
+                       const char *possibilities)
+{
+	/* We count how much times this was called */
+	pos_gets++;
+	return part_pos;
+}
+
+
 int
 init_tempfile() {
 	int i;
                                      PedPartitionType, const PedFileSystemType*,
                                      PedPartition **, UIOpts))
 {
+	int status;
+	string_gets = 0;
+	int strings;
 	switch(how % 3) {
 		/* We create the partition by specifying start and end */
 		case 0:
+			strings = 1;	
+			if (string[0][BUFSIZE] == 1) {
+				strings++;
+				string[0][BUFSIZE] = 2;
+			}
+			else
+				string[0][BUFSIZE] = 0;
 			uiquery.getstring = getstring;
 			strncpy(string[0], fs_type->name, BUFSIZE-1);
-			string[0][BUFSIZE] = 0;
-			return ch_mkpart(disk,start,end,type,NULL,newpart,
+			
+			status = ch_mkpart(disk,start,end,type,NULL,newpart,
 			                 UI_DEFAULT);
+			fail_unless(string_gets == strings,
+				"User queried for %d strings instead of %d",
+				string_gets, strings);
+			break;
 		/* We test that giving the default string is OK */
 		case 1:
 			strncpy(string[0],DEFAULT_STRING,BUFSIZE);
 			uiquery.getstring = getstring;
-			return ch_mkpart(disk,start,end,type,fs_type,newpart,
+			status = ch_mkpart(disk,start,end,type,fs_type,newpart,
 			                 UI_CUSTOM_VALUES);
+			fail_unless(string_gets == 2,
+				"User queried for %d strings instead of 2",
+				string_gets);
+			break;
 		/* We query the start and end */
 		case 2:
 			uiquery.getstring = getstring;
 			string[0][BUFSIZE] = 2;
 			snprintf(string[0],BUFSIZE,"%llds",start);
 			snprintf(string[1],BUFSIZE,"%llds",end);
-			return ch_mkpart(disk,0LL,0LL,type,fs_type,newpart,
+			status = ch_mkpart(disk,0LL,0LL,type,fs_type,newpart,
 			                 UI_CUSTOM_VALUES);
+			fail_unless(string_gets == 2,
+				"User queried for %d strings instead of 2",
+				string_gets);
+			break;
 	}
 	
 }
 	PedSector start, end, oldstart = -1, oldend = -1;
 	PedPartition *part = NULL;
 	PedFileSystemType *fs_type = ped_file_system_type_get("fat32");
+	int is_mac = !strcmp(ltype,"mac");
 	int i;
 	fail_unless(perform_mklabel(dev,&disk,ped_disk_type_get(ltype)),
 	            "We could create the %s label for resizing partitions",
 	            ltype);
+	
 	/* NOTE: This might blow up if ltype is less than three chars */
 	/* FIXME: This checks works differently on LE and BE platforms */
 	srand(1 + opts + ((int) ltype));
 	/* We will resize create 4 partitions */
+	if (is_mac) {
+		part = ped_disk_get_partition(disk,1);
+		geom = ped_geometry_new(dev,part->geom.start,part->geom.length);
+		part = NULL;
+		
+	}
 	for (i = 0; i < 4; i++) {		
 		next_part_geometry(&geom, constraint, 1);
-		string[0][BUFSIZE] = 0;
-		strncpy(string[0],"Label",BUFSIZE);
+		if (ped_disk_type_check_feature(disk->type,
+			PED_DISK_TYPE_PARTITION_NAME)) {
+			/* 1 means get second string on queue */
+			string[0][BUFSIZE] = 1;
+			strncpy(string[1],"Label",BUFSIZE);
+		}
+		else
+			string[0][BUFSIZE] = 0;
 		uiquery.getstring = getstring;
 		set_exception_error("Creating partition %d at %llds-%llds "
 			"with previous one at %llds-%llds on %s",
 	}
 	/* And we will resize them, 4 times each, moving them as near possible
 	   to end of the disk as a final result */
-	while (part) {
+	while (part && (!is_mac || part->num != 1)) {
 		get_max_geometry(&geom,constraint,part);
 		for (i = 0; i < 4; i++) {
 			randomize_position(&start,&end,geom,i);

tests/functions.h

 #define PUT_TWO_STRINGS(x,y) string[0][BUFSIZE] = 2; \
                              uiquery.getstring = getstring; \
                              strncpy(string[0], x, BUFSIZE-1); \
-                             strncpy(string[1], x, BUFSIZE-1)
+                             strncpy(string[1], y, BUFSIZE-1)
 
 			
 extern char string[2][BUFSIZE+1];
+extern int string_gets;
 extern int getstring (const char* prompt, char** val, const StrList* str_list,
                       const StrList* loc_str_list, int multi_word);
 
 extern PedFileSystemType *fs_type;
 extern int getfstype (const char* prompt, PedFileSystemType **value);
 
+extern int part_pos;
+extern int pos_gets;
+extern int getpartpos (const char* prompt, const void* context,
+                       const char *possibilities);
+
 /* Device init functions, we should make them one */
 extern int init_tempfile();
 extern void unlink_tempfile();
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.