util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 冰柯 <ziming_cool@126.com>
To: util-linux@vger.kernel.org
Subject: Bug report for libfdisk
Date: Sat, 23 Feb 2019 12:09:54 +0800 (CST)	[thread overview]
Message-ID: <2a76c584.126b.169188b95a6.Coremail.ziming_cool@126.com> (raw)

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.

             reply	other threads:[~2019-02-23  4:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-23  4:09 冰柯 [this message]
2019-02-25 11:56 ` Bug report for libfdisk Karel Zak
2019-02-25 13:11 ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a76c584.126b.169188b95a6.Coremail.ziming_cool@126.com \
    --to=ziming_cool@126.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).