Subject: bin/26921: fdisk(8) should show proper end sector number of each partition
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <tsutsui@ceres.dti.ne.jp>
List: netbsd-bugs
Date: 09/12/2004 17:11:07
>Number: 26921
>Category: bin
>Synopsis: fdisk(8) should show proper end sector number of each partition
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Sep 12 08:12:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator: Izumi Tsutsui
>Release: NetBSD 2.0G, but maybe 2.0-release/1.6-release also affected
>Organization:
>Environment:
System: NetBSD 2.0G, but maybe 2.0-release/1.6-release also affected
Architecture: i386, mipsel, but maybe on all ports
Machine: i386, cobalt, and maybe others
>Description:
fdisk(8) shows regions used by each partition in cylinder or C/H/S format,
but it doesn't show actual end cylinder or C/H/S number but start
cylinder or C/H/S of the next partition.
>How-To-Repeat:
Try fdisk(8) on disks. On my cobalt it shows:
---
Partition table:
0: Linux native (sysid 131)
start 1, size 1024127 (500 MB, Cyls 0/0/2-63/191/1)
1: Linux swap or Prime or Solaris (sysid 130)
start 1024128, size 263088 (128 MB, Cyls 63/191/1-80/32/1)
2: Linux native (sysid 131)
start 1287216, size 410256 (200 MB, Cyls 80/32/1-105/169/1)
3: NetBSD (sysid 169)
start 1697472, size 31324608 (15295 MB, Cyls 105/169/1-2055/135/1)
---
but it should be:
---
Partition table:
0: Linux native (sysid 131)
start 1, size 1024127 (500 MB, Cyls 0/0/2-63/190/63)
1: Linux swap or Prime or Solaris (sysid 130)
start 1024128, size 263088 (128 MB, Cyls 63/191/1-80/31/63)
2: Linux native (sysid 131)
start 1287216, size 410256 (200 MB, Cyls 80/32/1-105/168/63)
3: NetBSD (sysid 169)
start 1697472, size 31324608 (15295 MB, Cyls 105/169/1-2055/134/63)
---
>Fix:
Index: fdisk.c
===================================================================
RCS file: /cvsroot/src/sbin/fdisk/fdisk.c,v
retrieving revision 1.81
diff -u -r1.81 fdisk.c
--- fdisk.c 30 Jul 2004 23:42:29 -0000 1.81
+++ fdisk.c 12 Sep 2004 08:08:59 -0000
@@ -708,7 +708,7 @@
}
static void
-pr_cyls(daddr_t sector)
+pr_scyls(daddr_t sector)
{
ulong cyl, head, sect;
cyl = sector / dos_cylindersectors;
@@ -722,6 +722,21 @@
printf("/%lu/%lu", head, sect + 1);
}
+static void
+pr_ecyls(daddr_t sector)
+{
+ ulong cyl, head, sect;
+ cyl = sector / dos_cylindersectors;
+ sect = sector - cyl * dos_cylindersectors;
+ head = sect / dos_sectors;
+ sect -= head * dos_sectors;
+
+ printf("%lu", cyl);
+ if (head == dos_heads - 1 && sect == dos_sectors - 1)
+ return;
+ printf("/%lu/%lu", head, sect + 1);
+}
+
void
print_mbr_partition(struct mbr_sector *boot, int part,
daddr_t offset, daddr_t exoffset, int indent)
@@ -758,11 +773,11 @@
if (size != 0) {
printf(" (%u MB, Cyls ", SEC_TO_MB(size));
if (v_flag == 0 && le32toh(partp->mbrp_start) == dos_sectors)
- pr_cyls(start - dos_sectors);
+ pr_scyls(start - dos_sectors);
else
- pr_cyls(start);
+ pr_scyls(start);
printf("-");
- pr_cyls(start + size);
+ pr_ecyls(start + size - 1);
printf(")");
}
>Release-Note:
>Audit-Trail:
>Unformatted: