| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /************************************************************ |
|---|
| 2 | 3 | * EFI GUID Partition Table handling |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * efi.[ch] by Matt Domsch <Matt_Domsch@dell.com> |
|---|
| 8 | 9 | * Copyright 2000,2001,2002,2004 Dell Inc. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 12 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | | - * (at your option) any later version. |
|---|
| 14 | | - * |
|---|
| 15 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | | - * GNU General Public License for more details. |
|---|
| 19 | | - * |
|---|
| 20 | | - * You should have received a copy of the GNU General Public License |
|---|
| 21 | | - * along with this program; if not, write to the Free Software |
|---|
| 22 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | | - * |
|---|
| 24 | 10 | * |
|---|
| 25 | 11 | * TODO: |
|---|
| 26 | 12 | * |
|---|
| .. | .. |
|---|
| 671 | 657 | } |
|---|
| 672 | 658 | |
|---|
| 673 | 659 | /** |
|---|
| 660 | + * utf16_le_to_7bit(): Naively converts a UTF-16LE string to 7-bit ASCII characters |
|---|
| 661 | + * @in: input UTF-16LE string |
|---|
| 662 | + * @size: size of the input string |
|---|
| 663 | + * @out: output string ptr, should be capable to store @size+1 characters |
|---|
| 664 | + * |
|---|
| 665 | + * Description: Converts @size UTF16-LE symbols from @in string to 7-bit |
|---|
| 666 | + * ASCII characters and stores them to @out. Adds trailing zero to @out array. |
|---|
| 667 | + */ |
|---|
| 668 | +static void utf16_le_to_7bit(const __le16 *in, unsigned int size, u8 *out) |
|---|
| 669 | +{ |
|---|
| 670 | + unsigned int i = 0; |
|---|
| 671 | + |
|---|
| 672 | + out[size] = 0; |
|---|
| 673 | + |
|---|
| 674 | + while (i < size) { |
|---|
| 675 | + u8 c = le16_to_cpu(in[i]) & 0xff; |
|---|
| 676 | + |
|---|
| 677 | + if (c && !isprint(c)) |
|---|
| 678 | + c = '!'; |
|---|
| 679 | + out[i] = c; |
|---|
| 680 | + i++; |
|---|
| 681 | + } |
|---|
| 682 | +} |
|---|
| 683 | + |
|---|
| 684 | +/** |
|---|
| 674 | 685 | * efi_partition(struct parsed_partitions *state) |
|---|
| 675 | 686 | * @state: disk parsed partitions |
|---|
| 676 | 687 | * |
|---|
| .. | .. |
|---|
| 706 | 717 | |
|---|
| 707 | 718 | for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) { |
|---|
| 708 | 719 | struct partition_meta_info *info; |
|---|
| 709 | | - unsigned label_count = 0; |
|---|
| 710 | 720 | unsigned label_max; |
|---|
| 711 | 721 | u64 start = le64_to_cpu(ptes[i].starting_lba); |
|---|
| 712 | 722 | u64 size = le64_to_cpu(ptes[i].ending_lba) - |
|---|
| .. | .. |
|---|
| 727 | 737 | /* Naively convert UTF16-LE to 7 bits. */ |
|---|
| 728 | 738 | label_max = min(ARRAY_SIZE(info->volname) - 1, |
|---|
| 729 | 739 | ARRAY_SIZE(ptes[i].partition_name)); |
|---|
| 730 | | - info->volname[label_max] = 0; |
|---|
| 731 | | - while (label_count < label_max) { |
|---|
| 732 | | - u8 c = ptes[i].partition_name[label_count] & 0xff; |
|---|
| 733 | | - if (c && !isprint(c)) |
|---|
| 734 | | - c = '!'; |
|---|
| 735 | | - info->volname[label_count] = c; |
|---|
| 736 | | - label_count++; |
|---|
| 737 | | - } |
|---|
| 740 | + utf16_le_to_7bit(ptes[i].partition_name, label_max, info->volname); |
|---|
| 738 | 741 | state->parts[i + 1].has_info = true; |
|---|
| 739 | 742 | } |
|---|
| 740 | 743 | kfree(ptes); |
|---|