diff --git a/.gitignore b/.gitignore index 2b7a2e4..585d058 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -SOURCES/parted-3.4.tar.xz +SOURCES/parted-3.5.tar.xz SOURCES/pubkey.brian.lane SOURCES/pubkey.phillip.susi diff --git a/.parted.metadata b/.parted.metadata index 27f07bd..faa0b40 100644 --- a/.parted.metadata +++ b/.parted.metadata @@ -1,3 +1,3 @@ -903c58fab429d3b62aa324033a3e41b0b96ad810 SOURCES/parted-3.4.tar.xz +55023eb2acb3b22e6fc999d73e285f0a3706101a SOURCES/parted-3.5.tar.xz 2c4a3e3c329d04ece68fdca92225441bc7c28f09 SOURCES/pubkey.brian.lane 0ef8ad4c6cc02bbacd5c9de79187c116c3efb10a SOURCES/pubkey.phillip.susi diff --git a/SOURCES/0001-maint-post-release-administrivia.patch b/SOURCES/0001-maint-post-release-administrivia.patch new file mode 100644 index 0000000..c32732c --- /dev/null +++ b/SOURCES/0001-maint-post-release-administrivia.patch @@ -0,0 +1,50 @@ +From cec533a00a2cd0b64a7a0f5debc26554f6025831 Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Mon, 18 Apr 2022 15:10:06 -0400 +Subject: [PATCH 1/5] maint: post-release administrivia + +* NEWS: Add header line for next release. +* .prev-version: Record previous version. +* cfg.mk (old_NEWS_hash): Auto-update. +--- + .prev-version | 2 +- + NEWS | 3 +++ + cfg.mk | 2 +- + 3 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/.prev-version b/.prev-version +index e917998..5a95802 100644 +--- a/.prev-version ++++ b/.prev-version +@@ -1 +1 @@ +-3.4.64.2 ++3.5 +diff --git a/NEWS b/NEWS +index 68a164a..2bd161f 100644 +--- a/NEWS ++++ b/NEWS +@@ -1,5 +1,8 @@ + GNU parted NEWS -*- outline -*- + ++* Noteworthy changes in release ?.? (????-??-??) [?] ++ ++ + * Noteworthy changes in release 3.5 (2022-04-18) [stable] + + ** New Features +diff --git a/cfg.mk b/cfg.mk +index d5fdd80..11fa51b 100644 +--- a/cfg.mk ++++ b/cfg.mk +@@ -45,7 +45,7 @@ local-checks-to-skip = \ + export VERBOSE = yes + + # Hash of lines 42-208 for release 3.2 +-old_NEWS_hash = 64a8f4d9ec1a5c256f3cc792450dc257 ++old_NEWS_hash = 81f624d1d62a34f24e1286bd3cf5c736 + + include $(srcdir)/dist-check.mk + +-- +2.35.3 + diff --git a/SOURCES/0001-parted-add-fix-to-fix-in-script-mode.patch b/SOURCES/0001-parted-add-fix-to-fix-in-script-mode.patch deleted file mode 100644 index be907eb..0000000 --- a/SOURCES/0001-parted-add-fix-to-fix-in-script-mode.patch +++ /dev/null @@ -1,123 +0,0 @@ -From 7c9a96209af2b84e1eec98ad3527f82ddd966cdf Mon Sep 17 00:00:00 2001 -From: Cristian Klein -Date: Fri, 11 Dec 2020 22:19:22 +0100 -Subject: [PATCH 1/5] parted: add --fix to "fix" in script mode - -Use-case: VMs are booted from images that are smaller than their virtual -disk. This means that -- almost by definition -- the secondary GPT -header will be "misplaced", i.e., not at the end of the virtual disk. - -Without this patch, parted cannot be used for custom/exotic partitioning -when the VM boots (e.g., in cloud-init's `bootcmd`). Specifically, it -will fail as follows: - -``` -$ sudo parted --script /dev/vda "mkpart 2 10GB -1" -Warning: Not all of the space available to /dev/vda appears to be used, -you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting? -Error: Unable to satisfy all constraints on the partition. -``` - -This happens because, in script mode, exceptions are usually not -resolved. - -This patch adds `--fix`. This allows exceptions to be automatically -resolved with Fix. As a result, the following command will work: - -``` -$ sudo parted --fix --script /dev/vda "mkpart 2 10GB -1" -``` - -Signed-off-by: Brian C. Lane ---- - parted/parted.c | 8 ++++++-- - parted/ui.c | 7 +++++++ - parted/ui.h | 1 + - 3 files changed, 14 insertions(+), 2 deletions(-) - -diff --git a/parted/parted.c b/parted/parted.c -index e84e66d..41edb7f 100644 ---- a/parted/parted.c -+++ b/parted/parted.c -@@ -116,6 +116,7 @@ static struct option const options[] = { - {"list", 0, NULL, 'l'}, - {"machine", 0, NULL, 'm'}, - {"script", 0, NULL, 's'}, -+ {"fix", 0, NULL, 'f'}, - {"version", 0, NULL, 'v'}, - {"align", required_argument, NULL, 'a'}, - {"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY}, -@@ -127,12 +128,14 @@ static const char *const options_help [][2] = { - {"list", N_("lists partition layout on all block devices")}, - {"machine", N_("displays machine parseable output")}, - {"script", N_("never prompts for user intervention")}, -+ {"fix", N_("in script mode, fix instead of abort when asked")}, - {"version", N_("displays the version")}, - {"align=[none|cyl|min|opt]", N_("alignment for new partitions")}, - {NULL, NULL} - }; - - int opt_script_mode = 0; -+int opt_fix_mode = 0; - int pretend_input_tty = 0; - int opt_machine_mode = 0; - int disk_is_modified = 0; -@@ -2191,7 +2194,7 @@ int opt, help = 0, list = 0, version = 0, wrong = 0; - - while (1) - { -- opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsva:", -+ opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsfva:", - options, NULL); - if (opt == -1) - break; -@@ -2201,6 +2204,7 @@ while (1) - case 'l': list = 1; break; - case 'm': opt_machine_mode = 1; break; - case 's': opt_script_mode = 1; break; -+ case 'f': opt_fix_mode = 1; break; - case 'v': version = 1; break; - case 'a': - alignment = XARGMATCH ("--align", optarg, -@@ -2217,7 +2221,7 @@ while (1) - - if (wrong == 1) { - fprintf (stderr, -- _("Usage: %s [-hlmsv] [-a] [DEVICE [COMMAND [PARAMETERS]]...]\n"), -+ _("Usage: %s [-hlmsfv] [-a] [DEVICE [COMMAND [PARAMETERS]]...]\n"), - program_name); - return 0; - } -diff --git a/parted/ui.c b/parted/ui.c -index 973bd26..b5948d3 100644 ---- a/parted/ui.c -+++ b/parted/ui.c -@@ -644,6 +644,13 @@ exception_handler (PedException* ex) - if (!option_get_next (ex->options, opt)) - return opt; - -+ /* script-mode and fix? */ -+ int fix_is_an_option = (ex->options & PED_EXCEPTION_FIX); -+ if (opt_script_mode && opt_fix_mode && fix_is_an_option) { -+ printf ("Fixing, due to --fix\n"); -+ return PED_EXCEPTION_FIX; -+ } -+ - /* script-mode: don't handle the exception */ - if (opt_script_mode || (!isatty (0) && !pretend_input_tty)) - return PED_EXCEPTION_UNHANDLED; -diff --git a/parted/ui.h b/parted/ui.h -index 3b07782..e4e88b6 100644 ---- a/parted/ui.h -+++ b/parted/ui.h -@@ -89,6 +89,7 @@ extern void print_using_dev (PedDevice* dev); - - /* in parted.c */ - extern int opt_script_mode; -+extern int opt_fix_mode; - extern int pretend_input_tty; - - extern void print_options_help (); --- -2.26.2 - diff --git a/SOURCES/0002-doc-Document-fix-flag.patch b/SOURCES/0002-doc-Document-fix-flag.patch deleted file mode 100644 index 0961dda..0000000 --- a/SOURCES/0002-doc-Document-fix-flag.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 8aa569aa60c37526a8c37b06e88a833745a7a6ef Mon Sep 17 00:00:00 2001 -From: Cristian Klein -Date: Fri, 11 Dec 2020 22:19:23 +0100 -Subject: [PATCH 2/5] doc: Document --fix flag - -Also fix copyright year, to please `make syntax-check`. - -Signed-off-by: Brian C. Lane ---- - doc/C/parted.8 | 3 +++ - doc/parted.texi | 6 ++++++ - 2 files changed, 9 insertions(+) - -diff --git a/doc/C/parted.8 b/doc/C/parted.8 -index 297c39a..d8e556e 100644 ---- a/doc/C/parted.8 -+++ b/doc/C/parted.8 -@@ -27,6 +27,9 @@ displays machine parseable output - .B -s, --script - never prompts for user intervention - .TP -+.B -f, --fix -+automatically answer "fix" to exceptions in script mode -+.TP - .B -v, --version - displays the version - .TP -diff --git a/doc/parted.texi b/doc/parted.texi -index d89d74d..33212f0 100644 ---- a/doc/parted.texi -+++ b/doc/parted.texi -@@ -406,6 +406,12 @@ display a help message - @itemx --script - never prompt the user - -+@item -f -+@itemx --fix -+automatically answer exceptions with "fix" in script mode, whcih is useful for: -+GPT header not including full disk size; moving the backup GPT table to the end of the disk; -+MAC fix missing partition map entry; etc. -+ - @item -a alignment-type - @itemx --align alignment-type - Set alignment for newly created partitions, valid alignment types are: --- -2.26.2 - diff --git a/SOURCES/0002-parted-add-type-command.patch b/SOURCES/0002-parted-add-type-command.patch new file mode 100644 index 0000000..8472a6b --- /dev/null +++ b/SOURCES/0002-parted-add-type-command.patch @@ -0,0 +1,1636 @@ +From 61b3a9733c0e0a79ccc43096642d378c8706add6 Mon Sep 17 00:00:00 2001 +From: Arvin Schnell +Date: Wed, 11 May 2022 14:02:21 +0000 +Subject: [PATCH 2/5] parted: add type command + +Include the partition type-id and type-uuid in the JSON +output. Also add the the command 'type' to set them. Remove +redundant flags from DosPartitionData and use only the system +variable. + +Signed-off-by: Brian C. Lane +--- + NEWS | 3 + + doc/C/parted.8 | 5 + + doc/parted.texi | 20 + + include/parted/disk.in.h | 23 +- + libparted/disk.c | 102 +++++ + libparted/labels/dasd.c | 4 + + libparted/labels/dos.c | 621 ++++++++++++-------------- + libparted/labels/gpt.c | 44 +- + parted/parted.c | 113 ++++- + tests/Makefile.am | 4 + + tests/t0800-json-gpt.sh | 2 + + tests/t0801-json-msdos.sh | 5 +- + tests/t0900-type-gpt.sh | 69 +++ + tests/t0901-type-gpt-invalid.sh | 35 ++ + tests/t0910-type-dos.sh | 69 +++ + tests/t0911-type-dos-invalid.sh | 35 ++ + tests/t2400-dos-hfs-partition-type.sh | 2 +- + tests/t3300-palo-prep.sh | 8 +- + tests/t3310-flags.sh | 4 + + 19 files changed, 825 insertions(+), 343 deletions(-) + create mode 100755 tests/t0900-type-gpt.sh + create mode 100755 tests/t0901-type-gpt-invalid.sh + create mode 100755 tests/t0910-type-dos.sh + create mode 100755 tests/t0911-type-dos-invalid.sh + +diff --git a/NEWS b/NEWS +index 2bd161f..099f8bd 100644 +--- a/NEWS ++++ b/NEWS +@@ -2,6 +2,9 @@ GNU parted NEWS -*- outline -*- + + * Noteworthy changes in release ?.? (????-??-??) [?] + ++** New Features ++ ++ Add type commands to set type-id on MS-DOS and type-uuid on GPT. + + * Noteworthy changes in release 3.5 (2022-04-18) [stable] + +diff --git a/doc/C/parted.8 b/doc/C/parted.8 +index 7895440..ab34be7 100644 +--- a/doc/C/parted.8 ++++ b/doc/C/parted.8 +@@ -134,6 +134,11 @@ human-friendly form for output). + .B toggle \fIpartition\fP \fIflag\fP + Toggle the state of \fIflag\fP on \fIpartition\fP. + .TP ++.B type \fIpartition\fP \fIid\fP or \fIuuid\fP ++On MS-DOS set the type aka. partition id of \fIpartition\fP to ++\fIid\fP. The \fIid\fP is a value between "0x01" and "0xff". On GPT ++the type-uuid of \fIpartition\fP to \fIuuid\fP. ++.TP + .B disk_set \fIflag\fP \fIstate\fP + Change a \fIflag\fP on the disk to \fIstate\fP. A flag can be either "on" or "off". + Some or all of these flags will be available, depending on what disk label you +diff --git a/doc/parted.texi b/doc/parted.texi +index 8a3978a..9c9d282 100644 +--- a/doc/parted.texi ++++ b/doc/parted.texi +@@ -466,6 +466,7 @@ GNU Parted provides the following commands: + * select:: + * set:: + * toggle:: ++* type:: + * unit:: + @end menu + +@@ -1034,6 +1035,25 @@ Toggle the state of @var{flag} on partition @var{number}. + + @end deffn + ++@node type ++@subsection type ++@cindex type, command description ++@cindex command description, type ++ ++@deffn Command type @var{number} @var{id} or @var{uuid} ++ ++On MS-DOS set the type-id aka partition id to @var{id} on partition ++@var{number}. The id is a value between 0x01 and 0xff, e.g. the ID for ++Linux is 0x83. A list with some IDs is available at ++@uref{https://en.wikipedia.org/wiki/Partition_type}. ++ ++On GPT set the type-uuid to @var{uuid} on partition ++@var{number}. E.g. the UUID for Linux is ++0fc63daf-8483-4772-8e79-3d69d8477de4. A list with some UUIDs is availabe ++at @uref{https://en.wikipedia.org/wiki/GUID_Partition_Table}. ++ ++@end deffn ++ + @node unit + @subsection unit + @cindex unit, command description +diff --git a/include/parted/disk.in.h b/include/parted/disk.in.h +index 38e869d..672c4ee 100644 +--- a/include/parted/disk.in.h ++++ b/include/parted/disk.in.h +@@ -32,6 +32,7 @@ + */ + #include + #include ++#include + + /** + * Disk flags +@@ -91,11 +92,13 @@ enum _PedPartitionFlag { + #define PED_PARTITION_LAST_FLAG PED_PARTITION_LINUX_HOME + + enum _PedDiskTypeFeature { +- PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */ +- PED_DISK_TYPE_PARTITION_NAME=2 /**< supports partition names */ ++ PED_DISK_TYPE_EXTENDED=1, /**< supports extended partitions */ ++ PED_DISK_TYPE_PARTITION_NAME=2, /**< supports partition names */ ++ PED_DISK_TYPE_PARTITION_TYPE_ID=4, /**< supports partition type-ids */ ++ PED_DISK_TYPE_PARTITION_TYPE_UUID=8, /**< supports partition type-uuids */ + }; + #define PED_DISK_TYPE_FIRST_FEATURE PED_DISK_TYPE_EXTENDED +-#define PED_DISK_TYPE_LAST_FEATURE PED_DISK_TYPE_PARTITION_NAME ++#define PED_DISK_TYPE_LAST_FEATURE PED_DISK_TYPE_PARTITION_TYPE_UUID + + struct _PedDisk; + struct _PedPartition; +@@ -247,6 +250,13 @@ struct _PedDiskOps { + PedPartitionFlag flag); + void (*partition_set_name) (PedPartition* part, const char* name); + const char* (*partition_get_name) (const PedPartition* part); ++ ++ int (*partition_set_type_id) (PedPartition* part, uint8_t id); ++ uint8_t (*partition_get_type_id) (const PedPartition* part); ++ ++ int (*partition_set_type_uuid) (PedPartition* part, const uint8_t* uuid); ++ uint8_t* (*partition_get_type_uuid) (const PedPartition* part); ++ + int (*partition_align) (PedPartition* part, + const PedConstraint* constraint); + int (*partition_enumerate) (PedPartition* part); +@@ -347,6 +357,13 @@ extern int ped_partition_set_system (PedPartition* part, + const PedFileSystemType* fs_type); + extern int ped_partition_set_name (PedPartition* part, const char* name); + extern const char* ped_partition_get_name (const PedPartition* part); ++ ++extern int ped_partition_set_type_id (PedPartition* part, uint8_t id); ++extern uint8_t ped_partition_get_type_id (const PedPartition* part); ++ ++extern int ped_partition_set_type_uuid (PedPartition* part, const uint8_t* uuid); ++extern uint8_t* ped_partition_get_type_uuid (const PedPartition* part); ++ + extern int ped_partition_is_busy (const PedPartition* part); + extern char* ped_partition_get_path (const PedPartition* part); + +diff --git a/libparted/disk.c b/libparted/disk.c +index 3bf7634..22dff36 100644 +--- a/libparted/disk.c ++++ b/libparted/disk.c +@@ -1458,6 +1458,36 @@ _assert_partition_name_feature (const PedDiskType* disk_type) + return 1; + } + ++static int ++_assert_partition_type_id_feature (const PedDiskType* disk_type) ++{ ++ if (!ped_disk_type_check_feature ( ++ disk_type, PED_DISK_TYPE_PARTITION_TYPE_ID)) { ++ ped_exception_throw ( ++ PED_EXCEPTION_ERROR, ++ PED_EXCEPTION_CANCEL, ++ "%s disk labels do not support partition type-ids.", ++ disk_type->name); ++ return 0; ++ } ++ return 1; ++} ++ ++static int ++_assert_partition_type_uuid_feature (const PedDiskType* disk_type) ++{ ++ if (!ped_disk_type_check_feature ( ++ disk_type, PED_DISK_TYPE_PARTITION_TYPE_UUID)) { ++ ped_exception_throw ( ++ PED_EXCEPTION_ERROR, ++ PED_EXCEPTION_CANCEL, ++ "%s disk labels do not support partition type-uuids.", ++ disk_type->name); ++ return 0; ++ } ++ return 1; ++} ++ + /** + * Sets the name of a partition. + * +@@ -1510,6 +1540,78 @@ ped_partition_get_name (const PedPartition* part) + return part->disk->type->ops->partition_get_name (part); + } + ++/** ++ * Set the type-id of the partition \p part. This will only work if the disk label ++ * supports it. ++ */ ++int ++ped_partition_set_type_id (PedPartition *part, uint8_t id) ++{ ++ PED_ASSERT (part != NULL); ++ PED_ASSERT (part->disk != NULL); ++ PED_ASSERT (ped_partition_is_active (part)); ++ ++ if (!_assert_partition_type_id_feature (part->disk->type)) ++ return 0; ++ ++ PED_ASSERT (part->disk->type->ops->partition_set_type_id != NULL); ++ return part->disk->type->ops->partition_set_type_id (part, id); ++} ++ ++/** ++ * Get the type-id of the partition \p part. This will only work if the disk label ++ * supports it. ++ */ ++uint8_t ++ped_partition_get_type_id (const PedPartition *part) ++{ ++ PED_ASSERT (part != NULL); ++ PED_ASSERT (part->disk != NULL); ++ PED_ASSERT (ped_partition_is_active (part)); ++ ++ if (!_assert_partition_type_id_feature (part->disk->type)) ++ return 0; ++ ++ PED_ASSERT (part->disk->type->ops->partition_set_type_id != NULL); ++ return part->disk->type->ops->partition_get_type_id (part); ++} ++ ++/** ++ * Set the type-uuid of the partition \p part. This will only work if the disk label ++ * supports it. ++ */ ++int ++ped_partition_set_type_uuid (PedPartition *part, const uint8_t* uuid) ++{ ++ PED_ASSERT (part != NULL); ++ PED_ASSERT (part->disk != NULL); ++ PED_ASSERT (ped_partition_is_active (part)); ++ ++ if (!_assert_partition_type_uuid_feature (part->disk->type)) ++ return 0; ++ ++ PED_ASSERT (part->disk->type->ops->partition_set_type_uuid != NULL); ++ return part->disk->type->ops->partition_set_type_uuid (part, uuid); ++} ++ ++/** ++ * Get the type-uuid of the partition \p part. This will only work if the disk label ++ * supports it. ++ */ ++uint8_t* ++ped_partition_get_type_uuid (const PedPartition *part) ++{ ++ PED_ASSERT (part != NULL); ++ PED_ASSERT (part->disk != NULL); ++ PED_ASSERT (ped_partition_is_active (part)); ++ ++ if (!_assert_partition_type_uuid_feature (part->disk->type)) ++ return NULL; ++ ++ PED_ASSERT (part->disk->type->ops->partition_set_type_uuid != NULL); ++ return part->disk->type->ops->partition_get_type_uuid (part); ++} ++ + /** @} */ + + /** +diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c +index 38f2b00..0c00c4f 100644 +--- a/libparted/labels/dasd.c ++++ b/libparted/labels/dasd.c +@@ -117,6 +117,10 @@ static PedDiskOps dasd_disk_ops = { + + partition_set_name: NULL, + partition_get_name: NULL, ++ partition_set_type_id: NULL, ++ partition_get_type_id: NULL, ++ partition_set_type_uuid: NULL, ++ partition_get_type_uuid: NULL, + + get_partition_alignment: dasd_get_partition_alignment, + +diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c +index 26d8804..bd7465d 100644 +--- a/libparted/labels/dos.c ++++ b/libparted/labels/dos.c +@@ -100,6 +100,209 @@ static const char MBR_BOOT_CODE[] = { + #define PARTITION_LINUX_RAID 0xfd + #define PARTITION_LINUX_LVM_OLD 0xfe + ++struct flag_id_mapping_t ++{ ++ enum _PedPartitionFlag flag; ++ unsigned char type_id; ++ unsigned char alt_type_id; ++}; ++ ++static const struct flag_id_mapping_t flag_id_mapping[] = ++{ ++ { PED_PARTITION_BLS_BOOT, PARTITION_BLS_BOOT }, ++ { PED_PARTITION_DIAG, PARTITION_COMPAQ_DIAG, PARTITION_DELL_DIAG }, ++ { PED_PARTITION_ESP, PARTITION_ESP }, ++ { PED_PARTITION_IRST, PARTITION_IRST }, ++ { PED_PARTITION_LVM, PARTITION_LINUX_LVM, PARTITION_LINUX_LVM_OLD }, ++ { PED_PARTITION_MSFT_RESERVED, PARTITION_MSFT_RECOVERY }, ++ { PED_PARTITION_PALO, PARTITION_PALO }, ++ { PED_PARTITION_PREP, PARTITION_PREP }, ++ { PED_PARTITION_RAID, PARTITION_LINUX_RAID }, ++ { PED_PARTITION_SWAP, PARTITION_LINUX_SWAP }, ++}; ++ ++static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST ++dos_find_flag_id_mapping (PedPartitionFlag flag) ++{ ++ int n = sizeof(flag_id_mapping) / sizeof(flag_id_mapping[0]); ++ ++ for (int i = 0; i < n; ++i) ++ if (flag_id_mapping[i].flag == flag) ++ return &flag_id_mapping[i]; ++ ++ return NULL; ++} ++ ++/** ++ * Check whether the type_id supports the hidden flag. Returns true for both hidden and ++ * non-hidden id. ++ */ ++static bool ++dos_type_id_supports_hidden(unsigned char type_id) ++{ ++ switch (type_id) ++ { ++ case PARTITION_DOS_EXT: ++ case PARTITION_DOS_EXT_H: ++ case PARTITION_FAT12: ++ case PARTITION_FAT12_H: ++ case PARTITION_FAT16: ++ case PARTITION_FAT16_H: ++ case PARTITION_FAT16_LBA: ++ case PARTITION_FAT16_LBA_H: ++ case PARTITION_FAT16_SM: ++ case PARTITION_FAT16_SM_H: ++ case PARTITION_FAT32: ++ case PARTITION_FAT32_H: ++ case PARTITION_FAT32_LBA: ++ case PARTITION_FAT32_LBA_H: ++ case PARTITION_NTFS: ++ case PARTITION_NTFS_H: ++ return true; ++ ++ default: ++ return false; ++ } ++} ++ ++/** ++ * Check whether the type_id has the hidden flag set. ++ */ ++static bool ++dos_type_id_is_hidden(unsigned char type_id) ++{ ++ switch (type_id) ++ { ++ case PARTITION_DOS_EXT_H: ++ case PARTITION_FAT12_H: ++ case PARTITION_FAT16_H: ++ case PARTITION_FAT16_LBA_H: ++ case PARTITION_FAT16_SM_H: ++ case PARTITION_FAT32_H: ++ case PARTITION_FAT32_LBA_H: ++ case PARTITION_NTFS_H: ++ return true; ++ ++ default: ++ return false; ++ } ++} ++ ++/** ++ * Sets the hidden flag on type_id. ++ */ ++static bool ++dos_type_id_set_hidden(unsigned char* type_id, bool state) ++{ ++ PED_ASSERT (type_id); ++ ++ if (!dos_type_id_supports_hidden(*type_id)) ++ return false; ++ ++ if (state) ++ *type_id |= PART_FLAG_HIDDEN; ++ else ++ *type_id &= ~PART_FLAG_HIDDEN; ++ ++ return 1; ++} ++ ++/** ++ * Check whether the type_id supports the lba flag. Returns true for both lba and non-lba ++ * id. ++ */ ++static bool ++dos_type_id_supports_lba(unsigned char type_id) ++{ ++ switch (type_id) ++ { ++ case PARTITION_FAT16: ++ case PARTITION_FAT16_H: ++ case PARTITION_FAT16_LBA: ++ case PARTITION_FAT16_LBA_H: ++ case PARTITION_FAT32: ++ case PARTITION_FAT32_H: ++ case PARTITION_FAT32_LBA: ++ case PARTITION_FAT32_LBA_H: ++ case PARTITION_DOS_EXT: ++ case PARTITION_EXT_LBA: ++ return true; ++ ++ default: ++ return false; ++ } ++} ++ ++/** ++ * Check whether the type_id has the lba flag set. ++ */ ++static bool ++dos_type_id_is_lba(unsigned char type_id) ++{ ++ switch (type_id) ++ { ++ case PARTITION_FAT16_LBA: ++ case PARTITION_FAT16_LBA_H: ++ case PARTITION_FAT32_LBA: ++ case PARTITION_FAT32_LBA_H: ++ case PARTITION_EXT_LBA: ++ return true; ++ ++ default: ++ return false; ++ } ++} ++ ++/** ++ * Sets the lba flag on type_id. ++ */ ++static bool ++dos_type_id_set_lba(unsigned char* type_id, bool state) ++{ ++ PED_ASSERT (type_id); ++ ++ if (!dos_type_id_supports_lba(*type_id)) ++ return false; ++ ++ if (state) ++ { ++ switch (*type_id) ++ { ++ case PARTITION_FAT16: ++ *type_id = PARTITION_FAT16_LBA; ++ break; ++ ++ case PARTITION_FAT32: ++ *type_id = PARTITION_FAT32_LBA; ++ break; ++ ++ case PARTITION_DOS_EXT: ++ *type_id = PARTITION_EXT_LBA; ++ break; ++ } ++ } ++ else ++ { ++ switch (*type_id) ++ { ++ case PARTITION_FAT16_LBA: ++ *type_id = PARTITION_FAT16; ++ break; ++ ++ case PARTITION_FAT32_LBA: ++ *type_id = PARTITION_FAT32; ++ break; ++ ++ case PARTITION_EXT_LBA: ++ *type_id = PARTITION_DOS_EXT; ++ break; ++ } ++ } ++ ++ return true; ++} ++ ++ + /* This constant contains the maximum cylinder number that can be represented + * in (C,H,S) notation. Higher cylinder numbers are reserved for + * "too big" indicators (in which case only LBA addressing can be used). +@@ -156,18 +359,6 @@ typedef struct { + typedef struct { + unsigned char system; + int boot; +- int hidden; +- int msftres; +- int raid; +- int lvm; +- int swap; +- int lba; +- int palo; +- int prep; +- int diag; +- int irst; +- int esp; +- int bls_boot; + OrigState* orig; /* used for CHS stuff */ + } DosPartitionData; + +@@ -891,48 +1082,6 @@ raw_part_is_extended (const DosRawPartition* raw_part) + return 0; + } + +-static int _GL_ATTRIBUTE_PURE +-raw_part_is_hidden (const DosRawPartition* raw_part) +-{ +- PED_ASSERT (raw_part != NULL); +- +- switch (raw_part->type) { +- case PARTITION_FAT12_H: +- case PARTITION_FAT16_SM_H: +- case PARTITION_FAT16_H: +- case PARTITION_FAT32_H: +- case PARTITION_NTFS_H: +- case PARTITION_FAT32_LBA_H: +- case PARTITION_FAT16_LBA_H: +- return 1; +- +- default: +- return 0; +- } +- +- return 0; +-} +- +-static int _GL_ATTRIBUTE_PURE +-raw_part_is_lba (const DosRawPartition* raw_part) +-{ +- PED_ASSERT (raw_part != NULL); +- +- switch (raw_part->type) { +- case PARTITION_FAT32_LBA: +- case PARTITION_FAT16_LBA: +- case PARTITION_EXT_LBA: +- case PARTITION_FAT32_LBA_H: +- case PARTITION_FAT16_LBA_H: +- return 1; +- +- default: +- return 0; +- } +- +- return 0; +-} +- + static PedPartition* + raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part, + PedSector lba_offset, PedPartitionType type) +@@ -952,20 +1101,6 @@ raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part, + dos_data = part->disk_specific; + dos_data->system = raw_part->type; + dos_data->boot = raw_part->boot_ind != 0; +- dos_data->diag = raw_part->type == PARTITION_COMPAQ_DIAG || +- raw_part->type == PARTITION_DELL_DIAG; +- dos_data->msftres = raw_part->type == PARTITION_MSFT_RECOVERY; +- dos_data->hidden = raw_part_is_hidden (raw_part); +- dos_data->raid = raw_part->type == PARTITION_LINUX_RAID; +- dos_data->lvm = raw_part->type == PARTITION_LINUX_LVM_OLD +- || raw_part->type == PARTITION_LINUX_LVM; +- dos_data->swap = raw_part->type == PARTITION_LINUX_SWAP; +- dos_data->lba = raw_part_is_lba (raw_part); +- dos_data->palo = raw_part->type == PARTITION_PALO; +- dos_data->prep = raw_part->type == PARTITION_PREP; +- dos_data->irst = raw_part->type == PARTITION_IRST; +- dos_data->esp = raw_part->type == PARTITION_ESP; +- dos_data->bls_boot = raw_part->type == PARTITION_BLS_BOOT; + dos_data->orig = ped_malloc (sizeof (OrigState)); + if (!dos_data->orig) { + ped_partition_destroy (part); +@@ -1377,18 +1512,6 @@ msdos_partition_duplicate (const PedPartition* part) + new_dos_data = (DosPartitionData*) new_part->disk_specific; + new_dos_data->system = old_dos_data->system; + new_dos_data->boot = old_dos_data->boot; +- new_dos_data->diag = old_dos_data->diag; +- new_dos_data->hidden = old_dos_data->hidden; +- new_dos_data->msftres = old_dos_data->msftres; +- new_dos_data->raid = old_dos_data->raid; +- new_dos_data->lvm = old_dos_data->lvm; +- new_dos_data->swap = old_dos_data->swap; +- new_dos_data->lba = old_dos_data->lba; +- new_dos_data->palo = old_dos_data->palo; +- new_dos_data->prep = old_dos_data->prep; +- new_dos_data->irst = old_dos_data->irst; +- new_dos_data->esp = old_dos_data->esp; +- new_dos_data->bls_boot = old_dos_data->bls_boot; + + if (old_dos_data->orig) { + new_dos_data->orig = ped_malloc (sizeof (OrigState)); +@@ -1425,234 +1548,87 @@ msdos_partition_set_system (PedPartition* part, + + part->fs_type = fs_type; + +- if (dos_data->hidden +- && fs_type +- && strncmp (fs_type->name, "fat", 3) != 0 +- && strcmp (fs_type->name, "ntfs") != 0) +- dos_data->hidden = 0; +- +- if (dos_data->msftres +- && fs_type +- && strcmp (fs_type->name, "ntfs") != 0) +- dos_data->msftres = 0; +- + if (part->type & PED_PARTITION_EXTENDED) { +- dos_data->diag = 0; +- dos_data->raid = 0; +- dos_data->lvm = 0; +- dos_data->swap = 0; +- dos_data->palo = 0; +- dos_data->prep = 0; +- dos_data->irst = 0; +- dos_data->esp = 0; +- if (dos_data->lba) +- dos_data->system = PARTITION_EXT_LBA; +- else +- dos_data->system = PARTITION_DOS_EXT; +- return 1; +- } +- +- if (dos_data->diag) { +- /* Don't change the system if it already is a diag type, +- otherwise use Compaq as almost all vendors use that. */ +- if (dos_data->system != PARTITION_COMPAQ_DIAG && +- dos_data->system != PARTITION_DELL_DIAG) +- dos_data->system = PARTITION_COMPAQ_DIAG; +- return 1; +- } +- if (dos_data->msftres) { +- dos_data->system = PARTITION_MSFT_RECOVERY; +- return 1; +- } +- if (dos_data->lvm) { +- dos_data->system = PARTITION_LINUX_LVM; +- return 1; +- } +- if (dos_data->swap) { +- dos_data->system = PARTITION_LINUX_SWAP; +- return 1; +- } +- if (dos_data->raid) { +- dos_data->system = PARTITION_LINUX_RAID; +- return 1; +- } +- if (dos_data->palo) { +- dos_data->system = PARTITION_PALO; +- return 1; +- } +- if (dos_data->prep) { +- dos_data->system = PARTITION_PREP; +- return 1; +- } +- if (dos_data->irst) { +- dos_data->system = PARTITION_IRST; +- return 1; +- } +- if (dos_data->esp) { +- dos_data->system = PARTITION_ESP; +- return 1; +- } +- if (dos_data->bls_boot) { +- dos_data->system = PARTITION_BLS_BOOT; ++ dos_data->system = PARTITION_EXT_LBA; + return 1; + } + + if (!fs_type) + dos_data->system = PARTITION_LINUX; +- else if (!strcmp (fs_type->name, "fat16")) { +- dos_data->system = dos_data->lba +- ? PARTITION_FAT16_LBA : PARTITION_FAT16; +- dos_data->system |= dos_data->hidden ? PART_FLAG_HIDDEN : 0; +- } else if (!strcmp (fs_type->name, "fat32")) { +- dos_data->system = dos_data->lba +- ? PARTITION_FAT32_LBA : PARTITION_FAT32; +- dos_data->system |= dos_data->hidden ? PART_FLAG_HIDDEN : 0; +- } else if (!strcmp (fs_type->name, "ntfs") +- || !strcmp (fs_type->name, "hpfs")) { ++ else if (!strcmp (fs_type->name, "fat16")) ++ dos_data->system = PARTITION_FAT16; ++ else if (!strcmp (fs_type->name, "fat32")) ++ dos_data->system = PARTITION_FAT32; ++ else if (!strcmp (fs_type->name, "ntfs") ++ || !strcmp (fs_type->name, "hpfs")) + dos_data->system = PARTITION_NTFS; +- dos_data->system |= dos_data->hidden ? PART_FLAG_HIDDEN : 0; +- } else if (!strcmp (fs_type->name, "hfs") ++ else if (!strcmp (fs_type->name, "hfs") + || !strcmp (fs_type->name, "hfs+")) + dos_data->system = PARTITION_HFS; + else if (!strcmp (fs_type->name, "udf")) + dos_data->system = PARTITION_UDF; + else if (!strcmp (fs_type->name, "sun-ufs")) + dos_data->system = PARTITION_SUN_UFS; +- else if (is_linux_swap (fs_type->name)) { ++ else if (is_linux_swap (fs_type->name)) + dos_data->system = PARTITION_LINUX_SWAP; +- dos_data->swap = 1; +- } else ++ else + dos_data->system = PARTITION_LINUX; + + return 1; + } + +-static void +-clear_flags (DosPartitionData *dos_data) +-{ +- dos_data->diag = 0; +- dos_data->hidden = 0; +- dos_data->msftres = 0; +- dos_data->lvm = 0; +- dos_data->swap = 0; +- dos_data->palo = 0; +- dos_data->prep = 0; +- dos_data->irst = 0; +- dos_data->esp = 0; +- dos_data->raid = 0; +- dos_data->bls_boot = 0; +-} +- + static int + msdos_partition_set_flag (PedPartition* part, + PedPartitionFlag flag, int state) + { +- PedDisk* disk; +- PedPartition* walk; +- DosPartitionData* dos_data; +- + PED_ASSERT (part != NULL); + PED_ASSERT (part->disk_specific != NULL); + PED_ASSERT (part->disk != NULL); + +- dos_data = part->disk_specific; +- disk = part->disk; +- +- switch (flag) { +- case PED_PARTITION_HIDDEN: +- if (part->type == PED_PARTITION_EXTENDED) { +- ped_exception_throw ( +- PED_EXCEPTION_ERROR, +- PED_EXCEPTION_CANCEL, +- _("Extended partitions cannot be hidden on " +- "msdos disk labels.")); +- return 0; +- } +- dos_data->hidden = state; +- return ped_partition_set_system (part, part->fs_type); +- +- case PED_PARTITION_MSFT_RESERVED: +- if (part->type == PED_PARTITION_EXTENDED) { +- ped_exception_throw ( +- PED_EXCEPTION_ERROR, +- PED_EXCEPTION_CANCEL, +- _("Extended partitions cannot be recovery partitions on " +- "msdos disk labels.")); +- return 0; +- } +- dos_data->msftres = state; +- return ped_partition_set_system (part, part->fs_type); +- +- case PED_PARTITION_BOOT: +- dos_data->boot = state; +- if (!state) +- return 1; +- +- walk = ped_disk_next_partition (disk, NULL); +- for (; walk; walk = ped_disk_next_partition (disk, walk)) { +- if (walk == part || !ped_partition_is_active (walk)) +- continue; +- msdos_partition_set_flag (walk, PED_PARTITION_BOOT, 0); +- } +- return 1; ++ DosPartitionData* dos_data = part->disk_specific; + +- case PED_PARTITION_DIAG: +- if (state) +- clear_flags (dos_data); +- dos_data->diag = state; +- return ped_partition_set_system (part, part->fs_type); ++ const struct flag_id_mapping_t* p = dos_find_flag_id_mapping (flag); ++ if (p) ++ { ++ if (part->type & PED_PARTITION_EXTENDED) ++ return 0; + +- case PED_PARTITION_RAID: +- if (state) +- clear_flags (dos_data); +- dos_data->raid = state; ++ if (state) ++ dos_data->system = p->type_id; ++ else if (dos_data->system == p->type_id || dos_data->system == p->alt_type_id) + return ped_partition_set_system (part, part->fs_type); + +- case PED_PARTITION_LVM: +- if (state) +- clear_flags (dos_data); +- dos_data->lvm = state; +- return ped_partition_set_system (part, part->fs_type); ++ return 1; ++ } + +- case PED_PARTITION_SWAP: +- if (state) +- clear_flags (dos_data); +- dos_data->swap = state; +- return ped_partition_set_system (part, part->fs_type); ++ switch (flag) { ++ case PED_PARTITION_HIDDEN: ++ { ++ return dos_type_id_set_hidden(&dos_data->system, state); ++ } + + case PED_PARTITION_LBA: +- dos_data->lba = state; +- return ped_partition_set_system (part, part->fs_type); +- +- case PED_PARTITION_PALO: +- if (state) +- clear_flags (dos_data); +- dos_data->palo = state; +- return ped_partition_set_system (part, part->fs_type); +- +- case PED_PARTITION_PREP: +- if (state) +- clear_flags (dos_data); +- dos_data->prep = state; +- return ped_partition_set_system (part, part->fs_type); ++ { ++ return dos_type_id_set_lba(&dos_data->system, state); ++ } + +- case PED_PARTITION_IRST: +- if (state) +- clear_flags (dos_data); +- dos_data->irst = state; +- return ped_partition_set_system (part, part->fs_type); ++ case PED_PARTITION_BOOT: ++ { ++ dos_data->boot = state; + +- case PED_PARTITION_ESP: + if (state) +- clear_flags (dos_data); +- dos_data->esp = state; +- return ped_partition_set_system (part, part->fs_type); ++ { ++ PedDisk* disk = part->disk; ++ PedPartition* walk = ped_disk_next_partition (disk, NULL); ++ for (; walk; walk = ped_disk_next_partition (disk, walk)) { ++ if (walk == part || !ped_partition_is_active (walk)) ++ continue; ++ msdos_partition_set_flag (walk, PED_PARTITION_BOOT, 0); ++ } ++ } + +- case PED_PARTITION_BLS_BOOT: +- if (state) +- clear_flags (dos_data); +- dos_data->bls_boot = state; +- return ped_partition_set_system (part, part->fs_type); ++ return 1; ++ } + + default: + return 0; +@@ -1662,58 +1638,25 @@ msdos_partition_set_flag (PedPartition* part, + static int _GL_ATTRIBUTE_PURE + msdos_partition_get_flag (const PedPartition* part, PedPartitionFlag flag) + { +- DosPartitionData* dos_data; +- + PED_ASSERT (part != NULL); + PED_ASSERT (part->disk_specific != NULL); + +- dos_data = part->disk_specific; ++ DosPartitionData* dos_data = part->disk_specific; ++ ++ const struct flag_id_mapping_t* p = dos_find_flag_id_mapping (flag); ++ if (p) ++ return dos_data->system == p->type_id || dos_data->system == p->alt_type_id; ++ + switch (flag) { + case PED_PARTITION_HIDDEN: +- if (part->type == PED_PARTITION_EXTENDED) +- return 0; +- else +- return dos_data->hidden; ++ return dos_type_id_is_hidden(dos_data->system); + +- case PED_PARTITION_MSFT_RESERVED: +- if (part->type == PED_PARTITION_EXTENDED) +- return 0; +- else +- return dos_data->msftres; ++ case PED_PARTITION_LBA: ++ return dos_type_id_is_lba(dos_data->system); + + case PED_PARTITION_BOOT: + return dos_data->boot; + +- case PED_PARTITION_DIAG: +- return dos_data->diag; +- +- case PED_PARTITION_RAID: +- return dos_data->raid; +- +- case PED_PARTITION_LVM: +- return dos_data->lvm; +- +- case PED_PARTITION_SWAP: +- return dos_data->swap; +- +- case PED_PARTITION_LBA: +- return dos_data->lba; +- +- case PED_PARTITION_PALO: +- return dos_data->palo; +- +- case PED_PARTITION_PREP: +- return dos_data->prep; +- +- case PED_PARTITION_IRST: +- return dos_data->irst; +- +- case PED_PARTITION_ESP: +- return dos_data->esp; +- +- case PED_PARTITION_BLS_BOOT: +- return dos_data->bls_boot; +- + default: + return 0; + } +@@ -1723,30 +1666,19 @@ static int + msdos_partition_is_flag_available (const PedPartition* part, + PedPartitionFlag flag) + { ++ if (dos_find_flag_id_mapping (flag)) ++ return part->type != PED_PARTITION_EXTENDED; ++ ++ DosPartitionData* dos_data = part->disk_specific; ++ + switch (flag) { + case PED_PARTITION_HIDDEN: +- if (part->type == PED_PARTITION_EXTENDED) +- return 0; +- else +- return 1; ++ return dos_type_id_supports_hidden(dos_data->system); + +- case PED_PARTITION_MSFT_RESERVED: +- if (part->type == PED_PARTITION_EXTENDED) +- return 0; +- else +- return 1; ++ case PED_PARTITION_LBA: ++ return dos_type_id_supports_lba(dos_data->system); + + case PED_PARTITION_BOOT: +- case PED_PARTITION_RAID: +- case PED_PARTITION_LVM: +- case PED_PARTITION_SWAP: +- case PED_PARTITION_LBA: +- case PED_PARTITION_PALO: +- case PED_PARTITION_PREP: +- case PED_PARTITION_IRST: +- case PED_PARTITION_ESP: +- case PED_PARTITION_BLS_BOOT: +- case PED_PARTITION_DIAG: + return 1; + + default: +@@ -1754,6 +1686,27 @@ msdos_partition_is_flag_available (const PedPartition* part, + } + } + ++ ++int ++msdos_partition_set_type_id (PedPartition* part, uint8_t id) ++{ ++ DosPartitionData* dos_data = part->disk_specific; ++ ++ dos_data->system = id; ++ ++ return 1; ++} ++ ++ ++uint8_t _GL_ATTRIBUTE_PURE ++msdos_partition_get_type_id (const PedPartition* part) ++{ ++ const DosPartitionData* dos_data = part->disk_specific; ++ ++ return dos_data->system; ++} ++ ++ + static PedGeometry* + _try_constraint (const PedPartition* part, const PedConstraint* external, + PedConstraint* internal) +@@ -2590,6 +2543,10 @@ static PedDiskOps msdos_disk_ops = { + + partition_set_name: NULL, + partition_get_name: NULL, ++ partition_set_type_id: msdos_partition_set_type_id, ++ partition_get_type_id: msdos_partition_get_type_id, ++ partition_set_type_uuid: NULL, ++ partition_get_type_uuid: NULL, + + PT_op_function_initializers (msdos) + }; +@@ -2598,7 +2555,7 @@ static PedDiskType msdos_disk_type = { + next: NULL, + name: "msdos", + ops: &msdos_disk_ops, +- features: PED_DISK_TYPE_EXTENDED ++ features: PED_DISK_TYPE_EXTENDED | PED_DISK_TYPE_PARTITION_TYPE_ID + }; + + void +diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c +index 037d021..0e9e060 100644 +--- a/libparted/labels/gpt.c ++++ b/libparted/labels/gpt.c +@@ -1686,6 +1686,44 @@ gpt_partition_get_name (const PedPartition *part) + return gpt_part_data->translated_name; + } + ++ ++static int ++gpt_partition_set_type_uuid (PedPartition *part, const uint8_t *uuid) ++{ ++ GPTPartitionData *gpt_part_data = part->disk_specific; ++ ++ efi_guid_t* type_uuid = &gpt_part_data->type; ++ memcpy(type_uuid, uuid, sizeof (efi_guid_t)); ++ ++ /* type_uuid is always LE, while uint8_t is always kind of BE */ ++ ++ type_uuid->time_low = PED_SWAP32(type_uuid->time_low); ++ type_uuid->time_mid = PED_SWAP16(type_uuid->time_mid); ++ type_uuid->time_hi_and_version = PED_SWAP16(type_uuid->time_hi_and_version); ++ ++ return 1; ++} ++ ++ ++static uint8_t* ++gpt_partition_get_type_uuid (const PedPartition *part) ++{ ++ const GPTPartitionData *gpt_part_data = part->disk_specific; ++ ++ efi_guid_t type_uuid = gpt_part_data->type; ++ ++ /* type_uuid is always LE, while uint8_t is always kind of BE */ ++ ++ type_uuid.time_low = PED_SWAP32(type_uuid.time_low); ++ type_uuid.time_mid = PED_SWAP16(type_uuid.time_mid); ++ type_uuid.time_hi_and_version = PED_SWAP16(type_uuid.time_hi_and_version); ++ ++ uint8_t *buf = ped_malloc(sizeof (uuid_t)); ++ memcpy(buf, &type_uuid, sizeof (uuid_t)); ++ return buf; ++} ++ ++ + static int + gpt_get_max_primary_partition_count (const PedDisk *disk) + { +@@ -1781,6 +1819,10 @@ static PedDiskOps gpt_disk_ops = + + partition_set_name: gpt_partition_set_name, + partition_get_name: gpt_partition_get_name, ++ partition_set_type_id: NULL, ++ partition_get_type_id: NULL, ++ partition_set_type_uuid: gpt_partition_set_type_uuid, ++ partition_get_type_uuid: gpt_partition_get_type_uuid, + disk_set_flag: gpt_disk_set_flag, + disk_get_flag: gpt_disk_get_flag, + disk_is_flag_available: gpt_disk_is_flag_available, +@@ -1793,7 +1835,7 @@ static PedDiskType gpt_disk_type = + next: NULL, + name: "gpt", + ops: &gpt_disk_ops, +- features: PED_DISK_TYPE_PARTITION_NAME ++ features: PED_DISK_TYPE_PARTITION_NAME | PED_DISK_TYPE_PARTITION_TYPE_UUID + }; + + void +diff --git a/parted/parted.c b/parted/parted.c +index 5c7c270..b8a4acf 100644 +--- a/parted/parted.c ++++ b/parted/parted.c +@@ -19,6 +19,7 @@ + + #include + #include ++#include + + #include "argmatch.h" + #include "closeout.h" +@@ -174,6 +175,8 @@ static const char* end_msg = N_("END is disk location, such as " + static const char* state_msg = N_("STATE is one of: on, off\n"); + static const char* device_msg = N_("DEVICE is usually /dev/hda or /dev/sda\n"); + static const char* name_msg = N_("NAME is any word you want\n"); ++static const char* type_msg = N_("TYPE_ID is a value between 0x01 and 0xff, " ++ "TYPE_UUID is a UUID\n"); + + static const char* copyright_msg = N_( + "Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n" +@@ -917,6 +920,87 @@ error: + return 0; + } + ++static int ++do_type (PedDevice** dev, PedDisk** diskp) ++{ ++ if (!*diskp) ++ *diskp = ped_disk_new (*dev); ++ if (!*diskp) ++ goto error; ++ ++ bool has_type_id = ped_disk_type_check_feature ((*diskp)->type, ++ PED_DISK_TYPE_PARTITION_TYPE_ID); ++ bool has_type_uuid = ped_disk_type_check_feature ((*diskp)->type, ++ PED_DISK_TYPE_PARTITION_TYPE_UUID); ++ ++ PED_ASSERT (!(has_type_id && has_type_uuid)); ++ ++ if (!has_type_id && !has_type_uuid) { ++ ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, ++ _("%s disk labels do not support partition type."), ++ (*diskp)->type->name); ++ goto error; ++ } ++ ++ PedPartition* part = NULL; ++ if (!command_line_get_partition (_("Partition number?"), *diskp, &part)) ++ goto error; ++ ++ char* input = NULL; ++ ++ if (has_type_id) { ++ uint8_t type_id = ped_partition_get_type_id (part); ++ static char buf[8]; ++ snprintf(buf, 8, "0x%02x", type_id); ++ ++ input = command_line_get_word (_("Partition type-id?"), buf, NULL, 0); ++ if (!input) ++ goto error; ++ ++ unsigned int tmp = strtol (input, (char**) NULL, 16); ++ if (tmp < 0x01 || tmp > 0xff) { ++ ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, ++ _("Invalid type-id.")); ++ goto error_free_input; ++ } ++ ++ if (!ped_partition_set_type_id (part, tmp)) ++ goto error_free_input; ++ } ++ ++ if (has_type_uuid) { ++ uint8_t* type_uuid = ped_partition_get_type_uuid (part); ++ static char buf[UUID_STR_LEN]; ++ uuid_unparse_lower (type_uuid, buf); ++ free (type_uuid); ++ ++ input = command_line_get_word (_("Partition type-uuid?"), buf, NULL, 0); ++ if (!input) ++ goto error; ++ ++ uuid_t tmp; ++ if (uuid_parse (input, tmp) != 0 || uuid_is_null (tmp)) { ++ ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, ++ _("Invalid type-uuid.")); ++ goto error_free_input; ++ } ++ ++ if (!ped_partition_set_type_uuid (part, tmp)) ++ goto error_free_input; ++ } ++ ++ free (input); ++ ++ if (!ped_disk_commit (*diskp)) ++ goto error; ++ return 1; ++ ++error_free_input: ++ free (input); ++error: ++ return 0; ++} ++ + static char* + partition_print_flags (PedPartition const *part) + { +@@ -1270,6 +1354,10 @@ do_print (PedDevice** dev, PedDisk** diskp) + PED_DISK_TYPE_EXTENDED); + has_name = ped_disk_type_check_feature ((*diskp)->type, + PED_DISK_TYPE_PARTITION_NAME); ++ bool has_type_id = ped_disk_type_check_feature ((*diskp)->type, ++ PED_DISK_TYPE_PARTITION_TYPE_ID); ++ bool has_type_uuid = ped_disk_type_check_feature ((*diskp)->type, ++ PED_DISK_TYPE_PARTITION_TYPE_UUID); + + PedPartition* part; + if (opt_output_mode == HUMAN) { +@@ -1407,10 +1495,25 @@ do_print (PedDevice** dev, PedDisk** diskp) + + if (!(part->type & PED_PARTITION_FREESPACE)) { + ++ if (has_type_id) { ++ uint8_t type_id = ped_partition_get_type_id (part); ++ static char buf[8]; ++ snprintf(buf, 8, "0x%02x", type_id); ++ ul_jsonwrt_value_s (&json, "type-id", buf); ++ } ++ ++ if (has_type_uuid) { ++ uint8_t* type_uuid = ped_partition_get_type_uuid (part); ++ static char buf[UUID_STR_LEN]; ++ uuid_unparse_lower (type_uuid, buf); ++ ul_jsonwrt_value_s (&json, "type-uuid", buf); ++ free (type_uuid); ++ } ++ + if (has_name) { + name = ped_partition_get_name (part); + if (strcmp (name, "") != 0) +- ul_jsonwrt_value_s (&json, "name", ped_partition_get_name (part)); ++ ul_jsonwrt_value_s (&json, "name", name); + } + + if (part->fs_type) +@@ -2316,6 +2419,14 @@ _("toggle [NUMBER [FLAG]] toggle the state of FLAG on " + NULL), + str_list_create (_(number_msg), flag_msg, NULL), 1)); + ++command_register (commands, command_create ( ++ str_list_create_unique ("type", _("type"), NULL), ++ do_type, ++ str_list_create ( ++_("type NUMBER TYPE-ID or TYPE-UUID type set TYPE-ID or TYPE-UUID of partition NUMBER"), ++NULL), ++ str_list_create (_(number_msg), _(type_msg), NULL), 1)); ++ + command_register (commands, command_create ( + str_list_create_unique ("unit", _("unit"), NULL), + do_unit, +diff --git a/tests/Makefile.am b/tests/Makefile.am +index 5cb7aa3..2da653b 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -43,6 +43,10 @@ TESTS = \ + t0501-duplicate.sh \ + t0800-json-gpt.sh \ + t0801-json-msdos.sh \ ++ t0900-type-gpt.sh \ ++ t0901-type-gpt-invalid.sh \ ++ t0910-type-dos.sh \ ++ t0911-type-dos-invalid.sh \ + t1100-busy-label.sh \ + t1101-busy-partition.sh \ + t1102-loop-label.sh \ +diff --git a/tests/t0800-json-gpt.sh b/tests/t0800-json-gpt.sh +index 8dd1862..354c0bd 100755 +--- a/tests/t0800-json-gpt.sh ++++ b/tests/t0800-json-gpt.sh +@@ -62,6 +62,7 @@ cat < exp || fail=1 + "end": "20479s", + "size": "10240s", + "type": "primary", ++ "type-uuid": "0fc63daf-8483-4772-8e79-3d69d8477de4", + "name": "test1" + },{ + "number": 2, +@@ -69,6 +70,7 @@ cat < exp || fail=1 + "end": "61439s", + "size": "40960s", + "type": "primary", ++ "type-uuid": "a19d880f-05fc-4d3b-a006-743f0f84911e", + "name": "test2", + "flags": [ + "raid" +diff --git a/tests/t0801-json-msdos.sh b/tests/t0801-json-msdos.sh +index a14a5af..c5446d8 100755 +--- a/tests/t0801-json-msdos.sh ++++ b/tests/t0801-json-msdos.sh +@@ -52,13 +52,15 @@ cat < exp || fail=1 + "start": "5.00MiB", + "end": "10.0MiB", + "size": "5.00MiB", +- "type": "primary" ++ "type": "primary", ++ "type-id": "0x83" + },{ + "number": 2, + "start": "10.0MiB", + "end": "30.0MiB", + "size": "20.0MiB", + "type": "extended", ++ "type-id": "0x0f", + "flags": [ + "lba" + ] +@@ -68,6 +70,7 @@ cat < exp || fail=1 + "end": "20.0MiB", + "size": "10.0MiB", + "type": "logical", ++ "type-id": "0x8e", + "flags": [ + "lvm" + ] +diff --git a/tests/t0900-type-gpt.sh b/tests/t0900-type-gpt.sh +new file mode 100755 +index 0000000..2014820 +--- /dev/null ++++ b/tests/t0900-type-gpt.sh +@@ -0,0 +1,69 @@ ++#!/bin/sh ++ ++# Test type command with GPT label ++ ++# Copyright (C) 2022 SUSE LLC ++ ++# 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 3 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, see . ++ ++. "${srcdir=.}/init.sh"; path_prepend_ ../parted ++require_512_byte_sector_size_ ++ ++dev=loop-file ++ ++# create device ++truncate --size 50MiB "$dev" || fail=1 ++ ++# create gpt label and one partition ++parted --script "$dev" mklabel gpt > out 2>&1 || fail=1 ++parted --script "$dev" mkpart "''" "linux-swap" 10% 20% > out 2>&1 || fail=1 ++ ++# set type-uuid ++parted --script "$dev" type 1 "deadfd6d-a4ab-43c4-84e5-0933c84b4f4f" || fail=1 ++ ++# print with json format ++parted --script --json "$dev" unit s print > out 2>&1 || fail=1 ++ ++cat < exp || fail=1 ++{ ++ "disk": { ++ "path": "loop-file", ++ "size": "102400s", ++ "model": "", ++ "transport": "file", ++ "logical-sector-size": 512, ++ "physical-sector-size": 512, ++ "label": "gpt", ++ "max-partitions": 128, ++ "partitions": [ ++ { ++ "number": 1, ++ "start": "10240s", ++ "end": "20479s", ++ "size": "10240s", ++ "type": "primary", ++ "type-uuid": "deadfd6d-a4ab-43c4-84e5-0933c84b4f4f" ++ } ++ ] ++ } ++} ++EOF ++ ++# remove full path of device from actual output ++mv out o2 && sed "s,\"/.*/$dev\",\"$dev\"," o2 > out || fail=1 ++ ++# check for expected output ++compare exp out || fail=1 ++ ++Exit $fail +diff --git a/tests/t0901-type-gpt-invalid.sh b/tests/t0901-type-gpt-invalid.sh +new file mode 100755 +index 0000000..681df3a +--- /dev/null ++++ b/tests/t0901-type-gpt-invalid.sh +@@ -0,0 +1,35 @@ ++#!/bin/sh ++ ++# Test type command with GPT label ++ ++# Copyright (C) 2022 SUSE LLC ++ ++# 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 3 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, see . ++ ++. "${srcdir=.}/init.sh"; path_prepend_ ../parted ++require_512_byte_sector_size_ ++ ++dev=loop-file ++ ++# create device ++truncate --size 50MiB "$dev" || fail=1 ++ ++# create gpt label and one partition ++parted --script "$dev" mklabel gpt > out 2>&1 || fail=1 ++parted --script "$dev" mkpart "''" "linux-swap" 10% 20% > out 2>&1 || fail=1 ++ ++# set type-uuid ++parted --script "$dev" type 1 "invalidd-a4ab-43c4-84e5-0933c84b4f4f" && fail=1 ++ ++Exit $fail +diff --git a/tests/t0910-type-dos.sh b/tests/t0910-type-dos.sh +new file mode 100755 +index 0000000..d7cc37f +--- /dev/null ++++ b/tests/t0910-type-dos.sh +@@ -0,0 +1,69 @@ ++#!/bin/sh ++ ++# Test type command with MS-DOS label ++ ++# Copyright (C) 2022 SUSE LLC ++ ++# 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 3 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, see . ++ ++. "${srcdir=.}/init.sh"; path_prepend_ ../parted ++require_512_byte_sector_size_ ++ ++dev=loop-file ++ ++# create device ++truncate --size 50MiB "$dev" || fail=1 ++ ++# create msdos label and one partition ++parted --script "$dev" mklabel msdos > out 2>&1 || fail=1 ++parted --script "$dev" mkpart primary "linux-swap" 10% 20% > out 2>&1 || fail=1 ++ ++# set type-id ++parted --script "$dev" type 1 "0x83" || fail=1 ++ ++# print with json format ++parted --script --json "$dev" unit s print > out 2>&1 || fail=1 ++ ++cat < exp || fail=1 ++{ ++ "disk": { ++ "path": "loop-file", ++ "size": "102400s", ++ "model": "", ++ "transport": "file", ++ "logical-sector-size": 512, ++ "physical-sector-size": 512, ++ "label": "msdos", ++ "max-partitions": 4, ++ "partitions": [ ++ { ++ "number": 1, ++ "start": "10240s", ++ "end": "20479s", ++ "size": "10240s", ++ "type": "primary", ++ "type-id": "0x83" ++ } ++ ] ++ } ++} ++EOF ++ ++# remove full path of device from actual output ++mv out o2 && sed "s,\"/.*/$dev\",\"$dev\"," o2 > out || fail=1 ++ ++# check for expected output ++compare exp out || fail=1 ++ ++Exit $fail +diff --git a/tests/t0911-type-dos-invalid.sh b/tests/t0911-type-dos-invalid.sh +new file mode 100755 +index 0000000..f1036d1 +--- /dev/null ++++ b/tests/t0911-type-dos-invalid.sh +@@ -0,0 +1,35 @@ ++#!/bin/sh ++ ++# Test type command with MS-DOS label ++ ++# Copyright (C) 2022 SUSE LLC ++ ++# 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 3 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, see . ++ ++. "${srcdir=.}/init.sh"; path_prepend_ ../parted ++require_512_byte_sector_size_ ++ ++dev=loop-file ++ ++# create device ++truncate --size 50MiB "$dev" || fail=1 ++ ++# create msdos label and one partition ++parted --script "$dev" mklabel msdos > out 2>&1 || fail=1 ++parted --script "$dev" mkpart primary "linux-swap" 10% 20% > out 2>&1 || fail=1 ++ ++# set type-id ++parted --script "$dev" type 1 "0x101" && fail=1 ++ ++Exit $fail +diff --git a/tests/t2400-dos-hfs-partition-type.sh b/tests/t2400-dos-hfs-partition-type.sh +index 6733683..8c54ec4 100644 +--- a/tests/t2400-dos-hfs-partition-type.sh ++++ b/tests/t2400-dos-hfs-partition-type.sh +@@ -24,7 +24,7 @@ n_sectors=8000 + + dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || framework_failure + +-# create a GPT partition table ++# create a MS-DOS partition table + parted -s $dev mklabel msdos \ + mkpart pri hfs 2048s 4095s \ + mkpart pri hfs+ 4096s 6143s > out 2>&1 || fail=1 +diff --git a/tests/t3300-palo-prep.sh b/tests/t3300-palo-prep.sh +index 5005e0e..efe54db 100755 +--- a/tests/t3300-palo-prep.sh ++++ b/tests/t3300-palo-prep.sh +@@ -20,9 +20,9 @@ + ss=$sector_size_ + + cat > exp < out 2> err || fail=1 + +-grep -E '^1:2048s:4095s:2048s:ext2::lba, p...;$' out > k; mv k out ++grep -E '^1:2048s:4095s:2048s:ext2::p...;$' out > k; mv k out + + compare exp out || fail=1 + +diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh +index f2001c5..b35d443 100644 +--- a/tests/t3310-flags.sh ++++ b/tests/t3310-flags.sh +@@ -91,6 +91,10 @@ for table_type in aix amiga atari bsd dvh gpt mac msdos pc98 sun loop; do + # test to fail. + flags=`echo "$flags" | egrep -v 'lvm|raid'` + ;; ++ msdos) # FIXME: Exclude flags that can only be set in combination ++ # with certain other flags. ++ flags=`echo "$flags" | egrep -v 'hidden|lba'` ++ ;; + esac + + for mode in on_only on_and_off ; do +-- +2.35.3 + diff --git a/SOURCES/0003-libparted-add-swap-flag-for-DASD-label.patch b/SOURCES/0003-libparted-add-swap-flag-for-DASD-label.patch new file mode 100644 index 0000000..a9d7f7e --- /dev/null +++ b/SOURCES/0003-libparted-add-swap-flag-for-DASD-label.patch @@ -0,0 +1,228 @@ +From 29ffc6a1f285f48ac0b9efa7299373e486c486e8 Mon Sep 17 00:00:00 2001 +From: Arvin Schnell +Date: Fri, 8 Oct 2021 10:06:24 +0000 +Subject: [PATCH 3/5] libparted: add swap flag for DASD label + +Support the swap flag and fix reading flags from disk. Also +cleanup code by dropping the 2 flags "raid" and "lvm" from +DasdPartitionData and instead use "system" directly. + +Signed-off-by: Brian C. Lane +--- + include/parted/fdasd.in.h | 2 - + libparted/labels/dasd.c | 118 ++++++++++++++++---------------------- + 2 files changed, 50 insertions(+), 70 deletions(-) + +diff --git a/include/parted/fdasd.in.h b/include/parted/fdasd.in.h +index 9e5d7d1..e3ba183 100644 +--- a/include/parted/fdasd.in.h ++++ b/include/parted/fdasd.in.h +@@ -28,10 +28,8 @@ + + #define PARTITION_LINUX_SWAP 0x82 + #define PARTITION_LINUX 0x83 +-#define PARTITION_LINUX_EXT 0x85 + #define PARTITION_LINUX_LVM 0x8e + #define PARTITION_LINUX_RAID 0xfd +-#define PARTITION_LINUX_LVM_OLD 0xfe + + #define PART_TYPE_NATIVE "NATIVE" + #define PART_TYPE_SWAP "SWAP " +diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c +index 0c00c4f..27baad0 100644 +--- a/libparted/labels/dasd.c ++++ b/libparted/labels/dasd.c +@@ -53,10 +53,8 @@ + + #define PARTITION_LINUX_SWAP 0x82 + #define PARTITION_LINUX 0x83 +-#define PARTITION_LINUX_EXT 0x85 + #define PARTITION_LINUX_LVM 0x8e + #define PARTITION_LINUX_RAID 0xfd +-#define PARTITION_LINUX_LVM_OLD 0xfe + + extern void ped_disk_dasd_init (); + extern void ped_disk_dasd_done (); +@@ -66,8 +64,6 @@ extern void ped_disk_dasd_done (); + typedef struct { + int type; + int system; +- int raid; +- int lvm; + } DasdPartitionData; + + typedef struct { +@@ -134,6 +130,31 @@ static PedDiskType dasd_disk_type = { + features: 0 + }; + ++struct flag_id_mapping_t ++{ ++ enum _PedPartitionFlag flag; ++ int type_id; ++}; ++ ++static const struct flag_id_mapping_t flag_id_mapping[] = ++{ ++ { PED_PARTITION_LVM, PARTITION_LINUX_LVM }, ++ { PED_PARTITION_RAID, PARTITION_LINUX_RAID }, ++ { PED_PARTITION_SWAP, PARTITION_LINUX_SWAP }, ++}; ++ ++static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST ++dasd_find_flag_id_mapping (PedPartitionFlag flag) ++{ ++ int n = sizeof(flag_id_mapping) / sizeof(flag_id_mapping[0]); ++ ++ for (int i = 0; i < n; ++i) ++ if (flag_id_mapping[i].flag == flag) ++ return &flag_id_mapping[i]; ++ ++ return NULL; ++} ++ + static PedDisk* + dasd_alloc (const PedDevice* dev) + { +@@ -310,8 +331,6 @@ dasd_read (PedDisk* disk) + part->num = 1; + part->fs_type = ped_file_system_probe (&part->geom); + dasd_data = part->disk_specific; +- dasd_data->raid = 0; +- dasd_data->lvm = 0; + dasd_data->type = 0; + + if (!ped_disk_add_partition (disk, part, NULL)) +@@ -394,8 +413,6 @@ dasd_read (PedDisk* disk) + part->num = 1; + part->fs_type = ped_file_system_probe (&part->geom); + dasd_data = part->disk_specific; +- dasd_data->raid = 0; +- dasd_data->lvm = 0; + dasd_data->type = 0; + + if (!ped_disk_add_partition (disk, part, NULL)) +@@ -452,25 +469,12 @@ dasd_read (PedDisk* disk) + + dasd_data = part->disk_specific; + +- if ((strncmp(PART_TYPE_RAID, str, 6) == 0) && +- (ped_file_system_probe(&part->geom) == NULL)) +- ped_partition_set_flag(part, PED_PARTITION_RAID, 1); +- else +- ped_partition_set_flag(part, PED_PARTITION_RAID, 0); +- +- if ((strncmp(PART_TYPE_LVM, str, 6) == 0) && +- (ped_file_system_probe(&part->geom) == NULL)) +- ped_partition_set_flag(part, PED_PARTITION_LVM, 1); +- else +- ped_partition_set_flag(part, PED_PARTITION_LVM, 0); +- +- if (strncmp(PART_TYPE_SWAP, str, 6) == 0) { +- fs = ped_file_system_probe(&part->geom); +- if (fs && is_linux_swap(fs->name)) { +- dasd_data->system = PARTITION_LINUX_SWAP; +- PDEBUG; +- } +- } ++ if (strncmp(PART_TYPE_RAID, str, 6) == 0) ++ dasd_data->system = PARTITION_LINUX_RAID; ++ else if (strncmp(PART_TYPE_LVM, str, 6) == 0) ++ dasd_data->system = PARTITION_LINUX_LVM; ++ else if (strncmp(PART_TYPE_SWAP, str, 6) == 0) ++ dasd_data->system = PARTITION_LINUX_SWAP; + + vtoc_ebcdic_enc(p->f1->DS1DSNAM, p->f1->DS1DSNAM, 44); + +@@ -747,20 +751,17 @@ dasd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state) + PED_ASSERT(part->disk_specific != NULL); + dasd_data = part->disk_specific; + +- switch (flag) { +- case PED_PARTITION_RAID: +- if (state) +- dasd_data->lvm = 0; +- dasd_data->raid = state; +- return ped_partition_set_system(part, part->fs_type); +- case PED_PARTITION_LVM: +- if (state) +- dasd_data->raid = 0; +- dasd_data->lvm = state; +- return ped_partition_set_system(part, part->fs_type); +- default: +- return 0; ++ const struct flag_id_mapping_t* p = dasd_find_flag_id_mapping (flag); ++ if (p) ++ { ++ if (state) ++ dasd_data->system = p->type_id; ++ else if (dasd_data->system == p->type_id) ++ return dasd_partition_set_system (part, part->fs_type); ++ return 1; + } ++ ++ return 0; + } + + static int +@@ -772,14 +773,11 @@ dasd_partition_get_flag (const PedPartition* part, PedPartitionFlag flag) + PED_ASSERT (part->disk_specific != NULL); + dasd_data = part->disk_specific; + +- switch (flag) { +- case PED_PARTITION_RAID: +- return dasd_data->raid; +- case PED_PARTITION_LVM: +- return dasd_data->lvm; +- default: +- return 0; +- } ++ const struct flag_id_mapping_t* p = dasd_find_flag_id_mapping (flag); ++ if (p) ++ return dasd_data->system == p->type_id; ++ ++ return 0; + } + + /* +@@ -800,14 +798,10 @@ dasd_partition_is_flag_available (const PedPartition* part, + if (disk_specific->format_type == 1) + return 0; + +- switch (flag) { +- case PED_PARTITION_RAID: +- return 1; +- case PED_PARTITION_LVM: +- return 1; +- default: +- return 0; +- } ++ if (dasd_find_flag_id_mapping (flag)) ++ return 1; ++ ++ return 0; + } + + +@@ -938,18 +932,6 @@ dasd_partition_set_system (PedPartition* part, + + part->fs_type = fs_type; + +- if (dasd_data->lvm) { +- dasd_data->system = PARTITION_LINUX_LVM; +- PDEBUG; +- return 1; +- } +- +- if (dasd_data->raid) { +- dasd_data->system = PARTITION_LINUX_RAID; +- PDEBUG; +- return 1; +- } +- + if (!fs_type) { + dasd_data->system = PARTITION_LINUX; + PDEBUG; +-- +2.35.3 + diff --git a/SOURCES/0003-tests-Add-tests-for-fix.patch b/SOURCES/0003-tests-Add-tests-for-fix.patch deleted file mode 100644 index 4fe4ef9..0000000 --- a/SOURCES/0003-tests-Add-tests-for-fix.patch +++ /dev/null @@ -1,135 +0,0 @@ -From 6b2c8806b42a7214d726cc2b3dac6b96013a6cce Mon Sep 17 00:00:00 2001 -From: Cristian Klein -Date: Fri, 11 Dec 2020 22:19:24 +0100 -Subject: [PATCH 3/5] tests: Add tests for --fix - -Signed-off-by: Brian C. Lane ---- - tests/Makefile.am | 3 +- - tests/t9060-gpt-grow-script-fix.sh | 100 +++++++++++++++++++++++++++++ - 2 files changed, 102 insertions(+), 1 deletion(-) - create mode 100755 tests/t9060-gpt-grow-script-fix.sh - -diff --git a/tests/Makefile.am b/tests/Makefile.am -index 0d7c022..3473e6b 100644 ---- a/tests/Makefile.am -+++ b/tests/Makefile.am -@@ -89,7 +89,8 @@ TESTS = \ - t9040-many-partitions.sh \ - t9041-undetected-in-use-16th-partition.sh \ - t9042-dos-partition-limit.sh \ -- t9050-partition-table-types.sh -+ t9050-partition-table-types.sh \ -+ t9060-gpt-grow-script-fix.sh - - EXTRA_DIST = \ - $(TESTS) t-local.sh t-lvm.sh \ -diff --git a/tests/t9060-gpt-grow-script-fix.sh b/tests/t9060-gpt-grow-script-fix.sh -new file mode 100755 -index 0000000..4a3a8a9 ---- /dev/null -+++ b/tests/t9060-gpt-grow-script-fix.sh -@@ -0,0 +1,100 @@ -+#!/bin/sh -+# grow a gpt disk, ensure that parted offers to update the gpt size -+# do this in script mode with fix -+ -+# Copyright (C) 2009-2012, 2014, 2019 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 3 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, see . -+ -+. "${srcdir=.}/init.sh"; path_prepend_ ../parted -+require_512_byte_sector_size_ -+dev=loop-file -+ -+ss=$sector_size_ -+n_sectors=5000 -+ -+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1 -+ -+# create gpt label -+parted -s $dev mklabel gpt > empty 2>&1 || fail=1 -+compare /dev/null empty || fail=1 -+ -+# print the empty table -+parted -m -s $dev unit s print > t 2>&1 || fail=1 -+sed "s,.*/$dev:,$dev:," t > out || fail=1 -+ -+# check for expected output -+printf "BYT;\n$dev:${n_sectors}s:file:$sector_size_:$sector_size_:gpt::;\n" \ -+ > exp || fail=1 -+compare exp out || fail=1 -+ -+# grow disk -+n_sectors=5500 -+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1 -+ -+# printing must warn, but not fix in script mode -+parted -s $dev print > out 2>&1 || fail=1 -+ -+# Transform the actual output, to avoid spurious differences when -+# $PWD contains a symlink-to-dir. Also, remove the ^M ...^M bogosity. -+# normalize the actual output -+mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s, * ,,g;s, $,," \ -+ -e "s,^.*/lt-parted: ,parted: ," o2 > out -+ -+# check for expected diagnostic -+cat < exp || fail=1 -+Warning: Not all of the space available to DEVICE appears to be used, you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting? -+Model: (file) -+Disk DEVICE: 2816kB -+Sector size (logical/physical): 512B/512B -+Partition Table: gpt -+Disk Flags: -+ -+Number Start End Size File system Name Flags -+ -+EOF -+compare exp out || fail=1 -+ -+# now we fix -+parted --script --fix $dev print > out 2>&1 || fail=1 -+ -+# Transform the actual output, to avoid spurious differences when -+# $PWD contains a symlink-to-dir. Also, remove the ^M ...^M bogosity. -+# normalize the actual output -+mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s, * ,,g;s, $,," \ -+ -e "s,^.*/lt-parted: ,parted: ," o2 > out -+ -+# check for expected diagnostic -+cat < exp || fail=1 -+Warning: Not all of the space available to DEVICE appears to be used, you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting? -+Fixing, due to --fix -+Model: (file) -+Disk DEVICE: 2816kB -+Sector size (logical/physical): 512B/512B -+Partition Table: gpt -+Disk Flags: -+ -+Number Start End Size File system Name Flags -+ -+EOF -+compare exp out || fail=1 -+ -+ -+# Now should not warn -+ -+parted -s $dev print > err 2>&1 || fail=1 -+grep Warning: err > k ; mv k err -+compare /dev/null err || fail=1 -+ -+Exit $fail --- -2.26.2 - diff --git a/SOURCES/0004-parted-Reset-the-filesystem-type-when-changing-the-i.patch b/SOURCES/0004-parted-Reset-the-filesystem-type-when-changing-the-i.patch new file mode 100644 index 0000000..66f1a08 --- /dev/null +++ b/SOURCES/0004-parted-Reset-the-filesystem-type-when-changing-the-i.patch @@ -0,0 +1,30 @@ +From 9b0a83a747b28bd1b778bdd32616e6f7ea88c84d Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Fri, 13 May 2022 10:02:06 -0700 +Subject: [PATCH 4/5] parted: Reset the filesystem type when changing the + id/uuid + +Without this the print command keeps showing the type selected with +mkpart, which doesn't match the id/uuid set by the user. So rescan the +partition for a filesystem. +--- + parted/parted.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/parted/parted.c b/parted/parted.c +index b8a4acf..96da30d 100644 +--- a/parted/parted.c ++++ b/parted/parted.c +@@ -991,6 +991,9 @@ do_type (PedDevice** dev, PedDisk** diskp) + + free (input); + ++ // Reset the fs_type based on the filesystem, if it exists ++ part->fs_type = ped_file_system_probe (&part->geom); ++ + if (!ped_disk_commit (*diskp)) + goto error; + return 1; +-- +2.35.3 + diff --git a/SOURCES/0004-tests-Fix-test-t1700-probe-fs.patch b/SOURCES/0004-tests-Fix-test-t1700-probe-fs.patch deleted file mode 100644 index d96b771..0000000 --- a/SOURCES/0004-tests-Fix-test-t1700-probe-fs.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 9bb4afe61426419c8bb83a25aa9822e00611c8f3 Mon Sep 17 00:00:00 2001 -From: Cristian Klein -Date: Fri, 11 Dec 2020 22:19:25 +0100 -Subject: [PATCH 4/5] tests: Fix test t1700-probe-fs - -mkfs.ext3 (see version below) was complaining that the filesystem is too small -for a journal, which made the test fail. - -``` -$ mkfs.ext3 -V -mke2fs 1.45.5 (07-Jan-2020) - Using EXT2FS Library version 1.45.5 -``` - -Signed-off-by: Brian C. Lane ---- - tests/t1700-probe-fs.sh | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tests/t1700-probe-fs.sh b/tests/t1700-probe-fs.sh -index 848d3e3..5c08e97 100755 ---- a/tests/t1700-probe-fs.sh -+++ b/tests/t1700-probe-fs.sh -@@ -57,7 +57,7 @@ done - # Some features should indicate ext4 by themselves. - for feature in uninit_bg flex_bg; do - # create an ext3 file system -- dd if=/dev/null of=$dev bs=1024 seek=4096 >/dev/null || skip_ "dd failed" -+ dd if=/dev/null of=$dev bs=1024 seek=8192 >/dev/null || skip_ "dd failed" - mkfs.ext3 -F $dev >/dev/null || skip_ "mkfs.ext3 failed" - - # set the feature --- -2.26.2 - diff --git a/SOURCES/0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch b/SOURCES/0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch deleted file mode 100644 index a998543..0000000 --- a/SOURCES/0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 6ed9c9e82ea6cfbee93a47e82e92a90abdb82343 Mon Sep 17 00:00:00 2001 -From: Cristian Klein -Date: Fri, 11 Dec 2020 22:19:26 +0100 -Subject: [PATCH 5/5] tests: Fix t9041-undetected-in-use-16th-partition - -Sometimes fails with: -``` -+ mkfs.ext3 /dev/sda15 -mke2fs 1.45.5 (07-Jan-2020) -/dev/sda15: Not enough space to build proposed filesystem while setting up superblock -``` - -Signed-off-by: Brian C. Lane ---- - tests/t9041-undetected-in-use-16th-partition.sh | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tests/t9041-undetected-in-use-16th-partition.sh b/tests/t9041-undetected-in-use-16th-partition.sh -index a4a3020..129bf15 100644 ---- a/tests/t9041-undetected-in-use-16th-partition.sh -+++ b/tests/t9041-undetected-in-use-16th-partition.sh -@@ -25,7 +25,7 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null || - skip_ 'this system lacks a new-enough libblkid' - - ss=$sector_size_ --partition_sectors=256 # sectors per partition -+partition_sectors=512 # sectors per partition - n_partitions=17 # how many partitions to create - start=2048 # start sector for the first partition - gpt_slop=34 # sectors at end of disk reserved for GPT --- -2.26.2 - diff --git a/SOURCES/0005-tests-t3200-type-change-now-passes.patch b/SOURCES/0005-tests-t3200-type-change-now-passes.patch new file mode 100644 index 0000000..2b71270 --- /dev/null +++ b/SOURCES/0005-tests-t3200-type-change-now-passes.patch @@ -0,0 +1,23 @@ +From ac2a35c2214ef42352d0ddb4f7f4cb77d116e92e Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Fri, 13 May 2022 10:15:41 -0700 +Subject: [PATCH 5/5] tests: t3200-type-change now passes + +--- + tests/Makefile.am | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/tests/Makefile.am b/tests/Makefile.am +index 2da653b..1d109d7 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -1,6 +1,3 @@ +-XFAIL_TESTS = \ +- t3200-type-change.sh +- + TEST_EXTENSIONS = .sh + SH_LOG_COMPILER = $(SHELL) + +-- +2.35.3 + diff --git a/SOURCES/0006-libparted-Fix-fd-check-in-_flush_cache.patch b/SOURCES/0006-libparted-Fix-fd-check-in-_flush_cache.patch deleted file mode 100644 index ab81467..0000000 --- a/SOURCES/0006-libparted-Fix-fd-check-in-_flush_cache.patch +++ /dev/null @@ -1,26 +0,0 @@ -From dacdfc20957d92eff7a3c9fd72baa849b45485e3 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Thu, 10 Jun 2021 15:39:04 -0700 -Subject: [PATCH 06/13] libparted: Fix fd check in _flush_cache - -In theory open() could return 0 so the correct error value is -1. ---- - libparted/arch/linux.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c -index 94ea176..9dc90b5 100644 ---- a/libparted/arch/linux.c -+++ b/libparted/arch/linux.c -@@ -1678,7 +1678,7 @@ _flush_cache (PedDevice* dev) - break; - if (!_partition_is_mounted_by_path (name)) { - fd = open (name, WR_MODE, 0); -- if (fd > 0) { -+ if (fd > -1) { - ioctl (fd, BLKFLSBUF); - retry: - if (fsync (fd) < 0 || close (fd) < 0) --- -2.31.1 - diff --git a/SOURCES/0006-libparted-Fix-handling-of-gpt-partition-types.patch b/SOURCES/0006-libparted-Fix-handling-of-gpt-partition-types.patch new file mode 100644 index 0000000..2124a79 --- /dev/null +++ b/SOURCES/0006-libparted-Fix-handling-of-gpt-partition-types.patch @@ -0,0 +1,101 @@ +From 22ec6553b00b8cc21bf8e78529e1cd0f775ff36f Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Mon, 8 Aug 2022 12:04:32 -0700 +Subject: [PATCH 6/9] libparted: Fix handling of gpt partition types + +This restores the previous behavior by testing the GUID against the list +of known types and skipping the filesystem GUID reset. Now the sequence +of: + +ped_partition_new(...) +ped_partition_set_flag(part, PED_PARTITION_BIOS_GRUB, 1); +ped_partition_set_system(part, ped_file_system_type_get("ext4")); + +Will keep the GUID set to PED_PARTITION_BIOS_GRUB, which is how it used +to behave. +--- + libparted/labels/gpt.c | 45 ++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 43 insertions(+), 2 deletions(-) + +diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c +index 0e9e060..8e6a37d 100644 +--- a/libparted/labels/gpt.c ++++ b/libparted/labels/gpt.c +@@ -196,6 +196,24 @@ static const struct flag_uuid_mapping_t flag_uuid_mapping[] = + { PED_PARTITION_SWAP, PARTITION_SWAP_GUID }, + }; + ++static const efi_guid_t skip_set_system_guids[] = ++{ ++ PARTITION_LVM_GUID, ++ PARTITION_SWAP_GUID, ++ PARTITION_RAID_GUID, ++ PARTITION_PREP_GUID, ++ PARTITION_SYSTEM_GUID, ++ PARTITION_BIOS_GRUB_GUID, ++ PARTITION_HPSERVICE_GUID, ++ PARTITION_MSFT_RESERVED_GUID, ++ PARTITION_BASIC_DATA_GUID, ++ PARTITION_MSFT_RECOVERY, ++ PARTITION_APPLE_TV_RECOVERY_GUID, ++ PARTITION_IRST_GUID, ++ PARTITION_CHROMEOS_KERNEL_GUID, ++ PARTITION_BLS_BOOT_GUID, ++}; ++ + static const struct flag_uuid_mapping_t* _GL_ATTRIBUTE_CONST + gpt_find_flag_uuid_mapping (PedPartitionFlag flag) + { +@@ -1421,6 +1439,21 @@ gpt_partition_destroy (PedPartition *part) + _ped_partition_free (part); + } + ++/* is_skip_guid checks the guid against the list of guids that should not be ++ * overridden by set_system. It returns a 1 if it is in the list. ++*/ ++static bool ++is_skip_guid(efi_guid_t guid) { ++ int n = sizeof(skip_set_system_guids) / sizeof(skip_set_system_guids[0]); ++ for (int i = 0; i < n; ++i) { ++ if (guid_cmp(guid, skip_set_system_guids[i]) == 0) { ++ return true; ++ } ++ } ++ ++ return false; ++} ++ + static int + gpt_partition_set_system (PedPartition *part, + const PedFileSystemType *fs_type) +@@ -1431,6 +1464,11 @@ gpt_partition_set_system (PedPartition *part, + + part->fs_type = fs_type; + ++ // Is this a GUID that should skip fs_type checking? ++ if (is_skip_guid(gpt_part_data->type)) { ++ return 1; ++ } ++ + if (fs_type) + { + if (strncmp (fs_type->name, "fat", 3) == 0 +@@ -1563,10 +1601,13 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state) + const struct flag_uuid_mapping_t* p = gpt_find_flag_uuid_mapping (flag); + if (p) + { +- if (state) ++ if (state) { + gpt_part_data->type = p->type_uuid; +- else if (guid_cmp (gpt_part_data->type, p->type_uuid) == 0) ++ } else if (guid_cmp (gpt_part_data->type, p->type_uuid) == 0) { ++ // Clear the GUID so that fs_type will be used to return it to the default ++ gpt_part_data->type = PARTITION_LINUX_DATA_GUID; + return gpt_partition_set_system (part, part->fs_type); ++ } + return 1; + } + +-- +2.37.1 + diff --git a/SOURCES/0007-libparted-Fix-potential-memory-leak-in-sdmmc_get_pro.patch b/SOURCES/0007-libparted-Fix-potential-memory-leak-in-sdmmc_get_pro.patch deleted file mode 100644 index 4da211b..0000000 --- a/SOURCES/0007-libparted-Fix-potential-memory-leak-in-sdmmc_get_pro.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 8e6976661409d7c87b1f0a80ebdddc450b4db2dd Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Thu, 10 Jun 2021 15:41:33 -0700 -Subject: [PATCH 07/13] libparted: Fix potential memory leak in - sdmmc_get_product_info - ---- - libparted/arch/linux.c | 8 +++++++- - 1 file changed, 7 insertions(+), 1 deletion(-) - -diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c -index 9dc90b5..aacc94f 100644 ---- a/libparted/arch/linux.c -+++ b/libparted/arch/linux.c -@@ -1399,13 +1399,19 @@ static int - init_sdmmc (PedDevice* dev) - { - char id[128]; -- char *type, *name; -+ char *type = NULL; -+ char *name = NULL; - - if (sdmmc_get_product_info (dev, &type, &name)) { - snprintf (id, sizeof(id) - 1, "%s %s", type, name); - free (type); - free (name); - } else { -+ // One or the other may have been allocated, free it -+ if (type) -+ free(type); -+ if (name) -+ free(name); - snprintf (id, sizeof(id) - 1, "%s", - _("Generic SD/MMC Storage Card")); - } --- -2.31.1 - diff --git a/SOURCES/0007-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch b/SOURCES/0007-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch new file mode 100644 index 0000000..0667072 --- /dev/null +++ b/SOURCES/0007-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch @@ -0,0 +1,160 @@ +From 8b4a30cc60ecbe9b7bc966e70560e5ce0fc0c1ad Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Mon, 8 Aug 2022 13:49:09 -0700 +Subject: [PATCH 7/9] tests: Add a libparted test for ped_partition_set_system + on gpt + +Test the libparted API to make sure the flag is not cleared by calling +ped_partition_set_system. +--- + libparted/tests/Makefile.am | 6 ++- + libparted/tests/flags.c | 81 ++++++++++++++++++++++++++++++++++ + libparted/tests/t1001-flags.sh | 23 ++++++++++ + 3 files changed, 108 insertions(+), 2 deletions(-) + create mode 100644 libparted/tests/flags.c + create mode 100755 libparted/tests/t1001-flags.sh + +diff --git a/libparted/tests/Makefile.am b/libparted/tests/Makefile.am +index fd5cba5..260b692 100644 +--- a/libparted/tests/Makefile.am ++++ b/libparted/tests/Makefile.am +@@ -3,9 +3,10 @@ + # + # This file may be modified and/or distributed without restriction. + +-TESTS = t1000-label.sh t2000-disk.sh t2100-zerolen.sh t3000-symlink.sh t4000-volser.sh ++TESTS = t1000-label.sh t1001-flags.sh t2000-disk.sh t2100-zerolen.sh \ ++ t3000-symlink.sh t4000-volser.sh + EXTRA_DIST = $(TESTS) +-check_PROGRAMS = label disk zerolen symlink volser ++check_PROGRAMS = label disk zerolen symlink volser flags + AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) + + LDADD = \ +@@ -24,6 +25,7 @@ disk_SOURCES = common.h common.c disk.c + zerolen_SOURCES = common.h common.c zerolen.c + symlink_SOURCES = common.h common.c symlink.c + volser_SOURCES = common.h common.c volser.c ++flags_SOURCES = common.h common.c flags.c + + # Arrange to symlink to tests/init.sh. + CLEANFILES = init.sh +diff --git a/libparted/tests/flags.c b/libparted/tests/flags.c +new file mode 100644 +index 0000000..c83a361 +--- /dev/null ++++ b/libparted/tests/flags.c +@@ -0,0 +1,81 @@ ++#include ++#include ++ ++#include ++ ++#include ++ ++#include "common.h" ++#include "progname.h" ++ ++#define STREQ(a, b) (strcmp (a, b) == 0) ++ ++static char* temporary_disk; ++ ++static void ++create_disk (void) ++{ ++ temporary_disk = _create_disk (80 * 1024 * 1024); ++ fail_if (temporary_disk == NULL, "Failed to create temporary disk"); ++} ++ ++static void ++destroy_disk (void) ++{ ++ unlink (temporary_disk); ++ free (temporary_disk); ++} ++ ++/* TEST: Test partition type flag on gpt disklabel */ ++START_TEST (test_gpt_flag) ++{ ++ PedDevice* dev = ped_device_get (temporary_disk); ++ if (dev == NULL) ++ return; ++ ++ PedDisk* disk = ped_disk_new_fresh (dev, ped_disk_type_get ("gpt")); ++ PedConstraint *constraint = ped_constraint_any (dev); ++ PedPartition *part = ped_partition_new (disk, PED_PARTITION_NORMAL, ++ ped_file_system_type_get("ext4"), 2048, 4096); ++ ped_partition_set_flag(part, PED_PARTITION_BIOS_GRUB, 1); ++ // Type should remain set to BIOS_GRUB ++ ped_partition_set_system(part, ped_file_system_type_get("ext4")); ++ ++ ped_disk_add_partition (disk, part, constraint); ++ ped_disk_commit (disk); ++ ped_constraint_destroy (constraint); ++ ++ // Check flag to confirm it is still set ++ part = ped_disk_get_partition (disk, 1); ++ fail_if (ped_partition_get_flag(part, PED_PARTITION_BIOS_GRUB) != 1, "BIOS_GRUB flag not set"); ++ ++ ped_disk_destroy (disk); ++ ped_device_destroy (dev); ++} ++END_TEST ++ ++int ++main (int argc, char **argv) ++{ ++ set_program_name (argv[0]); ++ int number_failed; ++ Suite* suite = suite_create ("Partition Flags"); ++ TCase* tcase_gpt = tcase_create ("GPT"); ++ ++ /* Fail when an exception is raised */ ++ ped_exception_set_handler (_test_exception_handler); ++ ++ tcase_add_checked_fixture (tcase_gpt, create_disk, destroy_disk); ++ tcase_add_test (tcase_gpt, test_gpt_flag); ++ /* Disable timeout for this test */ ++ tcase_set_timeout (tcase_gpt, 0); ++ suite_add_tcase (suite, tcase_gpt); ++ ++ SRunner* srunner = srunner_create (suite); ++ srunner_run_all (srunner, CK_VERBOSE); ++ ++ number_failed = srunner_ntests_failed (srunner); ++ srunner_free (srunner); ++ ++ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; ++} +diff --git a/libparted/tests/t1001-flags.sh b/libparted/tests/t1001-flags.sh +new file mode 100755 +index 0000000..60a6248 +--- /dev/null ++++ b/libparted/tests/t1001-flags.sh +@@ -0,0 +1,23 @@ ++#!/bin/sh ++# run the flags unittest ++ ++# Copyright (C) 2007-2014, 2019-2022 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 3 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, see . ++ ++. "${top_srcdir=../..}/tests/init.sh"; path_prepend_ . ++ ++flags || fail=1 ++ ++Exit $fail +-- +2.37.1 + diff --git a/SOURCES/0008-fs-Fix-copy-paste-error-in-HFS-journal-code.patch b/SOURCES/0008-fs-Fix-copy-paste-error-in-HFS-journal-code.patch deleted file mode 100644 index 3965a91..0000000 --- a/SOURCES/0008-fs-Fix-copy-paste-error-in-HFS-journal-code.patch +++ /dev/null @@ -1,34 +0,0 @@ -From acb5300bfc37f8b8c217758e83a31b7ecca84f4a Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Thu, 10 Jun 2021 15:45:57 -0700 -Subject: [PATCH 08/13] fs: Fix copy-paste error in HFS journal code - ---- - libparted/fs/r/hfs/journal.c | 8 +++++--- - 1 file changed, 5 insertions(+), 3 deletions(-) - -diff --git a/libparted/fs/r/hfs/journal.c b/libparted/fs/r/hfs/journal.c -index 862d3d3..c7cd009 100644 ---- a/libparted/fs/r/hfs/journal.c -+++ b/libparted/fs/r/hfs/journal.c -@@ -337,12 +337,14 @@ hfsj_replay_journal(PedFileSystem* fs) - } - jh->checksum = HFS_CPU_TO_32(cksum, is_le); - -- /* The 2 following test are in the XNU Darwin source code */ -- /* so I assume they're needed */ -+ /* https://github.com/apple-opensource/hfs/blob/master/core/hfs_journal.c#L1167 -+ * indicates that this is: -+ * wrap the start ptr if it points to the very end of the journal -+ */ - if (jh->start == jh->size) - jh->start = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT, is_le); - if (jh->end == jh->size) -- jh->start = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT, is_le); -+ jh->end = HFS_CPU_TO_64(PED_SECTOR_SIZE_DEFAULT, is_le); - - if (jh->start == jh->end) - return 1; --- -2.31.1 - diff --git a/SOURCES/0008-libparted-Fix-handling-of-msdos-partition-types.patch b/SOURCES/0008-libparted-Fix-handling-of-msdos-partition-types.patch new file mode 100644 index 0000000..313406e --- /dev/null +++ b/SOURCES/0008-libparted-Fix-handling-of-msdos-partition-types.patch @@ -0,0 +1,109 @@ +From d37d5e7a9470bb5bf8446f79f8e9c508366e06b6 Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Mon, 8 Aug 2022 15:02:30 -0700 +Subject: [PATCH 8/9] libparted: Fix handling of msdos partition types + +This restores the previous behavior by testing the partition type +against the list of known types and skipping the filesystem type reset. +Now the sequence of: + +ped_partition_new(...) +ped_partition_set_flag(part, PED_PARTITION_BLS_BOOT, 1); +ped_partition_set_system(part, ped_file_system_type_get("ext4")); + +Will keep the type set to PED_PARTITION_BLS_BOOT, which is how it used +to behave. +--- + libparted/labels/dos.c | 54 +++++++++++++++++++++++++++++++++++------- + 1 file changed, 46 insertions(+), 8 deletions(-) + +diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c +index bd7465d..4359276 100644 +--- a/libparted/labels/dos.c ++++ b/libparted/labels/dos.c +@@ -121,6 +121,22 @@ static const struct flag_id_mapping_t flag_id_mapping[] = + { PED_PARTITION_SWAP, PARTITION_LINUX_SWAP }, + }; + ++static const unsigned char skip_set_system_types[] = ++{ ++ PARTITION_EXT_LBA, ++ PARTITION_DOS_EXT, ++ PARTITION_COMPAQ_DIAG, ++ PARTITION_MSFT_RECOVERY, ++ PARTITION_LINUX_LVM, ++ PARTITION_LINUX_SWAP, ++ PARTITION_LINUX_RAID, ++ PARTITION_PALO, ++ PARTITION_PREP, ++ PARTITION_IRST, ++ PARTITION_ESP, ++ PARTITION_BLS_BOOT ++}; ++ + static const struct flag_id_mapping_t* _GL_ATTRIBUTE_CONST + dos_find_flag_id_mapping (PedPartitionFlag flag) + { +@@ -1540,6 +1556,21 @@ msdos_partition_destroy (PedPartition* part) + free (part); + } + ++/* is_skip_type checks the type against the list of types that should not be ++ * overridden by set_system. It returns a 1 if it is in the list. ++*/ ++static bool ++is_skip_type(unsigned char type_id) { ++ int n = sizeof(skip_set_system_types) / sizeof(skip_set_system_types[0]); ++ for (int i = 0; i < n; ++i) { ++ if (type_id == skip_set_system_types[i]) { ++ return true; ++ } ++ } ++ ++ return false; ++} ++ + static int + msdos_partition_set_system (PedPartition* part, + const PedFileSystemType* fs_type) +@@ -1548,6 +1579,11 @@ msdos_partition_set_system (PedPartition* part, + + part->fs_type = fs_type; + ++ // Is this a type that should skip fs_type checking? ++ if (is_skip_type(dos_data->system)) { ++ return 1; ++ } ++ + if (part->type & PED_PARTITION_EXTENDED) { + dos_data->system = PARTITION_EXT_LBA; + return 1; +@@ -1590,15 +1626,17 @@ msdos_partition_set_flag (PedPartition* part, + const struct flag_id_mapping_t* p = dos_find_flag_id_mapping (flag); + if (p) + { +- if (part->type & PED_PARTITION_EXTENDED) +- return 0; +- +- if (state) +- dos_data->system = p->type_id; +- else if (dos_data->system == p->type_id || dos_data->system == p->alt_type_id) +- return ped_partition_set_system (part, part->fs_type); ++ if (part->type & PED_PARTITION_EXTENDED) ++ return 0; + +- return 1; ++ if (state) { ++ dos_data->system = p->type_id; ++ } else if (dos_data->system == p->type_id || dos_data->system == p->alt_type_id) { ++ // Clear the type so that fs_type will be used to return it to the default ++ dos_data->system = PARTITION_LINUX; ++ return ped_partition_set_system (part, part->fs_type); ++ } ++ return 1; + } + + switch (flag) { +-- +2.37.1 + diff --git a/SOURCES/0009-parted-Fix-end_input-leak-in-do_mkpart.patch b/SOURCES/0009-parted-Fix-end_input-leak-in-do_mkpart.patch deleted file mode 100644 index 9df39be..0000000 --- a/SOURCES/0009-parted-Fix-end_input-leak-in-do_mkpart.patch +++ /dev/null @@ -1,53 +0,0 @@ -From 3a7f644f21703afcf7088a5994be1a6dff19f679 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Thu, 10 Jun 2021 15:51:12 -0700 -Subject: [PATCH 09/13] parted: Fix end_input leak in do_mkpart - ---- - parted/parted.c | 5 +++-- - 1 file changed, 3 insertions(+), 2 deletions(-) - -diff --git a/parted/parted.c b/parted/parted.c -index 41edb7f..e9aa240 100644 ---- a/parted/parted.c -+++ b/parted/parted.c -@@ -645,6 +645,7 @@ do_mkpart (PedDevice** dev, PedDisk** diskp) - char* part_name = NULL; - char *start_usr = NULL, *end_usr = NULL; - char *start_sol = NULL, *end_sol = NULL; -+ char *end_input = NULL; - - if (*diskp) - disk = *diskp; -@@ -698,12 +699,10 @@ do_mkpart (PedDevice** dev, PedDisk** diskp) - - if (!command_line_get_sector (_("Start?"), *dev, &start, &range_start, NULL)) - goto error; -- char *end_input; - if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, &end_input)) - goto error; - - _adjust_end_if_iec(&start, &end, range_end, end_input); -- free(end_input); - - /* processing starts here */ - part = ped_partition_new (disk, part_type, fs_type, start, end); -@@ -839,6 +838,7 @@ do_mkpart (PedDevice** dev, PedDisk** diskp) - free (end_usr); - free (start_sol); - free (end_sol); -+ free(end_input); - - if ((*dev)->type != PED_DEVICE_FILE) - disk_is_modified = 1; -@@ -860,6 +860,7 @@ error: - free (end_usr); - free (start_sol); - free (end_sol); -+ free(end_input); - - return 0; - } --- -2.31.1 - diff --git a/SOURCES/0009-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch b/SOURCES/0009-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch new file mode 100644 index 0000000..b3284e7 --- /dev/null +++ b/SOURCES/0009-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch @@ -0,0 +1,75 @@ +From 3deaae7a19ebfbc2dad6ad67ba65409e7238efc8 Mon Sep 17 00:00:00 2001 +From: "Brian C. Lane" +Date: Mon, 8 Aug 2022 15:06:03 -0700 +Subject: [PATCH 9/9] tests: Add a libparted test for ped_partition_set_system + on msdos + +Test the libparted API to make sure the flag is not cleared by calling +ped_partition_set_system. +--- + libparted/tests/flags.c | 35 +++++++++++++++++++++++++++++++++++ + 1 file changed, 35 insertions(+) + +diff --git a/libparted/tests/flags.c b/libparted/tests/flags.c +index c83a361..c4b290b 100644 +--- a/libparted/tests/flags.c ++++ b/libparted/tests/flags.c +@@ -54,6 +54,34 @@ START_TEST (test_gpt_flag) + } + END_TEST + ++/* TEST: Test partition type flag on msdos disklabel */ ++START_TEST (test_msdos_flag) ++{ ++ PedDevice* dev = ped_device_get (temporary_disk); ++ if (dev == NULL) ++ return; ++ ++ PedDisk* disk = ped_disk_new_fresh (dev, ped_disk_type_get ("msdos")); ++ PedConstraint *constraint = ped_constraint_any (dev); ++ PedPartition *part = ped_partition_new (disk, PED_PARTITION_NORMAL, ++ ped_file_system_type_get("ext4"), 2048, 4096); ++ ped_partition_set_flag(part, PED_PARTITION_BLS_BOOT, 1); ++ // Type should remain set to BIOS_GRUB ++ ped_partition_set_system(part, ped_file_system_type_get("ext4")); ++ ++ ped_disk_add_partition (disk, part, constraint); ++ ped_disk_commit (disk); ++ ped_constraint_destroy (constraint); ++ ++ // Check flag to confirm it is still set ++ part = ped_disk_get_partition (disk, 1); ++ fail_if (ped_partition_get_flag(part, PED_PARTITION_BLS_BOOT) != 1, "BLS_BOOT flag not set"); ++ ++ ped_disk_destroy (disk); ++ ped_device_destroy (dev); ++} ++END_TEST ++ + int + main (int argc, char **argv) + { +@@ -61,6 +89,7 @@ main (int argc, char **argv) + int number_failed; + Suite* suite = suite_create ("Partition Flags"); + TCase* tcase_gpt = tcase_create ("GPT"); ++ TCase* tcase_msdos = tcase_create ("MSDOS"); + + /* Fail when an exception is raised */ + ped_exception_set_handler (_test_exception_handler); +@@ -71,6 +100,12 @@ main (int argc, char **argv) + tcase_set_timeout (tcase_gpt, 0); + suite_add_tcase (suite, tcase_gpt); + ++ tcase_add_checked_fixture (tcase_msdos, create_disk, destroy_disk); ++ tcase_add_test (tcase_msdos, test_msdos_flag); ++ /* Disable timeout for this test */ ++ tcase_set_timeout (tcase_msdos, 0); ++ suite_add_tcase (suite, tcase_msdos); ++ + SRunner* srunner = srunner_create (suite); + srunner_run_all (srunner, CK_VERBOSE); + +-- +2.37.1 + diff --git a/SOURCES/0010-parted-Free-tmp-usage-inside-do_print.patch b/SOURCES/0010-parted-Free-tmp-usage-inside-do_print.patch deleted file mode 100644 index d243374..0000000 --- a/SOURCES/0010-parted-Free-tmp-usage-inside-do_print.patch +++ /dev/null @@ -1,25 +0,0 @@ -From fbd83d9df7bf5fd0c830935decb9bbc482bf95f4 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Thu, 10 Jun 2021 15:52:28 -0700 -Subject: [PATCH 10/13] parted: Free tmp usage inside do_print - -str_list_create calls gettext_to_wchar which makes a copy of it. ---- - parted/parted.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/parted/parted.c b/parted/parted.c -index e9aa240..ba152c3 100644 ---- a/parted/parted.c -+++ b/parted/parted.c -@@ -1192,6 +1192,7 @@ do_print (PedDevice** dev, PedDisk** diskp) - sprintf (tmp, "%2s ", ""); - - StrList *row = str_list_create (tmp, NULL); -+ free(tmp); - - start = ped_unit_format (*dev, part->geom.start); - end = ped_unit_format_byte ( --- -2.31.1 - diff --git a/SOURCES/0011-parted-Fix-memory-leaks-in-do_resizepart.patch b/SOURCES/0011-parted-Fix-memory-leaks-in-do_resizepart.patch deleted file mode 100644 index 24ef01f..0000000 --- a/SOURCES/0011-parted-Fix-memory-leaks-in-do_resizepart.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 6c4050af2c6c0abdbe1d553fdf2f19a6b600e9d1 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Thu, 10 Jun 2021 15:55:59 -0700 -Subject: [PATCH 11/13] parted: Fix memory leaks in do_resizepart - ---- - parted/parted.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/parted/parted.c b/parted/parted.c -index ba152c3..22b5818 100644 ---- a/parted/parted.c -+++ b/parted/parted.c -@@ -1582,7 +1582,6 @@ do_resizepart (PedDevice** dev, PedDisk** diskp) - /* Push the End value back onto the command_line, if it exists */ - if (end_size) { - command_line_push_word(end_size); -- free(end_size); - } - - start = part->geom.start; -@@ -1590,7 +1589,7 @@ do_resizepart (PedDevice** dev, PedDisk** diskp) - if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, &end_input)) - goto error; - _adjust_end_if_iec(&start, &end, range_end, end_input); -- free(end_input); -+ - /* Do not move start of the partition */ - constraint = constraint_from_start_end_fixed_start (*dev, start, range_end); - if (!ped_disk_set_partition_geom (disk, part, constraint, -@@ -1616,6 +1615,9 @@ error_destroy_constraint: - error: - if (range_end != NULL) - ped_geometry_destroy (range_end); -+ free(end_input); -+ free(end_size); -+ - return rc; - } - --- -2.31.1 - diff --git a/SOURCES/0012-libparted-Fix-warning-about-buffer-size-in-Atari-lab.patch b/SOURCES/0012-libparted-Fix-warning-about-buffer-size-in-Atari-lab.patch deleted file mode 100644 index b7cd8e3..0000000 --- a/SOURCES/0012-libparted-Fix-warning-about-buffer-size-in-Atari-lab.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 86594612f8ae4dbc416e3cd1bc8bb05445df09e5 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Fri, 11 Jun 2021 12:05:22 -0700 -Subject: [PATCH 12/13] libparted: Fix warning about buffer size in Atari label - -When the Atari table is empty it copies 'PARTEDATARI' into the id, and -the start and size bytes. This can be confusion, so turn it into a -union of the string and the non-empty values. ---- - libparted/labels/atari.c | 17 +++++++++++------ - 1 file changed, 11 insertions(+), 6 deletions(-) - -diff --git a/libparted/labels/atari.c b/libparted/labels/atari.c -index 7923487..2ac03d2 100644 ---- a/libparted/labels/atari.c -+++ b/libparted/labels/atari.c -@@ -137,9 +137,14 @@ static AtariFS2PartId atr_fs2pid[] = { - - struct __attribute__ ((packed)) _AtariRawPartition { - uint8_t flag; /* bit 0: active; bit 7: bootable */ -- uint8_t id[3]; /* "GEM", "BGM", "XGM", ... */ -- uint32_t start; /* start of partition */ -- uint32_t size; /* length of partition */ -+ union { -+ uint8_t empty[11]; /* Empty table */ -+ struct __attribute__ ((packed)) { -+ uint8_t id[3]; /* "GEM", "BGM", "XGM", ... */ -+ uint32_t start; /* start of partition */ -+ uint32_t size; /* length of partition */ -+ }; -+ }; - }; - typedef struct _AtariRawPartition AtariRawPartition; - -@@ -241,8 +246,8 @@ static int - atr_is_signature_entry (AtariRawPartition* part) - { - return part->flag == 0 -- && !memcmp (part->id, SIGNATURE_EMPTY_TABLE, -- SIGNATURE_EMPTY_SIZE ); -+ && !memcmp (part->empty, SIGNATURE_EMPTY_TABLE, -+ SIGNATURE_EMPTY_SIZE ); - } - - /* Set Parted signature in an AHDI entry */ -@@ -250,7 +255,7 @@ static void - atr_put_signature_entry (AtariRawPartition* part) - { - part->flag = 0; -- memcpy (part->id, SIGNATURE_EMPTY_TABLE, SIGNATURE_EMPTY_SIZE); -+ memcpy (part->empty, SIGNATURE_EMPTY_TABLE, SIGNATURE_EMPTY_SIZE); - } - - #define atr_part_known(part, pid_list) (atr_pid_known ((part)->id, pid_list)) --- -2.31.1 - diff --git a/SOURCES/0013-libparted-Fix-potential-memory-leak-in-gpt_write.patch b/SOURCES/0013-libparted-Fix-potential-memory-leak-in-gpt_write.patch deleted file mode 100644 index 1164a27..0000000 --- a/SOURCES/0013-libparted-Fix-potential-memory-leak-in-gpt_write.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 16751493376db612abcceae5ae81fd798c0a4d18 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Fri, 11 Jun 2021 13:43:02 -0700 -Subject: [PATCH 13/13] libparted: Fix potential memory leak in gpt_write - -_generate_header() can return with 1 after allocating gpt so it needs to -be freed in the error path. ---- - libparted/labels/gpt.c | 12 ++++++++---- - 1 file changed, 8 insertions(+), 4 deletions(-) - -diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c -index 93f7add..9b987c1 100644 ---- a/libparted/labels/gpt.c -+++ b/libparted/labels/gpt.c -@@ -1292,8 +1292,10 @@ gpt_write (const PedDisk *disk) - - /* Write PTH and PTEs */ - /* FIXME: Caution: this code is nearly identical to what's just below. */ -- if (_generate_header (disk, 0, ptes_crc, &gpt) != 0) -- goto error_free_ptes; -+ if (_generate_header (disk, 0, ptes_crc, &gpt) != 0) { -+ pth_free(gpt); -+ goto error_free_ptes; -+ } - pth_raw = pth_get_raw (disk->dev, gpt); - pth_free (gpt); - if (pth_raw == NULL) -@@ -1307,8 +1309,10 @@ gpt_write (const PedDisk *disk) - - /* Write Alternate PTH & PTEs */ - /* FIXME: Caution: this code is nearly identical to what's just above. */ -- if (_generate_header (disk, 1, ptes_crc, &gpt) != 0) -- goto error_free_ptes; -+ if (_generate_header (disk, 1, ptes_crc, &gpt) != 0) { -+ pth_free(gpt); -+ goto error_free_ptes; -+ } - pth_raw = pth_get_raw (disk->dev, gpt); - pth_free (gpt); - if (pth_raw == NULL) --- -2.31.1 - diff --git a/SOURCES/0014-tests-t0400-Work-around-a-mkswap-bug-by-using-dev-ze.patch b/SOURCES/0014-tests-t0400-Work-around-a-mkswap-bug-by-using-dev-ze.patch deleted file mode 100644 index cc4a682..0000000 --- a/SOURCES/0014-tests-t0400-Work-around-a-mkswap-bug-by-using-dev-ze.patch +++ /dev/null @@ -1,34 +0,0 @@ -From f801496427db11cc468065dcd77d1c610c0a1047 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Mon, 14 Jun 2021 14:23:46 -0700 -Subject: [PATCH 14/15] tests: t0400 - Work around a mkswap bug by using - /dev/zero - -mkswap gets stuck, in some situations, when operating on a file full of -holes (see https://bugzilla.redhat.com/show_bug.cgi?id=1971877) so work -around that by using /dev/zero instead of /dev/null ---- - tests/t0400-loop-clobber-infloop.sh | 7 ++++++- - 1 file changed, 6 insertions(+), 1 deletion(-) - -diff --git a/tests/t0400-loop-clobber-infloop.sh b/tests/t0400-loop-clobber-infloop.sh -index 2d2190d..d05a8e0 100644 ---- a/tests/t0400-loop-clobber-infloop.sh -+++ b/tests/t0400-loop-clobber-infloop.sh -@@ -22,7 +22,12 @@ - - N=1M - dev=loop-file --dd if=/dev/null of=$dev bs=1 seek=$N || fail=1 -+ -+cleanup_() { -+ rm -f $dev; -+} -+ -+dd if=/dev/zero of=$dev bs=$N count=1 || fail=1 - - mkswap $dev || fail=1 - --- -2.31.1 - diff --git a/SOURCES/0015-tests-t9050-Use-dev-zero-for-temporary-file-and-mksw.patch b/SOURCES/0015-tests-t9050-Use-dev-zero-for-temporary-file-and-mksw.patch deleted file mode 100644 index 06e058e..0000000 --- a/SOURCES/0015-tests-t9050-Use-dev-zero-for-temporary-file-and-mksw.patch +++ /dev/null @@ -1,46 +0,0 @@ -From ea1a97b57d4e84005c66bc9c05f2e7c9244b5118 Mon Sep 17 00:00:00 2001 -From: "Brian C. Lane" -Date: Mon, 14 Jun 2021 15:04:05 -0700 -Subject: [PATCH 15/15] tests: t9050 Use /dev/zero for temporary file and - mkswap - -and clean up the usage a little bit by giving it a proper name and -removing the file when finished. ---- - tests/t9050-partition-table-types.sh | 14 ++++++++++---- - 1 file changed, 10 insertions(+), 4 deletions(-) - -diff --git a/tests/t9050-partition-table-types.sh b/tests/t9050-partition-table-types.sh -index 57e004a..d63fa80 100755 ---- a/tests/t9050-partition-table-types.sh -+++ b/tests/t9050-partition-table-types.sh -@@ -35,16 +35,22 @@ pc98 - sun - mkswap - ' -+N=1M -+dev=loop-file - --dd if=/dev/null of=f bs=1 seek=30M || framework_failure_ -+cleanup_() { -+ rm -f $dev; -+} -+ -+dd if=/dev/zero of=$dev bs=$N count=30 || framework_failure_ - - for i in $types; do - for j in $types; do - echo $i:$j -- case $i in mkswap) mkswap f || fail=1;; -- *) parted -s f mklabel $i || fail=1;; esac -+ case $i in mkswap) mkswap $dev || fail=1;; -+ *) parted -s $dev mklabel $i || fail=1;; esac - case $j in mkswap) continue;; esac -- parted -s f mklabel $j || fail=1 -+ parted -s $dev mklabel $j || fail=1 - done - done - --- -2.31.1 - diff --git a/SOURCES/parted-3.4.tar.xz.sig b/SOURCES/parted-3.4.tar.xz.sig deleted file mode 100644 index 8d64718..0000000 --- a/SOURCES/parted-3.4.tar.xz.sig +++ /dev/null @@ -1,11 +0,0 @@ ------BEGIN PGP SIGNATURE----- - -iQFDBAABCgAtFiEEtMa0UeT6i0IyyhkeEX6MFo7+On8FAmASBNUPHGJjbEByZWRo -YXQuY29tAAoJEBF+jBaO/jp/blAH+gNmum3xO2/fZhwRUo1mmb+qP9MlAexjt9VJ -KX79/5ICIFSubVLxzsJTN5g3hZQUoui3qcgdJhnp14bK3hSsvBKtvAAUp+myB+1t -9aypzK+qvw32aaCtPfS00qe4Re2ry6LyuW7hsATPIvcQWF/Xc76FLzG6ilzshxS0 -iftCM/NSp3aGBcNa4Ru3TkbQ1vFtuKYkt24hItODtrYAMGb2IQzSPHCbZw1kfV/J -pypllYB7A6ykr9xqhXPW30d3hERmvcJS0LoUzzEmHRf4YYkYk2N0BQoa4KYI1ULX -rlpG+iJSc0RN8EgHwecdHfPN3umE2UXn3aYCS5GX2Dn9xPsjaSM= -=HdSF ------END PGP SIGNATURE----- diff --git a/SOURCES/parted-3.5.tar.xz.sig b/SOURCES/parted-3.5.tar.xz.sig new file mode 100644 index 0000000..c003b4b --- /dev/null +++ b/SOURCES/parted-3.5.tar.xz.sig @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- + +iQEzBAABCgAdFiEEtMa0UeT6i0IyyhkeEX6MFo7+On8FAmJduCkACgkQEX6MFo7+ +On9cLAgAmAn86lYjZj+Ka5EHrVtaFgh1Nvz84EOwZd0TVRTJyP/u56QrOXxRYFFr +6SiJuI1sWfpkzMGG8RYhcr/hu0Os4rtDdhwXXA75QexpSZamPRSo/EU7skrPW0ZD +ycw6jUIBO5de4kCLmM/4byl6LV5eFixJYJ5zfD+SnQsMJvO6/fBo0Dv+pNGF/m5F +mQeLWmgfqCNZ3INoHLPxuP08gpA9aELp6UFipbqBZqeRIk4K+jGSWlLu62mwl2sQ +1OYIIdKacBrh14ZhRqXZKGKHk94RxiFtD/7CLXK/qzEFylKUMQ/XpUB0QkZNHVZW +l2kRXsEGC1c7dWSbMX8lgy02HjfuVQ== +=7scj +-----END PGP SIGNATURE----- diff --git a/SPECS/parted.spec b/SPECS/parted.spec index 8dec52e..1e87f16 100644 --- a/SPECS/parted.spec +++ b/SPECS/parted.spec @@ -1,7 +1,7 @@ Summary: The GNU disk partition manipulation program Name: parted -Version: 3.4 -Release: 6%{?dist} +Version: 3.5 +Release: 2%{?dist} License: GPLv3+ URL: http://www.gnu.org/software/parted @@ -10,22 +10,17 @@ Source1: https://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz.sig Source2: pubkey.phillip.susi Source3: pubkey.brian.lane -# Upstream patches since v3.4 release -Patch0001: 0001-parted-add-fix-to-fix-in-script-mode.patch -Patch0002: 0002-doc-Document-fix-flag.patch -Patch0003: 0003-tests-Add-tests-for-fix.patch -Patch0004: 0004-tests-Fix-test-t1700-probe-fs.patch -Patch0005: 0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch -Patch0006: 0006-libparted-Fix-fd-check-in-_flush_cache.patch -Patch0007: 0007-libparted-Fix-potential-memory-leak-in-sdmmc_get_pro.patch -Patch0008: 0008-fs-Fix-copy-paste-error-in-HFS-journal-code.patch -Patch0009: 0009-parted-Fix-end_input-leak-in-do_mkpart.patch -Patch0010: 0010-parted-Free-tmp-usage-inside-do_print.patch -Patch0011: 0011-parted-Fix-memory-leaks-in-do_resizepart.patch -Patch0012: 0012-libparted-Fix-warning-about-buffer-size-in-Atari-lab.patch -Patch0013: 0013-libparted-Fix-potential-memory-leak-in-gpt_write.patch -Patch0014: 0014-tests-t0400-Work-around-a-mkswap-bug-by-using-dev-ze.patch -Patch0015: 0015-tests-t9050-Use-dev-zero-for-temporary-file-and-mksw.patch +# Upstream patches since v3.5 release +Patch0001: 0001-maint-post-release-administrivia.patch +Patch0002: 0002-parted-add-type-command.patch +Patch0003: 0003-libparted-add-swap-flag-for-DASD-label.patch +Patch0004: 0004-parted-Reset-the-filesystem-type-when-changing-the-i.patch +Patch0005: 0005-tests-t3200-type-change-now-passes.patch +Patch0006: 0006-libparted-Fix-handling-of-gpt-partition-types.patch +Patch0007: 0007-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch +Patch0008: 0008-libparted-Fix-handling-of-msdos-partition-types.patch +Patch0009: 0009-tests-Add-a-libparted-test-for-ped_partition_set_sys.patch + BuildRequires: gcc BuildRequires: e2fsprogs-devel @@ -38,7 +33,9 @@ BuildRequires: libuuid-devel BuildRequires: libblkid-devel >= 2.17 BuildRequires: gnupg2 BuildRequires: git -BuildRequires: autoconf automake +BuildRequires: autoconf +BuildRequires: automake +BuildRequires: libtool BuildRequires: e2fsprogs BuildRequires: xfsprogs BuildRequires: dosfstools @@ -47,6 +44,7 @@ BuildRequires: bc Buildrequires: python3 BuildRequires: gperf BuildRequires: make +BuildRequires: check-devel # bundled gnulib library exception, as per packaging guidelines # https://fedoraproject.org/wiki/Packaging:No_Bundled_Libraries @@ -78,8 +76,9 @@ gpg2 --verify %{SOURCE1} %{SOURCE0} iconv -f ISO-8859-1 -t UTF8 AUTHORS > tmp; touch -r AUTHORS tmp; mv tmp AUTHORS %build -autoreconf -autoconf +# RHEL has 2.69 which works fine with the macros parted uses +sed -i s/2.71/2.69/ configure.ac +autoreconf -fiv CFLAGS="$RPM_OPT_FLAGS -Wno-unused-but-set-variable"; export CFLAGS %configure --disable-static --disable-gcc-warnings # Don't use rpath! @@ -114,9 +113,9 @@ make check %{_mandir}/man8/parted.8.gz %{_mandir}/man8/partprobe.8.gz %{_libdir}/libparted.so.2 -%{_libdir}/libparted.so.2.0.3 +%{_libdir}/libparted.so.2.0.4 %{_libdir}/libparted-fs-resize.so.0 -%{_libdir}/libparted-fs-resize.so.0.0.3 +%{_libdir}/libparted-fs-resize.so.0.0.4 %{_infodir}/parted.info.* %files devel @@ -129,6 +128,17 @@ make check %changelog +* Tue Aug 09 2022 Brian C. Lane - 3.5-2 +- Fix ped_partition_set_system handling of existing flags + Resolves: rhbz#2116505 + +* Fri May 27 2022 Brian C. Lane - 3.5-1 +- Rebase to upstream release 3.5 +- Drop patches included in new upstream tar +- Add upstream patches for new type command +- Add upstream patch for swap flag on DASD + Resolves: rhbz#1999333 + * Mon Aug 09 2021 Mohan Boddu - 3.4-6 - Rebuilt for IMA sigs, glibc 2.34, aarch64 flags Related: rhbz#1991688