Anonymous avatar Anonymous committed fc550a0

Move hacks to a seperate file. Implement partition info in cfdisk (need fixing). Try to introduce new bugs to cfdisk, hopefully unsuccessfully. (fdisk@sv.gnu.org/fdisk--main--0--patch-20)
fdisk@sv.gnu.org/fdisk--main--0--patch-20
Keywords:

Comments (0)

Files changed (6)

 		common.c	\
 		common.h	\
 		strlist.c	\
-		strlist.h
+		strlist.h	\
+		hacks.c		\
+		hacks.h
 
 cfdisk_LDADD = $(PARTED_LIBS) $(CURSES_LIBS)
 
 
 #include "../config.h"
 #include "common.h"
+#include "hacks.h"
 /*#include "command.h"*/
 /*#include "ui.h"*/
 
 	return message;
 }
 
-static void 
-display_message (const char *msg) {
-	int x, y, i;
-	StrList *message = _message_display_strlist(msg,&y,1);
+static void
+_display_strlist (const StrList *message, int y) {
+	int x, i;
 	/* TODO: Write this, for now I will test it this way */
 	y=LINES-3-MENUSIZE-y;
 	/*  */
 	for (i++; i < y; i++) {
 		move(i,0); clrtoeol();
 	}
-	StrList *current;
+	const StrList *current;
 	for (current = message; current && y < LINES-MENUSIZE-3; current = current->next, y++) {
 		char *temp = str_list_convert_node(current);
 		move(y,0); clrtoeol();
 		mvaddstr(y,1,temp);
 		free(temp);
 	}
+
+}
+
+static void 
+display_message (const char *msg) {
+	int y;
+	StrList *message = _message_display_strlist(msg,&y,1);
+	_display_strlist(message, y);
 	str_list_destroy(message);
 	
 }
 			/* Write the button. Highlight if is selected. */
 			
 			if (i == selected && !(opts & MENU_NOHIGHLIGHT)) attron(A_STANDOUT);
-			/*else if (strchr(keys,tolower(items[i].key))) attron(A_DIM);*/
+			//else if (strchr(keys,tolower(items[i].key))) attron(A_BOLD);
 	
 			mvaddstr(y,x,buf);
 	
 			if (i == selected && !(opts & MENU_NOHIGHLIGHT)) attroff(A_STANDOUT);
-			/*else if (strchr(keys,tolower(items[i].key))) attroff(A_BOLD);*/
+			//else if (strchr(keys,tolower(items[i].key))) attroff(A_BOLD);
 			
 			if (x + 2*item_size + 2*MENUDIV < COLS) {
 				x += item_size + MENUDIV;
 /* Menu display function. The selected parameter specifies the item that is selected by
  * default and the keys string includes the keys that should be accepted by the interface. */
 static int
-do_menu (const MenuItem *items, int item_len, MenuOptions opts, const char *keys, int selected) {
-	int i, key = 0, count = 0, redraw = 1;
-	
+do_menu (const MenuItem *items, int item_len, MenuOptions opts, const char *keys, int *sel) {
+	int i, key = 0, count = 0, redraw = 1, save_selection = 0, selected = 0;
+	if (sel) {
+		selected = *sel;
+	}
 	/* Count the items and make sure that the selected item is available */
 	for (count = 0; items[count].name; count++);
 	if (selected >= count)
 			break;
 		}
 	}
+	/* If the selected menu item was not not available, we save the pointer to change it back */
+	/* FIXME: The menu acts funny. Re-order the items so that it works better :) */
+	//if (selected == saved_selection) save_selection = 1;
 	while (!key) {
 		if (redraw) {
 			menu_draw (items, item_len, opts, keys, selected);
 					} while (!strchr(keys,tolower(items[selected].key)));
 					key = 0;
 					redraw = 1;
+					save_selection = 1;
 				}
 				else if (key == 'D') { /* ^[[D = Left arrow */
 					do {
 					} while (!strchr(keys,tolower(items[selected].key)));
 					key = 0;
 					redraw = 1;
+					save_selection = 1;
 				}
 			}
 		}
 			print_warning(_("Invalid key"),0);
 		}
 	}
