summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2010-06-30 22:53:42 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2010-06-30 22:53:42 +0000
commit0d02b8e4c98c741e7a0efca280db1e59259e2bca (patch)
treef3f7bdd11195bc6ff80257f381f9cfc0f4b7c12c /sbin/fdisk
parent8c106c54d8ea352c3a5cde7ab58fdb7eb7231a4a (diff)
Make 'fdisk -i' start the OpenBSD partition on a power of 2 512-byte
block boundary. In most modern (i.e. 'faked' geometry) situations this will start it at (0-based) block[64] rather than block[63] as now. This should help performance on disks which really have 4K sectors but report 512-byte sectors. Power of 2 idea from deraadt@. ok toby@ deraadt@
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/disk.c5
-rw-r--r--sbin/fdisk/disk.h4
-rw-r--r--sbin/fdisk/mbr.c15
3 files changed, 20 insertions, 4 deletions
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 8fe7ce2596a..a77ba5ae6dc 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.30 2010/05/18 04:41:14 dlg Exp $ */
+/* $OpenBSD: disk.c,v 1.31 2010/06/30 22:53:41 krw Exp $ */
/*
* Copyright (c) 1997, 2001 Tobias Weingartner
@@ -40,6 +40,8 @@
#include "disk.h"
#include "misc.h"
+struct disklabel dl;
+
DISK_metrics *DISK_getlabelmetrics(char *name);
int
@@ -67,7 +69,6 @@ DISK_metrics *
DISK_getlabelmetrics(char *name)
{
DISK_metrics *lm = NULL;
- struct disklabel dl;
int fd;
/* Get label metrics */
diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h
index 1be075d49a9..0ffd479c6b0 100644
--- a/sbin/fdisk/disk.h
+++ b/sbin/fdisk/disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.h,v 1.10 2009/02/08 18:03:18 krw Exp $ */
+/* $OpenBSD: disk.h,v 1.11 2010/06/30 22:53:41 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -47,4 +47,6 @@ int DISK_open(char *, int);
int DISK_getmetrics(disk_t *, DISK_metrics *);
int DISK_printmetrics(disk_t *, char *);
+extern struct disklabel dl;
+
#endif /* _DISK_H */
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c
index 5fa12606c8e..df93b3aace2 100644
--- a/sbin/fdisk/mbr.c
+++ b/sbin/fdisk/mbr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbr.c,v 1.24 2009/02/08 18:03:18 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.25 2010/06/30 22:53:41 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -48,6 +48,9 @@
void
MBR_init(disk_t *disk, mbr_t *mbr)
{
+ daddr64_t i;
+ int adj;
+
/* Fix up given mbr for this disk */
mbr->part[0].flag = 0;
mbr->part[1].flag = 0;
@@ -87,6 +90,16 @@ MBR_init(disk_t *disk, mbr_t *mbr)
/* Fix up start/length fields */
PRT_fix_BN(disk, &mbr->part[3], 3);
#endif
+
+ /* Start OpenBSD MBR partition on a power of 2 block number. */
+ i = 1;
+ while (i < DL_SECTOBLK(&dl, mbr->part[3].bs))
+ i *= 2;
+ i = DL_BLKTOSEC(&dl, i);
+ adj = i - mbr->part[3].bs;
+ mbr->part[3].bs += adj;
+ mbr->part[3].ns -= adj;
+ PRT_fix_CHS(disk, &mbr->part[3]);
}
void