Delivered-To: otavio.salvador@gmail.com Received: by 10.204.59.147 with SMTP id l19cs132424bkh; Sun, 16 Jan 2011 04:26:09 -0800 (PST) Received: by 10.90.113.8 with SMTP id l8mr1322981agc.21.1295180768845; Sun, 16 Jan 2011 04:26:08 -0800 (PST) Return-Path: Received: from master.debian.org (master.debian.org [70.103.162.29]) by mx.google.com with ESMTPS id c36si6867598ana.168.2011.01.16.04.26.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 16 Jan 2011 04:26:08 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning bug-parted-bounces+otavio=debian.org@gnu.org does not designate 70.103.162.29 as permitted sender) client-ip=70.103.162.29; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning bug-parted-bounces+otavio=debian.org@gnu.org does not designate 70.103.162.29 as permitted sender) smtp.mail=bug-parted-bounces+otavio=debian.org@gnu.org Received: from lists.gnu.org ([199.232.76.165]) by master.debian.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PeRgN-00069u-NM for otavio.salvador@gmail.com; Sun, 16 Jan 2011 12:26:08 +0000 Received: from localhost ([127.0.0.1]:34642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeRgL-0007eS-Ku for otavio@debian.org; Sun, 16 Jan 2011 07:26:05 -0500 Received: from [140.186.70.92] (port=41438 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeRgG-0007cP-GQ for bug-parted@gnu.org; Sun, 16 Jan 2011 07:26:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PeRgF-0003PP-7D for bug-parted@gnu.org; Sun, 16 Jan 2011 07:26:00 -0500 Received: from mx.meyering.net ([82.230.74.64]:52182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PeRgF-0003PL-0K for bug-parted@gnu.org; Sun, 16 Jan 2011 07:25:59 -0500 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 5C38F60466; Sun, 16 Jan 2011 13:25:56 +0100 (CET) From: Jim Meyering To: bug-parted@gnu.org Date: Sun, 16 Jan 2011 13:25:56 +0100 Message-ID: <8762tpox0r.fsf@meyering.net> Lines: 67 MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: treat "1MiB" like "1048576B" X-BeenThere: bug-parted@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports for the GNU Parted disk partition editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: bug-parted-bounces+otavio=debian.org@gnu.org Errors-To: bug-parted-bounces+otavio=debian.org@gnu.org [ I noticed that using a starting address of "1MiB" evokes a warning, along with the obviously unintended start sector of 34: parted -s -- $dev mklabel gpt mkpart PARTITION-NAME 1MiB -34s Warning: The resulting partition is not properly aligned for best performance. While the following, with "1048576B", works fine and creates the partition starting at the desired 1MiB address: parted -s -- $dev mklabel gpt mkpart PARTITION-NAME 1048576B -34s ] I made parted tell me why it was treating "1MiB" differently from "1048576B". Bottom line is that if you use a large unit, like MiB, it assumes you're being sloppy, but if you specify bytes or sectors, you require exactness (radius = 0). That may have made sense when people used sloppy units like MB (1,000,000), but obviously does not hold for most people who bother to type "MiB". Here's a proposed patch to make the command I gave work the way I intended. Opinions welcome. On one hand, I don't particularly like treating 1MiB differently from 1MB, but if someone is using 1MB and intends 1MiB, they need a little wake up call (or some RTFM). [the full patch will include a documentation update as well as a couple of tests to illustrate/exercise the difference. ] In the mean time, to get the proper 1MiB alignment, you'll have to use an explicit byte or sector count. I prefer byte counts, in spite of the greater number of digits, because that works the same regardless of a disk's sector size: dev=... k=1024 m=$((k*k)) parted -s -- $dev mklabel gpt mkpart P-NAME ${m}B -34s diff --git a/libparted/unit.c b/libparted/unit.c index 2670c38..59a9644 100644 --- a/libparted/unit.c +++ b/libparted/unit.c @@ -480,6 +480,12 @@ parse_unit_suffix (const char* suffix, PedUnit suggested_unit) return suggested_unit; } +static bool +is_power_of_2 (long long n) +{ + return (n & (n - 1)) == 0; +} + /** * If \p str contains a valid description of a location on \p dev, then * \p *sector is modified to describe the location and a geometry is created @@ -530,6 +536,13 @@ ped_unit_parse_custom (const char* str, const PedDevice* dev, PedUnit unit, radius = ped_div_round_up (unit_size, dev->sector_size) - 1; if (radius < 0) radius = 0; + /* If the user specified units in a power of 2, e.g., 1MiB, as in + parted -s -- $dev mklabel gpt mkpart P-NAME 1MiB -34s + do not use 1MiB as the range. Rather, presume that they + are specifying precisely the starting or ending number, + and treat "1MiB" just as we would treat "1048576B". */ + if (is_power_of_2 (unit_size)) + radius = 0; *sector = num * unit_size / dev->sector_size; /* negative numbers count from the end */ _______________________________________________ bug-parted mailing list bug-parted@gnu.org http://lists.gnu.org/mailman/listinfo/bug-parted