Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/efi/boot1/ufs_module.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | if (init_dev(dev) < 0) | ||||
return (EFI_UNSUPPORTED); | return (EFI_UNSUPPORTED); | ||||
add_device(&devices, dev); | add_device(&devices, dev); | ||||
return (EFI_SUCCESS); | return (EFI_SUCCESS); | ||||
} | } | ||||
static EFI_STATUS | static EFI_STATUS | ||||
try_load(dev_info_t *dev, const char *loader_path, void **bufp, size_t *bufsize) | load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize) | ||||
{ | { | ||||
ufs_ino_t ino; | ufs_ino_t ino; | ||||
EFI_STATUS status; | EFI_STATUS status; | ||||
size_t size; | size_t size; | ||||
ssize_t read; | ssize_t read; | ||||
void *buf; | void *buf; | ||||
if (init_dev(dev) < 0) | DPRINTF("Loading '%s' from %s\n", filepath, devpath_str(dev->devpath)); | ||||
if (init_dev(dev) < 0) { | |||||
DPRINTF("Failed to init device\n"); | |||||
return (EFI_UNSUPPORTED); | return (EFI_UNSUPPORTED); | ||||
} | |||||
if ((ino = lookup(loader_path)) == 0) | if ((ino = lookup(filepath)) == 0) { | ||||
DPRINTF("Failed to lookup '%s' (file not found?)\n", filepath); | |||||
return (EFI_NOT_FOUND); | return (EFI_NOT_FOUND); | ||||
} | |||||
if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) { | if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) { | ||||
printf("Failed to read size of '%s' ino: %d\n", loader_path, | printf("Failed to read size of '%s' ino: %d\n", filepath, ino); | ||||
ino); | |||||
return (EFI_INVALID_PARAMETER); | return (EFI_INVALID_PARAMETER); | ||||
} | } | ||||
if ((status = bs->AllocatePool(EfiLoaderData, size, &buf)) != | if ((status = bs->AllocatePool(EfiLoaderData, size, &buf)) != | ||||
EFI_SUCCESS) { | EFI_SUCCESS) { | ||||
printf("Failed to allocate read buffer (%lu)\n", | printf("Failed to allocate read buffer %zu for '%s' (%lu)\n", | ||||
EFI_ERROR_CODE(status)); | size, filepath, EFI_ERROR_CODE(status)); | ||||
return (status); | return (status); | ||||
} | } | ||||
read = fsread(ino, buf, size); | read = fsread(ino, buf, size); | ||||
if ((size_t)read != size) { | if ((size_t)read != size) { | ||||
printf("Failed to read '%s' (%zd != %zu)\n", loader_path, read, | printf("Failed to read '%s' (%zd != %zu)\n", filepath, read, | ||||
size); | size); | ||||
(void)bs->FreePool(buf); | (void)bs->FreePool(buf); | ||||
return (EFI_INVALID_PARAMETER); | return (EFI_INVALID_PARAMETER); | ||||
} | } | ||||
DPRINTF("Load complete\n"); | |||||
*bufp = buf; | *bufp = buf; | ||||
*bufsize = size; | *bufsize = size; | ||||
return (EFI_SUCCESS); | return (EFI_SUCCESS); | ||||
} | } | ||||
static EFI_STATUS | |||||
load(const char *loader_path, dev_info_t **devinfop, void **buf, | |||||
size_t *bufsize) | |||||
{ | |||||
dev_info_t *dev; | |||||
EFI_STATUS status; | |||||
for (dev = devices; dev != NULL; dev = dev->next) { | |||||
status = try_load(dev, loader_path, buf, bufsize); | |||||
if (status == EFI_SUCCESS) { | |||||
*devinfop = dev; | |||||
return (EFI_SUCCESS); | |||||
} else if (status != EFI_NOT_FOUND) { | |||||
return (status); | |||||
} | |||||
} | |||||
return (EFI_NOT_FOUND); | |||||
} | |||||
static void | static void | ||||
status() | status() | ||||
{ | { | ||||
int i; | int i; | ||||
dev_info_t *dev; | dev_info_t *dev; | ||||
for (dev = devices, i = 0; dev != NULL; dev = dev->next, i++) | for (dev = devices, i = 0; dev != NULL; dev = dev->next, i++) | ||||
; | ; | ||||
printf("%s found ", ufs_module.name); | printf("%s found ", ufs_module.name); | ||||
switch (i) { | switch (i) { | ||||
case 0: | case 0: | ||||
printf("no partitions\n"); | printf("no partitions\n"); | ||||
break; | break; | ||||
case 1: | case 1: | ||||
printf("%d partition\n", i); | printf("%d partition\n", i); | ||||
break; | break; | ||||
default: | default: | ||||
printf("%d partitions\n", i); | printf("%d partitions\n", i); | ||||
} | } | ||||
} | } | ||||
static dev_info_t * | |||||
_devices() | |||||
{ | |||||
return (devices); | |||||
} | |||||
const boot_module_t ufs_module = | const boot_module_t ufs_module = | ||||
{ | { | ||||
.name = "UFS", | .name = "UFS", | ||||
.probe = probe, | .probe = probe, | ||||
.load = load, | .load = load, | ||||
.status = status | .status = status, | ||||
.devices = _devices | |||||
}; | }; |