Improve partition detection on lesser used devices

The format strings in efi_get_info() are intended to extract both the
main device and partition number. However, this is only done correctly
for hd, sd and vd devices. The format strings for ram, dm-, md and loop
devices misparse the input. This causes the partition device to be
incorrectly labelled as the main device with the partition being
labelled 0.

Reported-by: ilovezfs <ilovezfs@icloud.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Refactor efi_parse_dev_path()

I have refactored efi_parse_dev_path to reduce code duplication and
avoid the use of constants. The latter was a criticism by ilovezfs of my
patch to fix the bug he reported during his review of it.

The previous code suffered from theoretical buffer overflows in strcpy()
and sscanf(). For instance, /dev/sdaaaaaaaaaaaaaa1 would cause an
overflow, despite being valid. The new code replaces strcpy() with
strlcpy() to truncate instead of overflowing, returns EINVAL on
truncation, and does a calculation to prove that the scanf() has enough
room to operate without overflowing, returning EINVAL otherwise.

This does not properly handle names where the partition number exceeds
the precision of an ushort_t. An example would be /dev/sda100000.
Should we ever encounter a situation where the partition number exceeds
the precision of an ushort_t, ZFS' internal partition number for this
device will be incorrect, but it should still operate. As such, the cost
to benefit ratio of handling this case to be too low to merit a fix
unless an attempt is made to produce a formally verified codebase.

Reviewed-by: ilovezfs <ilovezfs@icloud.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>