diff --git a/sys/lib/libsa/ext2fs.c b/sys/lib/libsa/ext2fs.c index b810947fdaf5..007c732dfacf 100644 --- a/sys/lib/libsa/ext2fs.c +++ b/sys/lib/libsa/ext2fs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ext2fs.c,v 1.30 2022/04/19 09:25:38 skrll Exp $ */ +/* $NetBSD: ext2fs.c,v 1.31 2022/04/24 06:48:15 mlelstv Exp $ */ /* * Copyright (c) 1997 Manuel Bouyer. @@ -415,9 +415,15 @@ read_sblock(struct open_file *f, struct m_ext2fs *fs) 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 / DEV_BSIZE, SBSIZE, sbbuf, &buf_size); + SBOFF / secsize, SBSIZE, sbbuf, &buf_size); if (rc) return rc; diff --git a/sys/lib/libsa/minixfs3.c b/sys/lib/libsa/minixfs3.c index e1622c2e6236..9903f12d4fd2 100644 --- a/sys/lib/libsa/minixfs3.c +++ b/sys/lib/libsa/minixfs3.c @@ -1,4 +1,4 @@ -/* $NetBSD: minixfs3.c,v 1.9 2022/04/19 09:25:38 skrll Exp $ */ +/* $NetBSD: minixfs3.c,v 1.10 2022/04/24 06:48:15 mlelstv Exp $ */ /*- * Copyright (c) 2012 @@ -449,6 +449,7 @@ read_sblock(struct open_file *f, struct mfs_sblock *fs) 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. @@ -456,8 +457,13 @@ read_sblock(struct open_file *f, struct mfs_sblock *fs) 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 / DEV_BSIZE, MINBSIZE, sbbuf, &buf_size); + SUPER_BLOCK_OFF / secsize, MINBSIZE, sbbuf, &buf_size); if (rc) return rc; diff --git a/sys/lib/libsa/saioctl.h b/sys/lib/libsa/saioctl.h index 8b0198a6a3c8..9b0fa68b1b7d 100644 --- a/sys/lib/libsa/saioctl.h +++ b/sys/lib/libsa/saioctl.h @@ -1,4 +1,4 @@ -/* $NetBSD: saioctl.h,v 1.4 2005/12/11 12:24:46 christos Exp $ */ +/* $NetBSD: saioctl.h,v 1.5 2022/04/24 06:48:15 mlelstv Exp $ */ /*- * Copyright (c) 1993 @@ -46,3 +46,5 @@ #define SAIOSSDEV (('d'<<8)|12) /* is device skip sector type? */ #define SAIODEBUG (('d'<<8)|13) /* enable/disable debugging */ #define SAIOGBADINFO (('d'<<8)|14) /* get bad-sector table */ + +#define SAIOSECSIZE (('d'<<8)|15) /* get sector size */ diff --git a/sys/lib/libsa/ufs.c b/sys/lib/libsa/ufs.c index df0e5a7b475d..8a8a328a96ac 100644 --- a/sys/lib/libsa/ufs.c +++ b/sys/lib/libsa/ufs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ufs.c,v 1.81 2022/04/19 09:25:38 skrll Exp $ */ +/* $NetBSD: ufs.c,v 1.82 2022/04/24 06:48:15 mlelstv Exp $ */ /*- * Copyright (c) 1993 @@ -594,13 +594,21 @@ ffs_find_superblock(struct open_file *f, FS *fs) 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] / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size); + sblock_try[i] / secsize, SBLOCKSIZE, fs, &buf_size); if (rc) return rc; if (buf_size != SBLOCKSIZE) @@ -615,7 +623,7 @@ ffs_find_superblock(struct open_file *f, FS *fs) return EINVAL; #else /* LIBSA_FFSv2 */ rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, - SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size); + SBLOCKOFFSET / secsize, SBLOCKSIZE, fs, &buf_size); if (rc) return rc; if (buf_size != SBLOCKSIZE)