hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/block/partitions/efi.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /************************************************************
23 * EFI GUID Partition Table handling
34 *
....@@ -6,21 +7,6 @@
67 *
78 * efi.[ch] by Matt Domsch <Matt_Domsch@dell.com>
89 * 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
- *
2410 *
2511 * TODO:
2612 *
....@@ -671,6 +657,31 @@
671657 }
672658
673659 /**
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
+/**
674685 * efi_partition(struct parsed_partitions *state)
675686 * @state: disk parsed partitions
676687 *
....@@ -706,7 +717,6 @@
706717
707718 for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) {
708719 struct partition_meta_info *info;
709
- unsigned label_count = 0;
710720 unsigned label_max;
711721 u64 start = le64_to_cpu(ptes[i].starting_lba);
712722 u64 size = le64_to_cpu(ptes[i].ending_lba) -
....@@ -727,14 +737,7 @@
727737 /* Naively convert UTF16-LE to 7 bits. */
728738 label_max = min(ARRAY_SIZE(info->volname) - 1,
729739 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);
738741 state->parts[i + 1].has_info = true;
739742 }
740743 kfree(ptes);