summaryrefslogtreecommitdiff
path: root/parted
Commit message (Collapse)AuthorAgeFilesLines
* maint: Update copyright statements to 2022Brian C. Lane2023-03-249-9/+9
| | | | By running make update-copyright
* parted: Fix ending sector location when using kibi IEC suffixBrian C. Lane2023-03-171-10/+19
| | | | | | | | | | | | | | | | | This fixes a bug when using KiB to specify the ending location of a partition. It was not subtracting 1s like it does with the other units because it was looking for a 'k' not a 'K'. This also fixes a quirk of the suffix checking code, it would check for matching case, but converting to the actual IEC value was case insensitive. This now uses common functions for the matching so that case doesn't matter. It also adds tests to check for the fix. The only change in behavior is that using KiB to specify the ending location of a partition will now correctly create the end 1s lower than the specified location like it does for MiB, GiB, etc.
* ui: Add checks for prompt being NULLBrian C. Lane2023-02-151-2/+5
| | | | | | | | Also removes a cast from const char* to char* when passing to readline that doesn't appear to be necessary any longer. Added asserts to make sure prompt isn't NULL after strdup and realloc calls.
* strlist: Handle realloc error in wchar_to_strBrian C. Lane2023-02-151-0/+2
| | | | | | It could return a NULL if the realloc fails. This handles the failure in the same way as other failures in wchar_to_str, it exits immediately with an error message.
* parted: Add display of GPT UUIDs in JSON outputArvin Schnell2022-09-301-0/+18
| | | | | | | | | | | This adds 2 new disk type features, one for the whole disk UUID and another for the per-partition UUID. It adds ped_disk_get_uuid and ped_partition_get_uuid functions to retrieve them. It adds them to the JSON output on GPT disklabeled disks as "uuid" in the disk and partitions sections of the JSON output. Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted: Simplify code for json outputArvin Schnell2022-07-271-3/+2
| | | | | | | | | _PedDiskOps::get_max_primary_partition_count is always available, the macro PT_op_function_initializers ensures it. So use ped_disk_get_max_primary_partition_count instead of _PedDiskOps::get_max_primary_partition_count directly. Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted: Reset the filesystem type when changing the id/uuidBrian C. Lane2022-05-131-0/+3
| | | | | | 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: add type commandArvin Schnell2022-05-131-1/+112
| | | | | | | | | 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 <bcl@redhat.com>
* bug#54649: [PATCH] usage: remove the mention of "a particular partition"Benno Schulenberg2022-03-311-2/+1
| | | | | | This complements commit b20227adf5 from five months ago. Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
* parted: Fix config.h include in jsonwrt.cBrian C. Lane2022-03-251-1/+1
|
* maint: Update copyright statements to 2022Brian C. Lane2022-03-239-9/+9
| | | | By running make update-copyright
* docs: Update documentation to be consistentBrian C. Lane2021-10-061-3/+1
| | | | | | | | | This fixes some missing commands in the parted.texi file used to generate the web manual and info document. It also removes documentation for the never-implemented 'print NUMBER' command which only returns 1. The parted manpage has been updated to document the available print options, disk_set, and disk_toggle commands.
* parted: Add --json cmdline switch to output JSONArvin Schnell2021-08-254-12/+431
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This outputs the disk's details as a JSON object. eg. a disk image with a single partition from 1M to 100M: { "disk": { "path": "/root/disk1.img", "size": "2097152s", "model": "", "transport": "file", "logical-sector-size": 512, "physical-sector-size": 512, "label": "gpt", "max-partitions": 128, "partitions": [ { "number": 0, "start": "34s", "end": "2047s", "size": "2014s", "type": "free" },{ "number": 1, "start": "2048s", "end": "200703s", "size": "198656s", "type": "primary", "name": "root" },{ "number": 0, "start": "200704s", "end": "2097118s", "size": "1896415s", "type": "free" } ] } } Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted: Allow empty string for partition nameArvin Schnell2021-08-251-2/+7
| | | | | | | | | | | This makes it possible to pass an empty string in script mode e.g. to set no partition name (on GPT): parted -s ./disk.img mklabel gpt mkpart '""' ext2 1 100M Includes a new test for this feature. Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted: Escape colons and backslashes in machine outputBrian C. Lane2021-08-101-4/+38
| | | | | | | The device path, device model, and partition name could all contain colons or backslashes. This escapes all of these with a backslash. Thanks to Arvin Schnell for the patch.
* parted: Fix memory leaks in do_resizepartBrian C. Lane2021-06-111-2/+4
|
* parted: Free tmp usage inside do_printBrian C. Lane2021-06-111-0/+1
| | | | str_list_create calls gettext_to_wchar which makes a copy of it.
* parted: Fix end_input leak in do_mkpartBrian C. Lane2021-06-111-2/+3
|
* parted: add --fix to "fix" in script modeCristian Klein2021-01-283-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <bcl@redhat.com>
* maint: Update copyright statements to 2021Brian C. Lane2021-01-189-9/+9
| | | | By running make update-copyright
* maint: Update copyright statements to 2020Brian C. Lane2020-12-119-13/+17
| | | | By running make update-copyright
* ui: Fix gcc 10 warning about snprintf truncating an intBrian C. Lane2020-11-201-2/+2
| | | | Double the storage to 20 bytes.
* ui: Fix command_line_get_disk_flagBrian C. Lane2020-11-201-1/+1
| | | | | It was using PedPartitionFlag instead of PedDiskFlag when walking the available flags.
* parted: Preserve resizepart End when prompted for busy partitionBrian C. Lane2020-08-311-0/+15
| | | | | | | Resizing busy partitions is allowed, but the user is prompted, which erases the cmdline. It is annoying to have to re-end the ending location after answering Yes. This saves the word and pushes it back onto the cmdline after the user agrees to resize the busy partition.
* Fix end_input usage in do_resizepartBrian C. Lane2019-12-161-1/+1
| | | | | It needs to be set to NULL, since it may not get set by the call to command_line_get_sector
* maint: Update copyright statements to 2019Brian C. Lane2019-08-129-9/+13
| | | | By running make update-copyright
* Remove trailing whitespaceBrian C. Lane2019-08-091-2/+2
| | | | Caught by make syntax-check
* Remove unnecessary if before free checksBrian C. Lane2019-08-091-9/+4
| | | | Caught by make syntax-check
* Fix align-check help outputBrian C. Lane2019-02-111-1/+1
|
* parted: Remove PED_ASSERT from ped_partition_set_nameBrian C. Lane2019-01-311-1/+3
| | | | | | Asserts should only check logic, not wrap functions with side-effects. When compiled with --disable-debug this causes the name field of mkpart to be ignored.
* Fix potential command line buffer overflowSimon Xu2018-10-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | parted terminates with 'stack smashing detected' when fed with a long command line argument, and segfaults when the argument is long enough: root # /sbin/parted /dev/sda $(perl -e 'print "a"x265') *** stack smashing detected ***: /sbin/parted terminated ... Aborted root # /sbin/parted /dev/sda $(perl -e 'print "a"x328') *** stack smashing detected ***: /sbin/parted terminated ... Command History: Segmentation fault parted should be able to detect it and exit with error and usage messages. This also makes command line buffer overflow exploit more possible. Fix it by adding length check in the condition of the for loop where command line arguments are copied. Signed-off-by: Simon Xu <xu.simon@oracle.com> Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted.c: Make sure dev_name is freedBrian C. Lane2018-08-221-6/+4
| | | | | | If there was a problem with ped_device_get or ped_device_open it would not be freed. Related: rhbz#1602652
* parted.c: Always free peek_wordBrian C. Lane2018-08-221-1/+2
| | | | | | | If command_line_get_fs_type failed it would never free it, so put a free in both branches of the if. Related: rhbz#1602652
* Fix resizepart iec unit end sectorPhillip Susi2018-06-051-1/+4
| | | | | | Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does.
* mkpart: Allow negative start value when FS-TYPE is not givenNiklas Hambüchen2018-06-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | The manual had long documented that negative values are allowed for both start and end values, but until now negative start values were rejected if FS-TYPE was not given. Example: # parted --script -a optimal /dev/loop0 -- mklabel gpt mkpart primary ext4 -5MiB 100% (succeeds) # parted --script -a optimal /dev/loop0 -- mklabel gpt mkpart primary -5MiB 100% parted: invalid token: -5MiB Error: Expecting a file system type. This commit fixes the latter error. The issue was an insufficient lookahead in command line parsing, looking only for digits when skipping over FS-TYPE. The fix is including the minus '-' in the lookahead. Originally reported as Debian bug #880035: "parted: fails to use negative start value for 'mkpart' command without specyfying FS-TYPE" https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=880035 Signed-off-by: Niklas Hambüchen <mail@nh2.me>
* Fix set and disk_set to not crash when no flags are supportedPhillip Susi2018-06-051-2/+16
| | | | | | | | Loop labels and file images support no flags. set and disk_set would prompt for a flag and accept any string since the list of flags was empty, then fail to look up an actual flag value, then throw an exception with a null string for the name of the flag, which would bug.
* Add support for NVDIMM devicesSebastian Parschauer2017-12-191-1/+2
| | | | | | | | | | | | | | | | | | | Recognize NVDIMM devices, so that "parted -s /dev/pmem7 p" now prints "Model: NVDIMM Device (pmem)" instead of "Model: Unknown (unknown)". In order for a device to be recognized as NVDIMM, it has to have a 'blkext' major number. But since this major can be used also by other device types, we also check that the device path contains 'pmem' as a substring. * NEWS: Mention the change * include/parted/device.h.in(PedDeviceType): Add PED_DEVICE_PMEM * libparted/arch/linux.c(_device_probe_type): Recognize NVDIMM devices. * libparted/arch/linux.c(linux_new): Handle NVDIMM devices. * parted/parted.c(do_print): Add "pmem" to list of transports. Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
* parted/ui: remove unneccesary information of command lineWang Dong2017-05-011-0/+1
| | | | | | | | | | | | | | | | | | | | When some command fails, the information still exists in command_line buffer. When in command mode or interactive mode, if an interactive exception prompts, the remained information will be processed as option from user. This will raise some other information or even unexpected results. So before getting option input from user, clean the command line buffer. Example: When the disk label is invalid and user tries to make new partition on the device with command like, mkpart 0 50%. Then parted will raise an exception telling an invalid disk label found and whether to correct it. But at this time 0 as the input of mkpart will be considered as the option input for the exception(yes/no). So one more exception will raised with error information. Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
* parted: check the name of partition first when to name a partitionWang Dong2017-05-011-0/+7
| | | | | | | | | | | | | | | The previous function works well for the labels supporting naming partition, but not for these which don't. If the disk label does not support partition naming, two exceptions will be raised. Even after the first error indicates it does not support name, parted yet asks user for name in iteractive mode. First check if the disk label supports partition naming and if it does, it will continue; otherwise, it will stop and raise an exception. Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
* Add support for RAM drivesSebastian Parschauer2017-05-011-1/+1
| | | | | | | | | | | | | | | | | | | Recognize RAM drives, so "parted -s /dev/ram0 p" now prints "RAM Drive (brd)" instead of "Model: Unknown (unknown)". In order for a device to be recognized as RAM drive, it has to have major number 1. Also the BLKFLSBUF ioctl shouldn't be used on RAM drives as it is used to zero the device. * NEWS: Mention the change * include/parted/device.h.in(PedDeviceType): Add PED_DEVICE_RAM. * libparted/arch/linux.c(RAM_MAJOR): New define. * libparted/arch/linux.c(_device_probe_type): Recognize RAM drives. * libparted/arch/linux.c(linux_new): Handle RAM drives. * libparted/arch/linux.c(_flush_cache): Skip RAM drives. * parted/parted.c(do_print): Add "brd" to list of transports. Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
* clean the disk information when commands fail in interactive mode.Wang Dong2017-05-012-5/+17
| | | | | | | | | | | | | | | | | | | | | | | parted always reads disk information to memory before any operations. The disk that user operates is actually a copy of real one in memory. When the information in memory is changed, it will commit the memory to device to update the disk information. Once the disk information is read, parted will never re-read it again unless another device is loaded or the device is re-read. Above work has been done in commit 7eac058 (parted: don't reload partition table on every command) Each command of parted always commits the memory when it succeeds. Then the disk information on device and in memory are the same. But when it fails, they might be different. User will be confused by this, and sometimes get undesired result with the contaminated memory. This memory should be cleaned if some command fails. Then the command followed will re-read the disk. Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
* parted: fix wrong error label jump in mkpartWang Dong2017-05-011-4/+5
| | | | | | | | | | | | | | | | | | | When the user makes a new partition, if parted fails to add the partition to disk, it jumps to wrong error label. In this situation, this new partition actually is not a node in disk data structure. But in the wrong error label, it pretends this is a node and removes it as a list node, leading to other partition in this disk deleted. This might lead to a memory leak. Because if there are other partitions, it just removes them from list without releasing the resource. And this also leads to different disk information between memory and device. This is confusing. But when the new partition is added to disk successfully and if any operations followed fail, this partition should be removed from disk and destroyed. Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
* parted: fix crash due to improper partition number inputWang Dong2017-05-011-4/+22
| | | | | | | | | | | | | | | | | | | When the user makes a new partition, if parted fails to add the partition to disk, it jumps to wrong error label. In this situation, this new partition actually is not a node in disk data structure. But in the wrong error label, it pretends this is a node and removes it as a list node, leading to other partition in this disk deleted. This might lead to a memory leak. Because if there are other partitions, it just removes them from list without releasing the resource. And this also leads to different disk information between memory and device. This is confusing. But when the new partition is added to disk successfully and if any operations followed fail, this partition should be removed from disk and destroyed. Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
* Fix crash when localizedPhillip Susi2017-04-171-1/+1
| | | | | | The _() macro is only for translating string literals. It was incorrectly applied to a runtime string representing the name of a partition and this sometimes caused a gettext crash.
* Add support for NVMe devicesPetr Uzel2016-06-231-1/+1
| | | | | | | | | | | | | | | | | | | | Recognize NVMe Devices, so "parted -s /dev/nvme0n1" now prints "NVMe Device (nvme)" instead of "Model: Unknown (unknown)". In order for a device to be recognized as NVMe, it has to have a 'blkext' major number. But since this major can be used also by other device types, we also check the device path contains 'nvme' as a substring. * NEWS: Mention the change * include/parted/device.h.in(PedDeviceType): Add PED_DEVICE_NVME * libparted/arch/linux.c(BLKEXT_MAJOR): New define. * libparted/arch/linux.c(_is_blkext_major): New function. * libparted/arch/linux.c(_device_probe_type): Recognize NVMe devices. * libparted/arch/linux.c(linux_new): Handle NVMe devices. * parted/parted.c(do_print): Add "nvme" to list of transports. Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted: Display details of partition alignment failure (#726856)Brian C. Lane2016-04-121-13/+51
| | | | | | | | | | | | | When alignment for a new partition fails it isn't always obvious why it failed. This adds printing the reason for the failure, in the form of: start % grain != offset This modifies align-check in interactive mode to print the alignment the error details if it isn't aligned. Script mode behavior is unchanged. Also cleanup pointer usage and handle asprintf failure by using a constant string in the error report - "unknown (malloc failure)".
* parted: fix the rescue commandPhillip Susi2016-04-101-0/+4
| | | | | | | The rescue command often failed to locate a filesystem due to it leaving cylinder alignment on, which snapped the allowed bounds of the filesystem down to the next lower cylinder boundary, causing the detected filesystem to be rejected due to not fitting.
* UI: Avoid memory leaks.Amarnath Valluri2015-08-031-1/+5
| | | | | | | | | * parted/ui.c(command_line_get_sector): Don't leak input string. * parted/ui.c(command_line_prompt_words): Don't leak _def string in opt script mode. Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> Signed-off-by: Brian C. Lane <bcl@redhat.com>
* parted: Fix crash with name command and no disklabel (#1226067)Brian C. Lane2015-07-131-1/+1
| | | | | | A typo (the last I think) from commit 7eac058 wasn't properly checking the result of ped_disk_new so it could crash if there was no disklabel on the device.
* parted: don't crash in disk_set when disk label not foundPhillip Susi2015-01-131-1/+1
| | | | | | Due to a typeo in commit 7eac058 "parted: don't reload partition table on every command", the disk_set command would crash if a disk label was not found.