From 55214d184ac38ea6e2d8b25c30c36b2e20523916 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 13 May 2023 06:58:48 +0300 Subject: [PATCH] Fix partition naming --- Core/Disk.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/Core/Disk.cpp b/Core/Disk.cpp index 7943c96f..bea825dd 100644 --- a/Core/Disk.cpp +++ b/Core/Disk.cpp @@ -43,7 +43,7 @@ namespace Disk for (unsigned char ItrPort = 0; ItrPort < this->AvailablePorts; ItrPort++) { Drive drive{}; - sprintf(drive.Name, "sd%ld-%d", DriverUID, this->AvailablePorts); + sprintf(drive.Name, "sd%ld", DriverUID); debug("Drive Name: %s", drive.Name); // TODO: Implement disk type detection. Very useful in the future. drive.MechanicalDisk = true; @@ -88,9 +88,29 @@ namespace Disk if (memcmp(GPTPartition.PartitionType, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(GPTPartition.PartitionType)) != 0) { Partition partition{}; + memset(partition.Label, '\0', sizeof(partition.Label)); + // Convert utf16 to utf8 for (int i = 0; i < 36; i++) - memcpy(partition.Label + i * 2, &GPTPartition.PartitionName[i], 2); - partition.Label[71] = '\0'; + { + uint16_t utf16 = GPTPartition.PartitionName[i]; + if (utf16 == 0) + break; + if (utf16 < 0x80) + partition.Label[i] = (char)utf16; + else if (utf16 < 0x800) + { + partition.Label[i] = (char)(0xC0 | (utf16 >> 6)); + partition.Label[i + 1] = (char)(0x80 | (utf16 & 0x3F)); + i++; + } + else + { + partition.Label[i] = (char)(0xE0 | (utf16 >> 12)); + partition.Label[i + 1] = (char)(0x80 | ((utf16 >> 6) & 0x3F)); + partition.Label[i + 2] = (char)(0x80 | (utf16 & 0x3F)); + i += 2; + } + } partition.StartLBA = GPTPartition.FirstLBA; partition.EndLBA = GPTPartition.LastLBA; partition.Sectors = partition.EndLBA - partition.StartLBA; @@ -103,14 +123,13 @@ namespace Disk trace("GPT partition \"%s\" found with %lld sectors", partition.Label, partition.Sectors); drive.Partitions.push_back(partition); - // char *PartitionName = new char[64]; - // sprintf(PartitionName, "sd%ldp%ld", drives.size() - 1, partition.Index); + char PartitionName[64]; + sprintf(PartitionName, "sd%ldp%ld", drives.size(), partition.Index); + fixme("PartitionName: %s", PartitionName); /* TODO: Add to devfs the disk */ - - // delete[] PartitionName; } } } @@ -133,14 +152,13 @@ namespace Disk trace("Partition \"%#llx\" found with %lld sectors.", drive.Table.MBR.UniqueID, partition.Sectors); drive.Partitions.push_back(partition); - // char *PartitionName = new char[64]; - // sprintf(PartitionName, "sd%ldp%ld", drives.size() - 1, partition.Index); + char PartitionName[64]; + sprintf(PartitionName, "sd%ldp%ld", drives.size(), partition.Index); + fixme("PartitionName: %s", PartitionName); /* TODO: Add to devfs the disk */ - - // delete[] PartitionName; } trace("%d MBR partitions found.", drive.Partitions.size()); }