[parted-devel] [PATCH 1/2] libparted: enforce dos partition limit

Jim Meyering jim at meyering.net
Mon Jan 23 20:37:05 UTC 2012


Phillip Susi wrote:
> On 1/23/2012 2:13 PM, Jim Meyering wrote:
>> To my dismay, parted could not even create a 100-partition GPT table.
>> But it was quick/easy to fix.
>> With the following, it can do 128.
>
> Boy, and here I thought that tests/t9040-many-partitions.sh was actually
> testing all 128 gpt partitions.  Instead it appears to only do 60.
> Maybe bump that up?

It stopped at 60 for a good reason.
>From the comments:

  # Fail the test if it takes too long.
  # On Fedora 13, it takes about 15 seconds.
  # With older kernels, it typically takes more than 150 seconds.
  $AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 180 < d;"\
  ' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
      || fail=1

However, I can do better by making it more like today's test
and not exec'ing parted once for each partition.
In addition, we need not use 256 sectors per partition
when just one will do.
And finally, I don't really care if it takes a long time
to run on a kernel that is that old.

Patch for that below.

I've also adjusted the preceding test:
* do initialize the shell variable, "cmd"
  (could have had nasty consequences for test runners with a
  pathologically chosen value of the cmd envvar)
* don't use seq, for the sake of portability

>From fd9fe8fa65019e62c80f87b68aa1dda46b63ecf8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 23 Jan 2012 20:01:30 +0100
Subject: [PATCH 1/2] tests: exercise today's bug fix, creating a GPT table
 with 128 entries

* tests/t0212-gpt-many-partitions.sh: New test.
* tests/Makefile.am (TESTS): Add it.
---
 tests/Makefile.am                  |    1 +
 tests/t0212-gpt-many-partitions.sh |   56 ++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)
 create mode 100644 tests/t0212-gpt-many-partitions.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 88efbdd..17486e2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,6 +22,7 @@ TESTS = \
   t0208-mkpart-end-in-IEC.sh \
   t0210-gpt-resized-partition-entry-array.sh \
   t0211-gpt-rewrite-header.sh \
+  t0212-gpt-many-partitions.sh \
   t0220-gpt-msftres.sh \
   t0250-gpt.sh \
   t0280-gpt-corrupt.sh \
diff --git a/tests/t0212-gpt-many-partitions.sh b/tests/t0212-gpt-many-partitions.sh
new file mode 100644
index 0000000..d0fc72e
--- /dev/null
+++ b/tests/t0212-gpt-many-partitions.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# gpt: create many partitions
+# Before parted-3.1, this would provoke an invalid free.
+
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir
+
+ss=$sector_size_
+
+ns=300
+n_partitions=128
+dev=dev-file
+start_sector=34
+
+# create a file large enough to hold a GPT partition table
+dd if=/dev/null of=$dev bs=$ss seek=$ns || framework_failure
+
+cmd=
+i=1
+while :; do
+  s=$((start_sector + i - 1))
+  cmd="$cmd mkpart p$i ${s}s ${s}s"
+  test $i = $n_partitions && break; i=$((i+1))
+done
+parted -m -a min -s $dev mklabel gpt $cmd u s p > out 2>&1 || fail=1
+
+nl='
+'
+exp=$(printf '%s\n' 'BYT;' "...:${ns}s:file:$ss:$ss:gpt:;")"$nl"
+
+i=1
+while :; do
+  s=$((start_sector + i - 1))
+  exp="$exp$i:${s}s:${s}s:1s::p$i:;$nl"
+  test $i = $n_partitions && break; i=$((i+1))
+done
+printf %s "$exp" > exp || fail=1
+
+sed '2s/^[^:]*:/...:/' out > k && mv k out
+compare exp out || fail=1
+
+Exit $fail
--
1.7.9.rc2.2.g183d6


>From cd280c622f5f5f8708ace2f04118d80d9a2c6a8f Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 23 Jan 2012 21:32:00 +0100
Subject: [PATCH 2/2] tests: create 128 partitions also in the scsi-backed
 test

* tests/t9040-many-partitions.sh: Tighten up: use less memory:
1 sector per partition rather than 256.
Exec parted just once, not once per partition.
With that, we can increase the number of partitions to create
from 60 (which used to take 2.5 minutes on an F12-era kernel)
to the standard-GPT-header-imposed maximum of 128.
Suggested by Phillip Susi.
---
 tests/t9040-many-partitions.sh |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/tests/t9040-many-partitions.sh b/tests/t9040-many-partitions.sh
index c77628c..db065f4 100644
--- a/tests/t9040-many-partitions.sh
+++ b/tests/t9040-many-partitions.sh
@@ -25,9 +25,9 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
   skip_ 'this system lacks a new-enough libblkid'

 ss=$sector_size_
-partition_sectors=256  # sectors per partition
-n_partitions=60        # how many partitions to create
-start=2048             # start sector for the first partition
+partition_sectors=1    # sectors per partition
+n_partitions=128       # how many partitions to create
+start=34               # start sector for the first partition
 gpt_slop=34            # sectors at end of disk reserved for GPT

 n_sectors=$(($start + n_partitions * partition_sectors + gpt_slop))
@@ -43,29 +43,35 @@ n=$((n_MiB * sectors_per_MiB))
 printf "BYT;\n$scsi_dev:${n}s:scsi:$ss:$ss:gpt:Linux scsi_debug;\n" \
   > exp || fail=1

-parted -s $scsi_dev mklabel gpt || fail=1
-parted -s $scsi_dev u s p || fail=1
-
+cmd=
 i=1
-t0=$(date +%s.%N)
 while :; do
-    end=$((start + partition_sectors - 1))
-    parted -s $scsi_dev mkpart p$i ${start}s ${end}s || fail=1
-    printf "$i:${start}s:${end}s:${partition_sectors}s::p$i:;\n" >> exp
-    test $i = $n_partitions && break
-    start=$((start + partition_sectors))
-    i=$((i+1))
+    s=$((start + i - 1))
+    e=$((s + partition_sectors - 1))
+    cmd="$cmd mkpart p$i ${s}s ${e}s"
+    test $i = $n_partitions && break; i=$((i+1))
 done
+
+# Time the actual command:
+t0=$(date +%s.%N)
+parted -m -a min -s $scsi_dev mklabel gpt $cmd u s p > out 2>&1 || fail=1
 t_final=$(date +%s.%N)

+i=1
+while :; do
+    s=$((start + i - 1))
+    e=$((s + partition_sectors - 1))
+    printf "$i:${s}s:${e}s:${partition_sectors}s::p$i:;\n" >> exp
+    test $i = $n_partitions && break; i=$((i+1))
+done
+
 # Fail the test if it takes too long.
-# On Fedora 13, it takes about 15 seconds.
-# With older kernels, it typically takes more than 150 seconds.
+# On Fedora 16, this takes about 10 seconds for me.
+# With Fedora-12-era kernels, it typically took more than 150 seconds.
 $AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 60 < d;"\
 ' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
     || fail=1

-parted -m -s $scsi_dev u s p > out || fail=1
 compare exp out || fail=1

 Exit $fail
--
1.7.9.rc2.2.g183d6



More information about the parted-devel mailing list