199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2010 Marcel Moolenaar
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic EFI_GUID devpath_guid = DEVICE_PATH_PROTOCOL;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int efipart_init(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int efipart_strategy(void *, int, daddr_t, size_t, size_t, char *,
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int efipart_realstrategy(void *, int, daddr_t, size_t, size_t, char *,
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int efipart_open(struct open_file *, ...);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int efipart_print(int);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * info structure to support bcache
199767f8919635c4928607450d9e0abb932109ceToomas Soome EFI_DEVICE_PATH *devpath, *devpathcpy, *tmpdevpath, *node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz,
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Filter handles to only include illumos partitions. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (n = 0; n < nin; n++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->HandleProtocol(hin[n], &devpath_guid,
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (!IsDevicePathEnd(NextDevicePathNode(node))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome devpathlen += DevicePathNodeLength(NextDevicePathNode(node));
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->HandleProtocol(hin[n], &blkio_guid,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If we come across a logical partition of subtype CDROM
199767f8919635c4928607450d9e0abb932109ceToomas Soome * it doesn't refer to the CD filesystem itself, but rather
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to any usable El Torito boot image on it. In this case
199767f8919635c4928607450d9e0abb932109ceToomas Soome * we try to find the parent device and add that instead as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * that will be the CD filesystem.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (DevicePathType(node) == MEDIA_DEVICE_PATH &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (!IsDevicePathEnd(NextDevicePathNode(node)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->LocateDevicePath(&blkio_guid, &tmpdevpath,
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = efi_register_handles(&efipart_dev, hout, aliases, nout);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (unit = 0, h = efi_find_handle(&efipart_dev, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome sprintf(line, " %s%d:", efipart_dev.dv_name, unit);
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio);
199767f8919635c4928607450d9e0abb932109ceToomas Soome (unsigned long long)(blkio->Media->LastBlock + 1));
199767f8919635c4928607450d9e0abb932109ceToomas Soome h = efi_find_handle(&efipart_dev, dev->d_unit);
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * efipart_readwrite()
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Internal equivalent of efipart_strategy(), which operates on the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * media-native block size. This function expects all I/O requests
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to be within the media size and returns an error if such is not
199767f8919635c4928607450d9e0abb932109ceToomas Soomeefipart_readwrite(EFI_BLOCK_IO *blkio, int rw, daddr_t blk, daddr_t nblks,
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((blk + nblks - 1) > blkio->Media->LastBlock)
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = blkio->ReadBlocks(blkio, blkio->Media->MediaId, blk,
199767f8919635c4928607450d9e0abb932109ceToomas Soome status = blkio->WriteBlocks(blkio, blkio->Media->MediaId, blk,
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s: rw=%d, status=%lu\n", __func__, rw, (u_long)status);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeefipart_strategy(void *devdata, int rw, daddr_t blk, size_t offset,
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (bcache_strategy(&bcd, rw, blk, offset, size,
199767f8919635c4928607450d9e0abb932109ceToomas Soomeefipart_realstrategy(void *devdata, int rw, daddr_t blk, size_t offset,
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct devdesc *dev = (struct devdesc *)devdata;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* make sure we don't read past disk end */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((off + size) / blkio->Media->BlockSize - 1 >
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (efipart_readwrite(blkio, rw, blk, size / 512, buf));
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The block size of the media is not 512B per sector.
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (size > 0) {