util-linux.vger.kernel.org archive mirror
 help / color / mirror / 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

end of thread, other threads:[~2019-02-25 13:11 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).