Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
* Bug report for libfdisk
@ 2019-02-23  4:09 冰柯
  2019-02-25 11:56 ` Karel Zak
  2019-02-25 13:11 ` Karel Zak
  0 siblings, 2 replies; 3+ messages in thread
From: 冰柯 @ 2019-02-23  4:09 UTC (permalink / raw)
  To: util-linux

Dear developer or maintainer of util-linux:
    Hi! And thanks for your attention to this email.
    I'm writing this to report a bug about libfdisk. I happened notice that fdisk gave me an incorrect value when prompt for first sector on creating a primary dos partition.
    I found this bug on util-linux-2.31.1, then I downloaded the newer version of 2.33.1, and noticed that the bug is still not fixed.
    The source code of `util-linux-2.31.1/libfdisk/src/dos.c` defines a function `get_possible_last`, it's partial content is shown below:

	} else {
		/* primary partitions */
		if (fdisk_use_cylinders(cxt) || !cxt->total_sectors)
			limit = cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders - 1;
		else
			limit = cxt->total_sectors - 1;      /* HERE */

		if (limit > UINT_MAX)
			limit = UINT_MAX;
	}

    When creating a primary partition and the measure unit is `sector`, it simply returns the value `cxt->total_sectors - 1`.
    How the bug 'worked' (I stripped some useless outputs):
      $ qemu-img create test.img 4G
      Formatting 'test.img', fmt=raw size=4294967296
      $ fdisk test.img
      Device does not contain a recognized partition table.
      Created a new DOS disklabel with disk identifier 0x873fd6f4.
      Command (m for help): n
      Partition type
         p   primary (0 primary, 0 extended, 4 free)
         e   extended (container for logical partitions)
      Select (default p): 
      Using default response p.
      Partition number (1-4, default 1): 2
      First sector (2048-8388607, default 2048): 4000000
      Last sector, +sectors or +size{K,M,G,T,P} (4000000-8388607, default 8388607): 
      Created a new partition 2 of type 'Linux' and of size 2.1 GiB.

    Till now, I've created a partition at the end of the disk. Then I'll create another one:

      Command (m for help): n
      Partition type
         p   primary (1 primary, 0 extended, 3 free)
         e   extended (container for logical partitions)
      Select (default p): 
      Using default response p.
      Partition number (1,3,4, default 1): 
      First sector (2048-8388607, default 2048):

    You can see it still prompts for `First sector` with the same range 2048-8388607, while it should be 2048-3999999. This is probably caused by the code I've listed already.
    I've also tried using cylinders as measure unit, and the problem repeated. However, it works properly when creating a GPT partition.
    I don't think this is correct, though it's not very important. So, hope this bug will be fixed soon.
    And last, thanks again for reading my entire email, and sorry for my poor English skill...
    Hive a nice day!
                                                           Yours sincerely,
                                                                           Icy.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug report for libfdisk
  2019-02-23  4:09 Bug report for libfdisk 冰柯
@ 2019-02-25 11:56 ` Karel Zak
  2019-02-25 13:11 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2019-02-25 11:56 UTC (permalink / raw)
  To: 冰柯; +Cc: util-linux

On Sat, Feb 23, 2019 at 12:09:54PM +0800, 冰柯 wrote:
>     You can see it still prompts for `First sector` with the same
>     range 2048-8388607, while it should be 2048-3999999. This is
>     probably caused by the code I've listed already.  I've also
>     tried using cylinders as measure unit, and the problem repeated.
>     However, it works properly when creating a GPT partition.  I
>     don't think this is correct, though it's not very important. So,
>     hope this bug will be fixed soon.

This is limitation of the original fdisk code. I'll rewrite fist/last
free sector detection...

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug report for libfdisk
  2019-02-23  4:09 Bug report for libfdisk 冰柯
  2019-02-25 11:56 ` Karel Zak
@ 2019-02-25 13:11 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2019-02-25 13:11 UTC (permalink / raw)
  To: 冰柯; +Cc: util-linux

On Sat, Feb 23, 2019 at 12:09:54PM +0800, 冰柯 wrote:
> 	} else {
> 		/* primary partitions */
> 		if (fdisk_use_cylinders(cxt) || !cxt->total_sectors)
> 			limit = cxt->geom.heads * cxt->geom.sectors * cxt->geom.cylinders - 1;
> 		else
> 			limit = cxt->total_sectors - 1;      /* HERE */
> 
> 		if (limit > UINT_MAX)
> 			limit = UINT_MAX;
> 	}

Fixed. Now the code follows situation on the device rather than total
sectors and first LBA.

Thanks for your report!

    Karel
                                                                           Icy.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-23  4:09 Bug report for libfdisk 冰柯
2019-02-25 11:56 ` Karel Zak
2019-02-25 13:11 ` Karel Zak

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org util-linux@archiver.kernel.org
	public-inbox-index util-linux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox