Anonymous avatar Anonymous committed c98e0f6

Implement changing system type and basic display of the "system type" on a msdos label. (fdisk@sv.gnu.org/fdisk--main--0--patch-14)
fdisk@sv.gnu.org/fdisk--main--0--patch-14
Keywords:

Comments (0)

Files changed (3)

 typedef enum _MenuOptions MenuOptions;
 
 #define TINYBUF 16	/* NOTE: Changing this may lead to segfaults. Double-check. */
+#define FSBUF 19	/* Don't touch unless you know what you are doing!! */
 #define SMALLBUF 128
 
 
 		{ 0, NULL, NULL }
 	};
 	int key;
-	//menu_title(_("Choose the display unit type"));
+	//menu_title(_("Choose the display unit type")); /* Heh, no place for a title, heh */
 	key = do_menu(units, 9, MENU_BUTTON, "1234567890abcde", 1);
 	switch (key) {
 		case '1': ped_unit_set_default(PED_UNIT_SECTOR); return 1;
 	}
 }
 
+/* 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) {
+	static MenuItem type_menu[] = {
+		{ 'f', N_("Auto"), N_("Try to automatically set the correct type") },
+		{ 'c', N_("Custom"), N_("Select a custom filesystem type (for experts only)") },
+		{ ESC, N_("Cancel"), N_("Do not change the filesystem type") },
+		{ 0, NULL, NULL }
+	};
+	static char keys [] = { 'f', 'c', ESC, '\0' };
+	const PedFileSystemType *type = NULL;
+	int key;
+	menu_title(_("Set the filesystem type of the partition")); 
+	key = do_menu(type_menu, 8, MENU_BUTTON | MENU_TITLE, keys, 0);
+
+	if (key == ESC)
+		return 0;
+	else if (key == 'f')
+		type = ped_file_system_probe(&(*part)->geom);
+	if (!do_set_system(disk,*part,type,&uiquery)) {
+		warning_waitkey(N_("Couldn't change the filesystem type"));
+		return 0;
+	}
+	return 1;
+}
+
 /* Here we begin with flag editing */
 static void
 printaflag (int *y, const PedPartition *part, PedPartitionFlag flag, PedPartitionFlag selected) {
 plist_draw (PedDisk *cdisk, PedPartition *selected, int selnum, int *start) {
 	PedPartition *part;
 	const char* temp;
-	char buf[SMALLBUF];
+	char buf[SMALLBUF],fsbuf[FSBUF];
 	int col_label = ((float)53/(80-col_fs))*(COLS-col_fs);
 	int col_size = ((float)66/(80-col_fs))*(COLS-col_fs);
 	int n,i,x,y = INFOSIZE;
 
 		snprintf(buf, SMALLBUF, "%-*s", col_fs-col_type, temp);
 		mvaddstr(y,col_type,buf);
-
-		temp = "";
-		if(part->fs_type)
-			temp = part->fs_type->name;
+		temp = NULL;
 		if (free)
 			temp = _("Free space");
+		else if(part->fs_type)
+			temp = part->fs_type->name;
+		if (temp) {
+			snprintf(buf, SMALLBUF, "%-*s", col_label-col_fs, temp);
+		} else {
+			temp = get_disk_specific_system_name(part);
+			if (temp) {
+				snprintf(fsbuf, FSBUF, "[%s]", temp);
+				temp = fsbuf;
+			} else {
+				temp = "";
+			}
+		}
 		snprintf(buf, SMALLBUF, "%-*s", col_label-col_fs, temp);
+			
 
+		
 		mvaddstr(y,col_fs,buf);
 		temp = NULL;
 		if (ped_disk_type_check_feature(cdisk->type,PED_DISK_TYPE_PARTITION_NAME) && !free)
 		//redraw = 1;
 		key = 0;
 	}
+	else if (key == 't') {
+		action_type(part);
+		//redraw = 0;
+		key = 0;
+	}
 	else {
 		warning_waitkey("Unimplemented");	 /* TODO */
 		key = 0;
 	return 1;
 }
 
+/* We need a function to get disk type-specific info about filesystem, for now only for msdos */
+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 is temporary, make it better, split data into a seperate file */
+const char*
+get_disk_specific_system_name (PedPartition* part) {
+	DosPartitionData *pdata;
+	if (!strcmp(part->disk->type->name,"msdos")) {
+		if (!part->disk_specific) return NULL;
+		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 return NULL;
+}
+
 
 int
 _can_create_primary (const PedDisk* disk)
         }
 
         if (!fs_type) {
-                if (!get_fs_type (_("File system type?"), &fs_type, 1, uiquery))
+                if (!get_fs_type (_("File system type"), &fs_type, 1, uiquery))
                         return 0;
         }
 	if (!do_mkpart(disk,start,end,part_type,fs_type,&part,opts,uiquery))
 }
 
 int
+do_set_system (PedDisk* disk, PedPartition* part, const PedFileSystemType *type, UICalls *uiquery)
+{
+	if (!disk)
+		return 0;
+	if (!part)
+		if (!get_partition(_("Partition"), disk, &part, uiquery))
+			return 0;
+	if (!type) {
+		if (!get_fs_type (_("File system type"), &type, 0, uiquery))
+			return 0;
+	}
+	/* FIXME: Is this needed? We don't touch the partition itself */
+	if (!_partition_warn_busy(part))
+		return 0;
+	if (!ped_partition_set_system(part,type))
+		return 0;
+	uiquery->need_commit = 1;
+	return 1;
+}
+
+
+int
 do_set (PedDisk *disk, PedPartition *part, PedPartitionFlag flag, UIOpts opts, UICalls *uiquery)
 {
         int                     state;
 	int need_commit;
 };
 
+
 typedef enum _UIOpts UIOpts;
 enum _UIOpts {
 	UI_DEFAULT = 0,
 extern int do_rescue (PedDisk*, PedSector start, PedSector end, UIOpts, UICalls *);
 extern int do_resize (PedDisk*, PedPartition*, PedSector start, PedSector end, UIOpts, UICalls*);
 extern int do_rm (PedDisk*, PedPartition*, UICalls*);
+extern int do_set_system (PedDisk*, PedPartition*, const PedFileSystemType*, UICalls*);
 extern int do_set (PedDisk*, PedPartition*, PedPartitionFlag, UIOpts, UICalls*);
 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*);
+
 #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.