[parted-devel] a problem about 100% indicating the whole disk
zhuyj
zyjzyj2000 at gmail.com
Thu Oct 31 10:10:41 UTC 2013
Hi, maintainers
I came across an interesting thing.
When I allocated a vm of virtual box 50G disk. And I run parted with
100% indicating the whole disk, it will fail.
I checked the source code. And I found that the following:
static PedGeometry*
geometry_from_centre_radius (const PedDevice* dev,
PedSector sector, PedSector radius)
{
PedSector start = clip (dev, sector - radius);
PedSector end = clip (dev, sector + radius);
if (sector - end > radius || start - sector >
radius)<-----After a series of calculations, sector is equal to
dev->length, and end is equal to dev->length - 1
return NULL; <-----NULL will be returned
return ped_geometry_new (dev, start, end - start + 1);
}
Thus parted will report the failure.
I checked the source code, and I found that it is difficult to modify.
Since 100% mean to use the whole disk, so sector is correct to be equal
to dev->length. And radius is equal to 0 since unit_size is power of 2.
So if we use 100% in the source code, it is difficult to avoid this failure.
Thus I made the following patch. The main object is to replace 100% with
-1. Finally, this failure can be avoided.
diff -urpN unit_orig.c unit.c
--- unit_orig.c
+++ unit.c
@@ -516,7 +516,12 @@ ped_unit_parse_custom (const char* str,
if (is_chs (str))
return parse_chs (str, dev, sector, range);
- copy = ped_strdup (str);
+ if ((strlen (str) == 4) && (strncmp (str, "100%", 4) == 0)){
+ copy = ped_strdup ("-1");
+ } else {
+ copy = ped_strdup (str);
+ }
+
if (!copy)
goto error;
strip_string (copy);
Please comment about this patch. If you all want to see the process, I
can provide the video. If you want to reproduce this problem, I can
provide a iso file.
Thanks a lot.
Zhu Yanjun
More information about the parted-devel
mailing list