Exemple #1
0
uint64_t
unparse_path(char *buffer, EFI_DEVICE_PATH *path, uint16_t pathsize)
{
	uint16_t parsed_length = 0;
	char *p = buffer;
	int exit_now = 0;

	while (parsed_length < pathsize && !exit_now) {
		switch (path->type) {
		case 0x01:
			p += unparse_hardware_path(p, path);
			break;
		case 0x02:
			p += unparse_acpi_path(p, path);
			break;
		case 0x03:
			p += unparse_messaging_path(p, path);
			break;
		case 0x04:
			p += unparse_media_path(p, path);
			break;
		case 0x05:
			p += unparse_bios_path(p, path);
			break;
		case 0x7F:
			exit_now = 1;
			break;
		case 0xFF:
			exit_now = 1;
			break;
		default:
			printf("\nwierd path");
			dump_raw_data(path, 4);
			break;
		}
//		p += sprintf(p, "\\");
		parsed_length += path->length;
		path = (EFI_DEVICE_PATH *) ((uint8_t *)path + path->length);
	}

	return p - buffer;
}
Exemple #2
0
ssize_t
unparse_path(char *buffer, size_t buffer_size,
		EFI_DEVICE_PATH *path, uint16_t pathsize)
{
	uint16_t parsed_length = 0;
	char *p = buffer;
	size_t needed;
	off_t buf_offset = 0;
	int exit_now = 0;

	while (parsed_length < pathsize && !exit_now) {
		switch (path->type) {
		case 0x01:
			needed = unparse_hardware_path(p + buf_offset,
				buffer_size == 0 ? 0 : buffer_size - buf_offset,
				path);
			if (needed < 0)
				return -1;
			buf_offset += needed;
			break;
		case 0x02:
			needed = unparse_acpi_path(p + buf_offset,
				buffer_size == 0 ? 0 : buffer_size - buf_offset,
				path);
			if (needed < 0)
				return -1;
			buf_offset += needed;
			break;
		case 0x03:
			needed = unparse_messaging_path(p + buf_offset,
				buffer_size == 0 ? 0 : buffer_size - buf_offset,
				path);
			if (needed < 0)
				return -1;
			buf_offset += needed;
			break;
		case 0x04:
			needed = unparse_media_path(p + buf_offset,
				buffer_size == 0 ? 0 : buffer_size - buf_offset,
				path);
			if (needed < 0)
				return -1;
			buf_offset += needed;
			break;
		case 0x05:
			needed = unparse_bios_path(p + buf_offset,
				buffer_size == 0 ? 0 : buffer_size - buf_offset,
				path);
			if (needed < 0)
				return -1;
			buf_offset += needed;
			break;
		case 0x7F:
			exit_now = 1;
			break;
		case 0xFF:
			exit_now = 1;
			break;
		default:
			needed = snprintf(p + buf_offset,
				buffer_size == 0 ? 0 : buffer_size - buf_offset,
				"Unknown(%d,%d,", path->type, path->subtype);
			if (needed < 0)
				return -1;
			buf_offset += needed;

			if (path->length + sizeof (END_DEVICE_PATH)
					> (uint64_t)(pathsize - parsed_length)){
				needed = snprintf(p + buf_offset,
					buffer_size == 0
						? 0
						: buffer_size - buf_offset,
					"invalid size)");
				if (needed < 0)
					return -1;
				buf_offset += needed;
				exit_now = 1;
			} else {
				needed = snprintf(p + buf_offset,
					buffer_size == 0
						? 0
						: buffer_size - buf_offset,
					"%d,", path->length);
				if (needed < 0)
					return -1;
				buf_offset += needed;

				needed = unparse_raw(p + buf_offset,
					buffer_size == 0
						? 0
						: buffer_size - buf_offset,
					(uint8_t *)path +
						offsetof(EFI_DEVICE_PATH, data),
					path->length);
				if (needed < 0)
					return -1;
				buf_offset += needed;

				needed = snprintf(p + buf_offset,
					buffer_size == 0
						? 0
						: buffer_size - buf_offset,
					")");
				if (needed < 0)
					return -1;
				buf_offset += needed;
			}
			break;
		}
//		p += sprintf(p, "\\");
		parsed_length += path->length;
		path = (EFI_DEVICE_PATH *) ((uint8_t *)path + path->length);
	}

	return buf_offset;
}