[Parted-maintainers] a problem about 100% indicating the whole disk

zhuyj zyjzyj2000 at gmail.com
Tue Nov 5 02:19:50 UTC 2013


Hi, maintainers

The problem is very interesting since the caculations results in this 
problem. If you all are interested this, I can provide an ISO file and 
the steps to reproduce this problem.
If you agree with me, would you like to merge this patch ?

Thanks a lot.
Zhu Yanjun
On 10/31/2013 06:10 PM, zhuyj wrote:
> 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-maintainers mailing list