diff -ru include/parted.h.orig include/parted/disk.h --- include/parted/disk.h.orig Tue Feb 5 10:58:19 2002 +++ include/parted/disk.h Tue Feb 12 00:06:27 2002 @@ -120,6 +120,9 @@ PedPartitionFlag flag); void (*partition_set_name) (PedPartition* part, const char* name); const char* (*partition_get_name) (const PedPartition* part); + int (*partition_set_type_name) (const PedPartition* part, + const char* name); + const char* (*partition_get_type_name) (const PedPartition* part); int (*partition_align) (PedPartition* part, const PedConstraint* constraint); int (*partition_enumerate) (PedPartition* part); @@ -197,6 +200,9 @@ extern PedPartitionFlag ped_partition_flag_get_by_name (const char* name); extern PedPartitionFlag ped_partition_flag_next (PedPartitionFlag flag); +extern int ped_partition_set_type_name (const PedPartition* part, + const char* name); +extern const char* ped_partition_get_type_name (const PedPartition* part); extern int ped_disk_add_partition (PedDisk* disk, PedPartition* part, const PedConstraint* constraint); extern int ped_disk_remove_partition (PedDisk* disk, PedPartition* part); diff -ru libparted/disk.c.orig libparted/disk.c --- libparted/disk.c.orig Sun Jan 13 17:54:18 2002 +++ libparted/disk.c Tue Feb 12 00:04:50 2002 @@ -1047,6 +1047,23 @@ return NULL; } +int +ped_partition_set_type_name (const PedPartition* part, const char* name) +{ + PED_ASSERT (part != NULL, return 0); + PED_ASSERT (name != NULL, return 0); + + return part->disk->type->ops->partition_set_type_name (part, name); +} + +const char * +ped_partition_get_type_name (const PedPartition* part) +{ + PED_ASSERT (part != NULL, return 0); + + return part->disk->type->ops->partition_get_type_name (part); +} + #ifdef DEBUG static int _disk_check_sanity (PedDisk* disk) diff -ru libparted/disk_bsd.c.orig libparted/disk_bsd.c --- libparted/disk_bsd.c.orig Tue Jan 15 06:27:35 2002 +++ libparted/disk_bsd.c Tue Feb 12 15:03:55 2002 @@ -23,6 +23,7 @@ #include "config.h" #include +#include #include #include @@ -113,6 +114,19 @@ u_int8_t type; } BSDPartitionData; +typedef struct { + const char* name; + int type; +} BSDPartitionTypeName; + +BSDPartitionTypeName bsd_name_table[] = { + { "empty", 0 }, + { "linux-swap", 1 }, + { "linux", 8 }, + { "raw", 8 }, + { NULL, 0 } +}; + static PedDiskType bsd_disk_type; /* XXX fixme: endian? */ @@ -466,6 +481,81 @@ return 0; } +static BSDPartitionTypeName* +_bsd_partition_find_type_name (const char* name) +{ + BSDPartitionTypeName* table = bsd_name_table; + + while (table->name) { + if (!strcmp(name, table->name)) { + return table; + } + table++; + } + + return NULL; +} + +static BSDPartitionTypeName* +_bsd_partition_find_type_id (const int id) +{ + BSDPartitionTypeName* table = bsd_name_table; + + while (table->name) { + if (id == table->type) { + return table; + } + table++; + } + + return NULL; +} + +static int +bsd_partition_set_type_name (const PedPartition* part, const char* name) +{ + int ret = 0; + + if (part && name) { + BSDPartitionData* bsd_part_data = part->disk_specific; + BSDPartitionTypeName* tmp; + + if (!strcmp(name, "type-")) { + if (isdigit(name[5])) { + bsd_part_data->type = name[5] - '0'; + ret = 1; + } + } else if ((tmp = _bsd_partition_find_type_name(name))) { + bsd_part_data->type = tmp->type; + ret = 1; + } + } + + return ret; +} + +static const char * +bsd_partition_get_type_name (const PedPartition* part) +{ + static char type_name[42]; + const char* ret = NULL; + + if (part) { + BSDPartitionData* bsd_part_data = part->disk_specific; + BSDPartitionTypeName* tmp; + + tmp = _bsd_partition_find_type_id(bsd_part_data->type); + + if (tmp) + ret = tmp->name; + else { + sprintf(type_name, "type-%x", bsd_part_data->type); + ret = type_name; + } + } + + return ret; +} static int bsd_get_max_primary_partition_count (const PedDisk* disk) @@ -577,6 +667,8 @@ partition_is_flag_available: bsd_partition_is_flag_available, partition_set_name: NULL, partition_get_name: NULL, + partition_set_type_name:bsd_partition_set_type_name, + partition_get_type_name:bsd_partition_get_type_name, partition_align: bsd_partition_align, partition_enumerate: bsd_partition_enumerate, diff -ru libparted/disk_dos.c.orig libparted/disk_dos.c --- libparted/disk_dos.c.orig Tue Feb 5 10:58:19 2002 +++ libparted/disk_dos.c Tue Feb 12 15:15:01 2002 @@ -91,6 +91,49 @@ #define PARTITION_LINUX_RAID 0xfd #define PARTITION_LINUX_LVM_OLD 0xfe +typedef struct { + const char* name; + int type; +} DosPartitionTypeName; + +DosPartitionTypeName msdos_name_table[] = { + { "empty", PARTITION_EMPTY }, + { "fat12", PARTITION_FAT12 }, + { "fat16-small", PARTITION_FAT16_SM }, + { "extended", PARTITION_EXT }, + { "fat16", PARTITION_FAT16 }, + { "ntfs", PARTITION_NTFS }, + { "hpfs", PARTITION_HPFS }, + { "fat32", PARTITION_FAT32 }, + { "fat32-lba", PARTITION_FAT32_LBA }, + { "fat16-lba", PARTITION_FAT16_LBA }, + { "extended-lba", PARTITION_EXT_LBA }, + { "fat12-hidden", PARTITION_FAT12_H }, + { "fat16-small-hidden", PARTITION_FAT16_SM_H }, + { "extended-hidden", PARTITION_EXT_H }, + { "fat16-hidden", PARTITION_FAT16_H }, + { "ntfs-hidden", PARTITION_NTFS_H }, + { "hpfs-hidden", PARTITION_HPFS_H }, + { "fat32-hidden", PARTITION_FAT32_H }, + { "fat32-lba-hidden", PARTITION_FAT32_LBA_H }, + { "fat16-lba-hidden", PARTITION_FAT16_LBA_H }, + { "linux-swap", PARTITION_LINUX_SWAP }, + { "linux", PARTITION_LINUX }, + { "raw", PARTITION_LINUX }, + { "extended-linux", PARTITION_LINUX_EXT }, + { "linux-raid", PARTITION_LINUX_RAID }, + { "linux-lvm", PARTITION_LINUX_LVM }, + { "linux-lvm", PARTITION_LINUX_LVM_OLD }, + { "ldm", PARTITION_WINDOWS_LDM }, + { "gpt", PARTITION_GPT }, + { "compaq-diag", PARTITION_COMPAQ_DIAG }, + { "msapm-suspend", PARTITION_MSAPM_SUSP }, + { "pheonix-suspend", PARTITION_PHEONIX_SUSP }, + { "dell-suspend", PARTITION_DELL_SUSP }, + { "dell-diag", PARTITION_DELL_DIAG }, + { NULL, PARTITION_EMPTY } +}; + typedef struct _DosRawPartition DosRawPartition; typedef struct _DosRawTable DosRawTable; @@ -1789,6 +1904,88 @@ return 1; } +static DosPartitionTypeName* +_msdos_partition_find_type_name (const char* name) +{ + DosPartitionTypeName* table = msdos_name_table; + + while (table->name) { + if (!strcmp(name, table->name)) { + return table; + } + table++; + } + + return NULL; +} + +static DosPartitionTypeName* +_msdos_partition_find_type_id (const int type) +{ + DosPartitionTypeName* table = msdos_name_table; + + while (table->name) { + if (type == table->type) { + return table; + } + table++; + } + + return NULL; +} + +static int +msdos_partition_set_type_name (const PedPartition* part, const char* name) +{ + int ret = 0; + + if (part && name) { + DosPartitionData* msdos_part_data = part->disk_specific; + DosPartitionTypeName* tmp; + + if (!strcmp(name, "type-")) { + unsigned long system; + char* end; + + system = strtoul(name + 5, &end, 16); + if (end != name + 5 && system < 256) { + msdos_part_data->system = system; + ret = 1; + } + } else if ((tmp = _msdos_partition_find_type_name(name))) { + msdos_part_data->system = tmp->type; + ret = 1; + } + } + + return ret; +} + +static const char * +msdos_partition_get_type_name (const PedPartition* part) +{ + static char type_name[16]; + const char* ret = NULL; + + if (part) { + DosPartitionData* msdos_part_data; + DosPartitionTypeName* tmp; + + msdos_part_data = part->disk_specific; + + tmp = _msdos_partition_find_type_id(msdos_part_data->system); + + if (tmp) + ret = tmp->name; + else { + sprintf(type_name, "type-%x", msdos_part_data->system); + ret = type_name; + } + } + + return ret; +} + static int msdos_get_max_primary_partition_count (const PedDisk* disk) { @@ -1821,6 +2018,8 @@ partition_is_flag_available: msdos_partition_is_flag_available, partition_set_name: NULL, partition_get_name: NULL, + partition_set_type_name:msdos_partition_set_type_name, + partition_get_type_name:msdos_partition_get_type_name, partition_align: msdos_partition_align, partition_enumerate: msdos_partition_enumerate, diff -ru libparted/disk_gpt.c.orig libparted/disk_gpt.c --- libparted/disk_gpt.c.orig Tue Feb 5 10:58:19 2002 +++ libparted/disk_gpt.c Mon Feb 11 23:59:28 2002 @@ -67,42 +67,62 @@ uint8_t node[6]; } __attribute__ ((packed)) efi_guid_t; -#define UNUSED_ENTRY_GUID \ +#define PARTITION_EMPTY_GUID \ ((efi_guid_t) { 0x00000000, 0x0000, 0x0000, 0x00, 0x00, \ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}) + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}) #define PARTITION_SYSTEM_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0xC12A7328), PED_CPU_TO_LE16 (0xF81F), \ - PED_CPU_TO_LE16 (0x11d2), 0xBA, 0x4B, \ + PED_CPU_TO_LE16 (0x11d2), 0xBA, 0x4B, \ { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B }}) -#define LEGACY_MBR_PARTITION_GUID \ +#define PARTITION_LEGACY_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0x024DEE41), PED_CPU_TO_LE16 (0x33E7), \ - PED_CPU_TO_LE16 (0x11d3, 0x9D, 0x69, \ + PED_CPU_TO_LE16 (0x11d3), 0x9D, 0x69, \ { 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F }}) #define PARTITION_MSFT_RESERVED_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0xE3C9E316), PED_CPU_TO_LE16 (0x0B5C), \ - PED_CPU_TO_LE16 (0x4DB8), 0x81, 0x7D, \ + PED_CPU_TO_LE16 (0x4DB8), 0x81, 0x7D, \ { 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE }}) #define PARTITION_BASIC_DATA_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0xEBD0A0A2), PED_CPU_TO_LE16 (0xB9E5), \ - PED_CPU_TO_LE16 (0x4433), 0x87, 0xC0, \ + PED_CPU_TO_LE16 (0x4433), 0x87, 0xC0, \ { 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7 }}) -#define PARTITION_RAID_GUID \ +#define PARTITION_LINUX_RAID_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0xa19d880f), PED_CPU_TO_LE16 (0x05fc), \ - PED_CPU_TO_LE16 (0x4d3b), 0xa0, 0x06, \ + PED_CPU_TO_LE16 (0x4d3b), 0xa0, 0x06, \ { 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e }}) -#define PARTITION_SWAP_GUID \ +#define PARTITION_LINUX_SWAP_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0x0657fd6d), PED_CPU_TO_LE16 (0xa4ab), \ - PED_CPU_TO_LE16 (0x43c4), 0x84, 0xe5, \ + PED_CPU_TO_LE16 (0x43c4), 0x84, 0xe5, \ { 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f }}) -#define PARTITION_LVM_GUID \ +#define PARTITION_LINUX_LVM_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0xe6d6d379), PED_CPU_TO_LE16 (0xf507), \ - PED_CPU_TO_LE16 (0x44c2), 0xa2, 0x3c, \ + PED_CPU_TO_LE16 (0x44c2), 0xa2, 0x3c, \ { 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28 }}) #define PARTITION_RESERVED_GUID \ ((efi_guid_t) { PED_CPU_TO_LE32 (0x8da63339), PED_CPU_TO_LE16 (0x0007), \ - PED_CPU_TO_LE16 (0x60c0), 0xc4, 0x36, \ + PED_CPU_TO_LE16 (0x60c0), 0xc4, 0x36, \ { 0x08, 0x3a, 0xc8, 0x23, 0x09, 0x08 }}) +typedef struct { + const char* name; + efi_guid_t type; +} GPTPartitionTypeName; + +GPTPartitionTypeName gpt_name_table[] = { + { "empty", PARTITION_EMPTY_GUID }, + { "system", PARTITION_SYSTEM_GUID }, + { "legacy", PARTITION_LEGACY_GUID }, + { "microsoft", PARTITION_MSFT_RESERVED_GUID }, + { "linux", PARTITION_BASIC_DATA_GUID }, + { "data", PARTITION_BASIC_DATA_GUID }, + { "raw", PARTITION_BASIC_DATA_GUID }, + { "linux-raid", PARTITION_LINUX_RAID_GUID }, + { "linux-swap", PARTITION_LINUX_SWAP_GUID }, + { "linux-lvm", PARTITION_LINUX_LVM_GUID }, + { "reserved", PARTITION_RESERVED_GUID }, + { NULL, PARTITION_EMPTY_GUID } +}; + typedef struct _GuidPartitionTableHeader_t { uint64_t Signature; uint32_t Revision; @@ -616,7 +636,7 @@ PedPartition* part; PedConstraint* constraint_exact; - if (!guid_cmp (ptes[i].PartitionTypeGuid, UNUSED_ENTRY_GUID)) + if (!guid_cmp (ptes[i].PartitionTypeGuid, PARTITION_EMPTY_GUID)) continue; part = _parse_part_entry (disk, &ptes[i]); @@ -902,7 +922,7 @@ || strcmp (fs_type->name, "ntfs") == 0) gpt_part_data->type = PARTITION_MSFT_RESERVED_GUID; else if (strstr (fs_type->name, "swap")) - gpt_part_data->type = PARTITION_SWAP_GUID; + gpt_part_data->type = PARTITION_LINUX_SWAP_GUID; } return 1; @@ -977,20 +997,23 @@ break; case PED_PARTITION_RAID: if (state) - gpt_part_data->type = PARTITION_RAID_GUID; - else if (!guid_cmp(gpt_part_data->type, PARTITION_RAID_GUID)) + gpt_part_data->type = PARTITION_LINUX_RAID_GUID; + else if (!guid_cmp(gpt_part_data->type, + PARTITION_LINUX_RAID_GUID)) gpt_part_data->type = PARTITION_BASIC_DATA_GUID; break; case PED_PARTITION_LVM: if (state) - gpt_part_data->type = PARTITION_LVM_GUID; - else if (!guid_cmp(gpt_part_data->type, PARTITION_LVM_GUID)) + gpt_part_data->type = PARTITION_LINUX_LVM_GUID; + else if (!guid_cmp(gpt_part_data->type, + PARTITION_LINUX_LVM_GUID)) gpt_part_data->type = PARTITION_BASIC_DATA_GUID; break; case PED_PARTITION_SWAP: if (state) - gpt_part_data->type = PARTITION_SWAP_GUID; - else if (!guid_cmp(gpt_part_data->type, PARTITION_SWAP_GUID)) + gpt_part_data->type = PARTITION_LINUX_SWAP_GUID; + else if (!guid_cmp(gpt_part_data->type, + PARTITION_LINUX_SWAP_GUID)) gpt_part_data->type = PARTITION_BASIC_DATA_GUID; break; case PED_PARTITION_ROOT: @@ -1011,13 +1034,13 @@ switch (flag) { case PED_PARTITION_RAID: - return !guid_cmp(gpt_part_data->type, PARTITION_RAID_GUID); + return !guid_cmp(gpt_part_data->type,PARTITION_LINUX_RAID_GUID); case PED_PARTITION_LVM: - return !guid_cmp(gpt_part_data->type, PARTITION_LVM_GUID); + return !guid_cmp(gpt_part_data->type,PARTITION_LINUX_LVM_GUID); case PED_PARTITION_BOOT: - return !guid_cmp(gpt_part_data->type, PARTITION_SYSTEM_GUID); + return !guid_cmp(gpt_part_data->type,PARTITION_SYSTEM_GUID); case PED_PARTITION_SWAP: - return !guid_cmp(gpt_part_data->type, PARTITION_SWAP_GUID); + return !guid_cmp(gpt_part_data->type,PARTITION_LINUX_SWAP_GUID); case PED_PARTITION_LBA: case PED_PARTITION_ROOT: case PED_PARTITION_HIDDEN: @@ -1049,7 +1072,7 @@ static void gpt_partition_set_name (PedPartition *part, const char *name) { - GPTPartitionData *gpt_part_data = part->disk_specific; + GPTPartitionData* gpt_part_data = part->disk_specific; strncpy (gpt_part_data->name, name, 36); gpt_part_data->name [36] = 0; @@ -1062,6 +1085,91 @@ return gpt_part_data->name; } +static GPTPartitionTypeName* +gpt_partition_find_type_name (const char* name) +{ + GPTPartitionTypeName* table = gpt_name_table; + + while (table->name) { + if (!strcmp(name, table->name)) { + return table; + } + table++; + } + + return NULL; +} + +static GPTPartitionTypeName* +gpt_partition_find_type_guid (const efi_guid_t guid) +{ + GPTPartitionTypeName* table = gpt_name_table; + + while (table->name) { + if (!guid_cmp(guid, table->type)) { + return table; + } + table++; + } + + return NULL; +} + +static int +gpt_partition_set_type_name (const PedPartition* part, const char* name) +{ + int ret = 0; + + if (part && name) { + GPTPartitionData* gpt_part_data = part->disk_specific; + GPTPartitionTypeName* tmp; + uuid_t guid; + + if (!strcmp(name, "type-")) { + if (uuid_parse(name + 5, guid) < 0) + return 0; + + swap_uuid_and_efi_guid((char *)guid); + uuid_copy((char *)&gpt_part_data->type, guid); + ret = 1; + } else if ((tmp = gpt_partition_find_type_name(name))) { + gpt_part_data->type = tmp->type; + ret = 1; + } + } + + return ret; +} + +static const char * +gpt_partition_get_type_name (const PedPartition* part) +{ + static char type_name[42]; + const char* ret = NULL; + + if (part) { + GPTPartitionData* gpt_part_data = part->disk_specific; + GPTPartitionTypeName* tmp; + + tmp = gpt_partition_find_type_guid(gpt_part_data->type); + + if (tmp) { + ret = tmp->name; + } else { + uuid_t guid; + + uuid_copy(guid, (char *)&gpt_part_data->type); + swap_uuid_and_efi_guid((char *)guid); + strcpy(type_name, "type-"); + uuid_unparse(guid, type_name + 5); + + ret = type_name; + } + } + + return ret; +} + static int gpt_get_max_primary_partition_count (const PedDisk *disk) { @@ -1120,6 +1226,8 @@ partition_is_flag_available: gpt_partition_is_flag_available, partition_set_name: gpt_partition_set_name, partition_get_name: gpt_partition_get_name, + partition_set_type_name: gpt_partition_set_type_name, + partition_get_type_name: gpt_partition_get_type_name, partition_align: gpt_partition_align, partition_enumerate: gpt_partition_enumerate, alloc_metadata: gpt_alloc_metadata, diff -ru libparted/disk_loop.c.orig libparted/disk_loop.c --- libparted/disk_loop.c.orig Tue Jan 1 10:42:34 2002 +++ libparted/disk_loop.c Mon Feb 11 22:05:04 2002 @@ -301,6 +301,8 @@ partition_is_flag_available: loop_partition_is_flag_available, partition_set_name: NULL, partition_get_name: NULL, + partition_set_type_name:NULL, + partition_get_type_name:NULL, partition_align: loop_partition_align, partition_enumerate: loop_partition_enumerate, diff -ru libparted/disk_mac.c.orig libparted/disk_mac.c --- libparted/disk_mac.c.orig Mon Jan 14 04:56:27 2002 +++ libparted/disk_mac.c Tue Feb 12 00:19:05 2002 @@ -1206,6 +1206,54 @@ return mac_data->volume_name; } +static int +mac_partition_set_type_name (const PedPartition* part, const char* name) +{ + int ret = 0; + + if (part && name) { + MacPartitionData* mac_data = part->disk_specific; + + if (!strcmp(name, "data") || !strcmp(name, "linux") || + !strcmp(name, "raw")) + strcpy (mac_data->system_name, "Apple_UNIX_SVR2"); + else if (!strcmp(name, "empty")) + memset (mac_data->system_name, '\0', 33); + else if (!strcmp(name, "hfs")) + strcpy (mac_data->system_name, "Apple_HFS"); + else { + strncpy(mac_data->system_name, name, 32); + mac_data->system_name[32] = '\0'; + } + + ret = 1; + } + + return ret; +} + +static const char * +mac_partition_get_type_name (const PedPartition* part) +{ + static char type_name[16]; + const char* ret = NULL; + + if (part) { + MacPartitionData* mac_data = part->disk_specific; + + if (mac_data->system_name[0] == '\0') + ret = "empty"; + else if (!strcmp(mac_data->system_name, "Apple_UNIX_SVR2")) + ret = "linux"; + else if (!strcmp(mac_data->system_name, "Apple_HFS")) + ret = "hfs"; + else + ret = mac_data->system_name; + } + + return ret; +} + static PedConstraint* _primary_constraint (PedDisk* disk) { @@ -1420,6 +1463,8 @@ partition_is_flag_available: mac_partition_is_flag_available, partition_set_name: mac_partition_set_name, partition_get_name: mac_partition_get_name, + partition_set_type_name:mac_partition_set_type_name, + partition_get_type_name:mac_partition_get_type_name, partition_align: mac_partition_align, partition_enumerate: mac_partition_enumerate, diff -ru libparted/disk_mips.c.orig libparted/disk_mips.c --- libparted/disk_mips.c.orig Wed Jan 16 13:44:28 2002 +++ libparted/disk_mips.c Mon Feb 11 22:30:51 2002 @@ -45,6 +45,25 @@ int real_file_size; /* boot volumes only */ } MIPSPartData; +MIPSPartitionTypeName mips_name_table[] = { + { "volhdr", PTYPE_VOLHDR }, + { "track_repl", PTYPE_TRKREPL }, + { "sector_repl", PTYPE_SECREPL }, + { "raw", PTYPE_RAW }, + { "bsd", PTYPE_BSD }, + { "bsd42", PTYPE_BSD42 }, + { "sysv", PTYPE_SYSV }, + { "volume", PTYPE_VOLUME }, + { "efs", PTYPE_EFS }, + { "lvol", PTYPE_LVOL }, + { "rlvol", PTYPE_RLVOL }, + { "xfs", PTYPE_XFS }, + { "xfs-log", PTYPE_XFSLOG }, + { "xlv", PTYPE_XLV }, + { "xvm", PTYPE_XVM }, + { NULL, 0 } +}; + static PedDiskType mips_disk_type; static int @@ -837,6 +856,89 @@ return 0; } +static MIPSPartitionTypeName* +_mips_partition_find_type_name (const char* name) +{ + MIPSPartitionTypeName* table = mips_name_table; + + while (table->name) { + if (!strcmp(name, table->name)) { + return table; + } + table++; + } + + return NULL; +} + +static MIPSPartitionTypeName* +_mips_partition_find_type_id (const int type) +{ + MIPSPartitionTypeName* table = mips_name_table; + + while (table->name) { + if (type == table->type) { + return table; + } + table++; + } + + return NULL; +} + +static int +mips_partition_set_type_name (const PedPartition* part, const char* name) +{ + int ret = 0; + + if (part && name) { + MIPSPartData* mips_part_data = part->disk_specific; + MIPSPartitionTypeName* tmp; + + if (!strcmp(name, "type-")) { + unsigned long type; + char* end; + + type = strtoul(name + 5, &end, 16); + if (end != name + 5 && type < NPTYPES) { + mips_part_data->type = type; + ret = 1; + } + } else if ((tmp = _mips_partition_find_type_name(name))) { + mips_part_data->type = tmp->type; + ret = 1; + } + } + + return ret; +} + +static const char * +mips_partition_get_type_name (const PedPartition* part) +{ + static char type_name[16]; + const char* ret = NULL; + + if (part) { + MIPSPartData* mips_part_data; + MIPSPartitionTypeName* tmp; + + mips_part_data = part->disk_specific; + + tmp = _mips_partition_find_type_id(mips_part_data->type); + + if (tmp) + ret = tmp->name; + else { + sprintf(type_name, "type-%x", mips_part_data->type); + ret = type_name; + } + } + + return ret; +} + + static int mips_get_max_primary_partition_count (const PedDisk* disk) { @@ -894,6 +996,8 @@ partition_is_flag_available: mips_partition_is_flag_available, partition_set_name: mips_partition_set_name, partition_get_name: mips_partition_get_name, + partition_set_type_name:mips_partition_set_type_name, + partition_get_type_name:mips_partition_get_type_name, partition_align: mips_partition_align, partition_enumerate: mips_partition_enumerate, diff -ru libparted/disk_pc98.c.orig libparted/disk_pc98.c --- libparted/disk_pc98.c.orig Tue Jan 15 06:26:34 2002 +++ libparted/disk_pc98.c Mon Feb 11 23:21:56 2002 @@ -852,6 +852,8 @@ partition_is_flag_available: pc98_partition_is_flag_available, partition_set_name: pc98_partition_set_name, partition_get_name: pc98_partition_get_name, + partition_set_type_name:NULL, /* FIXME: finish this */ + partition_get_type_name:NULL, /* FIXME: finish this */ partition_align: pc98_partition_align, partition_enumerate: pc98_partition_enumerate, diff -ru libparted/disk_sun.c.orig libparted/disk_sun.c --- libparted/disk_sun.c.orig Tue Jan 15 06:28:29 2002 +++ libparted/disk_sun.c Mon Feb 11 23:23:15 2002 @@ -800,8 +800,10 @@ get_max_primary_partition_count: sun_get_max_primary_partition_count, - partition_set_name: NULL, - partition_get_name: NULL, + partition_set_name: NULL, + partition_get_name: NULL, + partition_set_type_name:NULL, /* FIXME: finish this */ + partition_get_type_name:NULL, /* FIXME: finish this */ }; static PedDiskType sun_disk_type = { diff -ru libparted/dvh.h.orig libparted/dvh.h --- libparted/dvh.h.orig Sun Dec 30 11:11:41 2001 +++ libparted/dvh.h Mon Feb 11 22:24:06 2002 @@ -131,6 +131,11 @@ int pt_type; /* use of partition */ }; +#define VHMAGIC 0xbe5a941 /* randomly chosen value */ +#define NPARTAB 16 /* 16 unix partitions */ +#define NVDIR 15 /* max of 15 directory entries */ +#define BFNAMESIZE 16 /* max 16 chars in boot file name */ + #define PTYPE_VOLHDR 0 /* partition is volume header */ #define PTYPE_TRKREPL 1 /* partition is used for repl trks */ #define PTYPE_SECREPL 2 /* partition is used for repl secs */ @@ -148,10 +153,10 @@ #define PTYPE_XVM 13 /* partition is sgi XVM */ #define NPTYPES 16 -#define VHMAGIC 0xbe5a941 /* randomly chosen value */ -#define NPARTAB 16 /* 16 unix partitions */ -#define NVDIR 15 /* max of 15 directory entries */ -#define BFNAMESIZE 16 /* max 16 chars in boot file name */ +typedef struct { + char* name; + int type; +} MIPSPartitionTypeName; /* Partition types for ARCS */ #define NOT_USED 0 /* Not used */