Index: sys/lib/libsa/ext2fs.c =================================================================== RCS file: /cvsroot/src/sys/lib/libsa/ext2fs.c,v retrieving revision 1.30 diff -p -u -r1.30 ext2fs.c --- sys/lib/libsa/ext2fs.c 19 Apr 2022 09:25:38 -0000 1.30 +++ sys/lib/libsa/ext2fs.c 24 Apr 2022 05:17:31 -0000 @@ -415,9 +415,15 @@ 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 / DEV_BSIZE, SBSIZE, sbbuf, &buf_size); + SBOFF / secsize, SBSIZE, sbbuf, &buf_size); if (rc) return rc; Index: sys/lib/libsa/minixfs3.c =================================================================== RCS file: /cvsroot/src/sys/lib/libsa/minixfs3.c,v retrieving revision 1.9 diff -p -u -r1.9 minixfs3.c --- sys/lib/libsa/minixfs3.c 19 Apr 2022 09:25:38 -0000 1.9 +++ sys/lib/libsa/minixfs3.c 24 Apr 2022 05:17:31 -0000 @@ -449,6 +449,7 @@ 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. @@ -456,8 +457,13 @@ 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 / DEV_BSIZE, MINBSIZE, sbbuf, &buf_size); + SUPER_BLOCK_OFF / secsize, MINBSIZE, sbbuf, &buf_size); if (rc) return rc; Index: sys/lib/libsa/saioctl.h =================================================================== RCS file: /cvsroot/src/sys/lib/libsa/saioctl.h,v retrieving revision 1.4 diff -p -u -r1.4 saioctl.h --- sys/lib/libsa/saioctl.h 11 Dec 2005 12:24:46 -0000 1.4 +++ sys/lib/libsa/saioctl.h 24 Apr 2022 05:17:31 -0000 @@ -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 */ Index: sys/lib/libsa/ufs.c =================================================================== RCS file: /cvsroot/src/sys/lib/libsa/ufs.c,v retrieving revision 1.81 diff -p -u -r1.81 ufs.c --- sys/lib/libsa/ufs.c 19 Apr 2022 09:25:38 -0000 1.81 +++ sys/lib/libsa/ufs.c 24 Apr 2022 05:17:31 -0000 @@ -594,13 +594,21 @@ 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] / 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, 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) Index: sys/stand/efiboot/conf.c =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/conf.c,v retrieving revision 1.5 diff -p -u -r1.5 conf.c --- sys/stand/efiboot/conf.c 11 Oct 2020 14:03:33 -0000 1.5 +++ sys/stand/efiboot/conf.c 24 Apr 2022 05:17:31 -0000 @@ -41,7 +41,7 @@ struct devsw devsw[] = { { "efifile", efi_file_strategy, efi_file_open, efi_file_close, noioctl }, - { "efiblock", efi_block_strategy, efi_block_open, efi_block_close, noioctl }, + { "efiblock", efi_block_strategy, efi_block_open, efi_block_close, efi_block_ioctl }, { "net", net_strategy, net_open, net_close, noioctl }, }; int ndevs = __arraycount(devsw); Index: sys/stand/efiboot/efiblock.c =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/efiblock.c,v retrieving revision 1.18 diff -p -u -r1.18 efiblock.c --- sys/stand/efiboot/efiblock.c 30 Oct 2021 11:18:51 -0000 1.18 +++ sys/stand/efiboot/efiblock.c 24 Apr 2022 05:17:31 -0000 @@ -129,20 +129,21 @@ efi_block_do_read_blockio(struct efi_blo EFI_STATUS status; EFI_LBA lba_start, lba_end; UINT64 blkbuf_offset; - UINT64 blkbuf_size; + UINT64 blkbuf_size, alloc_size; lba_start = off / bdev->bio->Media->BlockSize; - lba_end = (off + bufsize + bdev->bio->Media->BlockSize - 1) / - bdev->bio->Media->BlockSize; + lba_end = (off + bufsize - 1) / bdev->bio->Media->BlockSize; blkbuf_offset = off % bdev->bio->Media->BlockSize; - blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize; + blkbuf_size = (lba_end - lba_start + 1) * bdev->bio->Media->BlockSize; + + alloc_size = blkbuf_size; if (bdev->bio->Media->IoAlign > 1) { - blkbuf_size = (blkbuf_size + bdev->bio->Media->IoAlign - 1) / + alloc_size = (blkbuf_size + bdev->bio->Media->IoAlign - 1) / bdev->bio->Media->IoAlign * bdev->bio->Media->IoAlign; } - blkbuf = AllocatePool(blkbuf_size); + blkbuf = AllocatePool(alloc_size); if (blkbuf == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -285,18 +286,16 @@ efi_block_find_partitions_disklabel(stru struct mbr_sector *mbr, uint32_t start, uint32_t size) { struct efi_block_part *bpart; - char buf[DEV_BSIZE]; + char buf[DEV_BSIZE]; /* XXX, arbitrary size >= struct disklabel */ struct disklabel d; struct partition *p; EFI_STATUS status; int n; status = efi_block_read(bdev, - ((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE, buf, sizeof(buf)); - if (EFI_ERROR(status) || getdisklabel(buf, &d) != NULL) { - FreePool(buf); + ((EFI_LBA)start + LABELSECTOR) * bdev->bio->Media->BlockSize, buf, sizeof(buf)); + if (EFI_ERROR(status) || getdisklabel(buf, &d) != NULL) return EIO; - } if (le32toh(d.d_magic) != DISKMAGIC || le32toh(d.d_magic2) != DISKMAGIC) return EINVAL; @@ -419,7 +418,7 @@ efi_block_find_partitions_gpt(struct efi void *buf; UINTN sz; - status = efi_block_read(bdev, GPT_HDR_BLKNO * DEV_BSIZE, &hdr, + status = efi_block_read(bdev, (EFI_LBA)GPT_HDR_BLKNO * bdev->bio->Media->BlockSize, &hdr, sizeof(hdr)); if (EFI_ERROR(status)) { return EIO; @@ -436,7 +435,7 @@ efi_block_find_partitions_gpt(struct efi return ENOMEM; status = efi_block_read(bdev, - le64toh(hdr.hdr_lba_table) * DEV_BSIZE, buf, sz); + le64toh(hdr.hdr_lba_table) * bdev->bio->Media->BlockSize, buf, sz); if (EFI_ERROR(status)) { FreePool(buf); return EIO; @@ -682,6 +681,7 @@ int efi_block_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize) { struct efi_block_part *bpart = devdata; + struct efi_block_dev *bdev = bpart->bdev; EFI_STATUS status; UINT64 off; @@ -692,13 +692,13 @@ efi_block_strategy(void *devdata, int rw switch (bpart->type) { case EFI_BLOCK_PART_DISKLABEL: - off = (dblk + bpart->disklabel.part.p_offset) * DEV_BSIZE; + off = ((EFI_LBA)dblk + bpart->disklabel.part.p_offset) * bdev->bio->Media->BlockSize; break; case EFI_BLOCK_PART_GPT: - off = (dblk + le64toh(bpart->gpt.ent.ent_lba_start)) * DEV_BSIZE; + off = ((EFI_LBA)dblk + le64toh(bpart->gpt.ent.ent_lba_start)) * bdev->bio->Media->BlockSize; break; case EFI_BLOCK_PART_CD9660: - off = dblk * ISO_DEFAULT_BLOCK_SIZE; + off = (EFI_LBA)dblk * ISO_DEFAULT_BLOCK_SIZE; break; default: return EINVAL; @@ -718,3 +718,22 @@ efi_block_set_readahead(bool onoff) { efi_ra_enable = onoff; } + +int +efi_block_ioctl(struct open_file *f, u_long cmd, void *data) +{ + struct efi_block_part *bpart = f->f_devdata; + struct efi_block_dev *bdev = bpart->bdev; + int error = 0; + + switch (cmd) { + case SAIOSECSIZE: + *(u_int *)data = bdev->bio->Media->BlockSize; + break; + default: + error = ENOTTY; + break; + } + + return error; +} Index: sys/stand/efiboot/efiblock.h =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/efiblock.h,v retrieving revision 1.6 diff -p -u -r1.6 efiblock.h --- sys/stand/efiboot/efiblock.h 21 Jun 2021 21:18:47 -0000 1.6 +++ sys/stand/efiboot/efiblock.h 24 Apr 2022 05:17:31 -0000 @@ -79,6 +79,7 @@ struct efi_block_part *efi_block_boot_pa int efi_block_open(struct open_file *, ...); int efi_block_close(struct open_file *); +int efi_block_ioctl(struct open_file *, u_long, void *); int efi_block_strategy(void *, int, daddr_t, size_t, void *, size_t *); void efi_block_set_readahead(bool);