Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/stand/efiboot Deal with devices that report either 512 o...



details:   https://anonhg.NetBSD.org/src/rev/f178b7577afb
branches:  trunk
changeset: 957433:f178b7577afb
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Nov 28 15:24:05 2020 +0000

description:
Deal with devices that report either 512 or 2048 as logical block size
for CD9660 file-systems.

diffstat:

 sys/stand/efiboot/efiblock.c |  39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diffs (81 lines):

diff -r 31bd1f4df4e7 -r f178b7577afb sys/stand/efiboot/efiblock.c
--- a/sys/stand/efiboot/efiblock.c      Sat Nov 28 14:38:50 2020 +0000
+++ b/sys/stand/efiboot/efiblock.c      Sat Nov 28 15:24:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.9 2020/10/18 18:05:48 tnn Exp $ */
+/* $NetBSD: efiblock.c,v 1.10 2020/11/28 15:24:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -127,28 +127,43 @@
        EFI_LBA lba;
        UINT32 sz;
 
+       if (bdev->bio->Media->BlockSize != DEV_BSIZE &&
+           bdev->bio->Media->BlockSize != ISO_DEFAULT_BLOCK_SIZE) {
+               return ENXIO;
+       }
+
        sz = __MAX(sizeof(*vd), bdev->bio->Media->BlockSize);
        sz = roundup(sz, bdev->bio->Media->BlockSize);
-       if ((buf = efi_block_allocate_device_buffer(bdev, sz, &buf_start)) == NULL)
+       if ((buf = efi_block_allocate_device_buffer(bdev, sz, &buf_start)) == NULL) {
                return ENOMEM;
+       }
 
        for (lba = 16;; lba++) {
-               status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id,
-                   lba, sz, buf_start);
-               if (EFI_ERROR(status))
+               status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5,
+                   bdev->bio,
+                   bdev->media_id,
+                   lba * ISO_DEFAULT_BLOCK_SIZE / bdev->bio->Media->BlockSize,
+                   sz,
+                   buf_start);
+               if (EFI_ERROR(status)) {
                        goto io_error;
+               }
 
                vd = (struct iso_primary_descriptor *)buf_start;
-               if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0)
+               if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0) {
+                       goto io_error;
+               }
+               if (isonum_711(vd->type) == ISO_VD_END) {
                        goto io_error;
-               if (isonum_711(vd->type) == ISO_VD_END)
-                       goto io_error;
-               if (isonum_711(vd->type) == ISO_VD_PRIMARY)
+               }
+               if (isonum_711(vd->type) == ISO_VD_PRIMARY) {
                        break;
+               }
        }
 
-       if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE)
+       if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) {
                goto io_error;
+       }
 
        bpart = alloc(sizeof(*bpart));
        bpart->index = 0;
@@ -593,6 +608,7 @@
                dblk += le64toh(bpart->gpt.ent.ent_lba_start);
                break;
        case EFI_BLOCK_PART_CD9660:
+               dblk *= ISO_DEFAULT_BLOCK_SIZE / bpart->bdev->bio->Media->BlockSize;
                break;
        default:
                return EINVAL;
@@ -603,8 +619,9 @@
                allocated_buf = NULL;
                aligned_buf = buf;
        } else if ((allocated_buf = efi_block_allocate_device_buffer(bpart->bdev,
-               size, &aligned_buf)) == NULL)
+               size, &aligned_buf)) == NULL) {
                return ENOMEM;
+       }
 
        status = uefi_call_wrapper(bpart->bdev->bio->ReadBlocks, 5,
                bpart->bdev->bio, bpart->bdev->media_id, dblk, size, aligned_buf);



Home | Main Index | Thread Index | Old Index