+	if (save_selection)
+		*sel = selected;
 	return key;
 }
 
 			key = getch();
 			if (key == '[' || key == 'O') {
 			key = getch();
-				if (key == 'B') { /* That's down arrow */
+				if (key == 'B' && !(opts & 2)) { /* That's down arrow */
 					if (!selected->next)
 						print_warning(end_warning,0);
 					else {
 						redraw = 1;
 					}
 				}
-				else if (key == 'A') { /* That's up arrow */
+				else if (key == 'A' && !(opts & 2)) { /* That's up arrow */
 					if (strlist == selected)
 						print_warning(end_warning,0);
 					else {
 static int
 getbool(const char* prompt, int* value) {
 	int result;
+	int menudef = !*value;
 	MenuItem yes_no[] = {
 		{'y', N_("Yes"), "" },
 		{'n', N_("No"), "" },
 		{0, NULL, NULL }
 	};
 	menu_title(prompt);
-	result = do_menu(yes_no, 5, MENU_BUTTON | MENU_TITLE, "yn", !*value);
+	result = do_menu(yes_no, 5, MENU_BUTTON | MENU_TITLE, "yn", &menudef);
 	*value = (result == 'y');
 	return 1;
 }
 static int
 getstring (const char* prompt, char **value, const StrList* words, const StrList* locwords, int mword) {
 	/* TODO: Implement multiword, etc. */
+
 	const StrList *selected;
 	if (words || locwords) {
 		if(locwords)
 		*value = str_list_convert_node(selected);
 		return (*value != NULL);
 	}
-	else return read_char(prompt,value);
+	else
+
+		return read_char(prompt,value);
 }
 
 static int
 #endif
 	keys[k] = '\0';
 	display_message(ex->message);
-	res = do_menu(ex_choices, 8, MENU_BUTTON, keys, 0);
+	res = do_menu(ex_choices, 8, MENU_BUTTON, keys, NULL);
 	for (i = 0; ex_keys[i].key; i++)
 		if (ex_keys[i].key == res)
 			return ex_keys[i].option;
 	};
 	if (warning)
 		waitkey[0].name = warning;
-	do_menu(waitkey,COLS-MENUDIV*2,MENU_ANYKEY | MENU_NOHIGHLIGHT,"k",0);
+	do_menu(waitkey,COLS-MENUDIV*2,MENU_ANYKEY | MENU_NOHIGHLIGHT,"k",NULL);
 }
 
 static void
 		keys [i] = '\0';
 		/* NOTE: Run menu_title before running this function */
 		//menu_title(_("Where do you want to put the partition"));
-		key = do_menu(menu, 11, MENU_BUTTON | MENU_TITLE, keys, 0);
+		key = do_menu(menu, 11, MENU_BUTTON | MENU_TITLE, keys, NULL);
 	}
 	if (key == ESC)
 		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);
+			key = do_menu(part_type, 8, MENU_BUTTON | MENU_TITLE, type_keys, NULL);
 			if (key == ESC)	return 1;
 			else if (key == 'p') type = PED_PARTITION_NORMAL;
 			else if (key == 'e') type = PED_PARTITION_EXTENDED;
 	if (!((*part)->type & PED_PARTITION_EXTENDED)) {
 		if ((*part)->fs_type->ops->resize != NULL) {
 			menu_title(_("What do you want to do?"));
-			key = do_menu(resize_menu, 11, MENU_BUTTON | MENU_TITLE,resize_keys, 0);
+			key = do_menu(resize_menu, 11, MENU_BUTTON | MENU_TITLE,resize_keys, NULL);
 		}
 		else {
 			key = 0;
 	const char keys[] = { 'g', 'c', ESC, '\0' };
 	int key;
 	menu_title(_("This will try to rescue broken or deleted partitions")); 
-	key = do_menu(rescue_menu, 8, MENU_BUTTON | MENU_TITLE, keys, 0);
+	key = do_menu(rescue_menu, 8, MENU_BUTTON | MENU_TITLE, keys, NULL);
 	if (key == ESC) return 0;
 	if(!do_rescue (disk, (*part)->geom.start, (*part)->geom.end, 
 	           UI_WARN_COMMIT | (key == 'c' ? UI_CUSTOM_VALUES : 0), &uiquery)) {
 		{ 0, NULL, NULL }
 	};
 	int key;
+	static int units_menu = 3;
 	//menu_title(_("Choose the display unit type")); /* Heh, no place for a title, heh */
-	key = do_menu(units, 9, MENU_BUTTON, "1234567890abcde", 1);
+	key = do_menu(units, 9, MENU_BUTTON, "1234567890abcde", &units_menu);
 	switch (key) {
 		case '1': ped_unit_set_default(PED_UNIT_SECTOR); return 1;
 		case '2': ped_unit_set_default(PED_UNIT_BYTE); return 1;
 	return 1;
 }
 
+static int
+action_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;
+	}
+	if (!do_name(disk,*part, NULL, &uiquery)) {
+		warning_waitkey(N_("Name wasn't changed successfully."));
+		return 0;
+	} 
+	notice_waitkey(N_("Name was changed successfully."));
+	return 1;
+}
+
 /* Here we begin with flag editing */
 static void
 printaflag (int *y, const PedPartition *part, PedPartitionFlag flag, PedPartitionFlag selected) {
 	StrList *message = _message_display_strlist(help,NULL,0);
 	do_strlist(_("cfdisk help"),message,1);
 	str_list_destroy(message);
+	return 1;
+}
+
+static int
+action_pinfo (PedPartition **part) {
+	StrList *info = NULL;
+	char buf[SMALLBUF];
+	const char *temp;
+	int i;
+
+	unsigned int system_type;
+	int system_type_size;
+
+
+	/* TODO: This now displays bullshit */
+	snprintf(buf,SMALLBUF,"%30s: %s%d", _("Possible partition device"), dev->path, (*part)->num);
+	info = str_list_append(info,buf);
+
+	if ((*part)->type & PED_PARTITION_LOGICAL)
+		temp = _("Logical");
+	else if ((*part)->type & PED_PARTITION_EXTENDED)
+		temp = _("Extended");
+	else
+		temp = _("Primary");
+	snprintf(buf,SMALLBUF,"%30s: %s", _("Partition type"), temp);
+	info = str_list_append(info,buf);
+	if (ped_disk_type_check_feature(disk->type,PED_DISK_TYPE_PARTITION_NAME)) {
+		snprintf(buf,SMALLBUF,"%30s: %s", _("Partition name"), ped_partition_get_name(*part));
+		info = str_list_append(info,buf);
+	}
+	info = str_list_append(info,"");
+
+	/* Partition size */
+	snprintf(buf,SMALLBUF,"%30s: %s", _("Partition size in bytes"),
+	         ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.length, PED_UNIT_BYTE));
+	info = str_list_append(info,buf);
+	snprintf(buf,SMALLBUF,"%30s: %s", _("Partition size in sectors"),
+	         ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.length, PED_UNIT_SECTOR));
+	info = str_list_append(info,buf);
+	snprintf(buf,SMALLBUF,"%30s: %s", _("Portion of the hard disk"),
+	         ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.length, PED_UNIT_PERCENT));
+	info = str_list_append(info,buf);
+	info = str_list_append(info,"");
+
+	/* Filesystem info */
+	if ((*part)->fs_type) {
+		snprintf(buf,SMALLBUF,"%30s: %s", _("Filesystem type"), (*part)->fs_type->name);
+		info = str_list_append(info,buf);
+	}
+
+	system_type = get_disk_specific_system_type(*part,&system_type_size);
+	if (system_type_size) {
+		system_type_size *= 2;
+		snprintf(buf,SMALLBUF,"%30s: 0x%0*x", _("System type"), system_type_size, system_type);
+		info = str_list_append(info,buf);
+	}
+	temp = get_disk_specific_system_name(*part);
+	if (temp) {
+		snprintf(buf,SMALLBUF,"%30s: %s", _("System type name"), temp);
+		info = str_list_append(info,buf);
+	}
+
+	info = str_list_append(info,"");
+
+	/* Start and end */
+	snprintf(buf,SMALLBUF,"%30s: %s", _("Start (cyl,heads,sector)"),
+	         ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.start, PED_UNIT_CHS));
+	info = str_list_append(info,buf);
+	snprintf(buf,SMALLBUF,"%30s: %s", _("End (cyl,heads,sector)"),
+	         ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.end, PED_UNIT_CHS));
+	info = str_list_append(info,buf);
+	info = str_list_append(info,"");
+	
+	/* Flags */
+	snprintf(buf,SMALLBUF,"%30s: %s", _("Flags"), partition_print_flags(*part));
+	info = str_list_append(info,buf);
+	info = str_list_append(info,"");
+	do_strlist(_("Partition info"),info,3);
+	str_list_destroy(info);
+	
+	return 1;
 }
 
 /* Define column positions. The first three will be fixed. */
 	{ 's', N_("Rescue"), N_("Look for deleted and corrupted partitions in the free space") },
 	{ 'f', N_("Format"), N_("Formats the partition with a filesystem") },
 	{ 'c', N_("Check"), N_("Check partition for consistency") },
