Module Name:    src
Committed By:   mlelstv
Date:           Mon Jan 25 14:51:03 UTC 2010

Modified Files:
        src/sys/dev/dkwedge: dk.c dkwedge_gpt.c

Log Message:
GPTs are defined in terms of physical blocks.
- Fix reading of GPT for devices with non-512byte sectors
- Fix bounds check to use DEV_BSIZE units.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/dkwedge/dk.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/dkwedge/dkwedge_gpt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.53 src/sys/dev/dkwedge/dk.c:1.54
--- src/sys/dev/dkwedge/dk.c:1.53	Sat Jan 23 18:31:04 2010
+++ src/sys/dev/dkwedge/dk.c	Mon Jan 25 14:51:03 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.53 2010/01/23 18:31:04 bouyer Exp $	*/
+/*	$NetBSD: dk.c,v 1.54 2010/01/25 14:51:03 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.53 2010/01/23 18:31:04 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.54 2010/01/25 14:51:03 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1098,6 +1098,7 @@
 dkstrategy(struct buf *bp)
 {
 	struct dkwedge_softc *sc = dkwedge_lookup(bp->b_dev);
+	uint64_t p_size, p_offset;
 	int s;
 
 	if (sc->sc_state != DKW_STATE_RUNNING) {
@@ -1109,12 +1110,15 @@
 	if (bp->b_bcount == 0)
 		goto done;
 
+	p_offset = sc->sc_offset << sc->sc_parent->dk_blkshift;
+	p_size   = sc->sc_size << sc->sc_parent->dk_blkshift;
+
 	/* Make sure it's in-range. */
-	if (bounds_check_with_mediasize(bp, DEV_BSIZE, sc->sc_size) <= 0)
+	if (bounds_check_with_mediasize(bp, DEV_BSIZE, p_size) <= 0)
 		goto done;
 
 	/* Translate it to the parent's raw LBA. */
-	bp->b_rawblkno = bp->b_blkno + sc->sc_offset;
+	bp->b_rawblkno = bp->b_blkno + p_offset;
 
 	/* Place it in the queue and start I/O on the unit. */
 	s = splbio();

Index: src/sys/dev/dkwedge/dkwedge_gpt.c
diff -u src/sys/dev/dkwedge/dkwedge_gpt.c:1.10 src/sys/dev/dkwedge/dkwedge_gpt.c:1.11
--- src/sys/dev/dkwedge/dkwedge_gpt.c:1.10	Thu Oct 23 19:37:40 2008
+++ src/sys/dev/dkwedge/dkwedge_gpt.c	Mon Jan 25 14:51:03 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dkwedge_gpt.c,v 1.10 2008/10/23 19:37:40 jakllsch Exp $	*/
+/*	$NetBSD: dkwedge_gpt.c,v 1.11 2010/01/25 14:51:03 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.10 2008/10/23 19:37:40 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dkwedge_gpt.c,v 1.11 2010/01/25 14:51:03 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -130,6 +130,7 @@
 	static const char gpt_hdr_sig[] = GPT_HDR_SIG;
 	struct dkwedge_info dkw;
 	void *buf;
+	uint32_t secsize;
 	struct gpt_hdr *hdr;
 	struct gpt_ent *ent;
 	uint32_t entries, entsz;
@@ -138,7 +139,8 @@
 	int error;
 	u_int i;
 
-	buf = malloc(DEV_BSIZE, M_DEVBUF, M_WAITOK);
+	secsize = DEV_BSIZE << pdk->dk_blkshift;
+	buf = malloc(secsize, M_DEVBUF, M_WAITOK);
 
 	/*
 	 * Note: We don't bother with a Legacy or Protective MBR
@@ -147,7 +149,7 @@
 	 */
 
 	/* Read in the GPT Header. */
-	error = dkwedge_read(pdk, vp, GPT_HDR_BLKNO, buf, DEV_BSIZE);
+	error = dkwedge_read(pdk, vp, GPT_HDR_BLKNO << pdk->dk_blkshift, buf, secsize);
 	if (error)
 		goto out;
 	hdr = buf;
@@ -163,7 +165,7 @@
 		error = ESRCH;
 		goto out;
 	}
-	if (le32toh(hdr->hdr_size) > DEV_BSIZE) {
+	if (le32toh(hdr->hdr_size) > secsize) {
 		/* XXX Should check at end-of-disk. */
 		error = ESRCH;
 		goto out;
@@ -212,9 +214,9 @@
 	}
 
 	free(buf, M_DEVBUF);
-	buf = malloc(roundup(entries * entsz, DEV_BSIZE), M_DEVBUF, M_WAITOK);
-	error = dkwedge_read(pdk, vp, lba_table, buf,
-			     roundup(entries * entsz, DEV_BSIZE));
+	buf = malloc(roundup(entries * entsz, secsize), M_DEVBUF, M_WAITOK);
+	error = dkwedge_read(pdk, vp, lba_table << pdk->dk_blkshift, buf,
+			     roundup(entries * entsz, secsize));
 	if (error) {
 		/* XXX Should check alternate location. */
 		aprint_error("%s: unable to read GPT partition array, "

Reply via email to