Example #1
0
static void
efipart_print(int verbose)
{
	char line[80];
	EFI_BLOCK_IO *blkio;
	EFI_HANDLE h;
	EFI_STATUS status;
	u_int unit;

	for (unit = 0, h = efi_find_handle(&efipart_dev, 0);
	    h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) {
		sprintf(line, "    %s%d:", efipart_dev.dv_name, unit);
		pager_output(line);

		status = BS->HandleProtocol(h, &blkio_guid, &blkio);
		if (!EFI_ERROR(status)) {
			sprintf(line, "    %llu blocks",
			    (unsigned long long)(blkio->Media->LastBlock + 1));
			pager_output(line);
			if (blkio->Media->RemovableMedia)
				pager_output(" (removable)");
		}
		pager_output("\n");
	}
}
Example #2
0
static int
efipart_print(int verbose)
{
	char line[80];
	EFI_BLOCK_IO *blkio;
	EFI_HANDLE h;
	EFI_STATUS status;
	u_int unit;
	int ret = 0;

	for (unit = 0, h = efi_find_handle(&efipart_dev, 0);
	    h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) {
		snprintf(line, sizeof(line), "    %s%d:",
		    efipart_dev.dv_name, unit);
		if ((ret = pager_output(line)) != 0)
			break;

		status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio);
		if (!EFI_ERROR(status)) {
			snprintf(line, sizeof(line), "    %llu blocks",
			    (unsigned long long)(blkio->Media->LastBlock + 1));
			if ((ret = pager_output(line)) != 0)
				break;
			if (blkio->Media->RemovableMedia)
				if ((ret = pager_output(" (removable)")) != 0)
					break;
		}
		if ((ret = pager_output("\n")) != 0)
			break;
	}
	return (ret);
}
Example #3
0
static int
efinet_dev_print(int verbose)
{
	CHAR16 *text;
	EFI_HANDLE h;
	int unit, ret = 0;

	printf("%s devices:", efinet_dev.dv_name);
	if ((ret = pager_output("\n")) != 0)
		return (ret);

	for (unit = 0, h = efi_find_handle(&efinet_dev, 0);
	    h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) {
		printf("    %s%d:", efinet_dev.dv_name, unit);
		if (verbose) {
			text = efi_devpath_name(efi_lookup_devpath(h));
			if (text != NULL) {
				printf("    %S", text);
				efi_free_devpath_name(text);
			}
		}
		if ((ret = pager_output("\n")) != 0)
			break;
	}
	return (ret);
}
Example #4
0
/*
 * Print information about disks
 */
