From: krw Date: Fri, 31 Mar 2023 19:12:32 +0000 (+0000) Subject: Refactor partition type menu code, disentangling mbr and gpt X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7d91647159257b31a2d233274299e309bd81844e;p=openbsd Refactor partition type menu code, disentangling mbr and gpt partition types from menu building and display. Some GPT partition names change to match their MBR bretheren. No intentional functional change. --- diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index 53c08698050..5fb1a670f05 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.146 2023/03/31 14:41:08 krw Exp $ */ +/* $OpenBSD: part.c,v 1.147 2023/03/31 19:12:32 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -33,7 +33,7 @@ struct mbr_type { int mt_type; - char *mt_name; + char *mt_desc; }; /* @@ -43,109 +43,108 @@ struct mbr_type { * https://www.win.tue.nl/~aeb/partitions/partition_types-1.html */ const struct mbr_type mbr_types[] = { - { 0x00, "unused" }, /* unused */ - { 0x01, "DOS FAT-12" }, /* Primary DOS with 12 bit FAT */ - { 0x02, "XENIX /" }, /* XENIX / filesystem */ - { 0x03, "XENIX /usr" }, /* XENIX /usr filesystem */ - { 0x04, "DOS FAT-16" }, /* Primary DOS with 16 bit FAT */ - { 0x05, "Extended DOS" }, /* Extended DOS */ - { 0x06, "DOS > 32MB" }, /* Primary 'big' DOS (> 32MB) */ - { 0x07, "NTFS" }, /* NTFS */ - { 0x08, "AIX fs" }, /* AIX filesystem */ - { 0x09, "AIX/Coherent" }, /* AIX boot partition or Coherent */ - { 0x0A, "OS/2 Bootmgr" }, /* OS/2 Boot Manager or OPUS */ - { 0x0B, "Win95 FAT-32" }, /* Primary Win95 w/ 32-bit FAT */ - { 0x0C, "Win95 FAT32L" }, /* Primary Win95 w/ 32-bit FAT LBA-mapped */ - { 0x0E, "DOS FAT-16" }, /* Primary DOS w/ 16-bit FAT, CHS-mapped */ - { 0x0F, "Extended LBA" }, /* Extended DOS LBA-mapped */ - { 0x10, "OPUS" }, /* OPUS */ - { 0x11, "OS/2 hidden" }, /* OS/2 BM: hidden DOS 12-bit FAT */ - { 0x12, "Compaq Diag" }, /* Compaq Diagnostics */ - { 0x14, "OS/2 hidden" }, /* OS/2 BM: hidden DOS 16-bit FAT <32M or Novell DOS 7.0 bug */ - { 0x16, "OS/2 hidden" }, /* OS/2 BM: hidden DOS 16-bit FAT >=32M */ - { 0x17, "OS/2 hidden" }, /* OS/2 BM: hidden IFS */ - { 0x18, "AST swap" }, /* AST Windows swapfile */ - { 0x19, "Willowtech" }, /* Willowtech Photon coS */ - { 0x1C, "ThinkPad Rec" }, /* IBM ThinkPad recovery partition */ - { 0x20, "Willowsoft" }, /* Willowsoft OFS1 */ - { 0x24, "NEC DOS" }, /* NEC DOS */ - { 0x27, "Win Recovery" }, /* Windows hidden Recovery Partition */ - { 0x38, "Theos" }, /* Theos */ - { 0x39, "Plan 9" }, /* Plan 9 */ - { 0x40, "VENIX 286" }, /* VENIX 286 or LynxOS */ - { 0x41, "Lin/Minux DR" }, /* Linux/MINIX (sharing disk with DRDOS) or Personal RISC boot */ - { 0x42, "LinuxSwap DR" }, /* SFS or Linux swap (sharing disk with DRDOS) */ - { 0x43, "Linux DR" }, /* Linux native (sharing disk with DRDOS) */ - { 0x4D, "QNX 4.2 Pri" }, /* QNX 4.2 Primary */ - { 0x4E, "QNX 4.2 Sec" }, /* QNX 4.2 Secondary */ - { 0x4F, "QNX 4.2 Ter" }, /* QNX 4.2 Tertiary */ - { 0x50, "DM" }, /* DM (disk manager) */ - { 0x51, "DM" }, /* DM6 Aux1 (or Novell) */ - { 0x52, "CP/M or SysV" }, /* CP/M or Microport SysV/AT */ - { 0x53, "DM" }, /* DM6 Aux3 */ - { 0x54, "Ontrack" }, /* Ontrack */ - { 0x55, "EZ-Drive" }, /* EZ-Drive (disk manager) */ - { 0x56, "Golden Bow" }, /* Golden Bow (disk manager) */ - { 0x5C, "Priam" }, /* Priam Edisk (disk manager) */ - { 0x61, "SpeedStor" }, /* SpeedStor */ - { 0x63, "ISC, HURD, *" }, /* ISC, System V/386, GNU HURD or Mach */ - { 0x64, "NetWare 2.xx" }, /* Novell NetWare 2.xx */ - { 0x65, "NetWare 3.xx" }, /* Novell NetWare 3.xx */ - { 0x66, "NetWare 386" }, /* Novell 386 NetWare */ - { 0x67, "Novell" }, /* Novell */ - { 0x68, "Novell" }, /* Novell */ - { 0x69, "Novell" }, /* Novell */ - { 0x70, "DiskSecure" }, /* DiskSecure Multi-Boot */ - { 0x75, "PCIX" }, /* PCIX */ - { 0x80, "Minix (old)" }, /* Minix 1.1 ... 1.4a */ - { 0x81, "Minix (new)" }, /* Minix 1.4b ... 1.5.10 */ - { 0x82, "Linux swap" }, /* Linux swap */ - { 0x83, "Linux files*" }, /* Linux filesystem */ - { 0x84, "OS/2 hidden" }, /* OS/2 hidden C: drive */ - { 0x85, "Linux ext." }, /* Linux extended */ - { 0x86, "NT FAT VS" }, /* NT FAT volume set */ - { 0x87, "NTFS VS" }, /* NTFS volume set or HPFS mirrored */ - { 0x8E, "Linux LVM" }, /* Linux LVM */ - { 0x93, "Amoeba FS" }, /* Amoeba filesystem */ - { 0x94, "Amoeba BBT" }, /* Amoeba bad block table */ - { 0x99, "Mylex" }, /* Mylex EISA SCSI */ - { 0x9F, "BSDI" }, /* BSDI BSD/OS */ - { 0xA0, "NotebookSave" }, /* Phoenix NoteBIOS save-to-disk */ - { 0xA5, "FreeBSD" }, /* FreeBSD */ - { 0xA6, "OpenBSD" }, /* OpenBSD */ - { 0xA7, "NEXTSTEP" }, /* NEXTSTEP */ - { 0xA8, "MacOS X" }, /* MacOS X main partition */ - { 0xA9, "NetBSD" }, /* NetBSD */ - { 0xAB, "MacOS X boot" }, /* MacOS X boot partition */ - { 0xAF, "MacOS X HFS+" }, /* MacOS X HFS+ partition */ - { 0xB7, "BSDI filesy*" }, /* BSDI BSD/386 filesystem */ - { 0xB8, "BSDI swap" }, /* BSDI BSD/386 swap */ - { 0xBF, "Solaris" }, /* Solaris */ - { 0xC0, "CTOS" }, /* CTOS */ - { 0xC1, "DRDOSs FAT12" }, /* DRDOS/sec (FAT-12) */ - { 0xC4, "DRDOSs < 32M" }, /* DRDOS/sec (FAT-16, < 32M) */ - { 0xC6, "DRDOSs >=32M" }, /* DRDOS/sec (FAT-16, >= 32M) */ - { 0xC7, "HPFS Disbled" }, /* Syrinx (Cyrnix?) or HPFS disabled */ - { 0xDB, "CPM/C.DOS/C*" }, /* Concurrent CPM or C.DOS or CTOS */ - { 0xDE, "Dell Maint" }, /* Dell maintenance partition */ - { 0xE1, "SpeedStor" }, /* DOS access or SpeedStor 12-bit FAT extended partition */ - { 0xE3, "SpeedStor" }, /* DOS R/O or SpeedStor or Storage Dimensions */ - { 0xE4, "SpeedStor" }, /* SpeedStor 16-bit FAT extended partition < 1024 cyl. */ - { 0xEB, "BeOS/i386" }, /* BeOS for Intel */ - { 0xEE, "EFI GPT" }, /* EFI Protective Partition */ - { 0xEF, "EFI Sys" }, /* EFI System Partition */ - { 0xF1, "SpeedStor" }, /* SpeedStor or Storage Dimensions */ - { 0xF2, "DOS 3.3+ Sec" }, /* DOS 3.3+ Secondary */ - { 0xF4, "SpeedStor" }, /* SpeedStor >1024 cyl. or LANstep or IBM PS/2 IML */ - { 0xFF, "Xenix BBT" }, /* Xenix Bad Block Table */ + { 0x00, NULL }, /* unused */ + { 0x01, NULL }, /* Primary DOS with 12 bit FAT */ + { 0x02, NULL }, /* XENIX / filesystem */ + { 0x03, NULL }, /* XENIX /usr filesystem */ + { 0x04, NULL }, /* Primary DOS with 16 bit FAT */ + { 0x05, NULL }, /* Extended DOS */ + { 0x06, NULL }, /* Primary 'big' DOS (> 32MB) */ + { 0x07, NULL }, /* NTFS */ + { 0x08, NULL }, /* AIX filesystem */ + { 0x09, NULL }, /* AIX boot partition or Coherent */ + { 0x0A, NULL }, /* OS/2 Boot Manager or OPUS */ + { 0x0B, NULL }, /* Primary Win95 w/ 32-bit FAT */ + { 0x0C, NULL }, /* Primary Win95 w/ 32-bit FAT LBA-mapped */ + { 0x0E, NULL }, /* Primary DOS w/ 16-bit FAT, CHS-mapped */ + { 0x0F, NULL }, /* Extended DOS LBA-mapped */ + { 0x10, NULL }, /* OPUS */ + { 0x11, NULL }, /* OS/2 BM: hidden DOS 12-bit FAT */ + { 0x12, NULL }, /* Compaq Diagnostics */ + { 0x14, NULL }, /* OS/2 BM: hidden DOS 16-bit FAT <32M or Novell DOS 7.0 bug */ + { 0x16, NULL }, /* OS/2 BM: hidden DOS 16-bit FAT >=32M */ + { 0x17, NULL }, /* OS/2 BM: hidden IFS */ + { 0x18, NULL }, /* AST Windows swapfile */ + { 0x19, NULL }, /* Willowtech Photon coS */ + { 0x1C, NULL }, /* IBM ThinkPad recovery partition */ + { 0x20, NULL }, /* Willowsoft OFS1 */ + { 0x24, NULL }, /* NEC DOS */ + { 0x27, NULL }, /* Windows hidden Recovery Partition */ + { 0x38, NULL }, /* Theos */ + { 0x39, NULL }, /* Plan 9 */ + { 0x40, NULL }, /* VENIX 286 or LynxOS */ + { 0x41, NULL }, /* Linux/MINIX (sharing disk with DRDOS) or Personal RISC boot */ + { 0x42, NULL }, /* SFS or Linux swap (sharing disk with DRDOS) */ + { 0x43, NULL }, /* Linux native (sharing disk with DRDOS) */ + { 0x4D, NULL }, /* QNX 4.2 Primary */ + { 0x4E, NULL }, /* QNX 4.2 Secondary */ + { 0x4F, NULL }, /* QNX 4.2 Tertiary */ + { 0x50, NULL }, /* DM (disk manager) */ + { 0x51, NULL }, /* DM6 Aux1 (or Novell) */ + { 0x52, NULL }, /* CP/M or Microport SysV/AT */ + { 0x53, NULL }, /* DM6 Aux3 */ + { 0x54, NULL }, /* Ontrack */ + { 0x55, NULL }, /* EZ-Drive (disk manager) */ + { 0x56, NULL }, /* Golden Bow (disk manager) */ + { 0x5C, NULL }, /* Priam Edisk (disk manager) */ + { 0x61, NULL }, /* SpeedStor */ + { 0x63, NULL }, /* ISC, System V/386, GNU HURD or Mach */ + { 0x64, NULL }, /* Novell NetWare 2.xx */ + { 0x65, NULL }, /* Novell NetWare 3.xx */ + { 0x66, NULL }, /* Novell 386 NetWare */ + { 0x67, NULL }, /* Novell */ + { 0x68, NULL }, /* Novell */ + { 0x69, NULL }, /* Novell */ + { 0x70, NULL }, /* DiskSecure Multi-Boot */ + { 0x75, NULL }, /* PCIX */ + { 0x80, NULL }, /* Minix 1.1 ... 1.4a */ + { 0x81, NULL }, /* Minix 1.4b ... 1.5.10 */ + { 0x82, NULL }, /* Linux swap */ + { 0x83, NULL }, /* Linux filesystem */ + { 0x84, NULL }, /* OS/2 hidden C: drive */ + { 0x85, NULL }, /* Linux extended */ + { 0x86, NULL }, /* NT FAT volume set */ + { 0x87, NULL }, /* NTFS volume set or HPFS mirrored */ + { 0x8E, NULL }, /* Linux LVM */ + { 0x93, NULL }, /* Amoeba filesystem */ + { 0x94, NULL }, /* Amoeba bad block table */ + { 0x99, NULL }, /* Mylex EISA SCSI */ + { 0x9F, NULL }, /* BSDI BSD/OS */ + { 0xA0, NULL }, /* Phoenix NoteBIOS save-to-disk */ + { 0xA5, NULL }, /* FreeBSD */ + { 0xA6, NULL }, /* OpenBSD */ + { 0xA7, NULL }, /* NEXTSTEP */ + { 0xA8, NULL }, /* MacOS X main partition */ + { 0xA9, NULL }, /* NetBSD */ + { 0xAB, NULL }, /* MacOS X boot partition */ + { 0xAF, NULL }, /* MacOS X HFS+ partition */ + { 0xB7, NULL }, /* BSDI BSD/386 filesystem */ + { 0xB8, NULL }, /* BSDI BSD/386 swap */ + { 0xBF, NULL }, /* Solaris */ + { 0xC0, NULL }, /* CTOS */ + { 0xC1, NULL }, /* DRDOS/sec (FAT-12) */ + { 0xC4, NULL }, /* DRDOS/sec (FAT-16, < 32M) */ + { 0xC6, NULL }, /* DRDOS/sec (FAT-16, >= 32M) */ + { 0xC7, NULL }, /* Syrinx (Cyrnix?) or HPFS disabled */ + { 0xDB, NULL }, /* Concurrent CPM or C.DOS or CTOS */ + { 0xDE, NULL }, /* Dell maintenance partition */ + { 0xE1, NULL }, /* DOS access or SpeedStor 12-bit FAT extended partition */ + { 0xE3, NULL }, /* DOS R/O or SpeedStor or Storage Dimensions */ + { 0xE4, NULL }, /* SpeedStor 16-bit FAT extended partition < 1024 cyl. */ + { 0xEB, NULL }, /* BeOS for Intel */ + { 0xEE, NULL }, /* EFI Protective Partition */ + { 0xEF, NULL }, /* EFI System Partition */ + { 0xF1, NULL }, /* SpeedStor or Storage Dimensions */ + { 0xF2, NULL }, /* DOS 3.3+ Secondary */ + { 0xF4, NULL }, /* SpeedStor >1024 cyl. or LANstep or IBM PS/2 IML */ + { 0xFF, NULL }, /* Xenix Bad Block Table */ }; struct gpt_type { - int gt_menuid; int gt_attr; #define GTATTR_PROTECT (1 << 0) #define GTATTR_PROTECT_EFISYS (1 << 1) - char *gt_name; + char *gt_desc; char *gt_guid; }; @@ -165,81 +164,202 @@ char * const EFI_SYSTEM_PARTITION_GUID = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"; char * const MICROSOFT_BASIC_DATA_GUID = "ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"; const struct gpt_type gpt_types[] = { - { 0x00, 0, "unused", + { 0, + NULL, /* Unused */ "00000000-0000-0000-0000-000000000000" }, - { 0x01, 0, "FAT12", - MICROSOFT_BASIC_DATA_GUID }, - { 0x04, 0, "FAT16S", - MICROSOFT_BASIC_DATA_GUID }, - { 0x06, 0, "FAT16B", - MICROSOFT_BASIC_DATA_GUID }, - { 0x07, 0, "NTFS", - MICROSOFT_BASIC_DATA_GUID }, - { 0x0B, 0, "FAT32", - MICROSOFT_BASIC_DATA_GUID }, - { 0x0C, 0, "FAT32L", - MICROSOFT_BASIC_DATA_GUID }, - { 0x0D, GTATTR_PROTECT, "BIOS Boot", - "21686148-6449-6e6f-744e-656564454649" }, - { 0x0E, 0, "FAT16L", - MICROSOFT_BASIC_DATA_GUID }, - { 0x11, 0, "OS/2 hidden", - MICROSOFT_BASIC_DATA_GUID }, - { 0x14, 0, "OS/2 hidden", - MICROSOFT_BASIC_DATA_GUID }, - { 0x16, 0, "OS/2 hidden", - MICROSOFT_BASIC_DATA_GUID }, - { 0x17, 0, "OS/2 hidden", - MICROSOFT_BASIC_DATA_GUID }, - { 0x1C, 0, "ThinkPad Rec", - MICROSOFT_BASIC_DATA_GUID }, - { 0x27, 0, "Win Recovery", - "de94bba4-06d1-4d40-a16a-bfd50179d6ac" }, - { 0x42, 0, "LinuxSwap DR", - "af9b60a0-1431-4f62-bc68-3311714a69ad" }, - { 0x7f, 0, "ChromeKernel", - "fe3a2a5d-4f32-41a7-b725-accc3285a309" }, - { 0x82, 0, "Linux swap", + { 0, + NULL, /* Legacy MBR */ + "024dee41-33e7-11d3-9d69-0008c781f39f" }, + { 0, + NULL, /* Linux swap */ "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f" }, - { 0x83, 0, "Linux files*", + { 0, + NULL, /* Linux files* */ "0fc63daf-8483-4772-8e79-3d69d8477de4" }, - { 0x8E, 0, "Linux LVM", - "e6d6d379-f507-44c2-a23c-238f2a3df928" }, - { 0xA5, 0, "FreeBSD", - "516e7cb4-6ecf-11d6-8ff8-00022d09712b" }, - { 0xA6, 0, "OpenBSD", - "824cc7a0-36a8-11e3-890a-952519ad3f61" }, - { 0xA8, 0, "MacOS X", - "55465300-0000-11aa-aa11-00306543ecac" }, - { 0xA9, 0, "NetBSD", - "49f48d5a-b10e-11dc-b99b-0019d1879648" }, - { 0xAB, 0, "MacOS X boot", + { GTATTR_PROTECT, + NULL, /* BIOS Boot */ + "21686148-6449-6e6f-744e-656564454649" }, + { GTATTR_PROTECT, + NULL, /* HiFive BBL */ + "2e54b353-1271-4842-806f-e436d6af6985" }, + { 0, + NULL, /* BeOS/i386 */ + "42465331-3ba3-10f1-802a-4861696b7521" }, + { 0, + NULL, /* MacOS X boot */ "426f6f74-0000-11aa-aa11-00306543ecac" }, - { 0xAF, 0, "MacOS X HFS+", + { 0, + NULL, /* MacOS X HFS+ */ "48465300-0000-11aa-aa11-00306543ecac" }, - { 0xB0, GTATTR_PROTECT | GTATTR_PROTECT_EFISYS, "APFS", - "7c3457ef-0000-11aa-aa11-00306543ecac" }, - { 0xB1, GTATTR_PROTECT | GTATTR_PROTECT_EFISYS, "APFS ISC", - "69646961-6700-11aa-aa11-00306543ecac" }, - { 0xB2, GTATTR_PROTECT | GTATTR_PROTECT_EFISYS, "APFS Recovery", + { 0, + NULL, /* NetBSD */ + "49f48d5a-b10e-11dc-b99b-0019d1879648" }, + { 0, + NULL, /* FreeBSD */ + "516e7cb4-6ecf-11d6-8ff8-00022d09712b" }, + { GTATTR_PROTECT | GTATTR_PROTECT_EFISYS, + NULL, /* APFS Recovery */ "52637672-7900-11aa-aa11-00306543ecac" }, - { 0xB3, GTATTR_PROTECT, "HiFive FSBL", + { 0, + NULL, /* MacOS X */ + "55465300-0000-11aa-aa11-00306543ecac" }, + { GTATTR_PROTECT, + NULL, /* HiFive FSBL */ "5b193300-fc78-40cd-8002-e86c45580b47" }, - { 0xB4, GTATTR_PROTECT, "HiFive BBL", - "2e54b353-1271-4842-806f-e436d6af6985" }, - { 0xBF, 0, "Solaris", + { GTATTR_PROTECT | GTATTR_PROTECT_EFISYS, + NULL, /* APFS ISC */ + "69646961-6700-11aa-aa11-00306543ecac" }, + { 0, + NULL, /* Solaris */ "6a85cf4d-1dd2-11b2-99a6-080020736631" }, - { 0xEB, 0, "BeOS/i386", - "42465331-3ba3-10f1-802a-4861696b7521" }, - { 0xEC, 0, "Legacy MBR", - "024dee41-33e7-11d3-9d69-0008c781f39f" }, - { 0xEF, 0, "EFI Sys", + { GTATTR_PROTECT | GTATTR_PROTECT_EFISYS, + NULL, /* APFS */ + "7c3457ef-0000-11aa-aa11-00306543ecac" }, + { 0, + NULL, /* OpenBSD */ + "824cc7a0-36a8-11e3-890a-952519ad3f61" }, + { 0, + NULL, /* LinuxSwap DR */ + "af9b60a0-1431-4f62-bc68-3311714a69ad" }, + { 0, + NULL, /* EFI Sys */ EFI_SYSTEM_PARTITION_GUID }, + { 0, + NULL, /* Win Recovery*/ + "de94bba4-06d1-4d40-a16a-bfd50179d6ac" }, + { 0, + NULL, /* Linux VM */ + "e6d6d379-f507-44c2-a23c-238f2a3df928" }, + { 0, + NULL, /* Microsoft basic data */ + MICROSOFT_BASIC_DATA_GUID }, + { 0, + NULL, /* ChromeKernel */ + "fe3a2a5d-4f32-41a7-b725-accc3285a309" }, +}; + +struct menu_item { + int mi_menuid; /* Unique hex octet */ + int mi_mbrid; /* -1 == not on MBR menu */ + char *mi_name; /* Truncated at 14 chars */ + char *mi_guid; /* NULL == not on GPT menu */ +}; + +const struct menu_item menu_items[] = { + { 0x00, 0x00, "Unused", "00000000-0000-0000-0000-000000000000" }, + { 0x01, 0x01, "DOS FAT-12", MICROSOFT_BASIC_DATA_GUID }, + { 0x02, 0x02, "XENIX /", NULL }, + { 0x03, 0x03, "XENIX /usr", NULL }, + { 0x04, 0x04, "DOS FAT-16", MICROSOFT_BASIC_DATA_GUID }, + { 0x05, 0x05, "Extended DOS", NULL }, + { 0x06, 0x06, "DOS > 32MB", MICROSOFT_BASIC_DATA_GUID }, + { 0x07, 0x07, "NTFS", MICROSOFT_BASIC_DATA_GUID }, + { 0x08, 0x08, "AIX fs", NULL }, + { 0x09, 0x09, "AIX/Coherent", NULL }, + { 0x0A, 0x0A, "OS/2 Bootmgr", NULL }, + { 0x0B, 0x0B, "Win95 FAT-32", MICROSOFT_BASIC_DATA_GUID }, + { 0x0C, 0x0C, "Win95 FAT32L", MICROSOFT_BASIC_DATA_GUID }, + { 0x0D, -1, "BIOS boot", "21686148-6449-6e6f-744e-656564454649" }, + { 0x0E, 0x0E, "DOS FAT-16", MICROSOFT_BASIC_DATA_GUID }, + { 0x0F, 0x0F, "Extended LBA", NULL }, + { 0x10, 0x10, "OPUS", NULL }, + { 0x11, 0x11, "OS/2 hidden", MICROSOFT_BASIC_DATA_GUID }, + { 0x12, 0x12, "Compaq Diag", NULL }, + { 0x14, 0x14, "OS/2 hidden", MICROSOFT_BASIC_DATA_GUID }, + { 0x16, 0x16, "OS/2 hidden", MICROSOFT_BASIC_DATA_GUID }, + { 0x17, 0x17, "OS/2 hidden", MICROSOFT_BASIC_DATA_GUID }, + { 0x18, 0x18, "AST swap", NULL }, + { 0x19, 0x19, "Willowtech", NULL }, + { 0x1C, 0x1C, "ThinkPad Rec", MICROSOFT_BASIC_DATA_GUID }, + { 0x20, 0x20, "Willowsoft", NULL }, + { 0x24, 0x24, "NEC DOS", NULL }, + { 0x27, 0x27, "Win Recovery", "de94bba4-06d1-4d40-a16a-bfd50179d6ac" }, + { 0x38, 0x38, "Theos", NULL }, + { 0x39, 0x39, "Plan 9", NULL }, + { 0x40, 0x40, "VENIX 286", NULL }, + { 0x41, 0x41, "Lin/Minux DR", NULL }, + { 0x42, 0x42, "LinuxSwap DR", "af9b60a0-1431-4f62-bc68-3311714a69ad" }, + { 0x43, 0x43, "Linux DR", NULL }, + { 0x4D, 0x4D, "QNX 4.2 Pri", NULL }, + { 0x4E, 0x4E, "QNX 4.2 Sec", NULL }, + { 0x4F, 0x4F, "QNX 4.2 Ter", NULL }, + { 0x50, 0x50, "DM", NULL }, + { 0x51, 0x51, "DM", NULL }, + { 0x52, 0x52, "CP/M or SysV", NULL }, + { 0x53, 0x53, "DM", NULL }, + { 0x54, 0x54, "Ontrack", NULL }, + { 0x55, 0x55, "EZ-Drive", NULL }, + { 0x56, 0x56, "Golden Bow", NULL }, + { 0x5C, 0x5C, "Priam" , NULL }, + { 0x61, 0x61, "SpeedStor", NULL }, + { 0x63, 0x63, "ISC, HURD, *", NULL }, + { 0x64, 0x64, "NetWare 2.xx", NULL }, + { 0x65, 0x65, "NetWare 3.xx", NULL }, + { 0x66, 0x66, "NetWare 386", NULL }, + { 0x67, 0x67, "Novell", NULL }, + { 0x68, 0x68, "Novell", NULL }, + { 0x69, 0x69, "Novell", NULL }, + { 0x70, 0x70, "DiskSecure", NULL }, + { 0x75, 0x75, "PCIX", NULL }, + { 0x7F, -1, "Chrome Kernel","fe3a2a5d-4f32-41a7-b725-accc3285a309" }, + { 0x80, 0x80, "Minix (old)", NULL }, + { 0x81, 0x81, "Minix (new)", NULL }, + { 0x82, 0x82, "Linux swap", "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f" }, + { 0x83, 0x83, "Linux files*", "0fc63daf-8483-4772-8e79-3d69d8477de4" }, + { 0x84, 0x84, "OS/2 hidden", NULL }, + { 0x85, 0x85, "Linux ext.", NULL }, + { 0x86, 0x86, "NT FAT VS", NULL }, + { 0x87, 0x87, "NTFS VS", NULL }, + { 0x8E, 0x8E, "Linux LVM", "e6d6d379-f507-44c2-a23c-238f2a3df928" }, + { 0x93, 0x93, "Amoeba FS", NULL }, + { 0x94, 0x94, "Amoeba BBT", NULL }, + { 0x99, 0x99, "Mylex" , NULL }, + { 0x9F, 0x9F, "BSDI", NULL }, + { 0xA0, 0xA0, "NotebookSave", NULL }, + { 0xA5, 0xA5, "FreeBSD", "516e7cb4-6ecf-11d6-8ff8-00022d09712b" }, + { 0xA6, 0xA6, "OpenBSD", "824cc7a0-36a8-11e3-890a-952519ad3f61" }, + { 0xA7, 0xA7, "NeXTSTEP", NULL }, + { 0xA8, 0xA8, "MacOS X", "55465300-0000-11aa-aa11-00306543ecac" }, + { 0xA9, 0xA9, "NetBSD", "49f48d5a-b10e-11dc-b99b-0019d1879648" }, + { 0xAB, 0xAB, "MacOS X boot", "426f6f74-0000-11aa-aa11-00306543ecac" }, + { 0xAF, 0xAF, "MacOS X HFS+", "48465300-0000-11aa-aa11-00306543ecac" }, + { 0xB0, -1, "APFS", "7c3457ef-0000-11aa-aa11-00306543ecac" }, + { 0xB1, -1, "APFS ISC", "69646961-6700-11aa-aa11-00306543ecac" }, + { 0xB2, -1, "APFS Recovery","52637672-7900-11aa-aa11-00306543ecac" }, + { 0xB3, -1, "HiFive FSBL", "5b193300-fc78-40cd-8002-e86c45580b47" }, + { 0xB4, -1, "HiFive BBL", "2e54b353-1271-4842-806f-e436d6af6985" }, + { 0xB7, 0xB7, "BSDI filesy*", NULL }, + { 0xB8, 0xB8, "BSDI swap", NULL }, + { 0xBF, 0xBF, "Solaris", "6a85cf4d-1dd2-11b2-99a6-080020736631" }, + { 0xC0, 0xC0, "CTOS", NULL }, + { 0xC1, 0xC1, "DRDOSs FAT12", NULL }, + { 0xC4, 0xC4, "DRDOSs < 32M", NULL }, + { 0xC6, 0xC6, "DRDOSs >=32M", NULL }, + { 0xC7, 0xC7, "HPFS Disbled", NULL }, + { 0xDB, 0xDB, "CPM/C.DOS/C*", NULL }, + { 0xDE, 0xDE, "Dell Maint", NULL }, + { 0xE1, 0xE1, "SpeedStor", NULL }, + { 0xE3, 0xE3, "SpeedStor", NULL }, + { 0xE4, 0xE4, "SpeedStor", NULL }, + { 0xEB, 0xEB, "BeOS/i386", "42465331-3ba3-10f1-802a-4861696b7521" }, + { 0xEC, -1, "Legacy MBR", "024dee41-33e7-11d3-9d69-0008c781f39f" }, + { 0xEE, 0xEE, "EFI GPT", NULL }, + { 0xEF, 0xEF, "EFI Sys", EFI_SYSTEM_PARTITION_GUID }, + { 0xF1, 0xF1, "SpeedStor", NULL }, + { 0xF2, 0xF2, "DOS 3.3+ Sec", NULL }, + { 0xF4, 0xF4, "SpeedStor", NULL }, + { 0xFF, 0xFF, "Xenix BBT", NULL }, }; const struct gpt_type *find_gpt_type(const struct uuid *); const struct mbr_type *find_mbr_type(const int); int uuid_attr(const struct uuid *); +int mbr_item(const unsigned int); +int gpt_item(const unsigned int); +int nth_menu_item(int (*)(const unsigned int), + const unsigned int, unsigned int); +void print_menu(int (*)(const unsigned int), + const unsigned int); const struct gpt_type * find_gpt_type(const struct uuid *uuid) @@ -289,6 +409,63 @@ uuid_attr(const struct uuid *uuid) return gt->gt_attr; } +void +print_menu(int (*test)(const unsigned int), const unsigned int columns) +{ + int col, col0; + unsigned int count, i, j, rows; + + count = 0; + for (i = 0; i < nitems(menu_items); i++) + if (test(i) == 0) + count++; + rows = (count + columns - 1) / columns; + + col0 = -1; + for (i = 0; i < rows; i++) { + col0 = nth_menu_item(test, col0, 1); + printf("%02X %-15s", menu_items[col0].mi_menuid, + menu_items[col0].mi_name); + for (j = 1; j < columns; j++) { + col = nth_menu_item(test, col0, j * rows); + if (col == -1) + break; + printf("%02X %-15s", menu_items[col].mi_menuid, + menu_items[col].mi_name); + } + printf("\n"); + } +} + +int +mbr_item(const unsigned int item) +{ + return menu_items[item].mi_mbrid == -1; +} + +int +gpt_item(const unsigned int item) +{ + return menu_items[item].mi_guid == NULL; +} + +int +nth_menu_item(int (*test)(const unsigned int), const unsigned int last, + unsigned int n) +{ + unsigned int i; + + for (i = last + 1; i < nitems(menu_items); i++) { + if (test(i) == 0) { + n--; + if (n == 0) + return i; + } + } + + return -1; +} + int PRT_protected_uuid(const struct uuid *uuid) { @@ -312,21 +489,10 @@ PRT_protected_uuid(const struct uuid *uuid) void PRT_print_mbrmenu(char *lbuf, size_t lbuflen) { - unsigned int cidx, i, idrows; - - idrows = (nitems(mbr_types) + 3) / 4; +#define MBR_MENU_COLUMNS 4 printf("Choose from the following Partition id values:\n"); - for (i = 0; i < idrows; i++) { - for (cidx = i; cidx < i + idrows * 3; cidx += idrows) { - printf("%02X %-15s", mbr_types[cidx].mt_type, - mbr_types[cidx].mt_name); - } - if (cidx < nitems(mbr_types)) - printf("%02X %s", mbr_types[cidx].mt_type, - mbr_types[cidx].mt_name); - printf("\n"); - } + print_menu(mbr_item, MBR_MENU_COLUMNS); memset(lbuf, 0, lbuflen); /* Just continue. */ } @@ -334,21 +500,10 @@ PRT_print_mbrmenu(char *lbuf, size_t lbuflen) void PRT_print_gptmenu(char *lbuf, size_t lbuflen) { - unsigned int cidx, i, idrows; - - idrows = (nitems(gpt_types) + 3) / 4; +#define GPT_MENU_COLUMNS 4 printf("Choose from the following Partition id values:\n"); - for (i = 0; i < idrows; i++) { - for (cidx = i; cidx < i + idrows * 3; cidx += idrows) { - printf("%02X %-15s", gpt_types[cidx].gt_menuid, - gpt_types[cidx].gt_name); - } - if (cidx < nitems(gpt_types)) - printf("%02X %s", gpt_types[cidx].gt_menuid, - gpt_types[cidx].gt_name); - printf("\n"); - } + print_menu(gpt_item, GPT_MENU_COLUMNS); memset(lbuf, 0, lbuflen); /* Just continue. */ } @@ -433,18 +588,29 @@ PRT_print_part(const int num, const struct prt *prt, const char *units) { const struct unit_type *ut; const struct mbr_type *mt; + const char *desc = NULL; struct chs start, end; double size; + unsigned int i; size = units_size(units, prt->prt_ns, &ut); PRT_lba_to_chs(prt, &start, &end); mt = find_mbr_type(prt->prt_id); + if (mt != NULL) { + if (mt->mt_desc != NULL) + desc = mt->mt_desc; + for (i = 0; i < nitems(menu_items) && desc == NULL; i++) { + if (mbr_item(i) == 0 && + menu_items[i].mi_mbrid == prt->prt_id) + desc = menu_items[i].mi_name; + } + } printf("%c%1d: %.2X %6llu %3u %3u - %6llu %3u %3u [%12llu:%12.0f%s] " "%s\n", (prt->prt_flag == DOSACTIVE) ? '*' : ' ', num, prt->prt_id, start.chs_cyl, start.chs_head, start.chs_sect, end.chs_cyl, end.chs_head, end.chs_sect, - prt->prt_bs, size, ut->ut_abbr, mt ? mt->mt_name : ""); + prt->prt_bs, size, ut->ut_abbr, desc ? desc : ""); if (prt->prt_bs >= DL_GETDSIZE(&dl)) printf("partition %d starts beyond the end of %s\n", num, @@ -493,19 +659,21 @@ const char * PRT_uuid_to_name(const struct uuid *uuid) { static char typename[UUID_STR_LEN + 1]; - const uint8_t gpt_uuid_msdos[] = GPT_UUID_MSDOS; - struct uuid uuid_msdos; const struct gpt_type *gt; char *uuidstr; + unsigned int i; uint32_t status; - uuid_dec_be(gpt_uuid_msdos, &uuid_msdos); - if (uuid_compare(&uuid_msdos, uuid, NULL) == 0) - return "Microsoft basic data"; - gt = find_gpt_type(uuid); - if (gt != NULL) - return gt->gt_name; + if (gt != NULL) { + if (gt->gt_desc != NULL) + return gt->gt_desc; + for (i = 0; i < nitems(menu_items); i++) { + if (gpt_item(i) == 0 && + strcasecmp(gt->gt_guid, menu_items[i].mi_guid) == 0) + return menu_items[i].mi_name; + } + } uuid_to_string(uuid, &uuidstr, &status); if (status == uuid_s_ok) @@ -521,28 +689,34 @@ int PRT_uuid_to_menuid(const struct uuid *uuid) { const struct gpt_type *gt; + unsigned int i; gt = find_gpt_type(uuid); - if (gt == NULL) - return -1; - else - return gt->gt_menuid; + if (gt != NULL) { + for (i = 0; i < nitems(menu_items); i++) { + if (gpt_item(i) == 0 && + strcasecmp(menu_items[i].mi_guid, gt->gt_guid) == 0) + return menu_items[i].mi_menuid; + } + } + + return -1; } const struct uuid * PRT_menuid_to_uuid(const int menuid) { static struct uuid guid; - int i; + unsigned int i; uint32_t status = uuid_s_ok; - for (i = 0; i < nitems(gpt_types); i++) { - if (gpt_types[i].gt_menuid == menuid) { - uuid_from_string(gpt_types[i].gt_guid, &guid, &status); + for (i = 0; i < nitems(menu_items); i++) { + if (gpt_item(i) == 0 && menu_items[i].mi_menuid == menuid) { + uuid_from_string(menu_items[i].mi_guid, &guid, &status); break; } } - if (i == nitems(gpt_types) || status != uuid_s_ok) + if (i == nitems(menu_items) || status != uuid_s_ok) uuid_create_nil(&guid, NULL); return &guid;