Ask driver about sector size to support reading superblocks from fixed

byte offsets.
This commit is contained in:
mlelstv 2022-04-24 06:48:15 +00:00
parent ab4be66edf
commit 5290066ee5
4 changed files with 30 additions and 8 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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)