[Parted-commits] GNU Parted Official Repository: Changes to 'master'
Jim Meyering
meyering at alioth.debian.org
Wed Mar 16 17:44:44 UTC 2011
NEWS | 5 +
parted/parted.c | 161 ++++++++++++++++++++++++---------------------
tests/Makefile.am | 1
tests/t0101-print-empty.sh | 47 +++++++++++++
4 files changed, 142 insertions(+), 72 deletions(-)
New commits:
commit c773932e690b09b965bdacc0b51cabcef3746ad2
Author: Petr Uzel <petr.uzel at suse.cz>
Date: Fri Mar 11 13:50:01 2011 +0100
tests: test 'parted print' with empty disk
* tests/t0101-print-empty.sh: New test.
* tests/Makefile.am: Add it.
Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index feafbed..4f95429 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,6 +7,7 @@ TESTS = \
t0001-tiny.sh \
t0010-script-no-ctrl-chars.sh \
t0100-print.sh \
+ t0101-print-empty.sh \
t0200-gpt.sh \
t0201-gpt.sh \
t0202-gpt-pmbr.sh \
diff --git a/tests/t0101-print-empty.sh b/tests/t0101-print-empty.sh
new file mode 100755
index 0000000..3e77850
--- /dev/null
+++ b/tests/t0101-print-empty.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# test 'parted $dev print' on empty device (without label)
+# Copyright (C) 2011 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
+ss=$sector_size_
+
+ss=$sector_size_
+dev=loop-file
+
+{
+ cat <<EOF
+Error: .../$dev: unrecognised disk label
+Model: (file)
+Disk .../$dev: 8s
+Sector size (logical/physical): ${ss}B/${ss}B
+Partition Table: unknown
+EOF
+} > exp || framework_failure
+
+# create 'empty' device
+dd if=/dev/zero of=$dev bs=$(expr 8 '*' $ss) count=1 >/dev/null 2>&1 || fail=1
+
+# print the empty table
+parted -s $dev unit s print >out 2>&1 || fail=1
+
+# prepare actual and expected output
+mv out o2 && sed "s,^Disk .*/$dev:,Disk .../$dev:,; \
+ s,^Error: .*/$dev:,Error: .../$dev:," o2 > out || fail=1
+
+# check for expected output
+compare out exp || fail=1
+
+Exit $fail
commit 3244fa1e26474b2b14d668677bf91794807789be
Author: Petr Uzel <petr.uzel at suse.cz>
Date: Fri Mar 11 13:50:00 2011 +0100
parted: rework 'parted print' so that it works with empty disk
'parted $dev print' on a device without a partition table used to fail
with an 'unrecognised disk label' error, without printing the following:
disk model, transport, size, sector size, BIOS geometry
all of which are available, and do not dependent on the partition table.
With this patch, parted prints all of this information (BIOS geometry
only if 'unit cyl' is specified) and reports success even if the disk
does not have a valid partition table.
As a side efect, 'parted $dev print devices/all/list' now prints
information about all the devices, even if $dev does not have a
partition table.
* parted/parted.c (_print_disk_info): New function.
(do_print): Do not immediately fail if the partition table is not
recognized, but print disk information and report success instead.
* NEWS (Changes in behavior): Mention it.
Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
diff --git a/NEWS b/NEWS
index fc44462..604b53d 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,11 @@ GNU parted NEWS -*- outline -*-
libparted: zero-length devices (other than files) are ignored rather than
throwing an exception.
+** Changes in behavior
+
+ "parted $dev print" now prints information about the device (model, size,
+ transport, sector size) even when it fails to recognize the disk label.
+
* Noteworthy changes in release 2.3 (2010-05-28) [stable]
diff --git a/parted/parted.c b/parted/parted.c
index 08ab4aa..35bfaf3 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1402,11 +1402,61 @@ _print_disk_geometry (const PedDevice *dev)
free (cyl_size);
}
+static void
+_print_disk_info (const PedDevice *dev, const PedDisk *disk)
+{
+ char *const transport[] = {"unknown", "scsi", "ide", "dac960",
+ "cpqarray", "file", "ataraid", "i2o",
+ "ubd", "dasd", "viodasd", "sx8", "dm",
+ "xvd", "sd/mmc", "virtblk", "aoe",
+ "md"};
+
+ char* start = ped_unit_format (dev, 0);
+ PedUnit default_unit = ped_unit_get_default ();
+ char* end = ped_unit_format_byte (dev, dev->length * dev->sector_size
+ - (default_unit == PED_UNIT_CHS ||
+ default_unit == PED_UNIT_CYLINDER));
+
+ const char* pt_name = disk ? disk->type->name : "unknown";
+
+ if (opt_machine_mode) {
+ switch (default_unit) {
+ case PED_UNIT_CHS: puts ("CHS;");
+ break;
+ case PED_UNIT_CYLINDER: puts ("CYL;");
+ break;
+ default: puts ("BYT;");
+ break;
+
+ }
+ printf ("%s:%s:%s:%lld:%lld:%s:%s;\n",
+ dev->path, end, transport[dev->type],
+ dev->sector_size, dev->phys_sector_size,
+ pt_name, dev->model);
+ } else {
+ printf (_("Model: %s (%s)\n"),
+ dev->model, transport[dev->type]);
+ printf (_("Disk %s: %s\n"), dev->path, end);
+ printf (_("Sector size (logical/physical): %lldB/%lldB\n"),
+ dev->sector_size, dev->phys_sector_size);
+ }
+
+ free (start);
+ free (end);
+
+ if (ped_unit_get_default () == PED_UNIT_CHS
+ || ped_unit_get_default () == PED_UNIT_CYLINDER)
+ _print_disk_geometry (dev);
+
+ if (!opt_machine_mode) {
+ printf (_("Partition Table: %s\n"), pt_name);
+ }
+}
+
static int
do_print (PedDevice** dev)
{
- PedUnit default_unit;
- PedDisk* disk;
+ PedDisk* disk = NULL;
Table* table;
int has_extended;
int has_name;
@@ -1414,11 +1464,6 @@ do_print (PedDevice** dev)
int has_free_arg = 0;
int has_list_arg = 0;
int has_num_arg = 0;
- const char *const transport[] = {"unknown", "scsi", "ide", "dac960",
- "cpqarray", "file", "ataraid", "i2o",
- "ubd", "dasd", "viodasd", "sx8", "dm",
- "xvd", "sd/mmc", "virtblk", "aoe",
- "md"};
char* peek_word;
char* start;
char* end;
@@ -1427,15 +1472,6 @@ do_print (PedDevice** dev)
char* tmp;
wchar_t* table_rendered;
- disk = ped_disk_new (*dev);
- if (!disk)
- goto error;
-
- if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
- if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
- alignment == ALIGNMENT_CYLINDER))
- goto error_destroy_disk;
-
peek_word = command_line_peek_word ();
if (peek_word) {
if (strncmp (peek_word, "devices", 7) == 0) {
@@ -1460,6 +1496,14 @@ do_print (PedDevice** dev)
free (peek_word);
}
+ if (!has_devices_arg && !has_list_arg)
+ disk = ped_disk_new (*dev);
+ if (disk &&
+ ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
+ if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
+ alignment == ALIGNMENT_CYLINDER))
+ goto error_destroy_disk;
+
if (has_devices_arg) {
char* dev_name;
PedDevice* current_dev = NULL;
@@ -1491,7 +1535,7 @@ do_print (PedDevice** dev)
else if (has_list_arg)
return _print_list ();
- else if (has_num_arg) {
+ else if (disk && has_num_arg) {
PedPartition* part = NULL;
int status = 0;
if (command_line_get_partition ("", disk, &part))
@@ -1500,52 +1544,17 @@ do_print (PedDevice** dev)
return status;
}
- start = ped_unit_format (*dev, 0);
- default_unit = ped_unit_get_default ();
- end = ped_unit_format_byte (*dev, (*dev)->length * (*dev)->sector_size
- - (default_unit == PED_UNIT_CHS ||
- default_unit == PED_UNIT_CYLINDER));
-
- if (opt_machine_mode) {
- switch (default_unit) {
- case PED_UNIT_CHS: puts ("CHS;");
- break;
- case PED_UNIT_CYLINDER: puts ("CYL;");
- break;
- default: puts ("BYT;");
- break;
-
- }
- printf ("%s:%s:%s:%lld:%lld:%s:%s;\n",
- (*dev)->path, end, transport[(*dev)->type],
- (*dev)->sector_size, (*dev)->phys_sector_size,
- disk->type->name, (*dev)->model);
- } else {
- printf (_("Model: %s (%s)\n"),
- (*dev)->model, transport[(*dev)->type]);
- printf (_("Disk %s: %s\n"), (*dev)->path, end);
- printf (_("Sector size (logical/physical): %lldB/%lldB\n"),
- (*dev)->sector_size, (*dev)->phys_sector_size);
- }
-
- free (start);
- free (end);
-
- if (ped_unit_get_default () == PED_UNIT_CHS
- || ped_unit_get_default () == PED_UNIT_CYLINDER)
- _print_disk_geometry (*dev);
-
- if (!opt_machine_mode) {
- printf (_("Partition Table: %s\n"), disk->type->name);
- putchar ('\n');
- }
+ _print_disk_info (*dev, disk);
+ if (!disk)
+ goto nopt;
+ if (!opt_machine_mode)
+ putchar ('\n');
has_extended = ped_disk_type_check_feature (disk->type,
PED_DISK_TYPE_EXTENDED);
has_name = ped_disk_type_check_feature (disk->type,
PED_DISK_TYPE_PARTITION_NAME);
-
PedPartition* part;
if (!opt_machine_mode) {
StrList *row1;
@@ -1707,6 +1716,8 @@ error_destroy_disk:
ped_disk_destroy (disk);
error:
return 0;
+nopt:
+ return 1;
}
static int
commit 8ce2e4f2858e42aa46074c6499df15dbe8347789
Author: Petr Uzel <petr.uzel at suse.cz>
Date: Fri Mar 11 13:49:59 2011 +0100
parted: factor out disk geometry printing into separate function
* parted/parted.c (_print_disk_geometry): New function.
(do_print): Use _print_disk_geometry.
Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
diff --git a/parted/parted.c b/parted/parted.c
index 9b4c1f2..08ab4aa 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1381,6 +1381,27 @@ partition_print (PedPartition* part)
return 1;
}
+static void
+_print_disk_geometry (const PedDevice *dev)
+{
+ PED_ASSERT (dev != NULL);
+ const PedCHSGeometry* chs = &dev->bios_geom;
+ char* cyl_size = ped_unit_format_custom (dev,
+ chs->heads * chs->sectors,
+ PED_UNIT_KILOBYTE);
+
+ if (opt_machine_mode) {
+ printf ("%d:%d:%d:%s;\n",
+ chs->cylinders, chs->heads, chs->sectors, cyl_size);
+ } else {
+ printf (_("BIOS cylinder,head,sector geometry: %d,%d,%d. "
+ "Each cylinder is %s.\n"),
+ chs->cylinders, chs->heads, chs->sectors, cyl_size);
+ }
+
+ free (cyl_size);
+}
+
static int
do_print (PedDevice** dev)
{
@@ -1511,23 +1532,8 @@ do_print (PedDevice** dev)
free (end);
if (ped_unit_get_default () == PED_UNIT_CHS
- || ped_unit_get_default () == PED_UNIT_CYLINDER) {
- PedCHSGeometry* chs = &(*dev)->bios_geom;
- char* cyl_size = ped_unit_format_custom (*dev,
- chs->heads * chs->sectors,
- PED_UNIT_KILOBYTE);
-
- if (opt_machine_mode) {
- printf ("%d:%d:%d:%s;\n",
- chs->cylinders, chs->heads, chs->sectors, cyl_size);
- } else {
- printf (_("BIOS cylinder,head,sector geometry: %d,%d,%d. "
- "Each cylinder is %s.\n"),
- chs->cylinders, chs->heads, chs->sectors, cyl_size);
- }
-
- free (cyl_size);
- }
+ || ped_unit_get_default () == PED_UNIT_CYLINDER)
+ _print_disk_geometry (*dev);
if (!opt_machine_mode) {
printf (_("Partition Table: %s\n"), disk->type->name);
More information about the Parted-commits
mailing list