Module Name:    src
Committed By:   rin
Date:           Fri Apr 29 07:42:07 UTC 2022

Modified Files:
        src/sys/lib/libsa: ext2fs.c minixfs3.c stand.h ufs.c

Log Message:
Re-introduce SA_HARDCODED_SECSIZE hack, by which hardcoded DEV_BSIZE is
used instead of secsize obtained by SAIOSECSIZE ioctl.

This hack avoids divdi3 and friends from being linked, in order to
support variable secsize for some archs.

Should be useful for ancient archs, for which secsize is fixed.

Thanks christos@ for comment.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/lib/libsa/ext2fs.c
cvs rdiff -u -r1.12 -r1.13 src/sys/lib/libsa/minixfs3.c
cvs rdiff -u -r1.85 -r1.86 src/sys/lib/libsa/stand.h src/sys/lib/libsa/ufs.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/lib/libsa/ext2fs.c
diff -u src/sys/lib/libsa/ext2fs.c:1.33 src/sys/lib/libsa/ext2fs.c:1.34
--- src/sys/lib/libsa/ext2fs.c:1.33	Wed Apr 27 14:48:50 2022
+++ src/sys/lib/libsa/ext2fs.c	Fri Apr 29 07:42:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ext2fs.c,v 1.33 2022/04/27 14:48:50 rin Exp $	*/
+/*	$NetBSD: ext2fs.c,v 1.34 2022/04/29 07:42:07 rin Exp $	*/
 
 /*
  * Copyright (c) 1997 Manuel Bouyer.
@@ -415,15 +415,9 @@ read_sblock(struct open_file *f, struct 
 	struct ext2fs ext2fs;
 	size_t buf_size;
 	int rc;
-	u_int secsize;
-
-	secsize = 0;
-	rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
-	if (rc != 0 || secsize == 0)
-		secsize = DEV_BSIZE;
 
 	rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-	    SBOFF / secsize, SBSIZE, sbbuf, &buf_size);
+	    SBOFF / GETSECSIZE(f), SBSIZE, sbbuf, &buf_size);
 	if (rc)
 		return rc;
 

Index: src/sys/lib/libsa/minixfs3.c
diff -u src/sys/lib/libsa/minixfs3.c:1.12 src/sys/lib/libsa/minixfs3.c:1.13
--- src/sys/lib/libsa/minixfs3.c:1.12	Wed Apr 27 14:48:50 2022
+++ src/sys/lib/libsa/minixfs3.c	Fri Apr 29 07:42:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: minixfs3.c,v 1.12 2022/04/27 14:48:50 rin Exp $	*/
+/*	$NetBSD: minixfs3.c,v 1.13 2022/04/29 07:42:07 rin Exp $	*/
 
 /*-
  * Copyright (c) 2012
@@ -449,7 +449,6 @@ read_sblock(struct open_file *f, struct 
 	static uint8_t sbbuf[MINBSIZE];
 	size_t buf_size;
 	int rc;
-	u_int secsize;
 
 	/* We must read amount multiple of sector size, hence we can't
 	 * read SBSIZE and read MINBSIZE.
@@ -457,13 +456,8 @@ read_sblock(struct open_file *f, struct 
 	if (SBSIZE > MINBSIZE)
 		return EINVAL;
 
-	secsize = 0;
-	rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
-	if (rc != 0 || secsize == 0)
-		secsize = DEV_BSIZE;
-
 	rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-	    SUPER_BLOCK_OFF / secsize, MINBSIZE, sbbuf, &buf_size);
+	    SUPER_BLOCK_OFF / GETSECSIZE(f), MINBSIZE, sbbuf, &buf_size);
 	if (rc)
 		return rc;
 

Index: src/sys/lib/libsa/stand.h
diff -u src/sys/lib/libsa/stand.h:1.85 src/sys/lib/libsa/stand.h:1.86
--- src/sys/lib/libsa/stand.h:1.85	Wed Apr 27 14:48:50 2022
+++ src/sys/lib/libsa/stand.h	Fri Apr 29 07:42:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: stand.h,v 1.85 2022/04/27 14:48:50 rin Exp $	*/
+/*	$NetBSD: stand.h,v 1.86 2022/04/29 07:42:07 rin Exp $	*/
 
 /*
  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
@@ -64,6 +64,7 @@
 #ifndef _LIBSA_STAND_H_
 #define	_LIBSA_STAND_H_
 
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/cdefs.h>
 #include <sys/stat.h>
@@ -320,4 +321,26 @@ void	bzero(void *, size_t);
 
 int	atoi(const char *);
 
+#if !defined(SA_HARDCODED_SECSIZE)
+#define	GETSECSIZE(f)	getsecsize(f)
+static inline u_int
+getsecsize(struct open_file *f)
+{
+	int rc;
+	u_int secsize = 0;
+
+	rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
+	if (rc != 0 || secsize == 0)
+		secsize = DEV_BSIZE;
+
+	return secsize;
+}
+#else
+/*
+ * For some archs, divdi3 and friends are required to support variable
+ * sector sizes. Shave them off by making secsize compile-time constant.
+ */
+#define	GETSECSIZE(f)	DEV_BSIZE
+#endif
+
 #endif /* _LIBSA_STAND_H_ */
Index: src/sys/lib/libsa/ufs.c
diff -u src/sys/lib/libsa/ufs.c:1.85 src/sys/lib/libsa/ufs.c:1.86
--- src/sys/lib/libsa/ufs.c:1.85	Wed Apr 27 14:48:50 2022
+++ src/sys/lib/libsa/ufs.c	Fri Apr 29 07:42:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs.c,v 1.85 2022/04/27 14:48:50 rin Exp $	*/
+/*	$NetBSD: ufs.c,v 1.86 2022/04/29 07:42:07 rin Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -594,21 +594,15 @@ ffs_find_superblock(struct open_file *f,
 	struct file *fp = (struct file *)f->f_fsdata;
 	int rc;
 	size_t buf_size;
-	u_int secsize;
 #ifdef LIBSA_FFSv2
 	static daddr_t sblock_try[] = SBLOCKSEARCH;
 	int i;
 #endif
 
-	secsize = 0;
-	rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
-	if (rc != 0 || secsize == 0)
-		secsize = DEV_BSIZE;
-
 #ifdef LIBSA_FFSv2
 	for (i = 0; sblock_try[i] != -1; i++) {
 		rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-		    sblock_try[i] / secsize, SBLOCKSIZE, fs, &buf_size);
+		    sblock_try[i] / GETSECSIZE(f), SBLOCKSIZE, fs, &buf_size);
 		if (rc)
 			return rc;
 		if (buf_size != SBLOCKSIZE)
@@ -623,7 +617,7 @@ ffs_find_superblock(struct open_file *f,
 	return EINVAL;
 #else /* LIBSA_FFSv2 */
 	rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
-		SBLOCKOFFSET / secsize, SBLOCKSIZE, fs, &buf_size);
+		SBLOCKOFFSET / GETSECSIZE(f), SBLOCKSIZE, fs, &buf_size);
 	if (rc)
 		return rc;
 	if (buf_size != SBLOCKSIZE)

Reply via email to