static void
efifs_dev_print(int verbose)
{
	union {
		EFI_FILE_SYSTEM_INFO info;
		char buffer[1024];
	} fi;
	char line[80];
	EFI_FILE_IO_INTERFACE *fsif;
	EFI_FILE *volume;
	EFI_HANDLE h;
	EFI_STATUS status;
	UINTN sz;
	int i, unit;

	for (unit = 0, h = efi_find_handle(&efifs_dev, 0);
	    h != NULL; h = efi_find_handle(&efifs_dev, ++unit)) {
		sprintf(line, "    %s%d: ", efifs_dev.dv_name, unit);
		pager_output(line);

		status = BS->HandleProtocol(h, &sfs_guid, (VOID **)&fsif);
		if (EFI_ERROR(status))
			goto err;

		status = fsif->OpenVolume(fsif, &volume);
		if (EFI_ERROR(status))
			goto err;

		sz = sizeof(fi);
		status = volume->GetInfo(volume, &fs_guid, &sz, &fi);
		volume->Close(volume);
		if (EFI_ERROR(status))
			goto err;

		if (fi.info.ReadOnly)
			pager_output("[RO] ");
		else
			pager_output("     ");
		for (i = 0; fi.info.VolumeLabel[i] != 0; i++)
			fi.buffer[i] = fi.info.VolumeLabel[i];
		fi.buffer[i] = 0;
		if (fi.buffer[0] != 0)
			pager_output(fi.buffer);
		else
			pager_output("EFI filesystem");
		pager_output("\n");
		continue;

	err:
		sprintf(line, "[--] error %d: unable to obtain information\n",
		    efi_status_to_errno(status));
		pager_output(line);
	}
}
Example #5
0
static void
efinet_dev_print(int verbose)
{
	char line[80];
	EFI_HANDLE h;
	int unit;

	for (unit = 0, h = efi_find_handle(&efinet_dev, 0);
	    h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) {
		sprintf(line, "    %s%d:\n", efinet_dev.dv_name, unit);
		pager_output(line);
	}
}
Example #6
0
static int 
efipart_open(struct open_file *f, ...)
{
	va_list args;
	struct devdesc *dev;
	EFI_BLOCK_IO *blkio;
	EFI_HANDLE h;
	EFI_STATUS status;

	va_start(args, f);
	dev = va_arg(args, struct devdesc*);
	va_end(args);

	h = efi_find_handle(&efipart_dev, dev->d_unit);
	if (h == NULL)
		return (EINVAL);

	status = BS->HandleProtocol(h, &blkio_guid, &blkio);
	if (EFI_ERROR(status))
		return (efi_status_to_errno(status));

	if (!blkio->Media->MediaPresent)
		return (EAGAIN);

	dev->d_opendata = blkio;
	return (0);
}
Example #7
0
static void
efi_zfs_probe(void)
{
	EFI_HANDLE h;
	u_int unit;
	int i;
	char dname[SPECNAMELEN + 1];
	uint64_t guid;

	unit = 0;
	h = efi_find_handle(&efipart_dev, 0);
	for (i = 0; h != NULL; h = efi_find_handle(&efipart_dev, ++i)) {
		snprintf(dname, sizeof(dname), "%s%d:", efipart_dev.dv_name, i);
		if (zfs_probe_dev(dname, &guid) == 0)
			(void)efi_handle_update_dev(h, &zfs_dev, unit++, guid);
	}
}
Example #8
0
static int
efinet_dev_print(int verbose)
{
    char line[80];
    EFI_HANDLE h;
    int unit, ret;

    printf("%s devices:", efinet_dev.dv_name);
    if ((ret = pager_output("\n")) != 0)
        return (ret);

    for (unit = 0, h = efi_find_handle(&efinet_dev, 0);
            h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) {
        sprintf(line, "    %s%d:\n", efinet_dev.dv_name, unit);
        ret = pager_output(line);
        if (ret)
            break;
    }
    return (ret);
}
Example #9
0
static void
efinet_dev_print(int verbose)
{
	CHAR16 *text;
	EFI_HANDLE h;
	int unit;

	pager_open();
	for (unit = 0, h = efi_find_handle(&efinet_dev, 0);
	    h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) {
		printf("    %s%d:", efinet_dev.dv_name, unit);
		text = efi_devpath_name(efi_lookup_devpath(h));
		if (text != NULL) {
			printf("    %S", text);
			efi_free_devpath_name(text);
		}
		if (pager_output("\n"))
			break;
	}
	pager_close();
}
Example #10
0
static int
efinet_dev_init(void)
{
	struct netif_dif *dif;
	struct netif_stats *stats;
	EFI_HANDLE *handles;
	EFI_STATUS status;
	UINTN sz;
	int err, i, nifs;

	sz = 0;
	handles = NULL;
	status = BS->LocateHandle(ByProtocol, &sn_guid, 0, &sz, 0);
	if (status == EFI_BUFFER_TOO_SMALL) {
		handles = (EFI_HANDLE *)malloc(sz);
		status = BS->LocateHandle(ByProtocol, &sn_guid, 0, &sz,
		    handles);
		if (EFI_ERROR(status))
			free(handles);
	}
	if (EFI_ERROR(status))
		return (efi_status_to_errno(status));
	nifs = sz / sizeof(EFI_HANDLE);
	err = efi_register_handles(&efinet_dev, handles, NULL, nifs);
	free(handles);
	if (err != 0)
		return (err);

	efinetif.netif_nifs = nifs;
	efinetif.netif_ifs = calloc(nifs, sizeof(struct netif_dif));

	stats = calloc(nifs, sizeof(struct netif_stats));

	for (i = 0; i < nifs; i++) {
		EFI_SIMPLE_NETWORK *net;
		EFI_HANDLE h;

		dif = &efinetif.netif_ifs[i];
		dif->dif_unit = -1;

		h = efi_find_handle(&efinet_dev, i);

		/*
		 * Open the network device in exclusive mode. Without this
		 * we will be racing with the UEFI network stack. It will
		 * pull packets off the network leading to lost packets.
		 */
		status = BS->OpenProtocol(h, &sn_guid, (void **)&net,
		    IH, 0, EFI_OPEN_PROTOCOL_EXCLUSIVE);
		if (status != EFI_SUCCESS) {
			printf("Unable to open network interface %d for "
			    "exclusive access\n", i);
		}

		dif->dif_unit = i;
		dif->dif_nsel = 1;
		dif->dif_stats = &stats[i];
		dif->dif_private = h;
	}

	return (0);
}
Example #11
0
static int
efifs_open(const char *upath, struct open_file *f)
{
	struct devdesc *dev = f->f_devdata;
	EFI_FILE_IO_INTERFACE *fsif;
	EFI_FILE *file, *root;
	EFI_HANDLE h;
	EFI_STATUS status;
	CHAR16 *cp, *path;

	if (f->f_dev != &efifs_dev || dev->d_unit < 0)
		return (EINVAL);

	h = efi_find_handle(f->f_dev, dev->d_unit);
	if (h == NULL)
		return (EINVAL);

	status = BS->HandleProtocol(h, &sfs_guid, (VOID **)&fsif);
	if (EFI_ERROR(status))
		return (efi_status_to_errno(status));

	/* Get the root directory. */
	status = fsif->OpenVolume(fsif, &root);
	if (EFI_ERROR(status))
		return (efi_status_to_errno(status));

	while (*upath == '/')
		upath++;

	/* Special case: opening the root directory. */
	if (*upath == '\0') {
		f->f_fsdata = root;
		return (0);
	}

	path = malloc((strlen(upath) + 1) * sizeof(CHAR16));
	if (path == NULL) {
		root->Close(root);
		return (ENOMEM);
	}

	cp = path;
	while (*upath != '\0') {
		if (*upath == '/') {
			*cp = '\\';
			while (upath[1] == '/')
				upath++;
		} else
			*cp = *upath;
		upath++;
		cp++;
	}
	*cp = 0;

	/* Open the file. */
	status = root->Open(root, &file, path,
	    EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
	if (status == EFI_ACCESS_DENIED || status == EFI_WRITE_PROTECTED)
		status = root->Open(root, &file, path, EFI_FILE_MODE_READ, 0);
	free(path);
	root->Close(root);
	if (EFI_ERROR(status))
		return (efi_status_to_errno(status));

	f->f_fsdata = file;
	return (0);
}