2 * Copyright (c) 1998 Robert Nordier
4 * Copyright (c) 2001 Robert Drehmel
6 * Copyright (c) 2014 Nathan Whitehorn
8 * Copyright (c) 2015 Eric McCorkle
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
38 #include <sys/param.h>
41 #include "boot_module.h"
43 static dev_info_t *devinfo;
44 static dev_info_t *devices;
47 dskread(void *buf, uint64_t lba, int nblk)
52 lba = lba / (devinfo->dev->Media->BlockSize / DEV_BSIZE);
53 size = nblk * DEV_BSIZE;
55 status = devinfo->dev->ReadBlocks(devinfo->dev,
56 devinfo->dev->Media->MediaId, lba, size, buf);
58 if (status != EFI_SUCCESS) {
59 DPRINTF("dskread: failed dev: %p, id: %u, lba: %ju, size: %d, "
60 "status: %lu\n", devinfo->dev,
61 devinfo->dev->Media->MediaId, (uintmax_t)lba, size,
62 EFI_ERROR_CODE(status));
71 static struct dmadat __dmadat;
74 init_dev(dev_info_t* dev)
80 return fsread(0, NULL, 0);
84 probe(dev_info_t* dev)
87 if (init_dev(dev) < 0)
88 return (EFI_UNSUPPORTED);
90 add_device(&devices, dev);
96 load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize)
106 CHAR16 *text = efi_devpath_name(dev->devpath);
107 DPRINTF("Loading '%s' from %S\n", filepath, text);
108 efi_free_devpath_name(text);
111 if (init_dev(dev) < 0) {
112 DPRINTF("Failed to init device\n");
113 return (EFI_UNSUPPORTED);
116 if ((ino = lookup(filepath)) == 0) {
117 DPRINTF("Failed to lookup '%s' (file not found?)\n", filepath);
118 return (EFI_NOT_FOUND);
121 if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) {
122 printf("Failed to read size of '%s' ino: %d\n", filepath, ino);
123 return (EFI_INVALID_PARAMETER);
126 if ((status = BS->AllocatePool(EfiLoaderData, size, &buf)) !=
128 printf("Failed to allocate read buffer %zu for '%s' (%lu)\n",
129 size, filepath, EFI_ERROR_CODE(status));
133 read = fsread(ino, buf, size);
134 if ((size_t)read != size) {
135 printf("Failed to read '%s' (%zd != %zu)\n", filepath, read,
137 (void)BS->FreePool(buf);
138 return (EFI_INVALID_PARAMETER);
141 DPRINTF("Load complete\n");
146 return (EFI_SUCCESS);
155 for (dev = devices, i = 0; dev != NULL; dev = dev->next, i++)
158 printf("%s found ", ufs_module.name);
161 printf("no partitions\n");
164 printf("%d partition\n", i);
167 printf("%d partitions\n", i);
178 const boot_module_t ufs_module =