Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/stand/efiboot Use physical sector size as unit for disk ...
details: https://anonhg.NetBSD.org/src/rev/3b394d3e31a5
branches: trunk
changeset: 365765:3b394d3e31a5
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sun Apr 24 06:49:38 2022 +0000
description:
Use physical sector size as unit for disk addresses.
Provide new ioctl to libsa to query for sector size.
diffstat:
sys/stand/efiboot/conf.c | 4 +-
sys/stand/efiboot/efiblock.c | 53 +++++++++++++++++++++++++++++--------------
sys/stand/efiboot/efiblock.h | 3 +-
3 files changed, 40 insertions(+), 20 deletions(-)
diffs (160 lines):
diff -r 24b7699fe7b3 -r 3b394d3e31a5 sys/stand/efiboot/conf.c
--- a/sys/stand/efiboot/conf.c Sun Apr 24 06:48:15 2022 +0000
+++ b/sys/stand/efiboot/conf.c Sun Apr 24 06:49:38 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.5 2020/10/11 14:03:33 jmcneill Exp $ */
+/* $NetBSD: conf.c,v 1.6 2022/04/24 06:49:38 mlelstv Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -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);
diff -r 24b7699fe7b3 -r 3b394d3e31a5 sys/stand/efiboot/efiblock.c
--- a/sys/stand/efiboot/efiblock.c Sun Apr 24 06:48:15 2022 +0000
+++ b/sys/stand/efiboot/efiblock.c Sun Apr 24 06:49:38 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.18 2021/10/30 11:18:51 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.19 2022/04/24 06:49:38 mlelstv Exp $ */
/*-
* Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -129,20 +129,21 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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_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;
+}
diff -r 24b7699fe7b3 -r 3b394d3e31a5 sys/stand/efiboot/efiblock.h
--- a/sys/stand/efiboot/efiblock.h Sun Apr 24 06:48:15 2022 +0000
+++ b/sys/stand/efiboot/efiblock.h Sun Apr 24 06:49:38 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.h,v 1.6 2021/06/21 21:18:47 jmcneill Exp $ */
+/* $NetBSD: efiblock.h,v 1.7 2022/04/24 06:49:38 mlelstv Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -79,6 +79,7 @@
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);
Home |
Main Index |
Thread Index |
Old Index