-	{ 'a', N_("Rename"), N_("Change partition name") },
+	{ 'm', N_("Rename"), N_("Change partition name") },
 	{ 'y', N_("Copy"), N_("Write another partition over this one (requires commit)") },
 	{ 'r', N_("Resize"), N_("Resizes the current partition (requires commit)") },
 	{ 'x', N_("Maximize"), N_("Enlarges the partition to the maximum possible size") },
 	{ 'u', N_("Units"), N_("Change units of the partition size display") },
 	{ 'w', N_("Commit"), N_("Write the changes to the disk") },
 	{ 'q', N_("Quit"), N_("Quit program without writing partition table") },
-	{ 'p', N_("Print"), N_("Print partition table to the screen or to a file") },
+	{ 'i', N_("Info"), N_("Display additional partition information") },
 	{ 'h', N_("Help"), N_("Display help") },
         { 0, NULL, NULL }
 };
 
-const char keys_ext[] = { 'd','u','w','q','p','h','r','x','z',UP_KEY,DOWN_KEY, '\0' };
-const char keys_free[] = { 'n','s','u','w','q','p','h',UP_KEY,DOWN_KEY, '\0' };
-const char keys_part[] = { 'b','f','c','a','y','r','o','d','t','u','w','q','p','h',UP_KEY,DOWN_KEY, '\0' };
+const char keys_ext[] = { 'm','d','u','w','q','i','h','r','x','z',UP_KEY,DOWN_KEY, '\0' };
+const char keys_free[] = { 'n','s','u','w','q','h',UP_KEY,DOWN_KEY, '\0' };
+const char keys_part[] = { 'b','f','c','m','y','r','o','d','t','u','w','q','i','h',UP_KEY,DOWN_KEY, '\0' };
 /*bfcayrodtuwqph*/
 
 static MenuItem partselect_menu[] = {
 			//redraw = 0;
 			key = 0;
 			break;
+		case 'm':
+			action_name(part);
+			//redraw = 0;
+			key = 0;
+			break;
+		case 'i':
+			action_pinfo(part);
+			//redraw = 0;
+			key = 0;
+			break;
 		default:
 			warning_waitkey("Unimplemented");	 /* TODO */
 			key = 0;
 	PedPartition *temp,*memp;
 	MenuOptions menu_opts = MENU_DEFAULT;
 	MenuItem *part_menu;
+	int menupos = 0;
 	if (!part) 
 		part_menu = main_menu;
 	else {
 			keys = keys_free;
 		else keys = keys_part;
 		
-		key = do_menu(part_menu, 8, MENU_BUTTON | menu_opts, keys, 0);
+		key = do_menu(part_menu, 8, MENU_BUTTON | menu_opts, keys, &menupos);
 		menu_opts &= ~MENU_LEAVE_WARNING;
 		if (key == UP_KEY) {
 
 	return 1;
 }
 
-/* We need a function to get disk type-specific info about filesystem */
-/* TODO: Decide if we actually need all these... I think we should leave them, at least for the 
-   msdos partition type. */
-
-/* NOTE: We will only read the first byte of the pointer, so I don't believe this can blow up
-   if someone decides to change the struct, only might begin showing wrong info. */
-typedef struct {
-        unsigned char   system;
-        int             boot;
-        int             hidden;
-        int             raid;
-        int             lvm;
-        int             lba;
-        int             palo;
-        int             prep;
-        void*      orig;                   /* We don't need this */
-} DosPartitionData;
-
-/* FIXME: This could lead to problems. I rely on the belief that the struct will change as little as
-   possible. If these strings are stored in memory as I believe they are, there is almost no possibility
-   that it leads to crashes if the struct changes */
-typedef struct {
-	char		volume_name[33];	/* eg: "Games" */
-	char		system_name[33];	/* eg: "Apple_Unix_SVR2" */
-	char		processor_name[17];
-
-	int		is_boot;
-	int		is_driver;
-	int		is_root;
-	int		is_swap;
-	int		is_lvm;
-	int		is_raid;
-
-	PedSector	data_region_length;
-	PedSector	boot_region_length;
-
-	long long	boot_base_address;
-	long long	boot_entry_address;
-	int		boot_checksum;
-
-	//uint32_t	status;
-	//uint32_t	driver_sig;
-} MacPartitionData;
-
-/* FIXME: This is temporary, make it better, split data into a seperate file */
-const char*
-get_disk_specific_system_name (PedPartition* part) {
-	if (!strcmp(part->disk->type->name,"msdos")) {
-		if (!part->disk_specific) return NULL;
-		DosPartitionData *pdata = (DosPartitionData *) part->disk_specific;
-		switch (pdata->system) {
-			/* TODO: I don't like some of the strings, change them */
-			case 0x00: return NULL;//return "Empty";
-			case 0x01: return "FAT12";
-			case 0x02: return "XENIX root";
-			case 0x03: return "XENIX usr";
-			case 0x04: return "Small FAT16";
-			case 0x05: return NULL;//return "Extended";
-			case 0x06: return "FAT16";
-			case 0x07: return "HPFS/NTFS";
-			case 0x08: return "AIX";
-			case 0x09: return "AIX bootable";
-			case 0x0a: return "OS/2 boot mgr";
-			case 0x0b: return "FAT32";
-			case 0x0c: return "FAT32 LBA";
-			case 0x0e: return "FAT16 LBA";
-			case 0x0f: return "Extended LBA";
-			case 0x10: return "OPUS";
-			case 0x11: return "Hidden FAT12";
-			case 0x12: return "Compaq diag";
-			case 0x14: return "Hidd Sm FAT16";
-			case 0x16: return "Hidd FAT16";
-			case 0x17: return "Hidd HPFS/NTFS";
-			case 0x18: return "AST SmartSleep";
-			case 0x1b: return "Hidd FAT32";
-			case 0x1c: return "Hidd FAT32 LBA";
-			case 0x1e: return "Hidd FAT16 LBA";
-			case 0x24: return "NEC DOS";
-			case 0x39: return "Plan 9";
-			case 0x3c: return "PMagic recovery";
-			case 0x40: return "Venix 80286";
-			case 0x41: return "PPC PReP Boot";
-			case 0x42: return "SFS";
-			case 0x4d: return "QNX4.x";
-			case 0x4e: return "QNX4.x 2nd part";
-			case 0x4f: return "QNX4.x 3rd part";
-			case 0x50: return "OnTrack DM";
-			case 0x51: return "OnTrackDM6 Aux1";
-			case 0x52: return "CP/M";
-			case 0x53: return "OnTrackDM6 Aux3";
-			case 0x54: return "OnTrack DM6";
-			case 0x55: return "EZ Drive";
-			case 0x56: return "Golden Bow";
-			case 0x5c: return "Priam Edisk";
-			case 0x61: return "SpeedStor";
-			case 0x63: return "GNU HURD/SysV";
-			case 0x64: return "Netware 286";
-			case 0x65: return "Netware 386";
-			case 0x70: return "DiskSec MltBoot";
-			case 0x75: return "PC/IX";
-			case 0x80: return "Minix <1.4a";
-			case 0x81: return "Minix >1.4b";
-			case 0x82: return "Linux swap";
-			case 0x83: return "Linux";
-			case 0x84: return "OS/2 hidden C:";
-			case 0x85: return "Linux extended";
-			case 0x86:
-			case 0x87: return "NTFS volume set";
-			case 0x88: return "Linux plaintext";
-			case 0x8e: return "Linux LVM";
-			case 0x93: return "Amoeba";
-			case 0x94: return "Amoeba BBT"; /*This guys created a seperate partition for badblocks?! */
-			case 0x9f: return "BSD/OS";
-			case 0xa0: return "Thinkpad hib";
-			case 0xa5: return "FreeBSD";
-			case 0xa6: return "OpenBSD";
-			case 0xa7: return "NeXTSTEP";
-			case 0xa8: return "Darwin UFS";
-			case 0xa9: return "NetBSD";
-			case 0xab: return "Darwin boot";
-			case 0xb7: return "BSDI fs";
-			case 0xb8: return "BSDI swap";
-			case 0xbb: return "Boot Wizard Hid"; /* Beware of the hidden wizard */
-			case 0xbe: return "Solaris boot";
-			case 0xbf: return "Solaris";
-			case 0xc1: return "DRDOS/2 FAT12";
-			case 0xc4: return "DRDOS/2 smFAT16";
-			case 0xc6: return "DRDOS/2 FAT16";
-			case 0xc7: return "Syrinx"; /* Reminds me of Rush - 2112 */
-			case 0xda: return "Non-FS data"; /* Whatever... */
-			case 0xdb: return "CP/M / CTOS";
-			case 0xde: return "Dell Utility";
-			case 0xdf: return "BootIt"; /* Should 0x20 be DontBootIt then? */
-			case 0xe1: return "DOS access";
-			case 0xe3: return "DOS R/O";
-			case 0xe4: return "SpeedStor"; /*I sense some strange déjà vu */
-			case 0xeb: return "BeOS fs";
-			case 0xee: return "EFI GPT";
-			case 0xef: return "EFI FAT";
-			case 0xf0: return "Lnx/PA-RISC bt";
-			case 0xf1: return "SpeedStor";
-			case 0xf2: return "DOS secondary";
-			case 0xf4: return "SpeedStor"; /* Are these guys trying for a Guinness record or something? */
-			case 0xfd: return "Lnx RAID auto";
-			case 0xfe: return "LANstep";
-			case 0xff: return "XENIX BBT";
-			default: return NULL;
-		}
-	}
-	else if (!strcmp(part->disk->type->name,"mac")) {
-		if (!part->disk_specific) return NULL;
-		MacPartitionData *pdata = (MacPartitionData *) part->disk_specific;
-		const char* type = pdata->system_name;
-		if (strncmp(type,"Apple_",6))
-			return NULL;
-		else {
-			int i;
-			static char buf[17];
-			for (i = 6; type[i] && i-6 < 16; i++) {
-				if (type[i] == '_')
-					buf[i-6] = ' ';
-				else
-					buf[i-6] = type[i];
-			}
-			buf[i-6] = '\0';
-			return buf;
-
-		}
-	}
-	else return NULL;
-}
-
 
 int
 _can_create_primary (const PedDisk* disk)
 	else return 0;
 }
 
+
+char*
+partition_print_flags (PedPartition* part)
+{
+        PedPartitionFlag        flag;
+        int                     first_flag;
+        const char*             name;
+        char*                   res = ped_malloc(1); 
+        void*                   _res = res;
+
+        *res = '\0';
+
+        first_flag = 1;
+        for (flag = ped_partition_flag_next (0); flag;
+             flag = ped_partition_flag_next (flag)) {
+                if (ped_partition_get_flag (part, flag)) {
+                        if (first_flag)
+                                first_flag = 0;
+                        else {
+                                _res = res;
+                                ped_realloc (&_res, strlen (res)
+                                                           + 1 + 2);
+                                res = _res;
+                                strncat (res, ", ", 2);
+                        }
+
+                        name = _(ped_partition_flag_get_name (flag));
+                        _res = res;
+                        ped_realloc (&_res, strlen (res) + 1
+                                                   + strlen (name));
+                        res = _res;
+                        strncat (res, name, 21);
+                }
+        }
+
+        return res;
+}
 extern int do_commit (PedDisk*, UICalls*);
 extern int do_maximize (PedDisk*, PedPartition*, UICalls*);
 
-/* Some extra functions */
-extern const char* get_disk_specific_system_name (PedPartition*);
+/* Additional functions */
+extern char* partition_print_flags (PedPartition*);
 
 #endif
+/*
+    GNU fdisk - a clone of Linux fdisk.
+
+    Copyright (C) 2006
+    Free Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+
+#include "../config.h"
+#include <string.h>
+#include <stdint.h>
+#include "hacks.h"
+
+#define MSDOS_HACK 1
+#define MAC_HACK 1
+#define SUN_HACK 1
+#define BSD_HACK 0
+#define DVH_HACK 0
+#define GPT_HACK 0 /* No, thank you */
+#define PC98_HACK 0
+#define AMIGA_HACK 0
+
+/* We need a function to get disk type-specific info about filesystem */
+/* TODO: Decide if we actually need all these... I think we should leave them, at least for the 
+   msdos partition type. */
+
+/* NOTE: We will only read the first byte of the pointer, so I don't believe this can blow up
+   if someone decides to change the struct, only might begin showing wrong info. */
+#if MSDOS_HACK
+typedef struct {
+        unsigned char   system;
+        int             boot;
+        int             hidden;
+        int             raid;
+        int             lvm;
+        int             lba;
+        int             palo;
+        int             prep;
+        void*      orig;                   /* We don't need this */
+} DosPartitionData;
+#endif
+
+#if MAC_HACK
+/* FIXME: This could lead to problems. I rely on the belief that the struct will change as little as
+   possible. If these strings are stored in memory as I believe they are, there is almost no possibility
+   that it leads to crashes if the struct changes */
+typedef struct {
+	char		volume_name[33];	/* eg: "Games" */
+	char		system_name[33];	/* eg: "Apple_Unix_SVR2" */
+	char		processor_name[17];
+
+	int		is_boot;
+	int		is_driver;
+	int		is_root;
+	int		is_swap;
+	int		is_lvm;
+	int		is_raid;
+
+	PedSector	data_region_length;
+	PedSector	boot_region_length;
+
+	long long	boot_base_address;
+	long long	boot_entry_address;
+	int		boot_checksum;
+
+	uint32_t	status;
+	uint32_t	driver_sig;
+} MacPartitionData;
+#endif
+
+#if SUN_HACK
+typedef struct {
+	u_int8_t		type;
+	int			is_boot;
+	int			is_root;
+	int			is_lvm;
+} SunPartitionData;
+#endif
+
+#if BSD_HACK
+typedef struct {
+	uint8_t		type;
+} BSDPartitionData;
+#endif
+
+#if DVH_HACK
+typedef struct  {
+	int	type;
+	//char	name[VDNAMESIZE + 1];	/* boot volumes only */
+	//int	real_file_size;		/* boot volumes only */
+} DVHPartitionData;
+#endif
+
+#if 0
+/* I don't think so... */
+typedef struct {
+        uint32_t time_low;
+        uint16_t time_mid;
+        uint16_t time_hi_and_version;
+        uint8_t  clock_seq_hi_and_reserved;
+        uint8_t  clock_seq_low;
+        uint8_t  node[6];
+} /* __attribute__ ((packed)) */ efi_guid_t;
+
+typedef struct {
+	efi_guid_t	type;
+	efi_guid_t	uuid;
+	char		name[37];
+	int		lvm;
+	int		raid;
+	int		boot;
+	int		hp_service;
+        int             hidden;
+        int             msftres;
+} GPTPartitionData;
+#endif
+
+#if PC98_HACK
+typedef struct {
+	PedSector	ipl_sector;
+	int		system;
+	int		boot;
+	int		hidden;
+	char		name [17];
+} PC98PartitionData;
+#endif
+
+#if AMIGA_HACK
+typedef struct {
+    uint32_t	pb_ID;			/* Identifier 32 bit word : 'PART' */
+    uint32_t	pb_SummedLongs;		/* Size of the structure for checksums */
+    int32_t	pb_ChkSum;		/* Checksum of the structure */
+    uint32_t	pb_HostID;		/* SCSI Target ID of host, not really used */
+    uint32_t	pb_Next;		/* Block number of the next PartitionBlock */
+    uint32_t	pb_Flags;		/* Part Flags (NOMOUNT and BOOTABLE) */
+    uint32_t	pb_Reserved1[2];
+    uint32_t	pb_DevFlags;		/* Preferred flags for OpenDevice */
+    char	pb_DriveName[32];	/* Preferred DOS device name: BSTR form */
+    uint32_t	pb_Reserved2[15];
+    uint32_t	de_TableSize;		/* Size of Environment vector */
+    uint32_t	de_SizeBlock;		/* Size of the blocks in 32 bit words, usually 128 */
+    uint32_t	de_SecOrg;	     	/* Not used; must be 0 */
+    uint32_t	de_Surfaces;		/* Number of heads (surfaces) */
+    uint32_t	de_SectorPerBlock;	/* Disk sectors per block, used with SizeBlock, usually 1 */
+    uint32_t	de_BlocksPerTrack;	/* Blocks per track. drive specific */
+    uint32_t	de_Reserved;		/* DOS reserved blocks at start of partition. */
+    uint32_t	de_PreAlloc;		/* DOS reserved blocks at end of partition */
+    uint32_t	de_Interleave;		/* Not used, usually 0 */
+    uint32_t	de_LowCyl;		/* First cylinder of the partition */
+    uint32_t	de_HighCyl;		/* Last cylinder of the partition */
+    uint32_t	de_NumBuffers;		/* Initial # DOS of buffers.  */
+    uint32_t	de_BufMemType;		/* Type of mem to allocate for buffers */
+    uint32_t	de_MaxTransfer;		/* Max number of bytes to transfer at a time */
+    uint32_t	de_Mask;		/* Address Mask to block out certain memory */
+    int32_t	de_BootPri;		/* Boot priority for autoboot */
+    uint32_t	de_DosType;		/* Dostype of the file system */
+    uint32_t	de_Baud;		/* Baud rate for serial handler */
+    uint32_t	de_Control;		/* Control word for handler/filesystem */
+    uint32_t	de_BootBlocks;		/* Number of blocks containing boot code */
+    uint32_t	pb_EReserved[12];
+} AmigaPartitionData;
+#endif
+
+/* FIXME: This is temporary, make it better, split data into a seperate file */
+const char*
+get_disk_specific_system_name (PedPartition* part) {
+	if (!part->disk_specific) return NULL;
+	#if MSDOS_HACK
+	if (!strcmp(part->disk->type->name,"msdos")) {
+		DosPartitionData *pdata = (DosPartitionData *) part->disk_specific;
+		switch (pdata->system) {
+			/* TODO: I don't like some of the strings, change them */
+			case 0x00: return NULL;//return "Empty";
+			case 0x01: return "FAT12";
+			case 0x02: return "XENIX root";
+			case 0x03: return "XENIX usr";
+			case 0x04: return "Small FAT16";
+			case 0x05: return NULL;//return "Extended";
+			case 0x06: return "FAT16";
+			case 0x07: return "HPFS/NTFS";
+			case 0x08: return "AIX";
+			case 0x09: return "AIX bootable";
+			case 0x0a: return "OS/2 boot mgr";
+			case 0x0b: return "FAT32";
+			case 0x0c: return "FAT32 LBA";
+			case 0x0e: return "FAT16 LBA";
+			case 0x0f: return "Extended LBA";
+			case 0x10: return "OPUS";
+			case 0x11: return "Hidden FAT12";
+			case 0x12: return "Compaq diag";
+			case 0x14: return "Hidd Sm FAT16";
+			case 0x16: return "Hidd FAT16";
+			case 0x17: return "Hidd HPFS/NTFS";
+			case 0x18: return "AST SmartSleep";
+			case 0x1b: return "Hidd FAT32";
+			case 0x1c: return "Hidd FAT32 LBA";
+			case 0x1e: return "Hidd FAT16 LBA";
+			case 0x24: return "NEC DOS";
+			case 0x39: return "Plan 9";
+			case 0x3c: return "PMagic recovery";
+			case 0x40: return "Venix 80286";
+			case 0x41: return "PPC PReP Boot";
+			case 0x42: return "SFS";
+			case 0x4d: return "QNX4.x";
+			case 0x4e: return "QNX4.x 2nd part";
+			case 0x4f: return "QNX4.x 3rd part";
+			case 0x50: return "OnTrack DM";
+			case 0x51: return "OnTrackDM6 Aux1";
+			case 0x52: return "CP/M";
+			case 0x53: return "OnTrackDM6 Aux3";
+			case 0x54: return "OnTrack DM6";
+			case 0x55: return "EZ Drive";
+			case 0x56: return "Golden Bow";
+			case 0x5c: return "Priam Edisk";
+			case 0x61: return "SpeedStor";
+			case 0x63: return "GNU HURD/SysV";
+			case 0x64: return "Netware 286";
+			case 0x65: return "Netware 386";
+			case 0x70: return "DiskSec MltBoot";
+			case 0x75: return "PC/IX";
+			case 0x80: return "Minix <1.4a";
+			case 0x81: return "Minix >1.4b";
+			case 0x82: return "Linux swap";
+			case 0x83: return "Linux";
+			case 0x84: return "OS/2 hidden C:";
+			case 0x85: return "Linux extended";
+			case 0x86:
+			case 0x87: return "NTFS volume set";
+			case 0x88: return "Linux plaintext";
+			case 0x8e: return "Linux LVM";
+			case 0x93: return "Amoeba";
+			case 0x94: return "Amoeba BBT"; /*This guys created a seperate partition for badblocks?! */
+			case 0x9f: return "BSD/OS";
+			case 0xa0: return "Thinkpad hib";
+			case 0xa5: return "FreeBSD";
+			case 0xa6: return "OpenBSD";
+			case 0xa7: return "NeXTSTEP";
+			case 0xa8: return "Darwin UFS";
+			case 0xa9: return "NetBSD";
+			case 0xab: return "Darwin boot";
+			case 0xb7: return "BSDI fs";
+			case 0xb8: return "BSDI swap";
+			case 0xbb: return "Boot Wizard Hid"; /* Beware of the hidden wizard */
+			case 0xbe: return "Solaris boot";
+			case 0xbf: return "Solaris";
+			case 0xc1: return "DRDOS/2 FAT12";
+			case 0xc4: return "DRDOS/2 smFAT16";
+			case 0xc6: return "DRDOS/2 FAT16";
+			case 0xc7: return "Syrinx"; /* Reminds me of Rush - 2112 */
+			case 0xda: return "Non-FS data"; /* Whatever... */
+			case 0xdb: return "CP/M / CTOS";
+			case 0xde: return "Dell Utility";
+			case 0xdf: return "BootIt"; /* Should 0x20 be DontBootIt then? */
+			case 0xe1: return "DOS access";
+			case 0xe3: return "DOS R/O";
+			case 0xe4: return "SpeedStor"; /*I sense some strange déjà vu */
+			case 0xeb: return "BeOS fs";
+			case 0xee: return "EFI GPT";
+			case 0xef: return "EFI FAT";
+			case 0xf0: return "Lnx/PA-RISC bt";
+			case 0xf1: return "SpeedStor";
+			case 0xf2: return "DOS secondary";
+			case 0xf4: return "SpeedStor"; /* Are these guys trying for a Guinness record or something? */
+			case 0xfd: return "Lnx RAID auto";
+			case 0xfe: return "LANstep";
+			case 0xff: return "XENIX BBT";
+			default: return NULL;
+		}
+	}
+	else
+	#endif
+	#if MAC_HACK
+	if (!strcmp(part->disk->type->name,"mac")) {
+		MacPartitionData *pdata = (MacPartitionData *) part->disk_specific;
+		const char* type = pdata->system_name;
+		if (strncmp(type,"Apple_",6))
+			return NULL;
+		else {
+			int i;
+			static char buf[17];
+			for (i = 6; type[i] && i-6 < 16; i++) {
+				if (type[i] == '_')
+					buf[i-6] = ' ';
+				else
+					buf[i-6] = type[i];
+			}
+			buf[i-6] = '\0';
+			return buf;
+
+		}
+	}
+	else
+	#endif
+	return NULL;
+}
+/* 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; \
+		if (size) \
+			*size = sizeof(pdata->type_var); \
+		return pdata->type_var; \
+	}
+unsigned int
+get_disk_specific_system_type (PedPartition *part, int *size) {
+	if (!part->disk_specific) {
+		*size = 0;
+		return 0;
+	}
+	#if MSDOS_HACK
+	return_system_type("msdos",DosPartitionData,system);
+	#endif
+	#if SUN_HACK
+	return_system_type("sun",SunPartitionData,type);
+	#endif
+	#if BSD_HACK
+	return_system_type("bsd",BSDPartitionData,type);
+	#endif
+	#if DVH_HACK
+	/* OK, here type is int... Hope we don't break anything... */
+	return_system_type("dvh",DVHPartitionData,type);
+	#endif
+	#if PC98_HACK
+	/* OK, here type is int... Hope we don't break anything... */
+	return_system_type("pc98",PC98PartitionData,system);
+	#endif
+	#if AMIGA_HACK
+	return_system_type("amiga",AmigaPartitionData,de_DosType);
+	#endif
+	{
+		*size = 0;
+		return 0;
+	}
+	
+}
+/*
+    GNU fdisk - a clone of Linux fdisk.
+
+    Copyright (C) 2006
+    Free Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+*/
+
+#ifndef HACKS_H_INCLUDED
+#define HACKS_H_INCLUDED
+#include <parted/parted.h>
+
+extern const char* get_disk_specific_system_name (PedPartition*);
+extern unsigned int get_disk_specific_system_type (PedPartition *part, int *size);
+#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.