Module Name:    src
Committed By:   hannken
Date:           Mon Jan  2 16:08:13 UTC 2023

Modified Files:
        src/sbin/fsck: partutil.c

Log Message:
Change getdiskinfo() to no longer infer the partition from the device name.
Since 2016-06-16 we create disk devices "<type><<unit>" as an alias
for "<type><<unit><part>" where "<part>" is the raw partition.
These devices are treated as invalid partitions and a zero geometry
is returned.

Take the partition from "st_rdev" instead.

Fix for PR kern/57134: st_size of stat on vnd raw partition sometimes
is 0, causing newfs to fail


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sbin/fsck/partutil.c

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

Modified files:

Index: src/sbin/fsck/partutil.c
diff -u src/sbin/fsck/partutil.c:1.17 src/sbin/fsck/partutil.c:1.18
--- src/sbin/fsck/partutil.c:1.17	Sat Sep 28 18:03:18 2019
+++ src/sbin/fsck/partutil.c	Mon Jan  2 16:08:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: partutil.c,v 1.17 2019/09/28 18:03:18 bad Exp $	*/
+/*	$NetBSD: partutil.c,v 1.18 2023/01/02 16:08:13 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: partutil.c,v 1.17 2019/09/28 18:03:18 bad Exp $");
+__RCSID("$NetBSD: partutil.c,v 1.18 2023/01/02 16:08:13 hannken Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -155,9 +155,8 @@ getdiskinfo(const char *s, int fd, const
 	if (stat(s, &sb) == -1)
 		return 0;
 
-	ptn = strchr(s, '\0')[-1] - 'a';
-	if ((unsigned)ptn >= lp->d_npartitions ||
-	    (devminor_t)ptn != DISKPART(sb.st_rdev))
+	ptn = DISKPART(sb.st_rdev);
+	if (ptn < 0 || ptn >= lp->d_npartitions)
 		return 0;
 
 	pp = &lp->d_partitions[ptn];

Reply via email to